detailsPageEdit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <template>
  2. <div class="borderless">
  3. <div class="customer-head">
  4. <div class="customer-back">
  5. <!-- <i class="back-icon el-icon-arrow-left"></i><i style="font-style:normal">返回管理列表</i>-->
  6. <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
  7. @click="backToList">返回列表
  8. </el-button>
  9. </div>
  10. <el-button
  11. class="el-button--small-yh add-customer-btn"
  12. type="primary"
  13. :disabled="disabled"
  14. size="small"
  15. @click="editCustomer"
  16. >{{ form.id ? '确认修改' : '确认新增' }}
  17. </el-button>
  18. </div>
  19. <div style="margin-top: 60px">
  20. <el-form :model="form" ref="form" label-width="130px" class="demo-ruleForm">
  21. <containerTitle title="基础资料"></containerTitle>
  22. <basic-container style="margin-bottom: 10px">
  23. <el-row>
  24. <el-col v-for="(item,index) in basicData.column" :key="index" :span="item.span?item.span:8">
  25. <el-form-item :label="item.label" :prop="item.prop" :rules="item.rules">
  26. <!-- <avue-input-tree v-if="item.prop === 'corpsTypeId'" leaf-only multiple :props="{label:'title'}"v-model="form[item.prop]" placeholder="请选择内容" type="tree" :dic="dic"/>-->
  27. <el-date-picker v-if="item.type === 'datetime'" style="width: 100%;" v-model="form[item.prop]" size="small" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss"/>
  28. <span v-else-if="item.type === 'select'">
  29. <el-select v-model="form[item.prop]" slot="prepend" style="width: 100%;" size="small" placeholder="请选择">
  30. <el-option v-for="item in item.dicData" :label="item.label" :value="item.value"></el-option>
  31. </el-select>
  32. </span>
  33. <selectComponent v-else-if="item.prop === 'corps'" v-model="form[item.prop]"
  34. :configuration="configuration" style="width: 100%"/>
  35. <el-input type="textarea" v-else-if="item.type === 'textarea'" v-model="form[item.prop]" size="small" autocomplete="off" :disabled="item.disabled"></el-input>
  36. <el-input type="age" v-else v-model="form[item.prop]" size="small" autocomplete="off" :disabled="item.disabled?item.disabled:false"></el-input>
  37. </el-form-item>
  38. </el-col>
  39. </el-row>
  40. </basic-container>
  41. <containerTitle title="特价促销"></containerTitle>
  42. <basic-container style="margin-bottom: 10px">
  43. <avue-crud
  44. :option="customerContact"
  45. v-model="contactsForm"
  46. :data="contactsData"
  47. ref="crudContact"
  48. @row-save="rowSave"
  49. @row-click="handleRowClick"
  50. @row-update="rowUpdate"
  51. @row-del="rowDel">
  52. <template slot="code" slot-scope="{ row, index }">
  53. <el-button
  54. size="small"
  55. type="text"
  56. @click="rePick(row, index, 1)"
  57. :disabled="disabled"
  58. class="picker"
  59. style="padding:4px 10px;float:left"
  60. >选择</el-button
  61. >
  62. <span> {{ row.code }}</span>
  63. </template>
  64. <template slot="menuLeft">
  65. <el-button
  66. type="primary"
  67. icon="el-icon-plus"
  68. size="small"
  69. @click.stop="newSpecial"
  70. >新增明细</el-button>
  71. </template>
  72. <template slot-scope="{row,index}" slot="menu">
  73. <el-button
  74. type="text"
  75. size="small"
  76. @click="rowCell(row,index)"
  77. >{{ row.$cellEdit ? '保存' : '修改' }}
  78. </el-button>
  79. <el-button
  80. size="small"
  81. icon="el-icon-delete"
  82. type="text"
  83. @click="rowDel(row, index)"
  84. >删 除</el-button>
  85. </template>
  86. </avue-crud>
  87. </basic-container>
  88. <containerTitle title="买赠促销"></containerTitle>
  89. <basic-container style="margin-bottom: 10px">
  90. <avue-crud
  91. :option="customerBuyFree"
  92. v-model="contactsFormBuyFree"
  93. :data="contactsDataBuyFree"
  94. ref="crudContactE"
  95. @row-save="rowSaveBuyFree"
  96. @row-click="handleRowClickBuyFree"
  97. @row-update="rowUpdateBuyFree"
  98. @row-del="rowDelBuyFree">
  99. <template slot="code" slot-scope="{ row, index }">
  100. <el-button
  101. size="small"
  102. type="text"
  103. @click="rePick(row, index, 2)"
  104. :disabled="disabled"
  105. class="picker"
  106. style="padding:4px 10px;float:left"
  107. >选择</el-button
  108. >
  109. <span> {{ row.code }}</span>
  110. </template>
  111. <template slot="menuLeft">
  112. <el-button
  113. type="primary"
  114. icon="el-icon-plus"
  115. size="small"
  116. @click.stop="newBuyFree"
  117. >新增明细</el-button>
  118. </template>
  119. <template slot-scope="{row,index}" slot="menu">
  120. <el-button
  121. type="text"
  122. size="small"
  123. @click="rowCellE(row,index)"
  124. >{{ row.$cellEdit ? '保存' : '修改' }}
  125. </el-button>
  126. <el-button
  127. size="small"
  128. icon="el-icon-delete"
  129. type="text"
  130. @click="rowDelBuyFree(row, index)"
  131. >删 除</el-button>
  132. </template>
  133. </avue-crud>
  134. </basic-container>
  135. </el-form>
  136. <el-dialog
  137. title="导入商品"
  138. append-to-body
  139. class="el-dialogDeep"
  140. :visible.sync="dialogVisible"
  141. width="60%"
  142. :close-on-click-modal="false"
  143. :destroy-on-close="true"
  144. :close-on-press-escape="false"
  145. @close="closeGoods"
  146. top="10vh"
  147. v-dialogdrag
  148. >
  149. <span>
  150. <el-row>
  151. <el-col :span="5">
  152. <div>
  153. <el-scrollbar>
  154. <basic-container style="margin-top:45px">
  155. <avue-tree :option="treeOption" @node-click="nodeClick" />
  156. </basic-container>
  157. </el-scrollbar>
  158. </div>
  159. </el-col>
  160. <el-col :span="19">
  161. <avue-crud
  162. :option="goodsOption"
  163. :table-loading="loading"
  164. :data="goodsList"
  165. ref="goodsCrud"
  166. @refresh-change="refreshChange"
  167. @selection-change="selectionChange"
  168. @row-click="rowClick"
  169. :page.sync="page"
  170. @on-load="onLoad"
  171. @saveColumn="saveGoodsColumn"
  172. @search-change="goodsSearch"
  173. ></avue-crud>
  174. </el-col>
  175. </el-row>
  176. </span>
  177. <span slot="footer" class="dialog-footer">
  178. <el-button @click="dialogVisible = false">取 消</el-button>
  179. <el-button
  180. type="primary"
  181. @click="importGoods"
  182. :disabled="selectionList.length == 0"
  183. >导入</el-button>
  184. </span>
  185. </el-dialog>
  186. </div>
  187. </div>
  188. </template>
  189. <script>
  190. import customerContact from "./configuration/customerContact.json"
  191. import BuyFree from "./configuration/BuyFree.json"
  192. import {detail,corpsattn,typeSave} from "@/api/maintenance/salesPolicy"
  193. import {
  194. submit,
  195. delItem,
  196. getDeptLazyTree,
  197. getGoods,
  198. savePurchase,
  199. saveShipping,
  200. getPorts,
  201. getSpecification,
  202. saveSell
  203. } from "@/api/basicData/customerInquiry";
  204. import goodsOption from "./configuration/commodity.json";
  205. export default {
  206. name: "detailsPage",
  207. data() {
  208. return {
  209. configuration: {
  210. multipleChoices: true,
  211. multiple: true,
  212. collapseTags: false,
  213. placeholder: '请点击右边按钮选择',
  214. dicData: []
  215. },
  216. form: {},
  217. disabled: false,
  218. customerContact: customerContact,
  219. contactsForm: {},
  220. contactsData: [],
  221. customerBuyFree: BuyFree,
  222. contactsFormBuyFree: {},
  223. contactsDataBuyFree: [],
  224. basicData: {
  225. column: [
  226. {
  227. label: '政策名称',
  228. prop: 'cname',
  229. rules: [
  230. {
  231. required: true,
  232. message: ' ',
  233. trigger: 'blur'
  234. }
  235. ]
  236. }, {
  237. label: '状态',
  238. prop: 'status',
  239. type: 'select',
  240. dicData:[{
  241. label:'正常',
  242. value:0
  243. },{
  244. label:'停用',
  245. value:1
  246. }],
  247. rules: [
  248. {
  249. required: true,
  250. message: ' ',
  251. trigger: 'blur'
  252. }
  253. ]
  254. }, {
  255. label: '品牌',
  256. prop: 'brand',
  257. rules: [
  258. {
  259. required: true,
  260. message: ' ',
  261. trigger: 'blur'
  262. }
  263. ]
  264. }, {
  265. label: '操作员',
  266. prop: 'createUserName',
  267. disabled:true,
  268. rules: [
  269. {
  270. required: false,
  271. message: ' ',
  272. trigger: 'blur'
  273. }
  274. ]
  275. }, {
  276. label: '有效期开始时间',
  277. prop: 'startTime',
  278. type:'datetime',
  279. rules: [
  280. {
  281. required: true,
  282. message: ' ',
  283. trigger: 'blur'
  284. }
  285. ]
  286. }, {
  287. label: '有效期结束时间',
  288. prop: 'endTime',
  289. type:'datetime',
  290. rules: [
  291. {
  292. required: true,
  293. message: ' ',
  294. trigger: 'blur'
  295. }
  296. ]
  297. }, {
  298. //多选
  299. label: '代理商',
  300. prop: 'corps',
  301. span: 16,
  302. rules: [
  303. {
  304. required: true,
  305. message: ' ',
  306. trigger: 'blur'
  307. }
  308. ]
  309. },
  310. {
  311. label: "备注",
  312. type: 'textarea',
  313. span: 24,
  314. prop: "remarks",
  315. mock: {
  316. type: 'county'
  317. }
  318. }
  319. ]
  320. },
  321. dialogVisible: false,
  322. selectionList: [],
  323. treeDeptId: null,
  324. treeOption: {
  325. nodeKey: "id",
  326. lazy: true,
  327. treeLoad: function(node, resolve) {
  328. const parentId = node.level === 0 ? 0 : node.data.id;
  329. getDeptLazyTree(parentId).then(res => {
  330. resolve(
  331. res.data.data.map(item => {
  332. return {
  333. ...item,
  334. leaf: !item.hasChildren
  335. };
  336. })
  337. );
  338. });
  339. },
  340. addBtn: false,
  341. menu: false,
  342. size: "small",
  343. props: {
  344. label: "title",
  345. value: "value",
  346. children: "children"
  347. }
  348. },
  349. goodsOption: goodsOption,
  350. loading: false,
  351. goodsList: [],
  352. page: {
  353. pageSize: 10,
  354. currentPage: 1,
  355. total: 0
  356. },
  357. // 1特价 2买赠
  358. salesType: 1,
  359. reData: null,
  360. }
  361. },
  362. //初始化查询
  363. created() {
  364. if (this.$route.query.id) {
  365. detail(JSON.parse(this.$route.query.id)).then(res =>{
  366. this.form = res.data.data
  367. if (this.form.corpNameList) {
  368. this.configuration.dicData = this.form.corpNameList
  369. }
  370. this.form.corps = this.form.corps.split(',')
  371. if (res.data.data.specialItemList) this.contactsData = res.data.data.specialItemList
  372. if (res.data.data.presentItemList) this.contactsDataBuyFree = res.data.data.presentItemList
  373. delete this.form.specialItemList
  374. delete this.form.presentItemList
  375. })
  376. } else {
  377. this.form = {}
  378. this.contactsData = []
  379. }
  380. },
  381. watch: {
  382. '$route'(to, from) {
  383. console.log(to, from);
  384. if (this.$route.query.id) {
  385. } else {
  386. this.form = {}
  387. }
  388. }
  389. },
  390. methods: {
  391. rePick(row, index,type) {
  392. this.reData = {
  393. ...row,
  394. index: index
  395. };
  396. if (type == 1) {
  397. this.newSpecial();
  398. } else {
  399. this.newBuyFree()
  400. }
  401. },
  402. // 新增特价弹窗
  403. newSpecial() {
  404. this.salesType = 1
  405. this.dialogVisible = !this.dialogVisible
  406. },
  407. // 买赠弹窗
  408. newBuyFree() {
  409. this.salesType = 2
  410. this.dialogVisible = !this.dialogVisible
  411. },
  412. closeGoods() {
  413. this.selectionList = [];
  414. this.treeDeptId = "";
  415. this.reData = null;
  416. },
  417. nodeClick(data) {
  418. this.treeDeptId = data.id;
  419. this.page.currentPage = 1;
  420. this.onLoad(this.page);
  421. },
  422. selectionChange(list) {
  423. this.selectionList = list;
  424. },
  425. rowClick(row) {
  426. this.$refs.goodsCrud.toggleSelection([this.goodsList[row.$index]]);
  427. },
  428. goodsSearch(params, done) {
  429. this.onLoad(this.page, params);
  430. done()
  431. },
  432. //商品查询
  433. onLoad(page, params = {}) {
  434. this.loading = true;
  435. getGoods(page.currentPage, page.pageSize, this.treeDeptId,params)
  436. .then(res => {
  437. const data = res.data.data;
  438. this.page.total = data.total;
  439. this.goodsList = data.records;
  440. if (this.page.total) {
  441. this.goodsOption.height = window.innerHeight - 550;
  442. } else {
  443. this.goodsOption.height = window.innerHeight - 475;
  444. }
  445. })
  446. .finally(() => {
  447. this.loading = false;
  448. });
  449. },
  450. // 确认导入商品
  451. importGoods() {
  452. if (this.reData) {
  453. if (this.selectionList.length != 1) {
  454. return this.$message.error("重新选择的时候只能选择一条数据");
  455. } else {
  456. this.selectionList.forEach(e => {
  457. if (this.reData.salesType == 1) {
  458. this.contactsData.forEach((item, index) => {
  459. if (index == this.reData.index) {
  460. item.itemId = e.id
  461. item.code = e.code
  462. item.cname = e.cname
  463. item.brand = e.brand
  464. item.productCategory = e.goodsTypeName
  465. item.typeno = e.typeno
  466. item.brandItem = e.brandItem
  467. // item.purchasePrice = this.brand.purchasePrice
  468. // item.salesPrice = this.brand.salesPrice
  469. // item.specialOffer = this.brand.specialOffer
  470. // item.updateUserName = this.brand.updateUserName
  471. // item.updateTime = this.brand.updateTime
  472. // item.salesType = this.brand.salesType
  473. }
  474. })
  475. } else {
  476. this.contactsDataBuyFree.forEach((item, index) => {
  477. item.itemId = e.id
  478. item.code = e.code
  479. item.cname = e.cname
  480. item.brand = e.brand
  481. item.productCategory = e.goodsTypeName
  482. item.typeno = e.typeno
  483. item.brandItem = e.brandItem
  484. // item.purchasePrice = this.brand.purchasePrice
  485. // item.salesPrice = this.brand.salesPrice
  486. // item.salesPrice = this.brand.purchaseAmount
  487. // item.updateUserName = this.brand.salesVolume
  488. // item.updateUserName = this.brand.updateUserName
  489. // item.updateTime = this.brand.updateTime
  490. // item.salesType = this.brand.salesType
  491. })
  492. }
  493. })
  494. }
  495. } else {
  496. if (this.salesType == 1) {
  497. this.selectionList.forEach(item => {
  498. this.contactsData.push({
  499. itemId: item.id,
  500. code: item.code,
  501. brand: item.brand,
  502. productCategory: item.goodsTypeName,
  503. typeno: item.typeno,
  504. brandItem: item.brandItem,
  505. purchasePrice: '',
  506. salesPrice: '',
  507. specialOffer: '',
  508. updateUserName: '',
  509. updateTime: '',
  510. salesType: '1',
  511. })
  512. })
  513. } else if (this.salesType == 2) {
  514. this.selectionList.forEach(item => {
  515. this.contactsDataBuyFree.push({
  516. itemId: item.id,
  517. code: item.code,
  518. brand: item.brand,
  519. productCategory: item.goodsTypeName,
  520. typeno: item.typeno,
  521. brandItem: item.brandItem,
  522. purchasePrice: '',
  523. salesPrice: '',
  524. purchaseAmount: '',
  525. salesVolume: '',
  526. updateUserName: '',
  527. updateTime: '',
  528. salesType: '2',
  529. })
  530. })
  531. }
  532. }
  533. this.dialogVisible = false;
  534. },
  535. //买赠列表信息保存触发
  536. rowSaveBuyFree(row, done, loading) {
  537. console.log(row)
  538. console.log(this.contactsData)
  539. // this.contactsData.push(row)
  540. done()
  541. },
  542. //买赠列表点击行可编辑
  543. handleRowClickBuyFree(row, event, column) {
  544. console.log(row.$index)
  545. },
  546. //买赠列表修改信息触发
  547. rowUpdateBuyFree(row, index, done, loading) {
  548. done(row);
  549. },
  550. //买赠列表删除信息触发
  551. rowDelBuyFree(row, index, donerowDel) {
  552. this.$confirm("确定将选择数据删除?", {
  553. confirmButtonText: "确定",
  554. cancelButtonText: "取消",
  555. type: "warning"
  556. }).then(() => {
  557. //商品判断是否需要调用删除接口
  558. if (row.id) {
  559. corpsattn(row.id).then(res => {
  560. this.$message({
  561. type: "success",
  562. message: "操作成功!"
  563. });
  564. this.contactsDataBuyFree.splice(index, 1);
  565. })
  566. } else {
  567. this.$message({
  568. type: "success",
  569. message: "操作成功!"
  570. });
  571. this.contactsDataBuyFree.splice(index, 1);
  572. }
  573. })
  574. },
  575. //新增商品信息保存触发
  576. rowSave(row, done, loading) {
  577. console.log(row)
  578. console.log(this.contactsData)
  579. // this.contactsData.push(row)
  580. done()
  581. },
  582. //点击行可编辑
  583. handleRowClick(row, event, column) {
  584. console.log(row.$index)
  585. },
  586. //商品编辑
  587. rowCell(row, index) {
  588. console.log(row)
  589. this.$refs.crudContact.rowCell(row, index)
  590. },
  591. //买赠编辑
  592. rowCellE(row, index) {
  593. console.log(row)
  594. this.$refs.crudContactE.rowCell(row, index)
  595. },
  596. //修改商品信息触发
  597. rowUpdate(row, index, done, loading) {
  598. done(row);
  599. },
  600. //删除商品信息触发
  601. rowDel(row, index, donerowDel) {
  602. this.$confirm("确定将选择数据删除?", {
  603. confirmButtonText: "确定",
  604. cancelButtonText: "取消",
  605. type: "warning"
  606. }).then(() => {
  607. //商品判断是否需要调用删除接口
  608. if (row.id) {
  609. corpsattn(row.id).then(res => {
  610. this.$message({
  611. type: "success",
  612. message: "操作成功!"
  613. });
  614. this.contactsData.splice(index, 1);
  615. })
  616. } else {
  617. this.$message({
  618. type: "success",
  619. message: "操作成功!"
  620. });
  621. this.contactsData.splice(index, 1);
  622. }
  623. })
  624. },
  625. //修改提交触发
  626. editCustomer() {
  627. console.log(this.form)
  628. this.$refs["form"].validate((valid) => {
  629. if (valid) {
  630. this.form.corps = this.form.corps.join(',')
  631. this.form.specialItemList = this.contactsData
  632. this.form.presentItemList = this.contactsDataBuyFree
  633. typeSave(this.form).then(res=>{
  634. this.$message({
  635. type: "success",
  636. message: this.form.id ? "修改成功!" : "新增成功!"
  637. });
  638. this.backToList()
  639. })
  640. } else {
  641. return false;
  642. }
  643. });
  644. },
  645. //返回列表
  646. backToList() {
  647. this.$emit("goBack");
  648. // this.$router.$avueRouter.closeTag();
  649. // this.$router.push({
  650. // path: '/maintenance/salesPolicy/index',
  651. // query: {}
  652. // });
  653. },
  654. async saveGoodsColumn() {
  655. // const inSave = await this.saveColumnData(
  656. // this.getColumnName(26),
  657. // this.goodsOption
  658. // );
  659. // if (inSave) {
  660. // this.$message.success("保存成功");
  661. // //关闭窗口
  662. // this.$refs.goodsCrud.$refs.dialogColumn.columnBox = false;
  663. // }
  664. }
  665. }
  666. }
  667. </script>
  668. <style lang="scss" scoped>
  669. .back-icon {
  670. line-height: 64px;
  671. font-size: 20px;
  672. margin-right: 8px;
  673. }
  674. ::v-deep .el-form-item {
  675. margin-bottom: 0;
  676. }
  677. .el-dialogDeep {
  678. ::v-deep .el-dialog {
  679. margin: 1vh auto 0 !important;
  680. padding-bottom: 10px !important;
  681. .el-dialog__body, .el-dialog__footer {
  682. padding-bottom: 0 !important;
  683. padding-top: 0 !important;
  684. }
  685. }
  686. }
  687. ::v-deep .el-form-item {
  688. margin-bottom: 0;
  689. }
  690. ::v-deep .el-form-item__content{
  691. line-height: 32px;
  692. }
  693. </style>