detailsPageEdit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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,index) in item.dicData" :label="item.label" :value="item.value" :key="index"></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. props:{
  208. detailData:Object
  209. },
  210. data() {
  211. return {
  212. configuration: {
  213. multipleChoices: true,
  214. multiple: true,
  215. collapseTags: false,
  216. placeholder: '请点击右边按钮选择',
  217. dicData: []
  218. },
  219. form: {},
  220. disabled: false,
  221. customerContact: customerContact,
  222. contactsForm: {},
  223. contactsData: [],
  224. customerBuyFree: BuyFree,
  225. contactsFormBuyFree: {},
  226. contactsDataBuyFree: [],
  227. basicData: {
  228. column: [
  229. {
  230. label: '政策名称',
  231. prop: 'cname',
  232. rules: [
  233. {
  234. required: true,
  235. message: ' ',
  236. trigger: 'blur'
  237. }
  238. ]
  239. }, {
  240. label: '状态',
  241. prop: 'status',
  242. type: 'select',
  243. dicData:[{
  244. label:'正常',
  245. value:0
  246. },{
  247. label:'停用',
  248. value:1
  249. }],
  250. rules: [
  251. {
  252. required: true,
  253. message: ' ',
  254. trigger: 'blur'
  255. }
  256. ]
  257. }, {
  258. label: '品牌',
  259. prop: 'brand',
  260. rules: [
  261. {
  262. required: true,
  263. message: ' ',
  264. trigger: 'blur'
  265. }
  266. ]
  267. }, {
  268. label: '操作员',
  269. prop: 'createUserName',
  270. disabled:true,
  271. rules: [
  272. {
  273. required: false,
  274. message: ' ',
  275. trigger: 'blur'
  276. }
  277. ]
  278. }, {
  279. label: '有效期开始时间',
  280. prop: 'startTime',
  281. type:'datetime',
  282. rules: [
  283. {
  284. required: true,
  285. message: ' ',
  286. trigger: 'blur'
  287. }
  288. ]
  289. }, {
  290. label: '有效期结束时间',
  291. prop: 'endTime',
  292. type:'datetime',
  293. rules: [
  294. {
  295. required: true,
  296. message: ' ',
  297. trigger: 'blur'
  298. }
  299. ]
  300. }, {
  301. //多选
  302. label: '代理商',
  303. prop: 'corps',
  304. span: 16,
  305. rules: [
  306. {
  307. required: true,
  308. message: ' ',
  309. trigger: 'blur'
  310. }
  311. ]
  312. },
  313. {
  314. label: "备注",
  315. type: 'textarea',
  316. span: 24,
  317. prop: "remarks",
  318. mock: {
  319. type: 'county'
  320. }
  321. }
  322. ]
  323. },
  324. dialogVisible: false,
  325. selectionList: [],
  326. treeDeptId: null,
  327. treeOption: {
  328. nodeKey: "id",
  329. lazy: true,
  330. treeLoad: function(node, resolve) {
  331. const parentId = node.level === 0 ? 0 : node.data.id;
  332. getDeptLazyTree(parentId).then(res => {
  333. resolve(
  334. res.data.data.map(item => {
  335. return {
  336. ...item,
  337. leaf: !item.hasChildren
  338. };
  339. })
  340. );
  341. });
  342. },
  343. addBtn: false,
  344. menu: false,
  345. size: "small",
  346. props: {
  347. label: "title",
  348. value: "value",
  349. children: "children"
  350. }
  351. },
  352. goodsOption: goodsOption,
  353. loading: false,
  354. goodsList: [],
  355. page: {
  356. pageSize: 10,
  357. currentPage: 1,
  358. total: 0
  359. },
  360. // 1特价 2买赠
  361. salesType: 1,
  362. reData: null,
  363. }
  364. },
  365. //初始化查询
  366. created() {
  367. if (this.detailData.id) {
  368. detail(JSON.parse(this.detailData.id)).then(res =>{
  369. this.form = res.data.data
  370. if (this.form.corpNameList) {
  371. this.configuration.dicData = this.form.corpNameList
  372. }
  373. this.form.corps = this.form.corps.split(',')
  374. if (res.data.data.specialItemList) this.contactsData = res.data.data.specialItemList
  375. if (res.data.data.presentItemList) this.contactsDataBuyFree = res.data.data.presentItemList
  376. delete this.form.specialItemList
  377. delete this.form.presentItemList
  378. })
  379. } else {
  380. this.form = {}
  381. this.contactsData = []
  382. }
  383. },
  384. watch: {
  385. '$route'(to, from) {
  386. console.log(to, from);
  387. if (this.detailData.id) {
  388. } else {
  389. this.form = {}
  390. }
  391. }
  392. },
  393. methods: {
  394. rePick(row, index,type) {
  395. this.reData = {
  396. ...row,
  397. index: index
  398. };
  399. if (type == 1) {
  400. this.newSpecial();
  401. } else {
  402. this.newBuyFree()
  403. }
  404. },
  405. // 新增特价弹窗
  406. newSpecial() {
  407. this.salesType = 1
  408. this.dialogVisible = !this.dialogVisible
  409. },
  410. // 买赠弹窗
  411. newBuyFree() {
  412. this.salesType = 2
  413. this.dialogVisible = !this.dialogVisible
  414. },
  415. closeGoods() {
  416. this.selectionList = [];
  417. this.treeDeptId = "";
  418. this.reData = null;
  419. },
  420. nodeClick(data) {
  421. this.treeDeptId = data.id;
  422. this.page.currentPage = 1;
  423. this.onLoad(this.page);
  424. },
  425. selectionChange(list) {
  426. this.selectionList = list;
  427. },
  428. rowClick(row) {
  429. this.$refs.goodsCrud.toggleSelection([this.goodsList[row.$index]]);
  430. },
  431. goodsSearch(params, done) {
  432. this.onLoad(this.page, params);
  433. done()
  434. },
  435. //商品查询
  436. onLoad(page, params = {}) {
  437. this.loading = true;
  438. getGoods(page.currentPage, page.pageSize, this.treeDeptId,params)
  439. .then(res => {
  440. const data = res.data.data;
  441. this.page.total = data.total;
  442. this.goodsList = data.records;
  443. if (this.page.total) {
  444. this.goodsOption.height = window.innerHeight - 550;
  445. } else {
  446. this.goodsOption.height = window.innerHeight - 475;
  447. }
  448. })
  449. .finally(() => {
  450. this.loading = false;
  451. });
  452. },
  453. // 确认导入商品
  454. importGoods() {
  455. if (this.reData) {
  456. if (this.selectionList.length != 1) {
  457. return this.$message.error("重新选择的时候只能选择一条数据");
  458. } else {
  459. this.selectionList.forEach(e => {
  460. if (this.reData.salesType == 1) {
  461. this.contactsData.forEach((item, index) => {
  462. if (index == this.reData.index) {
  463. item.itemId = e.id
  464. item.code = e.code
  465. item.cname = e.cname
  466. item.brand = e.brand
  467. item.productCategory = e.goodsTypeName
  468. item.typeno = e.typeno
  469. item.brandItem = e.brandItem
  470. // item.purchasePrice = this.brand.purchasePrice
  471. // item.salesPrice = this.brand.salesPrice
  472. // item.specialOffer = this.brand.specialOffer
  473. // item.updateUserName = this.brand.updateUserName
  474. // item.updateTime = this.brand.updateTime
  475. // item.salesType = this.brand.salesType
  476. }
  477. })
  478. } else {
  479. this.contactsDataBuyFree.forEach((item, index) => {
  480. item.itemId = e.id
  481. item.code = e.code
  482. item.cname = e.cname
  483. item.brand = e.brand
  484. item.productCategory = e.goodsTypeName
  485. item.typeno = e.typeno
  486. item.brandItem = e.brandItem
  487. // item.purchasePrice = this.brand.purchasePrice
  488. // item.salesPrice = this.brand.salesPrice
  489. // item.salesPrice = this.brand.purchaseAmount
  490. // item.updateUserName = this.brand.salesVolume
  491. // item.updateUserName = this.brand.updateUserName
  492. // item.updateTime = this.brand.updateTime
  493. // item.salesType = this.brand.salesType
  494. })
  495. }
  496. })
  497. }
  498. } else {
  499. if (this.salesType == 1) {
  500. this.selectionList.forEach(item => {
  501. this.contactsData.push({
  502. itemId: item.id,
  503. code: item.code,
  504. brand: item.brand,
  505. productCategory: item.goodsTypeName,
  506. typeno: item.typeno,
  507. brandItem: item.brandItem,
  508. purchasePrice: '',
  509. salesPrice: '',
  510. specialOffer: '',
  511. updateUserName: '',
  512. updateTime: '',
  513. salesType: '1',
  514. })
  515. })
  516. } else if (this.salesType == 2) {
  517. this.selectionList.forEach(item => {
  518. this.contactsDataBuyFree.push({
  519. itemId: item.id,
  520. code: item.code,
  521. brand: item.brand,
  522. productCategory: item.goodsTypeName,
  523. typeno: item.typeno,
  524. brandItem: item.brandItem,
  525. purchasePrice: '',
  526. salesPrice: '',
  527. purchaseAmount: '',
  528. salesVolume: '',
  529. updateUserName: '',
  530. updateTime: '',
  531. salesType: '2',
  532. })
  533. })
  534. }
  535. }
  536. this.dialogVisible = false;
  537. },
  538. //买赠列表信息保存触发
  539. rowSaveBuyFree(row, done, loading) {
  540. console.log(row)
  541. console.log(this.contactsData)
  542. // this.contactsData.push(row)
  543. done()
  544. },
  545. //买赠列表点击行可编辑
  546. handleRowClickBuyFree(row, event, column) {
  547. console.log(row.$index)
  548. },
  549. //买赠列表修改信息触发
  550. rowUpdateBuyFree(row, index, done, loading) {
  551. done(row);
  552. },
  553. //买赠列表删除信息触发
  554. rowDelBuyFree(row, index, donerowDel) {
  555. this.$confirm("确定将选择数据删除?", {
  556. confirmButtonText: "确定",
  557. cancelButtonText: "取消",
  558. type: "warning"
  559. }).then(() => {
  560. //商品判断是否需要调用删除接口
  561. if (row.id) {
  562. corpsattn(row.id).then(res => {
  563. this.$message({
  564. type: "success",
  565. message: "操作成功!"
  566. });
  567. this.contactsDataBuyFree.splice(index, 1);
  568. })
  569. } else {
  570. this.$message({
  571. type: "success",
  572. message: "操作成功!"
  573. });
  574. this.contactsDataBuyFree.splice(index, 1);
  575. }
  576. })
  577. },
  578. //新增商品信息保存触发
  579. rowSave(row, done, loading) {
  580. console.log(row)
  581. console.log(this.contactsData)
  582. // this.contactsData.push(row)
  583. done()
  584. },
  585. //点击行可编辑
  586. handleRowClick(row, event, column) {
  587. console.log(row.$index)
  588. },
  589. //商品编辑
  590. rowCell(row, index) {
  591. console.log(row)
  592. this.$refs.crudContact.rowCell(row, index)
  593. },
  594. //买赠编辑
  595. rowCellE(row, index) {
  596. console.log(row)
  597. this.$refs.crudContactE.rowCell(row, index)
  598. },
  599. //修改商品信息触发
  600. rowUpdate(row, index, done, loading) {
  601. done(row);
  602. },
  603. //删除商品信息触发
  604. rowDel(row, index, donerowDel) {
  605. this.$confirm("确定将选择数据删除?", {
  606. confirmButtonText: "确定",
  607. cancelButtonText: "取消",
  608. type: "warning"
  609. }).then(() => {
  610. //商品判断是否需要调用删除接口
  611. if (row.id) {
  612. corpsattn(row.id).then(res => {
  613. this.$message({
  614. type: "success",
  615. message: "操作成功!"
  616. });
  617. this.contactsData.splice(index, 1);
  618. })
  619. } else {
  620. this.$message({
  621. type: "success",
  622. message: "操作成功!"
  623. });
  624. this.contactsData.splice(index, 1);
  625. }
  626. })
  627. },
  628. //修改提交触发
  629. editCustomer() {
  630. console.log(this.form)
  631. this.$refs["form"].validate((valid) => {
  632. if (valid) {
  633. this.form.corps = this.form.corps.join(',')
  634. this.form.specialItemList = this.contactsData
  635. this.form.presentItemList = this.contactsDataBuyFree
  636. typeSave(this.form).then(res=>{
  637. this.$message({
  638. type: "success",
  639. message: this.form.id ? "修改成功!" : "新增成功!"
  640. });
  641. this.backToList()
  642. })
  643. } else {
  644. return false;
  645. }
  646. });
  647. },
  648. //返回列表
  649. backToList() {
  650. this.$emit("goBack");
  651. // this.$router.$avueRouter.closeTag();
  652. // this.$router.push({
  653. // path: '/maintenance/salesPolicy/index',
  654. // query: {}
  655. // });
  656. },
  657. async saveGoodsColumn() {
  658. // const inSave = await this.saveColumnData(
  659. // this.getColumnName(26),
  660. // this.goodsOption
  661. // );
  662. // if (inSave) {
  663. // this.$message.success("保存成功");
  664. // //关闭窗口
  665. // this.$refs.goodsCrud.$refs.dialogColumn.columnBox = false;
  666. // }
  667. }
  668. }
  669. }
  670. </script>
  671. <style lang="scss" scoped>
  672. .back-icon {
  673. line-height: 64px;
  674. font-size: 20px;
  675. margin-right: 8px;
  676. }
  677. ::v-deep .el-form-item {
  678. margin-bottom: 0;
  679. }
  680. .el-dialogDeep {
  681. ::v-deep .el-dialog {
  682. margin: 1vh auto 0 !important;
  683. padding-bottom: 10px !important;
  684. .el-dialog__body, .el-dialog__footer {
  685. padding-bottom: 0 !important;
  686. padding-top: 0 !important;
  687. }
  688. }
  689. }
  690. ::v-deep .el-form-item {
  691. margin-bottom: 0;
  692. }
  693. ::v-deep .el-form-item__content{
  694. line-height: 32px;
  695. }
  696. </style>