index.vue 34 KB

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