index.vue 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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. rows = rows.map((item) => {
  716. let obj = {};
  717. for (const key in dataMapping) {
  718. obj[key] = item[dataMapping[key]];
  719. }
  720. return obj;
  721. });
  722. let invariant = this.params.puOrderItemList.filter(
  723. (item) => item.rowNo < source.rowNo || item.delFlag !== "0"
  724. );
  725. let change = this.params.puOrderItemList
  726. .filter(
  727. (item) => !(item.rowNo < source.rowNo) && item.delFlag === "0"
  728. )
  729. .map((item, index) => {
  730. return {
  731. ...item,
  732. ...rows[index],
  733. };
  734. });
  735. this.params.puOrderItemList = [...invariant, ...change];
  736. }
  737. }
  738. } catch (error) {
  739. } finally {
  740. this.tabLoading = false;
  741. }
  742. },
  743. inputTabChange(prop, { column, source }) {
  744. let { key, copy } = column;
  745. // 数量-批量复制
  746. if (copy) {
  747. if (key === "qty") {
  748. let munList = prop.split(/,|,|\s+/);
  749. let invariant = this.params.puOrderItemList.filter(
  750. (item) => item.rowNo < source.rowNo || item.delFlag !== "0"
  751. );
  752. let change = this.params.puOrderItemList
  753. .filter(
  754. (item) => !(item.rowNo < source.rowNo) && item.delFlag === "0"
  755. )
  756. .map((item, index) => {
  757. return {
  758. ...item,
  759. qty: munList[index] || item.qty,
  760. };
  761. });
  762. this.params.puOrderItemList = [...invariant, ...change];
  763. if (this.params.status === "2") {
  764. // 修订
  765. this.handleCalculateOrderAmount();
  766. } else {
  767. this.handleGetPrice();
  768. }
  769. }
  770. }
  771. },
  772. onHide(prop) {
  773. this.innerColumns = prop;
  774. },
  775. },
  776. created() {},
  777. mounted() {},
  778. updated() {
  779. this.$nextTick(() => {
  780. // this.$refs.puOrderExecuteList &&
  781. // this.$refs.puOrderExecuteList[0].doLayout();
  782. this.$refs.puOrderItemList && this.$refs.puOrderItemList[0].doLayout();
  783. });
  784. },
  785. destroyed() {},
  786. };
  787. </script>
  788. <template>
  789. <el-drawer
  790. direction="btt"
  791. size="100%"
  792. :with-header="false"
  793. :visible.sync="visible"
  794. @open="beforeOpen"
  795. @close="$emit('close')"
  796. >
  797. <el-form
  798. :key="count"
  799. v-loading="loading"
  800. :size="size"
  801. ref="orderEditForm"
  802. class="orderEditForm"
  803. label-position="right"
  804. label-width="140px"
  805. :model="params"
  806. :rules="rules"
  807. >
  808. <el-card
  809. :body-style="{
  810. padding: '20px',
  811. display: 'flex',
  812. 'flex-wrap': 'wrap',
  813. }"
  814. style="margin: 10px"
  815. >
  816. <div
  817. slot="header"
  818. style="
  819. display: flex;
  820. justify-content: space-between;
  821. align-items: center;
  822. "
  823. >
  824. <h3>{{ handleIsRevise() ? "修订" : "编辑" }}</h3>
  825. <div style="text-align: right">
  826. <el-button :size="size" type="primary" @click="handleSava"
  827. >更 新</el-button
  828. >
  829. <el-button :size="size" @click="handleCancel">取 消</el-button>
  830. </div>
  831. </div>
  832. <el-row style="display: flex; flex-wrap: wrap">
  833. <el-col
  834. v-for="(column, index) in columns"
  835. :key="index"
  836. :span="column.span || 6"
  837. >
  838. <el-form-item
  839. :prop="column.key"
  840. :label="column.title"
  841. v-if="column.isShow"
  842. >
  843. <el-input
  844. v-if="column.inputType === 'Input'"
  845. v-model="params[column.key]"
  846. :placeholder="column.placeholder"
  847. :clearable="column.clearable"
  848. :disabled="column.disabled"
  849. style="width: 100%"
  850. ></el-input>
  851. <dr-popover-select
  852. v-if="column.inputType === 'PopoverSelect'"
  853. v-model="params[column.key]"
  854. :size="size"
  855. :value-key="column.valueKey"
  856. :source.sync="params"
  857. :title="column.title"
  858. :type="column.referName"
  859. :multiple="column.multiple"
  860. :placeholder="column.placeholder"
  861. :data-mapping="column.dataMapping"
  862. :disabled="column.disabled"
  863. :query-params="column.queryParams"
  864. @change="handleReferChange"
  865. ></dr-popover-select>
  866. <el-input
  867. v-if="column.inputType === 'Textarea'"
  868. v-model="params[column.key]"
  869. type="textarea"
  870. :rows="column.rows"
  871. :placeholder="column.placeholder"
  872. :clearable="column.clearable"
  873. :disabled="column.disabled"
  874. style="width: 100%"
  875. ></el-input>
  876. <el-input-number
  877. v-if="column.inputType === 'InputNumber'"
  878. v-model="params[column.key]"
  879. :precision="column.precision"
  880. :controls-position="column.controlsPosition"
  881. :placeholder="column.placeholder"
  882. :clearable="column.clearable"
  883. :disabled="column.disabled"
  884. style="width: 100%"
  885. ></el-input-number>
  886. <el-select
  887. v-if="column.inputType === 'Select'"
  888. v-model="params[column.key]"
  889. :disabled="column.disabled"
  890. :clearable="column.clearable"
  891. :placeholder="column.placeholder"
  892. style="width: 100%"
  893. @change="handleSelectChange(column.key, column.referName)"
  894. >
  895. <el-option
  896. v-for="item in dict.type[column.referName]"
  897. :key="item.value"
  898. :label="item.label"
  899. :value="item.value"
  900. ></el-option>
  901. </el-select>
  902. <el-select
  903. v-if="column.inputType === 'TagSelect'"
  904. v-model="params[column.key]"
  905. multiple
  906. clearable
  907. collapse-tags
  908. :placeholder="column.placeholder"
  909. :clearable="column.clearable"
  910. :disabled="column.disabled"
  911. style="width: 100%"
  912. >
  913. <template #prefix>
  914. <el-icon
  915. class="el-icon-view"
  916. style="cursor: pointer"
  917. @click.stop="$message.info(234)"
  918. ></el-icon>
  919. </template>
  920. <el-option
  921. v-for="item in options"
  922. :key="item.value"
  923. :label="item.label"
  924. :value="item.value"
  925. ></el-option>
  926. </el-select>
  927. <el-date-picker
  928. v-if="column.inputType === 'DatePicker'"
  929. v-model="params[column.key]"
  930. :type="column.type"
  931. :placeholder="column.placeholder"
  932. :clearable="column.clearable"
  933. :disabled="column.disabled"
  934. :picker-options="column.pickerOptions"
  935. style="width: 100%"
  936. ></el-date-picker>
  937. <el-checkbox
  938. v-if="column.inputType === 'Checkbox'"
  939. v-model="params[column.key]"
  940. :disabled="column.disabled"
  941. true-label="Y"
  942. false-label="N"
  943. >
  944. </el-checkbox>
  945. <file-upload-center
  946. v-if="column.inputType === 'Upload'"
  947. v-model="params[column.key]"
  948. :file-type="column.fileType"
  949. :disabled="handleIsRevise()"
  950. ></file-upload-center>
  951. </el-form-item>
  952. </el-col>
  953. </el-row>
  954. </el-card>
  955. <el-card
  956. :body-style="{
  957. padding: '20px',
  958. display: 'flex',
  959. 'flex-wrap': 'wrap',
  960. position: 'relative',
  961. }"
  962. style="margin: 10px"
  963. >
  964. <el-tabs v-model="tabName" style="width: 100%" v-loading="tabLoading">
  965. <el-tab-pane
  966. v-for="(column, index) in tabColumns"
  967. :key="index"
  968. :label="column.title"
  969. :name="column.key"
  970. >
  971. <ux-grid
  972. border
  973. use-virtual
  974. keep-source
  975. show-summary
  976. show-overflow
  977. beautify-table
  978. :ref="column.key"
  979. :size="size"
  980. :height="tabHeight"
  981. style="width: 100%"
  982. :data="params[column.key].filter((item) => item.delFlag === '0')"
  983. :summary-method="getSummaries"
  984. :header-row-style="{
  985. color: '#515a6e',
  986. }"
  987. >
  988. <ux-table-column
  989. title="序号"
  990. type="index"
  991. width="60"
  992. ></ux-table-column>
  993. <ux-table-column
  994. v-for="(cColumn, cIndex) in column.tableColumns.filter(
  995. (item) => item.hidden
  996. )"
  997. :key="cColumn.key + cColumn.hidden"
  998. :field="cColumn.key"
  999. :title="cColumn.title"
  1000. :width="cColumn.width || 80"
  1001. resizable
  1002. >
  1003. <template slot="header" slot-scope="scope">
  1004. <span v-if="cColumn.require" style="color: #ff4949">*</span>
  1005. <span>
  1006. {{ cColumn.title }}
  1007. </span>
  1008. </template>
  1009. <template slot-scope="scope">
  1010. <el-form-item label-width="0">
  1011. <span v-if="!cColumn.inputType">
  1012. {{ scope.row[cColumn.key] }}
  1013. </span>
  1014. <el-input
  1015. v-if="cColumn.inputType === 'Input'"
  1016. v-model="scope.row[cColumn.key]"
  1017. :placeholder="cColumn.placeholder"
  1018. :clearable="cColumn.clearable"
  1019. :disabled="cColumn.disabled"
  1020. :size="size"
  1021. style="width: 100%"
  1022. @change="
  1023. (prop) =>
  1024. inputTabChange(prop, {
  1025. column: cColumn,
  1026. source: scope.row,
  1027. })
  1028. "
  1029. ></el-input>
  1030. <dr-popover-select
  1031. v-if="cColumn.inputType === 'PopoverSelect'"
  1032. v-model="scope.row[cColumn.key]"
  1033. :source.sync="scope.row"
  1034. :title="cColumn.title"
  1035. :value-key="cColumn.valueKey"
  1036. :disabled="cColumn.disabled"
  1037. :copy="cColumn.copy"
  1038. :type="cColumn.referName"
  1039. :multiple="cColumn.multiple"
  1040. :placeholder="cColumn.placeholder"
  1041. :data-mapping="cColumn.dataMapping"
  1042. :query-params="
  1043. cColumn.key !== 'goodsAllocationName'
  1044. ? cColumn.queryParams
  1045. : () => ({
  1046. stordocId: params.warehouse,
  1047. pkOrg: params.puOrg,
  1048. })
  1049. "
  1050. :size="size"
  1051. @change="handleTabReferChange"
  1052. @copyChange="
  1053. (prop) =>
  1054. tabCopyChange(prop, {
  1055. column: cColumn,
  1056. source: scope.row,
  1057. })
  1058. "
  1059. ></dr-popover-select>
  1060. <el-select
  1061. v-if="cColumn.inputType === 'Select'"
  1062. v-model="scope.row[cColumn.key]"
  1063. :size="size"
  1064. :disabled="cColumn.disabled"
  1065. :clearable="cColumn.clearable"
  1066. :placeholder="cColumn.placeholder"
  1067. style="width: 100%"
  1068. @change="handleTabSelectChange(cColumn.key, scope.row)"
  1069. >
  1070. <el-option
  1071. v-for="item in dict.type[cColumn.referName]"
  1072. :key="item.value"
  1073. :label="item.label"
  1074. :value="item.value"
  1075. ></el-option>
  1076. </el-select>
  1077. <el-checkbox
  1078. v-if="cColumn.inputType === 'Checkbox'"
  1079. v-model="scope.row[cColumn.key]"
  1080. :disabled="cColumn.disabled"
  1081. true-label="Y"
  1082. false-label="N"
  1083. @change="handleTabCheckbox(cColumn.key, scope.row)"
  1084. ></el-checkbox>
  1085. <el-input-number
  1086. v-if="cColumn.inputType === 'InputNumber'"
  1087. v-model="scope.row[cColumn.key]"
  1088. :precision="cColumn.precision"
  1089. :controls-position="cColumn.controlsPosition"
  1090. :max="getInputNumberMax(cColumn.key, scope.row)"
  1091. :min="cColumn.key === 'reservedQty' ? 0 : -Infinity"
  1092. @change="handleInputChange(scope.row, cColumn.key)"
  1093. :placeholder="cColumn.placeholder"
  1094. :clearable="cColumn.clearable"
  1095. :disabled="cColumn.disabled"
  1096. :size="size"
  1097. style="width: 100%"
  1098. ></el-input-number>
  1099. </el-form-item>
  1100. </template>
  1101. </ux-table-column>
  1102. <!-- 修订:不可删除、增行
  1103. 编辑:自制:可删可增 -->
  1104. <!-- v-if="!handleIsRevise()" -->
  1105. <ux-table-column
  1106. v-if="!handleIsRevise()"
  1107. fixed="right"
  1108. label="操作"
  1109. width="120"
  1110. >
  1111. <template slot-scope="scope">
  1112. <el-button
  1113. @click.native.prevent="
  1114. delTableRow(params[tabName], scope.row, tabName)
  1115. "
  1116. type="text"
  1117. :size="size"
  1118. >
  1119. 删行
  1120. </el-button>
  1121. </template>
  1122. </ux-table-column>
  1123. </ux-grid>
  1124. <!-- </template>
  1125. </virtual-scroll> -->
  1126. </el-tab-pane>
  1127. </el-tabs>
  1128. <el-row style="position: absolute; top: 20px; right: 20px">
  1129. <el-button
  1130. v-if="params.source == '3' && !handleIsRevise()"
  1131. :size="size"
  1132. @click="addTableRow(params[tabName])"
  1133. >增行</el-button
  1134. >
  1135. <BatchImport
  1136. v-if="params.source == '3' && !handleIsRevise()"
  1137. ref="batchImport"
  1138. @import="handelImport"
  1139. @temDownload="handleTemDownload"
  1140. :fileSize="2"
  1141. ></BatchImport>
  1142. </el-row>
  1143. <el-row style="margin-top: 10px">
  1144. <el-col>
  1145. <button-hide v-model="innerColumns" @change="onHide"></button-hide>
  1146. </el-col>
  1147. </el-row>
  1148. </el-card>
  1149. </el-form>
  1150. </el-drawer>
  1151. </template>
  1152. <style scoped>
  1153. .orderEditForm >>> .el-form-item {
  1154. margin-bottom: 5px;
  1155. }
  1156. ::v-deep .singleTable .el-form-item {
  1157. margin-bottom: 0px;
  1158. }
  1159. ::v-deep.uxbeautifyTableClass
  1160. .elx-header--column
  1161. .elx-resizable.is--line:before {
  1162. height: 100%;
  1163. background-color: #dfe6ec;
  1164. }
  1165. </style>