Add.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <a-button @click="addClass" :disabled="props.disabled" type="primary" size="samll" class="mr-10">新建</a-button>
  3. <a-drawer
  4. ref="drawer"
  5. v-model:open="modeVisible"
  6. rootClassName="customNotiveClass"
  7. placement="right"
  8. :width="'98%'"
  9. :closable="false"
  10. title="新建商品"
  11. v-if="modeVisible"
  12. >
  13. <div class="detail__panel" v-if="modeVisible">
  14. <a-row :gutter="16">
  15. <a-col :span="10">
  16. <a-row>
  17. <a-card title="设置商品" :bordered="false" style="margin-bottom: 10px;">
  18. <a-form ref="formRef" :model="form" layout="vertical">
  19. <a-row>
  20. <a-col :span="24">
  21. <a-form-item label="商品名称" name="name" :rules="[{ required: true, message: '请填写商品名称',trigger:'blur'}]">
  22. <a-input v-model:value="form.name" ></a-input>
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="24">
  26. <a-form-item label="副标题" name="subtitle">
  27. <a-input v-model:value="form.subtitle"></a-input>
  28. </a-form-item>
  29. </a-col>
  30. <a-col :span="24">
  31. <a-form-item label="型号" name="model">
  32. <a-input v-model:value="form.model"></a-input>
  33. </a-form-item>
  34. </a-col>
  35. <a-col :span="24">
  36. <a-form-item label="标签" name="tag" :rules="[{ min:0,max:8,message: '最大8个字符',trigger:'blur'}]">
  37. <a-input v-model:value="form.tag"></a-input>
  38. </a-form-item>
  39. </a-col>
  40. <a-col :span="24">
  41. <a-form-item label="分类" name="class" :rules="[{ required: true, message: '请选择分类',trigger:'blur'}]">
  42. <a-select
  43. ref="select"
  44. :multiple="true"
  45. mode="tags"
  46. v-model:value="form.class"
  47. placeholder="选择分类"
  48. style="width: 100%"
  49. @change="mxChange"
  50. >
  51. <a-select-option :value="item.value" v-for="item in classArr()" :key="item.index">{{item.remarks?item.remarks:item.value}}</a-select-option>
  52. </a-select>
  53. </a-form-item>
  54. </a-col>
  55. <a-col :span="24">
  56. <a-form-item label="类型" name="pricetype" :rules="[{ required: true, message: '请选择类型',trigger:'change'}]">
  57. <a-select
  58. ref="select"
  59. v-model:value="form.pricetype"
  60. placeholder="选择类型"
  61. style="width: 100%"
  62. @change="priceChange"
  63. >
  64. <a-select-option value="一口价">一口价</a-select-option>
  65. <a-select-option value="阶梯价">阶梯价</a-select-option>
  66. </a-select>
  67. </a-form-item>
  68. </a-col>
  69. <a-col :span="24" v-if="form.pricetype == '一口价'">
  70. <a-form-item label="价格(元)" name="price" :rules="[{pattern:/^([1-9][0-9]*)+(\.[0-9]{1,2})?$/,required: true, message: '请输入数字,最多两位小数',trigger:'blur'}]">
  71. <a-input v-model:value="form.price"></a-input>
  72. </a-form-item>
  73. </a-col>
  74. <a-col :span="24" v-if="form.pricetype == '阶梯价'">
  75. <a-form-item label="原价(元)" name="price_original" :rules="[{pattern:/^([1-9][0-9]*)+(\.[0-9]{1,2})?$/,required: true, message: '请输入数字,最多两位小数',trigger:'blur'}]">
  76. <a-input v-model:value="form.price_original"></a-input>
  77. </a-form-item>
  78. </a-col>
  79. <a-col :span="24" v-if="form.pricetype == '阶梯价'">
  80. <a-form-item label="店面最低价(元)" name="price_store" :rules="[{pattern:/^([1-9][0-9]*)+(\.[0-9]{1,2})?$/,required: true, message: '请输入数字,最多两位小数',trigger:'blur'}]">
  81. <a-input v-model:value="form.price_store"></a-input>
  82. </a-form-item>
  83. </a-col>
  84. <a-col :span="24" v-if="form.pricetype == '阶梯价'">
  85. <a-form-item label="总部返利价(元)" name="price_rebate" :rules="[{pattern:/^([1-9][0-9]*)+(\.[0-9]{1,2})?$/,required: true, message: '请输入数字,最多两位小数',trigger:'blur'}]">
  86. <a-input v-model:value="form.price_rebate"></a-input>
  87. </a-form-item>
  88. </a-col>
  89. <a-col :span="24" v-if="form.pricetype == '阶梯价'">
  90. <a-form-item label="定金(元)" name="price_deposit" :rules="[{pattern:/^([1-9][0-9]*)+(\.[0-9]{1,2})?$/,required: true, message: '请输入数字,最多两位小数',trigger:'blur'}]">
  91. <a-input v-model:value="form.price_deposit"></a-input>
  92. </a-form-item>
  93. </a-col>
  94. <a-col :span="24">
  95. <a-form-item label="单位" name="unitname">
  96. <a-input v-model:value="form.unitname"></a-input>
  97. </a-form-item>
  98. </a-col>
  99. <a-col :span="24">
  100. <a-form-item label="经销商调整" name="canadjust" :rules="[{ required: true, message: '请选择',trigger:'change'}]">
  101. <a-radio-group v-model:value="form.canadjust">
  102. <a-radio :value="1">允许</a-radio>
  103. <a-radio :value="0">禁止</a-radio>
  104. </a-radio-group>
  105. </a-form-item>
  106. </a-col>
  107. <a-col :span="24">
  108. <a-form-item label="推荐" name="isnew">
  109. <a-checkbox v-model:checked="form.isnew">新品</a-checkbox>
  110. </a-form-item>
  111. </a-col>
  112. <a-col :span="24">
  113. <a-form-item label="排序" name="sequence" :rules="[{ pattern:/^[0-9]*$/,message:'请输入整数',trigger:'blur'}]">
  114. <a-input v-model:value="form.sequence" ></a-input>
  115. </a-form-item>
  116. </a-col>
  117. <a-col :span="24">
  118. <a-form-item label="状态" name="isonsale">
  119. <a-radio-group v-model:value="form.isonsale">
  120. <a-radio :value="0">下架</a-radio>
  121. <a-radio :value="1">上架</a-radio>
  122. </a-radio-group>
  123. </a-form-item>
  124. </a-col>
  125. </a-row>
  126. </a-form>
  127. </a-card>
  128. <a-card title="商品详情" :bordered="false" style="margin: 10px 0;">
  129. <wangEditor ref="editor" v-model="form.contentstr" :id="form.sa_fadid" style="margin-bottom: 10px"></wangEditor>
  130. </a-card>
  131. <a-card :bordered="false" style="margin: 10px 0 50px 0;">
  132. <template #title>
  133. <div class="ant-card-head-title redlitt">图集管理</div>
  134. </template>
  135. <AddImg :id="form.sa_fadid" @onSuccess="$refs.table.listData()"></AddImg>
  136. <normalTable rowKey="sys_attachment_linksid" sequenceKey="linksid" :is-select="false" ref="table" size="small" :columns="utils.TBLayout('imgManageTable')" :param="imgParam">
  137. <template #tb_cell="{data}">
  138. <template v-if="data.column.dataIndex === 'attinfos'">
  139. <a-image v-if="data.record.attinfos.length" :src="data.record.attinfos[0].url" style="width:100px;height: 100px;"></a-image>
  140. </template>
  141. <template v-else-if="data.column.dataIndex == 'operation'">
  142. <CustomButton
  143. btnName="删除"
  144. idName="20240407135902"
  145. keyName="linksids"
  146. :id="[data.record.linksid]"
  147. type="link"
  148. message="确定删除当前资源吗?"
  149. @onSuccess="$refs.table.listData()"
  150. size="middle"
  151. />
  152. </template>
  153. </template>
  154. </normalTable>
  155. </a-card>
  156. </a-row>
  157. </a-col>
  158. <a-col :span="14" style="margin-bottom:60px">
  159. <a-card title="权限设置" :bordered="false">
  160. <a-row>
  161. <span style="width:240px" class="redlitt">浏览权限:(至少选择一个范围)</span>
  162. <a-col :span="24" style="margin:20px 0 20px 20px;padding-right: 20px;">
  163. <div class="flex-center mt-10">
  164. <span style="width:50px">区域:</span>
  165. <SelectModel
  166. ref="selectArea"
  167. @selectRowData="$event => addData('sa_saleareaids',$event,() =>{$refs.areaTable.listData()})"
  168. rowKey="sa_saleareaid"
  169. :param="{'classname': 'webmanage.sale.salearea.salearea',method:'query_area',content:{pageNumber:1,pageSize:20,where:{}}}"
  170. :columns="utils.TBLayout('areaTable')" title="选择区域"
  171. >
  172. <template v-slot:slot1>
  173. <a-button size="middle" type="primary" @click="$refs.selectArea.modeVisible=true">添加</a-button>
  174. </template>
  175. <template #titleLeft="{data}">
  176. <uploadAllData
  177. dataType="区域"
  178. :total="data.total"
  179. @handlePullApi="areaHandlePullApi"
  180. @handleUploadApi="areaHandleUploadApi"
  181. @onSuccess="$refs.areaTable.listData()"
  182. ></uploadAllData>
  183. </template>
  184. </SelectModel>
  185. </div>
  186. <normalTable :is-select="false" ref="areaTable" style="width:100%" size="small" :columns="utils.TBLayout('areaTable')" :param="{id:20240402101802,content:{ownertable:'sa_fad',ownerid:form.sa_fadid,pageNumber:1,pageSize:20,where:{}}}">
  187. <template #tb_cell="{data}">
  188. <template v-if="data.column.dataIndex === 'operation'">
  189. <a-popconfirm
  190. title="确认删除当前区域吗?"
  191. ok-text="确认"
  192. cancel-text="取消"
  193. @confirm="delData('sa_saleareaids',data,() =>{$refs.areaTable.listData()})"
  194. >
  195. <a-button type="link" size="samll">删除</a-button>
  196. </a-popconfirm>
  197. </template>
  198. </template>
  199. </normalTable>
  200. </a-col>
  201. <a-col :span="24" style="margin:0 0 20px 20px;padding-right: 20px">
  202. <div class="flex-center mt-10">
  203. <span style="width:80px">经销商:</span>
  204. <SelectModel
  205. ref="selectEnterprise"
  206. @selectRowData="$event => addData('sys_enterpriseids',$event,() =>{$refs.enterpriseTable.listData()})"
  207. rowKey="sys_enterpriseid"
  208. :param="{id:20240312151602,content:{pageNumber:1,pageSize:20,where:{}}}"
  209. :columns="utils.TBLayout('enterpriseTable').splice(0,utils.TBLayout('enterpriseTable').length - 1)" title="选择经销商"
  210. >
  211. <template v-slot:slot1>
  212. <a-button size="middle" type="primary" @click="$refs.selectEnterprise.modeVisible=true">添加</a-button>
  213. </template>
  214. <template #titleLeft="{data}">
  215. <uploadAllData
  216. dataType="经销商"
  217. :total="data.total"
  218. @handlePullApi="enterpriseHandlePullApi"
  219. @handleUploadApi="enterpriseHandleUploadApi"
  220. @onSuccess="$refs.enterpriseTable.listData()"
  221. ></uploadAllData>
  222. </template>
  223. </SelectModel>
  224. </div>
  225. <normalTable :is-select="false" ref="enterpriseTable" style="width:100%" size="small" :columns="utils.TBLayout('enterpriseTable')" :param="{id:20240402101902,content:{ownertable:'sa_fad',ownerid:form.sa_fadid,pageNumber:1,pageSize:20,where:{}}}">
  226. <template #tb_cell="{data}">
  227. <template v-if="data.column.dataIndex === 'operation'">
  228. <a-popconfirm
  229. title="确认删除当前经销商吗?"
  230. ok-text="确认"
  231. cancel-text="取消"
  232. @confirm="delData('sys_enterpriseids',data,() =>{$refs.enterpriseTable.listData()})"
  233. >
  234. <a-button type="link" size="samll">删除</a-button>
  235. </a-popconfirm>
  236. </template>
  237. </template>
  238. </normalTable>
  239. </a-col>
  240. </a-row>
  241. </a-card>
  242. </a-col>
  243. </a-row>
  244. <div class="fixed__btn__panel">
  245. <CustomButton @click="submit" type="primary" size="samll" class="mr-10">保 存</CustomButton>
  246. <a-button @click="modeVisible=false" size="samll" class="mr-10">取 消</a-button>
  247. </div>
  248. </div>
  249. </a-drawer>
  250. </template>
  251. <script setup>
  252. import {ref, defineProps, defineEmits,watch, nextTick, onMounted, inject} from 'vue'
  253. import Api from '@/api/api'
  254. import {Cascader} from 'ant-design-vue'
  255. import utils from '@/utils/utils'
  256. import { message, Modal } from 'ant-design-vue';
  257. import { useRouter } from "vue-router";
  258. import AddImg from './addImg.vue'
  259. import normalTable from '@/template/MARnormalTable/index.vue'
  260. import SelectModel from '@/components/selectModel/index2.vue'
  261. import uploadAllData from '@/components/uploadAllData/index.vue'
  262. import WangEditor from '@/components/wangEditor/index.vue'
  263. import { useAuthStore } from '@/stores/modules/auth'
  264. let classArr = inject('classArr')
  265. const router = useRouter()
  266. let emit = defineEmits(['back','onSuccess'])
  267. let props = defineProps(['disabled'])
  268. let formRef = ref()
  269. let modeVisible = ref(false)
  270. let form = ref({
  271. "sa_fadid": 0,
  272. "itemid": 0,
  273. "itemno": "",
  274. "name": "",
  275. "subtitle": "",
  276. "model": "",
  277. "class": [],
  278. "pricetype": "一口价",
  279. "price": "", //
  280. "price_deposit": "", //定金(元)
  281. "price_store": "", //店面最低价(元)
  282. "price_rebate": "", //总部返利价
  283. "unitname": "",
  284. "isnew": 0,
  285. "sequence": 0,
  286. "contentstr": "",
  287. "parentid": 0,
  288. "tag": "",
  289. "canadjust": 1,
  290. "isonsale": 1
  291. })
  292. let imgParam = ref({
  293. "id": "20240407140002",
  294. "content": {
  295. "ownertable":'sa_fad',
  296. "ownerid": '',
  297. "pageNumber": 1,
  298. "pageSize": 20,
  299. "where": {
  300. }
  301. }
  302. })
  303. watch(() => modeVisible.value,(val) => {
  304. if (!val) {
  305. emit('back',form.value.sa_fadid,save.value)
  306. save.value = false
  307. refresh()
  308. }
  309. })
  310. const priceChange = () => {
  311. if (form.value.pricetype == '一口价') form.value.price_original = ''
  312. if (form.value.pricetype == '阶梯价') form.value.price = ''
  313. }
  314. //新建
  315. const addClass = async () => {
  316. modeVisible.value = true
  317. const res = await Api.requested({
  318. "id": "20240428154102",
  319. "content": {
  320. "sa_fadid": 0,
  321. "itemid": 0,
  322. "itemno": "",
  323. "name": "",
  324. "subtitle": "",
  325. "model": "",
  326. "class": [],
  327. "pricetype": "一口价",
  328. "price": "", //
  329. "price_deposit": "", //定金(元)
  330. "price_store": "", //店面最低价(元)
  331. "price_rebate": "", //总部返利价
  332. "unitname": "",
  333. "isnew": 0,
  334. "sequence": useAuthStore().nowAccount.userid+'99999',
  335. "contentstr": "",
  336. "parentid": 0,
  337. "tag": "",
  338. "canadjust": 1,
  339. "isonsale": 1
  340. }
  341. })
  342. imgParam.value.content.ownerid = res.data.sa_fadid
  343. Api.requested({
  344. classname:'webmanage.sale.salearea.salearea',
  345. method:'query_area',
  346. content: {
  347. pageNumber:1,pageSize:20,where:{}
  348. }
  349. }).then(res1 => {
  350. if (!res1.data.length) return
  351. Api.requested({
  352. id:20240402101402,
  353. content: {
  354. "ownertable": "sa_fad",
  355. "ownerid": res.data.sa_fadid,
  356. "sa_saleareaids": [res1.data[0].sa_saleareaid]
  357. }
  358. })
  359. })
  360. queryNoticeMain(res.data.sa_fadid)
  361. }
  362. //商品详情
  363. const queryNoticeMain = async (id) => {
  364. const res = await Api.requested({
  365. "id": "20240428154202",
  366. "content": {
  367. "sa_fadid": id
  368. }
  369. })
  370. form.value = Object.assign({}, form.value, res.data)
  371. form.value.sequence = ''
  372. console.log(form.value,'form');
  373. }
  374. let save = ref(false)
  375. let table = ref()
  376. let areaTable = ref()
  377. let enterpriseTable = ref()
  378. //保存
  379. const submit = async () => {
  380. if (!areaTable.value.data.length && !enterpriseTable.value.data.length) {
  381. return message.warning('浏览权限至少选择一项!!')
  382. }
  383. const values = await formRef.value.validateFields()
  384. if (!table.value.data.length)return message.warning('图集至少上传一个!!')
  385. const res = await Api.requested({
  386. "id": "20240428154102",
  387. "content": form.value
  388. })
  389. utils.message(res,'保存成功',async () => {
  390. save.value = true
  391. modeVisible.value = false
  392. })
  393. }
  394. const addData = async (key,data,callback) => {
  395. let ids = data.map(item => item[key.slice(0,key.length - 1)])
  396. const res = await Api.requested({
  397. "id": "20240402101402",
  398. "content": {
  399. "ownertable": "sa_fad",
  400. "ownerid": form.value.sa_fadid,
  401. [key]:ids
  402. }
  403. })
  404. if (res.code) {
  405. callback && callback()
  406. }
  407. }
  408. //删除数据
  409. const delData = async (key,data,callback) => {
  410. const res = await Api.requested({
  411. "id": "20240402101502",
  412. "content": {
  413. "ownertable": "sa_fad",
  414. "ownerid": form.value.sa_fadid,
  415. [key]:[data.record[key.slice(0,key.length - 1)]]
  416. }
  417. })
  418. utils.message(res,'删除成功',() => {
  419. callback && callback()
  420. })
  421. }
  422. //区域全选
  423. const areaHandlePullApi = async (pullApi) => {
  424. pullApi.content = {pageNumber:1,pageSize:20,where:{}}
  425. pullApi.classname = 'webmanage.sale.salearea.salearea'
  426. pullApi.method = 'query_area'
  427. }
  428. const areaHandleUploadApi = async (uploadApi,data) => {
  429. uploadApi.id = 20240402101402
  430. uploadApi.content = {
  431. "ownertable": "sa_fad",
  432. "ownerid": form.value.sa_fadid,
  433. "sa_saleareaids": data.map(e=>e.sa_saleareaid)
  434. }
  435. }
  436. //经销商全选
  437. const enterpriseHandlePullApi = async (pullApi) => {
  438. pullApi.content = {pageNumber:1,pageSize:20,where:{}}
  439. pullApi.id = 20240312151602
  440. }
  441. const enterpriseHandleUploadApi = async (uploadApi,data) => {
  442. uploadApi.id = 20240402101402
  443. uploadApi.content = {
  444. "ownertable": "sa_fad",
  445. "ownerid": form.value.sa_fadid,
  446. "sys_enterpriseids": data.map(e=>e.sys_enterpriseid)
  447. }
  448. }
  449. const refresh = () => {
  450. form.value = {
  451. "sa_fadid": 0,
  452. "itemid": 0,
  453. "itemno": "",
  454. "name": "",
  455. "subtitle": "",
  456. "model": "",
  457. "class": [],
  458. "pricetype": "一口价",
  459. "price": "", //
  460. "price_deposit": "", //定金(元)
  461. "price_store": "", //店面最低价(元)
  462. "price_rebate": "", //总部返利价
  463. "unitname": "",
  464. "isnew": 0,
  465. "sequence": 0,
  466. "contentstr": "",
  467. "parentid": 0,
  468. "tag": "",
  469. "canadjust": 1,
  470. "isonsale": 1
  471. }
  472. }
  473. onMounted(async() => {
  474. })
  475. </script>
  476. <style scoped>
  477. .ant-select {
  478. width:100%;
  479. }
  480. .ant-divider {
  481. margin-top: 0 !important;
  482. }
  483. </style>
  484. <style>
  485. .customNotiveClass .ant-drawer-header {
  486. display: none !important;
  487. }
  488. .customNotiveClass .ant-drawer-content {
  489. background: #F1F2F3 !important;
  490. }
  491. .customNotiveClass .ant-drawer-body {
  492. padding: 0 !important;
  493. }
  494. .customNotiveClass .ant-form {
  495. width: 100%;
  496. }
  497. .detail__panel .ant-card {
  498. width: 100%;
  499. }
  500. .ant-tree-treenode {
  501. width:100% !important;
  502. }
  503. .ant-tree-node-content-wrapper {
  504. width:100% !important;
  505. }
  506. .timeClass .ant-form-item {
  507. margin-bottom:0px !important;
  508. }
  509. .detail__panel .ant-card-head {
  510. min-height:35px !important;
  511. }
  512. </style>