index.vue 40 KB

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