index.vue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. <script>
  2. import {
  3. editColumns,
  4. editTabColumns,
  5. forbidden,
  6. SelectColumns,
  7. } from "./initColumn";
  8. import orderApi from "@/api/business/purchase/purchase-order";
  9. import { initDicts, initRules, initParams } from "@/utils/init/index.js";
  10. import { tax, currency } from "@/components/popover-select-v2/fetch";
  11. import VirtualScroll from "el-table-virtual-scroll";
  12. import { VirtualColumn } from "el-table-virtual-scroll";
  13. export default {
  14. name: "EditPurchaseOrderDrawer",
  15. dicts: initDicts(SelectColumns),
  16. components: {
  17. "virtual-scroll": VirtualScroll,
  18. VirtualColumn,
  19. FileUploadCenter: () => import("../components/FileUploadCenter/index.vue"),
  20. BatchImport: () => import("@/components/BatchImport/index.vue"),
  21. ButtonHide: () => import("../components/hide/index.vue"),
  22. },
  23. data() {
  24. return {
  25. size: "mini",
  26. visible: false,
  27. loading: false,
  28. tabLoading: false,
  29. columns: editColumns,
  30. rules: initRules(editColumns),
  31. params: {
  32. ...initParams(editColumns),
  33. puOrderItemList: [],
  34. // puOrderExecuteList: [],
  35. },
  36. tabColumns: editTabColumns,
  37. tabName: "puOrderItemList",
  38. count: 1,
  39. tableData: [], //虚拟滚动加载显示的数据
  40. };
  41. },
  42. computed: {
  43. role: {
  44. get() {
  45. let { roles } = this.$store.state.user;
  46. return (
  47. roles.find((item) => item === "syfz-purchaseorder") ||
  48. "procurementManager"
  49. );
  50. },
  51. set() {},
  52. },
  53. tabHeight: {
  54. get() {
  55. let length = this.params["puOrderItemList"].filter(
  56. (item) => item.delFlag === "0"
  57. ).length;
  58. return `${length ? (length > 8 ? 500 : length * 36 + 120) : 120}px`;
  59. },
  60. set() {},
  61. },
  62. innerColumns: {
  63. get() {
  64. let { tabName, tabColumns } = this;
  65. let obj = tabColumns.find(({ key }) => key === tabName).tableColumns;
  66. return obj;
  67. },
  68. set(value) {
  69. let { tabName, tabColumns } = this;
  70. this.tabColumns = tabColumns.map((item) => {
  71. if (item.key === tabName) {
  72. item.tableColumns = value;
  73. }
  74. return { ...item };
  75. });
  76. this.$nextTick(() => {
  77. this.$refs.puOrderItemList &&
  78. this.$refs.puOrderItemList[0].doLayout();
  79. });
  80. },
  81. },
  82. },
  83. watch: {
  84. "params.contractType": function (newProp) {
  85. this.tabColumns = editTabColumns.filter((element) =>
  86. newProp === "1" ? element.key !== "puOrderItemList" : element
  87. );
  88. this.tabName = this.tabColumns[0].key;
  89. },
  90. tabName: function (newProp) {
  91. const { id } = this.params;
  92. // this.fetchTable(id, newProp);
  93. },
  94. // "params.puOrderItemList": {
  95. // handler(nVal, oVal) {
  96. // this.params.source == 3 &&
  97. // this.handleSynchronousMaterial(
  98. // "puOrderItemList",
  99. // "puOrderExecuteList"
  100. // );
  101. // },
  102. // deep: true,
  103. // immediate: true,
  104. // },
  105. // "params.puOrderExecuteList": {
  106. // handler(nVal, oVal) {
  107. // this.params.source == 3 &&
  108. // this.handleSynchronousMaterial(
  109. // "puOrderExecuteList",
  110. // "puOrderItemList"
  111. // );
  112. // },
  113. // deep: true,
  114. // immediate: true,
  115. // },
  116. "params.billType": {
  117. handler(nVal, oVal) {
  118. let billList = ["21-Cxx-02", "21-Cxx-04", "21-Cxx-10", "21-Cxx-14"];
  119. if (billList.find((item) => item === nVal)) {
  120. this.rules.warehouseName = [
  121. {
  122. required: true,
  123. message: "WMS入库仓库不能为空",
  124. trigger: "change",
  125. },
  126. ];
  127. } else {
  128. this.rules.warehouseName = null;
  129. }
  130. this.count++;
  131. },
  132. },
  133. "params.isBack": {
  134. handler(nVal, oVal) {
  135. if (nVal === "Y") {
  136. this.rules.retReasonName = [
  137. { required: true, message: "退换原因不能为空", trigger: "change" },
  138. ];
  139. this.rules.processTypeName = [
  140. { required: true, message: "处理方式不能为空", trigger: "change" },
  141. ];
  142. } else {
  143. this.rules.retReasonName = null;
  144. this.rules.processTypeName = null;
  145. }
  146. this.count++;
  147. },
  148. },
  149. },
  150. methods: {
  151. setVisible(prop) {
  152. this.visible = prop;
  153. if (!this.visible) {
  154. this.$refs["orderEditForm"].clearValidate();
  155. }
  156. },
  157. // 同步子表物料
  158. handleSynchronousMaterial(tableOne, tableTwo) {
  159. let _this = this;
  160. // this.params[tableOne]-- -> this.params[tableTwo]
  161. this.params[tableOne] &&
  162. this.params[tableOne].length &&
  163. this.params[tableOne].forEach((item, index) => {
  164. for (const key in item) {
  165. if (
  166. _this.params[tableTwo][index] &&
  167. key in _this.params[tableTwo][index]
  168. ) {
  169. _this.params[tableTwo][index].material = item.material;
  170. key !== "id" && (_this.params[tableTwo][index][key] = item[key]);
  171. }
  172. }
  173. });
  174. },
  175. // 判断属性是否禁用
  176. async handleIsForbidden(status, source) {
  177. let { updateColumns, updateTabColumns } = await forbidden(
  178. status != "2",
  179. source
  180. );
  181. this.columns = updateColumns;
  182. this.tabColumns = updateTabColumns;
  183. try {
  184. const { code, rows } = await orderApi.REFER(
  185. {
  186. type: "WAREHOUSE_PARAM",
  187. // search: this.params.warehouseName,
  188. search: "",
  189. id: this.params.warehouse,
  190. isPage: true,
  191. },
  192. { pageNum: 1, pageSize: 10 }
  193. );
  194. if (code == 200) {
  195. this.judgeGoodsAllocation(rows[0].csFlag);
  196. }
  197. } catch (error) {}
  198. this.count++;
  199. },
  200. // 查询详细
  201. async fetchItem(prop) {
  202. try {
  203. this.loading = true;
  204. const { code, msg, data } = await orderApi.details(prop);
  205. if (code === 200) {
  206. this.params = { ...this.params, ...data };
  207. this.handleIsForbidden(this.params.status, this.params.source);
  208. }
  209. } catch (err) {
  210. //
  211. } finally {
  212. this.loading = false;
  213. }
  214. },
  215. // 新增行
  216. addTableRow(prop) {
  217. for (const key in this.params) {
  218. // if (key === "puOrderItemList" || key === "puOrderExecuteList") {
  219. if (key === "puOrderItemList") {
  220. const arr = this.tabColumns.find(
  221. (element) => element["key"] === key
  222. ).tableColumns;
  223. let rowData = initParams(arr, "key", "value");
  224. "rowno" in rowData &&
  225. (rowData["rowno"] = this.params[key].length
  226. ? this.params[key][this.params[key].length - 1]["rowno"] + 1
  227. : this.params[key].length + 1);
  228. // 物料
  229. if ("rowNo" in rowData) {
  230. rowData["rowNo"] = this.params[key].length
  231. ? this.params[key][this.params[key].length - 1]["rowNo"] + 1
  232. : this.params[key].length + 1;
  233. // 扣税类别
  234. rowData["taxDeductClassify"] = "1";
  235. // 折本汇率
  236. rowData["exchangeRate"] = "1";
  237. // 价格类型
  238. rowData["priceType"] = "order";
  239. // 币种
  240. rowData["currency"] = "1002Z0100000000001K1";
  241. rowData["currencyName"] = "人民币";
  242. }
  243. // 是否完成询价,新增明细行需默认明细为false
  244. // rowData['whetherCompleteInquiry'] = false;
  245. rowData["delFlag"] = "0";
  246. rowData["insertId"] = new Date().getTime();
  247. this.params[key].push(rowData);
  248. }
  249. }
  250. // const arr = this.tabColumns.find(
  251. // (element) => element.key === this.tabName
  252. // ).tableColumns;
  253. // prop.push(initParams(arr, "key", "value"));
  254. },
  255. // 删除行
  256. async delTableRow(prop, row, name) {
  257. let delNo = name === "puOrderItemList" ? "rowNo" : "rowno";
  258. if (prop.length === 1) {
  259. this.$alert("订单行不允许为空", "提示", {
  260. confirmButtonText: "确定",
  261. callback: (action) => {
  262. // this.$message({
  263. // type: 'info',
  264. // message: `action: ${ action }`
  265. // });
  266. },
  267. });
  268. } else {
  269. for (const key in this.params) {
  270. // if (key === "puOrderItemList" || key === "puOrderExecuteList") {
  271. if (key === "puOrderItemList") {
  272. this.params[key].forEach((item, index) => {
  273. let flag = key === "puOrderItemList" ? "rowNo" : "rowno";
  274. if (item[flag] && item[flag] === row[delNo]) {
  275. item.id
  276. ? (item["delFlag"] = "2")
  277. : this.params[key].splice(index, 1);
  278. }
  279. });
  280. // this.params[key][index].id ?
  281. // (this.params[key][index]['delFlag'] = '2') :
  282. // this.params[key].splice(index, 1);
  283. }
  284. }
  285. await this.handleGetPrice();
  286. }
  287. },
  288. // 取消
  289. handleCancel() {
  290. this.params = {
  291. ...initParams(this.columns),
  292. puOrderItemList: [],
  293. // puOrderExecuteList: [],
  294. };
  295. this.setVisible(false);
  296. },
  297. // 判断保存条件
  298. judgeSaveCondition(cb) {
  299. const _this = this;
  300. this.$refs["orderEditForm"].validate(async (valid) => {
  301. if (valid) {
  302. // 执行结果在审批之后出现
  303. let validList = _this.params["puOrderItemList"].filter(
  304. (item) => item.delFlag === "0"
  305. );
  306. if (!validList.length) {
  307. _this.$notify.error({
  308. title: "错误",
  309. message: "请填写订单行!",
  310. });
  311. return false;
  312. }
  313. // let isPrice = _this.params.puOrderItemList.filter(item => !item.whetherCompleteInquiry);
  314. // if(isPrice.length && this.role === 'procurementManager'){
  315. // _this.$notify.error({
  316. // title: '错误',
  317. // message: '询价失败!'
  318. // });
  319. // return false
  320. // }
  321. cb();
  322. } else {
  323. _this.$notify.error({
  324. title: "错误",
  325. message: "存在必填项未填写",
  326. });
  327. console.log("error submit!!");
  328. return false;
  329. }
  330. });
  331. },
  332. // 保存
  333. handleSava() {
  334. console.log(this.params, "this.params---------");
  335. this.judgeSaveCondition(async () => {
  336. try {
  337. this.loading = true;
  338. const { code, msg } = await (this.handleIsRevise()
  339. ? orderApi.revision(this.params)
  340. : orderApi.edit(this.params));
  341. if (code === 200) {
  342. this.handleCancel();
  343. }
  344. } catch (err) {
  345. //
  346. } finally {
  347. this.loading = false;
  348. }
  349. });
  350. },
  351. beforeOpen() {},
  352. judgeGoodsAllocation(porp) {
  353. if (porp === "Y") {
  354. this.rules.goodsAllocationName = [
  355. { required: true, message: "货位不能为空", trigger: "change" },
  356. ];
  357. } else {
  358. this.rules.goodsAllocationName = null;
  359. }
  360. this.count++;
  361. },
  362. // 主表参照改变之后
  363. async handleReferChange(val, type, source) {
  364. // 供应商选择
  365. if (type === "SUPPLIER_PARAM") {
  366. let page = { pageNum: 1, pageSize: 10 };
  367. let relevanceRefer = [
  368. {
  369. // 供应商联系人
  370. key: "supplierContacts",
  371. params: {
  372. type: "SUPPLIERCONTACTS_PARAM",
  373. supplierId: val.id,
  374. },
  375. },
  376. {
  377. // 供应商业务员
  378. key: "supplierPersonal",
  379. params: {
  380. type: "PSNLICENSE_PARAM",
  381. supplierId: val.id,
  382. pkOrg: source.puOrg,
  383. },
  384. },
  385. ];
  386. try {
  387. let promiseArr = relevanceRefer.map((refer) => {
  388. return new Promise((resolve, reject) => {
  389. orderApi
  390. .REFER(
  391. {
  392. ...refer.params,
  393. search: "",
  394. isPage: true,
  395. },
  396. page
  397. )
  398. .then((res) => {
  399. let { code, rows } = res;
  400. if (code === 200) {
  401. source[refer.key] = rows[0] ? rows[0].id : "";
  402. source[`${refer.key}Name`] = rows[0] ? rows[0].name : "";
  403. resolve();
  404. }
  405. });
  406. });
  407. });
  408. Promise.all(promiseArr).then(async () => {
  409. // 明细不为空的情况下进行询价
  410. let detailList = this.params["puOrderItemList"].filter(
  411. (item) => item.material && item.material != ""
  412. );
  413. if (detailList.length) {
  414. await this.handleGetPrice();
  415. }
  416. });
  417. } catch (error) {}
  418. }
  419. // 组织
  420. if (type === "ORG_PARAM") {
  421. for (const key in this.params) {
  422. // if (key === "puOrderItemList" || key === "puOrderExecuteList") {
  423. if (key === "puOrderItemList") {
  424. this.params[key] = [];
  425. } else if (key === "sysFileRecordList") {
  426. this.params[key] = [];
  427. } else if (
  428. key != "puOrg" &&
  429. key != "puOrgName" &&
  430. // key != "buyer" &&
  431. // key != "buyerName" &&
  432. // key != "puDept" &&
  433. // key != "puDeptName" &&
  434. key != "status" &&
  435. key != "billDate" &&
  436. key != "createTime" &&
  437. key != "source"
  438. ) {
  439. this.params[key] = "";
  440. } else {
  441. }
  442. }
  443. }
  444. // WMS仓库
  445. if (type === "WAREHOUSE_PARAM") {
  446. // this.judgeGoodsAllocation(val.csFlag);
  447. // source.goodsAllocation = "";
  448. // source.goodsAllocationName = "";
  449. this.params.puOrderItemList = this.params.puOrderItemList.map(
  450. (item) => ({
  451. ...item,
  452. goodsAllocation: "",
  453. goodsAllocationName: "",
  454. })
  455. );
  456. // this.count++
  457. }
  458. },
  459. // 子表参照改变之后
  460. async handleTabReferChange(val, type, source) {
  461. // 触发物料参照
  462. if (type == "MATERIAL_PARAM" && source.qty && source.qty != "") {
  463. source["qty"] = 0;
  464. // source['whetherCompleteInquiry'] = false;
  465. source["taxPrice"] = 0;
  466. source["money"] = 0;
  467. source["taxDeductMoneya"] = 0;
  468. source["price"] = 0;
  469. source["notaxMoney"] = 0;
  470. source["tax"] = 0;
  471. this.params["qty"] = 0;
  472. this.params["originalQty"] = 0;
  473. this.params["money"] = 0;
  474. this.params["originalMoney"] = 0;
  475. this.params["notaxMoney"] = 0;
  476. source.isDrug = val.materialMedcine.isDrug == "0" ? "Y" : "N";
  477. // await this.handleGetPrice();
  478. }
  479. // 物料触发税率
  480. if (type == "MATERIAL_PARAM") {
  481. let { rateCode } = source;
  482. try {
  483. // try
  484. this.loading = true;
  485. const { ntaxrate } = await tax(rateCode);
  486. source.tax = ntaxrate === "0E-8" ? 0 : ntaxrate;
  487. } catch (err) {
  488. // catch
  489. console.error(err);
  490. } finally {
  491. // finally
  492. this.loading = false;
  493. }
  494. }
  495. },
  496. // Select改变之后
  497. handleSelectChange(val, typeName) {
  498. if (val === "billType") {
  499. this.params["billTypeName"] = this.dict.type[typeName].find(
  500. (item) => item.value == this.params[val]
  501. ).label;
  502. this.params.warehouse = "";
  503. this.params.warehouseName = "";
  504. this.params.goodsAllocation = "";
  505. this.params.goodsAllocationName = "";
  506. this.rules.goodsAllocationName = null;
  507. this.params["puOrderItemList"] = this.params["puOrderItemList"].map(
  508. (item) => ({
  509. ...item,
  510. goodsAllocation: "",
  511. goodsAllocationName: "",
  512. })
  513. );
  514. }
  515. },
  516. // 子表下拉框改变
  517. handleTabSelectChange(type, row) {
  518. // && row.qty
  519. if (type == "priceType" && row.material && row.qty != "") {
  520. // row['whetherCompleteInquiry'] = false;
  521. this.handleGetPrice();
  522. }
  523. },
  524. // 子表inputNumber
  525. handleInputChange(row, type) {
  526. // 物料数量变化----询价
  527. if (
  528. (type == "qty" || type == "taxPrice" || type == "taxDeductMoneya") &&
  529. row.material
  530. ) {
  531. if (this.params.status === "2") {
  532. // 修订
  533. this.handleCalculateOrderAmount();
  534. } else {
  535. // row['whetherCompleteInquiry'] = false;
  536. this.handleGetPrice();
  537. }
  538. this.$refs.puOrderItemList[0].updateFooter();
  539. // this.$refs.puOrderExecuteList[0].updateFooter();
  540. }
  541. // // 物料数量变化----询价
  542. // if (type == 'qty' && row.material) {
  543. // row['whetherCompleteInquiry'] = false;
  544. // // row.qty && this.handleGetPrice();
  545. // this.handleGetPrice();
  546. // }
  547. },
  548. // 子表多选框改变
  549. handleTabCheckbox(type, source) {
  550. // 勾选赠品,价税合计更新为0,含税单价、无税单价更新为0
  551. if (
  552. type === "isGift" &&
  553. source.material &&
  554. source.qty &&
  555. source.qty != ""
  556. ) {
  557. // source['whetherCompleteInquiry'] = false;
  558. this.handleGetPrice();
  559. }
  560. },
  561. // 询价 getPrice
  562. async handleGetPrice() {
  563. // if(this.role === 'procurementManager'){
  564. try {
  565. // action:insert(新增)、revise(修订)、update(编辑)
  566. let { code, data } = await orderApi.getPrice({
  567. ...this.params,
  568. action: this.handleIsRevise() ? "revise" : "update",
  569. });
  570. if (code == 200) {
  571. this.params = data;
  572. }
  573. } catch (error) {
  574. } finally {
  575. }
  576. // }
  577. },
  578. // 修订——计算金额
  579. async handleCalculateOrderAmount() {
  580. try {
  581. let { code, data } = await orderApi.calculateOrderAmount({
  582. ...this.params,
  583. action: this.handleIsRevise() ? "revise" : "update",
  584. });
  585. code == 200 && (this.params = data);
  586. } catch (error) {
  587. } finally {
  588. }
  589. },
  590. // 判断修订还是编辑
  591. handleIsRevise() {
  592. return this.params.status == "2";
  593. },
  594. // /handleIsRevise() ? scope.row[cColumn.key] : Infinity
  595. getInputNumberMax(key, row) {
  596. if (key === "qty") {
  597. return this.handleIsRevise()
  598. ? Math.sign(row["originalQty"]) == -1
  599. ? 0
  600. : row["originalQty"]
  601. : this.params.source == "3"
  602. ? Infinity
  603. : row["originalQty"];
  604. }
  605. return Infinity;
  606. },
  607. async handelImport(fileList) {
  608. try {
  609. let formData = new FormData();
  610. formData.append("file", fileList[0].raw);
  611. let tabList = {
  612. puOrderItemList: [...this.params.puOrderItemList],
  613. warehouse: this.params.warehouse,
  614. // puOrderExecuteList: [...this.params.puOrderExecuteList],
  615. };
  616. const blob = new Blob([JSON.stringify(tabList)], {
  617. type: "application/json",
  618. });
  619. formData.append("tabList", blob);
  620. this.$modal.loading("正在上传文件,请稍候...");
  621. let {
  622. code,
  623. data: { puOrderItemList, puOrderExecuteList },
  624. } = await orderApi.orderImport(formData);
  625. if (code == 200) {
  626. // for (const key in data) {
  627. // this.params[key].push(...data[key]);
  628. // }
  629. this.params["puOrderItemList"] = [...puOrderItemList];
  630. this.params["puOrderExecuteList"] = [...puOrderExecuteList];
  631. let { setVisible } = this.$refs.batchImport;
  632. setVisible(false);
  633. // if(num > total)
  634. this.handleGetPrice();
  635. }
  636. } catch (error) {
  637. } finally {
  638. this.$modal.closeLoading();
  639. }
  640. },
  641. async handleTemDownload() {
  642. this.download(
  643. "/pu/order/downloadFailData",
  644. {},
  645. `物料信息模板${new Date().getTime()}.xlsx`
  646. );
  647. },
  648. getSummaries({ columns, data }) {
  649. const means = []; // 合计
  650. let { tabColumns, tabName } = this;
  651. columns.forEach((column, columnIndex) => {
  652. if (columnIndex === 0) {
  653. means.push("合计");
  654. } else {
  655. const values = data.map((item) => Number(item[column.property]));
  656. let sumColumn = tabColumns
  657. .find((tab) => tab.key === tabName)
  658. .tableColumns.filter((item) => item.hidden)
  659. .filter(
  660. ({ key, isSummary }) => isSummary && key === column.property
  661. );
  662. // 合计
  663. // if (!values.every(value => isNaN(value))) {
  664. if (sumColumn.length) {
  665. means[columnIndex] = values.reduce((prev, curr) => {
  666. const value = Number(curr);
  667. if (!isNaN(value)) {
  668. return prev + curr;
  669. } else {
  670. return prev;
  671. }
  672. }, 0);
  673. means[columnIndex] = means[columnIndex].toFixed(2);
  674. } else {
  675. means[columnIndex] = "";
  676. }
  677. }
  678. });
  679. // sums[index] = sums[index] && sums[index].toFixed(2); // 保留2位小数,解决小数合计列
  680. return [means];
  681. },
  682. // 子表-批量复制
  683. async tabCopyChange(prop, { column, source }) {
  684. let { key, referName, dataMapping } = column;
  685. try {
  686. this.tabLoading = true;
  687. if (key === "materialCode") {
  688. let {
  689. code,
  690. data: { puOrderItemList },
  691. } = await orderApi.materialCopy({
  692. materialCode: prop,
  693. puOrderItemList: this.params.puOrderItemList.filter(
  694. (item) => item.rowNo != source.rowNo
  695. ),
  696. // puOrderExecuteList
  697. });
  698. if (code == 200) {
  699. this.params.puOrderItemList = [...puOrderItemList];
  700. // this.params.puOrderExecuteList = [...puOrderExecuteList];
  701. }
  702. } else {
  703. let params = {
  704. searchList: prop,
  705. type: referName,
  706. };
  707. key === "goodsAllocationName" &&
  708. (params["stordocId"] = this.params.warehouse);
  709. let { code, rows } = await orderApi.REFER(params);
  710. if (code == 200) {
  711. // !rows.length &&
  712. // this.$notify.warning({
  713. // message: "粘贴数据检索为空,请检查是否符合要求!",
  714. // });
  715. if (!rows.length) {
  716. this.$notify.warning({
  717. message: "粘贴数据检索为空,请检查是否符合要求!",
  718. });
  719. for (const key in dataMapping) {
  720. source[key] = "";
  721. }
  722. }
  723. rows = rows.map((item) => {
  724. let obj = {};
  725. for (const key in dataMapping) {
  726. obj[key] = item[dataMapping[key]];
  727. }
  728. return obj;
  729. });
  730. let invariant = this.params.puOrderItemList.filter(
  731. (item) => item.rowNo < source.rowNo || item.delFlag !== "0"
  732. );
  733. let change = this.params.puOrderItemList
  734. .filter(
  735. (item) => !(item.rowNo < source.rowNo) && item.delFlag === "0"
  736. )
  737. .map((item, index) => {
  738. return {
  739. ...item,
  740. ...rows[index],
  741. };
  742. });
  743. this.params.puOrderItemList = [...invariant, ...change];
  744. }
  745. }
  746. } catch (error) {
  747. } finally {
  748. this.tabLoading = false;
  749. }
  750. },
  751. inputTabChange(prop, { column, source }) {
  752. let { key, copy } = column;
  753. // 数量-批量复制
  754. if (copy) {
  755. if (key === "qty") {
  756. let munList = prop.split(/,|,|\s+/);
  757. let invariant = this.params.puOrderItemList.filter(
  758. (item) => item.rowNo < source.rowNo || item.delFlag !== "0"
  759. );
  760. let change = this.params.puOrderItemList
  761. .filter(
  762. (item) => !(item.rowNo < source.rowNo) && item.delFlag === "0"
  763. )
  764. .map((item, index) => {
  765. return {
  766. ...item,
  767. qty: munList[index] || item.qty,
  768. };
  769. });
  770. this.params.puOrderItemList = [...invariant, ...change];
  771. if (this.params.status === "2") {
  772. // 修订
  773. this.handleCalculateOrderAmount();
  774. } else {
  775. this.handleGetPrice();
  776. }
  777. }
  778. }
  779. },
  780. onHide(prop) {
  781. this.innerColumns = prop;
  782. },
  783. },
  784. created() {},
  785. mounted() {},
  786. updated() {
  787. this.$nextTick(() => {
  788. // this.$refs.puOrderExecuteList &&
  789. // this.$refs.puOrderExecuteList[0].doLayout();
  790. this.$refs.puOrderItemList && this.$refs.puOrderItemList[0].doLayout();
  791. });
  792. },
  793. destroyed() {},
  794. };
  795. </script>
  796. <template>
  797. <el-drawer
  798. direction="btt"
  799. size="100%"
  800. :with-header="false"
  801. :visible.sync="visible"
  802. @open="beforeOpen"
  803. @close="$emit('close')"
  804. >
  805. <el-form
  806. :key="count"
  807. v-loading="loading"
  808. :size="size"
  809. ref="orderEditForm"
  810. class="orderEditForm"
  811. label-position="right"
  812. label-width="140px"
  813. :model="params"
  814. :rules="rules"
  815. >
  816. <el-card
  817. :body-style="{
  818. padding: '20px',
  819. display: 'flex',
  820. 'flex-wrap': 'wrap',
  821. }"
  822. style="margin: 10px"
  823. >
  824. <div
  825. slot="header"
  826. style="
  827. display: flex;
  828. justify-content: space-between;
  829. align-items: center;
  830. "
  831. >
  832. <h3>{{ handleIsRevise() ? "修订" : "编辑" }}</h3>
  833. <div style="text-align: right">
  834. <el-button :size="size" type="primary" @click="handleSava"
  835. >更 新</el-button
  836. >
  837. <el-button :size="size" @click="handleCancel">取 消</el-button>
  838. </div>
  839. </div>
  840. <el-row style="display: flex; flex-wrap: wrap">
  841. <el-col
  842. v-for="(column, index) in columns"
  843. :key="index"
  844. :span="column.span || 6"
  845. >
  846. <el-form-item
  847. :prop="column.key"
  848. :label="column.title"
  849. v-if="column.isShow"
  850. >
  851. <el-input
  852. v-if="column.inputType === 'Input'"
  853. v-model="params[column.key]"
  854. :placeholder="column.placeholder"
  855. :clearable="column.clearable"
  856. :disabled="column.disabled"
  857. style="width: 100%"
  858. ></el-input>
  859. <dr-popover-select
  860. v-if="column.inputType === 'PopoverSelect'"
  861. v-model="params[column.key]"
  862. :size="size"
  863. :value-key="column.valueKey"
  864. :source.sync="params"
  865. :title="column.title"
  866. :type="column.referName"
  867. :multiple="column.multiple"
  868. :placeholder="column.placeholder"
  869. :data-mapping="column.dataMapping"
  870. :disabled="column.disabled"
  871. :clearable="column.clearable"
  872. :query-params="column.queryParams"
  873. @change="handleReferChange"
  874. ></dr-popover-select>
  875. <el-input
  876. v-if="column.inputType === 'Textarea'"
  877. v-model="params[column.key]"
  878. type="textarea"
  879. :rows="column.rows"
  880. :placeholder="column.placeholder"
  881. :clearable="column.clearable"
  882. :disabled="column.disabled"
  883. style="width: 100%"
  884. ></el-input>
  885. <el-input-number
  886. v-if="column.inputType === 'InputNumber'"
  887. v-model="params[column.key]"
  888. :precision="column.precision"
  889. :controls-position="column.controlsPosition"
  890. :placeholder="column.placeholder"
  891. :clearable="column.clearable"
  892. :disabled="column.disabled"
  893. style="width: 100%"
  894. ></el-input-number>
  895. <el-select
  896. v-if="column.inputType === 'Select'"
  897. v-model="params[column.key]"
  898. :disabled="column.disabled"
  899. :clearable="column.clearable"
  900. :placeholder="column.placeholder"
  901. style="width: 100%"
  902. @change="handleSelectChange(column.key, column.referName)"
  903. >
  904. <el-option
  905. v-for="item in dict.type[column.referName]"
  906. :key="item.value"
  907. :label="item.label"
  908. :value="item.value"
  909. ></el-option>
  910. </el-select>
  911. <el-select
  912. v-if="column.inputType === 'TagSelect'"
  913. v-model="params[column.key]"
  914. multiple
  915. clearable
  916. collapse-tags
  917. :placeholder="column.placeholder"
  918. :clearable="column.clearable"
  919. :disabled="column.disabled"
  920. style="width: 100%"
  921. >
  922. <template #prefix>
  923. <el-icon
  924. class="el-icon-view"
  925. style="cursor: pointer"
  926. @click.stop="$message.info(234)"
  927. ></el-icon>
  928. </template>
  929. <el-option
  930. v-for="item in options"
  931. :key="item.value"
  932. :label="item.label"
  933. :value="item.value"
  934. ></el-option>
  935. </el-select>
  936. <el-date-picker
  937. v-if="column.inputType === 'DatePicker'"
  938. v-model="params[column.key]"
  939. :type="column.type"
  940. :placeholder="column.placeholder"
  941. :clearable="column.clearable"
  942. :disabled="column.disabled"
  943. :picker-options="column.pickerOptions"
  944. style="width: 100%"
  945. ></el-date-picker>
  946. <el-checkbox
  947. v-if="column.inputType === 'Checkbox'"
  948. v-model="params[column.key]"
  949. :disabled="column.disabled"
  950. true-label="Y"
  951. false-label="N"
  952. >
  953. </el-checkbox>
  954. <file-upload-center
  955. v-if="column.inputType === 'Upload'"
  956. v-model="params[column.key]"
  957. :file-type="column.fileType"
  958. :disabled="handleIsRevise()"
  959. ></file-upload-center>
  960. </el-form-item>
  961. </el-col>
  962. </el-row>
  963. </el-card>
  964. <el-card
  965. :body-style="{
  966. padding: '20px',
  967. display: 'flex',
  968. 'flex-wrap': 'wrap',
  969. position: 'relative',
  970. }"
  971. style="margin: 10px"
  972. >
  973. <el-tabs v-model="tabName" style="width: 100%" v-loading="tabLoading">
  974. <el-tab-pane
  975. v-for="(column, index) in tabColumns"
  976. :key="index"
  977. :label="column.title"
  978. :name="column.key"
  979. >
  980. <ux-grid
  981. border
  982. use-virtual
  983. keep-source
  984. show-summary
  985. show-overflow
  986. beautify-table
  987. :ref="column.key"
  988. :size="size"
  989. :height="tabHeight"
  990. style="width: 100%"
  991. :data="params[column.key].filter((item) => item.delFlag === '0')"
  992. :summary-method="getSummaries"
  993. :header-row-style="{
  994. color: '#515a6e',
  995. }"
  996. >
  997. <ux-table-column
  998. title="序号"
  999. type="index"
  1000. width="60"
  1001. ></ux-table-column>
  1002. <ux-table-column
  1003. v-for="(cColumn, cIndex) in column.tableColumns.filter(
  1004. (item) => item.hidden
  1005. )"
  1006. :key="cColumn.key + cColumn.hidden"
  1007. :field="cColumn.key"
  1008. :title="cColumn.title"
  1009. :width="cColumn.width || 80"
  1010. resizable
  1011. >
  1012. <template slot="header" slot-scope="scope">
  1013. <span v-if="cColumn.require" style="color: #ff4949">*</span>
  1014. <span>
  1015. {{ cColumn.title }}
  1016. </span>
  1017. </template>
  1018. <template slot-scope="scope">
  1019. <el-form-item label-width="0">
  1020. <span v-if="!cColumn.inputType">
  1021. {{ scope.row[cColumn.key] }}
  1022. </span>
  1023. <el-input
  1024. v-if="cColumn.inputType === 'Input'"
  1025. v-model="scope.row[cColumn.key]"
  1026. :placeholder="cColumn.placeholder"
  1027. :clearable="cColumn.clearable"
  1028. :disabled="cColumn.disabled"
  1029. :size="size"
  1030. style="width: 100%"
  1031. @change="
  1032. (prop) =>
  1033. inputTabChange(prop, {
  1034. column: cColumn,
  1035. source: scope.row,
  1036. })
  1037. "
  1038. ></el-input>
  1039. <dr-popover-select
  1040. v-if="cColumn.inputType === 'PopoverSelect'"
  1041. v-model="scope.row[cColumn.key]"
  1042. :source.sync="scope.row"
  1043. :title="cColumn.title"
  1044. :value-key="cColumn.valueKey"
  1045. :disabled="cColumn.disabled"
  1046. :clearable="cColumn.clearable"
  1047. :copy="cColumn.copy"
  1048. :type="cColumn.referName"
  1049. :multiple="cColumn.multiple"
  1050. :placeholder="cColumn.placeholder"
  1051. :data-mapping="cColumn.dataMapping"
  1052. :query-params="
  1053. cColumn.key !== 'goodsAllocationName'
  1054. ? cColumn.queryParams
  1055. : () => ({
  1056. stordocId: params.warehouse,
  1057. pkOrg: params.puOrg,
  1058. })
  1059. "
  1060. :size="size"
  1061. @change="handleTabReferChange"
  1062. @copyChange="
  1063. (prop) =>
  1064. tabCopyChange(prop, {
  1065. column: cColumn,
  1066. source: scope.row,
  1067. })
  1068. "
  1069. ></dr-popover-select>
  1070. <el-select
  1071. v-if="cColumn.inputType === 'Select'"
  1072. v-model="scope.row[cColumn.key]"
  1073. :size="size"
  1074. :disabled="cColumn.disabled"
  1075. :clearable="cColumn.clearable"
  1076. :placeholder="cColumn.placeholder"
  1077. style="width: 100%"
  1078. @change="handleTabSelectChange(cColumn.key, scope.row)"
  1079. >
  1080. <el-option
  1081. v-for="item in dict.type[cColumn.referName]"
  1082. :key="item.value"
  1083. :label="item.label"
  1084. :value="item.value"
  1085. ></el-option>
  1086. </el-select>
  1087. <el-checkbox
  1088. v-if="cColumn.inputType === 'Checkbox'"
  1089. v-model="scope.row[cColumn.key]"
  1090. :disabled="cColumn.disabled"
  1091. true-label="Y"
  1092. false-label="N"
  1093. @change="handleTabCheckbox(cColumn.key, scope.row)"
  1094. ></el-checkbox>
  1095. <el-input-number
  1096. v-if="cColumn.inputType === 'InputNumber'"
  1097. v-model="scope.row[cColumn.key]"
  1098. :precision="cColumn.precision"
  1099. :controls-position="cColumn.controlsPosition"
  1100. :max="getInputNumberMax(cColumn.key, scope.row)"
  1101. :min="cColumn.key === 'reservedQty' ? 0 : -Infinity"
  1102. @change="handleInputChange(scope.row, cColumn.key)"
  1103. :placeholder="cColumn.placeholder"
  1104. :clearable="cColumn.clearable"
  1105. :disabled="cColumn.disabled"
  1106. :size="size"
  1107. style="width: 100%"
  1108. ></el-input-number>
  1109. <el-date-picker
  1110. v-if="cColumn.inputType === 'DatePicker'"
  1111. v-model="scope.row[cColumn.key]"
  1112. :type="cColumn.type"
  1113. :placeholder="cColumn.placeholder"
  1114. :clearable="cColumn.clearable"
  1115. :disabled="cColumn.disabled"
  1116. :picker-options="cColumn.pickerOptions"
  1117. style="width: 100%"
  1118. ></el-date-picker>
  1119. </el-form-item>
  1120. </template>
  1121. </ux-table-column>
  1122. <!-- 修订:不可删除、增行
  1123. 编辑:自制:可删可增 -->
  1124. <!-- v-if="!handleIsRevise()" -->
  1125. <ux-table-column
  1126. v-if="!handleIsRevise()"
  1127. fixed="right"
  1128. label="操作"
  1129. width="120"
  1130. >
  1131. <template slot-scope="scope">
  1132. <el-button
  1133. @click.native.prevent="
  1134. delTableRow(params[tabName], scope.row, tabName)
  1135. "
  1136. type="text"
  1137. :size="size"
  1138. >
  1139. 删行
  1140. </el-button>
  1141. </template>
  1142. </ux-table-column>
  1143. </ux-grid>
  1144. <!-- </template>
  1145. </virtual-scroll> -->
  1146. </el-tab-pane>
  1147. </el-tabs>
  1148. <el-row style="position: absolute; top: 20px; right: 20px">
  1149. <el-button
  1150. v-if="params.source == '3' && !handleIsRevise()"
  1151. :size="size"
  1152. @click="addTableRow(params[tabName])"
  1153. >增行</el-button
  1154. >
  1155. <BatchImport
  1156. v-if="params.source == '3' && !handleIsRevise()"
  1157. ref="batchImport"
  1158. @import="handelImport"
  1159. @temDownload="handleTemDownload"
  1160. :fileSize="2"
  1161. ></BatchImport>
  1162. </el-row>
  1163. <el-row style="margin-top: 10px">
  1164. <el-col>
  1165. <button-hide v-model="innerColumns" @change="onHide"></button-hide>
  1166. </el-col>
  1167. </el-row>
  1168. </el-card>
  1169. </el-form>
  1170. </el-drawer>
  1171. </template>
  1172. <style scoped>
  1173. .orderEditForm >>> .el-form-item {
  1174. margin-bottom: 5px;
  1175. }
  1176. ::v-deep .singleTable .el-form-item {
  1177. margin-bottom: 0px;
  1178. }
  1179. ::v-deep.uxbeautifyTableClass
  1180. .elx-header--column
  1181. .elx-resizable.is--line:before {
  1182. height: 100%;
  1183. background-color: #dfe6ec;
  1184. }
  1185. </style>