index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <script>
  2. import orderApi from "@/api/business/purchase/purchase-order";
  3. import { initColumns, initDicts, initRules, initParams } from "@/utils/init";
  4. import { async } from "q";
  5. import { Columns, TabColumns } from "./column";
  6. const NewColumns = initColumns(Columns);
  7. const NewTabColumns = TabColumns.map((element) => ({
  8. ...element,
  9. tableColumns: initColumns(element.tableColumns),
  10. }));
  11. const SelectColumns = NewColumns.filter(
  12. (column) => column.inputType === "Select"
  13. );
  14. NewTabColumns.forEach((column) => {
  15. SelectColumns.push(
  16. ...column.tableColumns.filter((cColumn) => cColumn.inputType === "Select")
  17. );
  18. });
  19. export default {
  20. name: "AddPurchaseOrderDrawer",
  21. dicts: initDicts(SelectColumns),
  22. components: {
  23. FileUploadCenter: () => import("../components/FileUploadCenter/index.vue"),
  24. popDialog: () => import("@/components/PopDialog/index.vue"),
  25. },
  26. data() {
  27. return {
  28. visible: false,
  29. columns: NewColumns,
  30. rules: initRules(NewColumns),
  31. params: {
  32. ...initParams(NewColumns),
  33. puOrderItemList: [],
  34. puOrderExecuteList: [],
  35. },
  36. tabColumns: NewTabColumns,
  37. tabName: "puOrderItemList",
  38. };
  39. },
  40. computed: {},
  41. watch: {
  42. "params.puOrderItemList": {
  43. handler(nVal, oVal) {
  44. this.visible &&
  45. this.handleSynchronousMaterial(
  46. "puOrderItemList",
  47. "puOrderExecuteList"
  48. );
  49. },
  50. deep: true,
  51. },
  52. "params.puOrderExecuteList": {
  53. handler(nVal, oVal) {
  54. this.visible &&
  55. this.handleSynchronousMaterial(
  56. "puOrderExecuteList",
  57. "puOrderItemList"
  58. );
  59. },
  60. deep: true,
  61. },
  62. params: {
  63. handler(nVal, oVal) {
  64. // 组织变化
  65. if (this.visible && nVal.puOrg != oVal.puOrg) {
  66. for (const key in this.params) {
  67. if (Array.isArray(this.params[key])) {
  68. this.params[key] = [];
  69. } else if (
  70. key != "puOrg" &&
  71. key != "puOrgName" &&
  72. key != "buyer" &&
  73. key != "buyerName" &&
  74. key != "puDept" &&
  75. key != "puDeptName" &&
  76. key != "status"
  77. ) {
  78. this.params[key] = "";
  79. } else {
  80. }
  81. }
  82. }
  83. },
  84. deep: true,
  85. },
  86. },
  87. methods: {
  88. beforeOpen() {
  89. const { deptName, deptId, name, nickName, orgName, orgId } = this.$store.state.user;
  90. this.params.puOrg = orgId;
  91. this.params.puOrgName = orgName;
  92. this.params.buyer = name;
  93. this.params.buyerName = nickName;
  94. this.params.puDept = deptId;
  95. this.params.puDeptName = deptName;
  96. this.params.billDate = new Date().Format('yyyy-MM-dd');
  97. this.addTableRow();
  98. },
  99. setVisible(prop) {
  100. this.visible = prop;
  101. if(!this.visible){
  102. this.$refs['orderAddForm'].clearValidate();
  103. }
  104. },
  105. // 复制赋值
  106. async setCopyParams(id) {
  107. try {
  108. const { code, msg, data } = await orderApi.details(id);
  109. if (code === 200) {
  110. this.params = {
  111. ...data,
  112. id: "",
  113. code: "",
  114. status: "0",
  115. source: "3",
  116. paymentMoney:'',
  117. applyPaymentMoney:'',
  118. closeTime:'',
  119. isClose:'N',
  120. isSendWms:'N',
  121. rebateMoney:'',
  122. isInvoice:'N',
  123. invoiceMoney:'',
  124. isEnd:'N',
  125. };
  126. for (const key in this.params) {
  127. // if (Array.isArray(this.params[key])) {
  128. if (key === 'puOrderItemList' || key === 'puOrderExecuteList') {
  129. this.params[key].forEach((v) => {
  130. v.id = "";
  131. });
  132. }
  133. }
  134. // 清空 累计本币开票金额、
  135. // 累计付款金额、累计付款申请金额、累计开票主数量、最终关闭时间
  136. // 、最终关闭、已同步WMS 、订单抵扣余额金额、订单使用返利金额、 发票标识
  137. }
  138. } catch (err) {
  139. //
  140. } finally {
  141. // this.loading = false;
  142. }
  143. },
  144. // 增行
  145. addTableRow(prop) {
  146. for (const key in this.params) {
  147. // if (Array.isArray(this.params[key])) {
  148. if (key === 'puOrderItemList' || key === 'puOrderExecuteList') {
  149. const arr = this.tabColumns.find(
  150. (element) => element.key === key
  151. ).tableColumns;
  152. let rowData = initParams(arr, "key", "value");
  153. "rowno" in rowData &&
  154. (rowData["rowno"] = this.params[key].length + 1);
  155. // 物料
  156. if("rowNo" in rowData){
  157. rowData["rowNo"] = this.params[key].length + 1;
  158. // 扣税类别
  159. rowData["taxDeductClassify"] = '1';
  160. // 价格类型
  161. rowData["priceType"] = 'order';
  162. // 币种
  163. rowData["currency"] = '1002Z0100000000001K1';
  164. rowData["currencyName"] = '人民币';
  165. }
  166. // 是否完成询价,新增明细行需默认明细为false
  167. rowData["whetherCompleteInquiry"] = false;
  168. this.params[key].push(rowData);
  169. }
  170. }
  171. // const arr = this.tabColumns.find(
  172. // (element) => element.key === this.tabName
  173. // ).tableColumns;
  174. // prop.push(initParams(arr, "key", "value"));
  175. },
  176. // 删行
  177. delTableRow(prop, index) {
  178. for (const key in this.params) {
  179. if (Array.isArray(this.params[key])) {
  180. this.params[key].splice(index, 1);
  181. }
  182. }
  183. // prop.splice(index, 1);
  184. },
  185. // 同步子表物料
  186. handleSynchronousMaterial(tableOne, tableTwo) {
  187. let _this = this;
  188. // this.params[tableOne]-- -> this.params[tableTwo]
  189. this.params[tableOne] &&
  190. this.params[tableOne].forEach((item, index) => {
  191. for (const key in item) {
  192. if (key in _this.params[tableTwo][index]) {
  193. _this.params[tableTwo][index].material = item.material;
  194. key !== 'id' && ( _this.params[tableTwo][index][key] = item[key]);
  195. }
  196. }
  197. });
  198. },
  199. // 取消
  200. handleCancel() {
  201. this.params = {
  202. ...initParams(this.columns),
  203. puOrderItemList: [],
  204. puOrderExecuteList: [],
  205. };
  206. this.setVisible(false);
  207. },
  208. // 判断保存条件
  209. judgeSaveCondition(cb){
  210. this.$refs['orderAddForm'].validate(async (valid) => {
  211. if (valid) {
  212. if(!this.params['puOrderItemList'].length || !this.params['puOrderExecuteList'].length){
  213. this.$message.error('请填写订单行!');
  214. return false;
  215. }
  216. // puOrderItemList
  217. let isPrice = this.params.puOrderItemList.filter(item => !item.whetherCompleteInquiry);
  218. if(isPrice.length){
  219. this.$message.error('询价失败!');
  220. return false
  221. }
  222. console.log(isPrice,'isPrice');
  223. cb();
  224. } else {
  225. this.$message.error('存在必填项未填写');
  226. console.log('error submit!!');
  227. return false;
  228. }
  229. });
  230. },
  231. // 保存
  232. handleSava() {
  233. console.log(this.params,'this.params---------');
  234. this.judgeSaveCondition(async()=>{
  235. try {
  236. this.loading = true;
  237. const { code, msg } = await orderApi.create(this.params);
  238. if (code === 200) {
  239. this.handleCancel();
  240. }
  241. } catch (err) {
  242. //
  243. } finally {
  244. this.loading = false;
  245. }
  246. })
  247. },
  248. // 保存并新增
  249. async handleSubmit() {
  250. this.judgeSaveCondition(async()=>{
  251. try {
  252. const createById = this.params.buyer;
  253. const createByName = this.params.buyerName;
  254. const updateById = this.$store.state.user.id;
  255. const updateByName = this.$store.state.user.name;
  256. const { code, msg } = await orderApi.create({
  257. createById,
  258. createByName,
  259. updateById,
  260. updateByName,
  261. ...this.params,
  262. });
  263. if (code === 200) {
  264. this.setVisible(false);
  265. }
  266. } catch (err) {
  267. this.$notify.error({ title: "error", message: err });
  268. } finally {
  269. // this.setVisible(false);
  270. }
  271. })
  272. },
  273. // 主表参照改变之后
  274. async handleReferChange(val, type, source){
  275. // 供应商选择
  276. if( type === 'SUPPLIER_PARAM' ){
  277. let page = { pageNum: 1 , pageSize: 10 };
  278. let relevanceRefer = [
  279. {
  280. // 供应商联系人
  281. key:'supplierContacts',
  282. params:{
  283. type:'SUPPLIERCONTACTS_PARAM',
  284. supplierId:val.id,
  285. }
  286. },
  287. {
  288. // 供应商业务员
  289. key:'supplierPersonal',
  290. params:{
  291. type:'PSNLICENSE_PARAM',
  292. supplierId:val.id,
  293. pkOrg: source.puOrg,
  294. }
  295. }
  296. ]
  297. await relevanceRefer.forEach(async (refer) =>{
  298. try {
  299. const { code, rows} = await orderApi.REFER(
  300. {
  301. ...refer.params,
  302. search: "",
  303. isPage: true,
  304. }, page );
  305. if (code === 200) {
  306. source[refer.key] = rows[0]? rows[0].id :'';
  307. source[`${refer.key}Name`] = rows[0] ? rows[0].name :'';
  308. }
  309. } catch (error) {}
  310. })
  311. }
  312. },
  313. // 下拉框选择改变
  314. handleSelectChange(val,typeName){
  315. if(val === 'billType'){
  316. this.params['billTypeName'] = this.dict.type[typeName].find(item => item.value == this.params[val]).label;
  317. }
  318. },
  319. // 子表参照改变之后
  320. async handleTabReferChange(val, type, source) {
  321. // 触发物料参照询价 && source.qty && source.qty != ""
  322. if (type == "MATERIAL_PARAM" && source.qty && source.qty != "") {
  323. source['qty'] = 0;
  324. source['whetherCompleteInquiry'] = false;
  325. source['taxPrice'] = 0;
  326. source['money'] = 0;
  327. source['taxDeductMoneya'] = 0;
  328. source['price'] = 0;
  329. source['notaxMoney'] = 0;
  330. source['tax'] = 0;
  331. this.params['qty'] = 0;
  332. this.params['originalQty'] = 0;
  333. this.params['money'] = 0;
  334. this.params['originalMoney'] = 0;
  335. this.params['notaxMoney'] = 0;
  336. source.isDrug = val.materialMedcine.isDrug == '0' ? 'Y' : 'N';
  337. await this.handleGetPrice();
  338. }
  339. },
  340. // 子表下拉框改变
  341. async handleTabSelectChange(type,row){
  342. if(type == 'priceType' && row.material && row.qty && row.qty != ""){
  343. row['whetherCompleteInquiry'] = false;
  344. await this.handleGetPrice();
  345. }
  346. },
  347. // 子表inputNumber
  348. handleInputChange(row, type) {
  349. // 物料数量变化----询价
  350. if (type == "qty" && row.material) {
  351. row['whetherCompleteInquiry'] = false;
  352. this.handleGetPrice();
  353. }
  354. },
  355. // 子表多选框改变
  356. handleTabCheckbox(type,source){
  357. // 勾选赠品,价税合计更新为0,含税单价、无税单价更新为0
  358. if(type === 'isGift' && source.material && source.qty && source.qty != ""){
  359. source['whetherCompleteInquiry'] = false;
  360. this.handleGetPrice()
  361. }
  362. },
  363. // 询价 getPrice
  364. async handleGetPrice() {
  365. try {
  366. // let { puOrg, priceType, customer, assignSupplier, material, } = data;
  367. let { code, data } = await orderApi.getPrice({ ...this.params });
  368. if (code == 200) {
  369. this.params = data;
  370. }
  371. } catch (error) {
  372. } finally {
  373. }
  374. },
  375. },
  376. created() {
  377. console.log("ADD CREATED", this.params);
  378. },
  379. mounted() {},
  380. destroyed() {},
  381. };
  382. </script>
  383. <template>
  384. <el-drawer
  385. direction="btt"
  386. size="100%"
  387. :with-header="false"
  388. :visible.sync="visible"
  389. @open="beforeOpen"
  390. @close="$emit('close')"
  391. >
  392. <el-form
  393. size="mini"
  394. label-position="right"
  395. ref="orderAddForm"
  396. label-width="140px"
  397. :model="params"
  398. :rules="rules"
  399. >
  400. <el-card
  401. :body-style="{
  402. padding: '20px',
  403. display: 'flex',
  404. 'flex-wrap': 'wrap',
  405. }"
  406. style="margin: 10px"
  407. >
  408. <div
  409. slot="header"
  410. style="
  411. display: flex;
  412. justify-content: space-between;
  413. align-items: center;
  414. "
  415. >
  416. <h3>新增</h3>
  417. <div style="text-align: right">
  418. <el-button size="mini" @click="handleCancel">取消</el-button>
  419. <el-button
  420. size="mini"
  421. type="danger"
  422. @click="handleSava"
  423. >保存</el-button>
  424. <!-- <el-button size="mini" type="info" @click="handleSubmit">
  425. 保存并新增
  426. </el-button> -->
  427. </div>
  428. </div>
  429. <el-row style="display: flex; flex-wrap: wrap">
  430. <el-col
  431. v-for="(column, index) in columns"
  432. :key="index"
  433. :span="column.span || 6"
  434. >
  435. <el-form-item
  436. :prop="column.key"
  437. :label="column.title"
  438. v-if="column.isShow"
  439. >
  440. <el-input
  441. v-if="column.inputType === 'Input'"
  442. v-model="params[column.key]"
  443. :placeholder="column.placeholder"
  444. :clearable="column.clearable"
  445. :disabled="column.disabled"
  446. style="width: 100%"
  447. >
  448. </el-input>
  449. <dr-popover-select
  450. v-if="column.inputType === 'PopoverSelect'"
  451. v-model="params[column.key]"
  452. :value-key="column.valueKey"
  453. :source.sync="params"
  454. :title="column.title"
  455. :type="column.referName"
  456. :disabled="column.disabled"
  457. :multiple="column.multiple"
  458. :placeholder="column.placeholder"
  459. :data-mapping="column.dataMapping"
  460. :query-params="column.queryParams"
  461. @change="handleReferChange"
  462. ></dr-popover-select>
  463. <el-input
  464. v-if="column.inputType === 'Textarea'"
  465. v-model="params[column.key]"
  466. type="textarea"
  467. :placeholder="column.placeholder"
  468. :clearable="column.clearable"
  469. :disabled="column.disabled"
  470. style="width: 100%"
  471. ></el-input>
  472. <el-input-number
  473. v-if="column.inputType === 'InputNumber'"
  474. v-model="params[column.key]"
  475. :controls-position="column.controlsPosition"
  476. :placeholder="column.placeholder"
  477. :clearable="column.clearable"
  478. :disabled="column.disabled"
  479. style="width: 100%"
  480. >
  481. </el-input-number>
  482. <el-select
  483. v-if="column.inputType === 'Select'"
  484. v-model="params[column.key]"
  485. :disabled="column.disabled"
  486. :clearable="column.clearable"
  487. :placeholder="column.placeholder"
  488. style="width: 100%"
  489. @change="handleSelectChange(column.key,column.referName)"
  490. >
  491. <el-option
  492. v-for="item in dict.type[column.referName]"
  493. :key="item.value"
  494. :label="item.label"
  495. :value="item.value"
  496. ></el-option>
  497. </el-select>
  498. <el-select
  499. v-if="column.inputType === 'TagSelect'"
  500. v-model="params[column.key]"
  501. multiple
  502. clearable
  503. collapse-tags
  504. :placeholder="column.placeholder"
  505. :clearable="column.clearable"
  506. :disabled="column.disabled"
  507. style="width: 100%"
  508. >
  509. <template #prefix>
  510. <el-icon
  511. class="el-icon-view"
  512. style="cursor: pointer"
  513. @click.stop="$message.info(234)"
  514. >
  515. </el-icon>
  516. </template>
  517. <el-option
  518. v-for="item in options"
  519. :key="item.value"
  520. :label="item.label"
  521. :value="item.value"
  522. ></el-option>
  523. </el-select>
  524. <el-date-picker
  525. v-if="column.inputType === 'DatePicker'"
  526. v-model="params[column.key]"
  527. :type="column.type"
  528. :placeholder="column.placeholder"
  529. :clearable="column.clearable"
  530. :disabled="column.disabled"
  531. :picker-options="column.pickerOptions"
  532. style="width: 100%"
  533. ></el-date-picker>
  534. <el-checkbox
  535. v-if="column.inputType === 'Checkbox'"
  536. v-model="params[column.key]"
  537. :disabled="column.disabled"
  538. true-label="Y"
  539. false-label="N"
  540. ></el-checkbox>
  541. <file-upload-center
  542. v-if="column.inputType === 'Upload'"
  543. v-model="params[column.key]"
  544. :file-type="column.fileType"
  545. ></file-upload-center>
  546. </el-form-item>
  547. </el-col>
  548. </el-row>
  549. </el-card>
  550. <el-card
  551. :body-style="{
  552. padding: '20px',
  553. display: 'flex',
  554. 'flex-wrap': 'wrap',
  555. position: 'relative',
  556. }"
  557. style="margin: 10px"
  558. >
  559. <el-tabs v-model="tabName" style="width: 100%">
  560. <el-tab-pane
  561. v-for="(column, index) in tabColumns"
  562. :key="index"
  563. :label="column.title"
  564. :name="column.key"
  565. >
  566. <el-table
  567. :data="params[column.key]"
  568. style="width: 100%"
  569. :height="params[column.key].length ? 300 : 100"
  570. >
  571. <el-table-column
  572. v-for="(cColumn, cIndex) in column.tableColumns"
  573. :key="cIndex"
  574. :label="cColumn.title"
  575. :width="cColumn.width || 80"
  576. >
  577. <template slot-scope="scope">
  578. <el-form-item
  579. label-width="0"
  580. :prop="`${column.key}.${scope.$index}.${[cColumn.key]}`"
  581. :rules="{ required: cColumn.require || false, message: `${cColumn.title}不能为空`, trigger: 'change' }"
  582. >
  583. <el-tag v-if="cColumn.key === 'index'" >
  584. {{ scope.$index + 1 }}
  585. </el-tag>
  586. <el-input
  587. v-if="cColumn.inputType === 'Input'"
  588. v-model="scope.row[cColumn.key]"
  589. :placeholder="cColumn.placeholder"
  590. :clearable="cColumn.clearable"
  591. :disabled="cColumn.disabled"
  592. size="mini"
  593. style="width: 100%"
  594. ></el-input>
  595. <!-- -->
  596. <dr-popover-select
  597. v-if="cColumn.inputType === 'PopoverSelect'"
  598. v-model="scope.row[cColumn.key]"
  599. :source.sync="scope.row"
  600. :title="cColumn.title"
  601. :value-key="cColumn.valueKey"
  602. :type="cColumn.referName"
  603. :disabled="cColumn.disabled"
  604. :multiple="cColumn.multiple"
  605. :placeholder="cColumn.placeholder"
  606. :data-mapping="cColumn.dataMapping"
  607. :query-params="cColumn.queryParams"
  608. @change="handleTabReferChange"
  609. size="mini"
  610. >
  611. </dr-popover-select>
  612. <el-input-number
  613. v-if="cColumn.inputType === 'InputNumber'"
  614. v-model="scope.row[cColumn.key]"
  615. :controls-position="cColumn.controlsPosition"
  616. :placeholder="cColumn.placeholder"
  617. @change="handleInputChange(scope.row, cColumn.key)"
  618. :clearable="cColumn.clearable"
  619. :disabled="cColumn.disabled"
  620. size="mini"
  621. style="width: 100%"
  622. ></el-input-number>
  623. <el-select
  624. v-if="cColumn.inputType === 'Select'"
  625. v-model="scope.row[cColumn.key]"
  626. size="mini"
  627. :disabled="cColumn.disabled"
  628. :clearable="cColumn.clearable"
  629. :placeholder="cColumn.placeholder"
  630. style="width: 100%"
  631. @change="handleTabSelectChange(cColumn.key,scope.row)"
  632. >
  633. <el-option
  634. v-for="item in dict.type[cColumn.referName]"
  635. :key="item.value"
  636. :label="item.label"
  637. :value="item.value"
  638. ></el-option>
  639. </el-select>
  640. <el-checkbox
  641. v-if="cColumn.inputType === 'Checkbox'"
  642. v-model="scope.row[cColumn.key]"
  643. :disabled="cColumn.disabled"
  644. true-label="Y"
  645. false-label="N"
  646. @change="handleTabCheckbox(cColumn.key,scope.row)"
  647. ></el-checkbox>
  648. </el-form-item>
  649. </template>
  650. </el-table-column>
  651. <el-table-column fixed="right" label="操作" width="80">
  652. <template slot-scope="scope">
  653. <el-button
  654. @click.native.prevent="
  655. delTableRow(params[tabName], scope.$index)
  656. "
  657. type="text"
  658. size="small"
  659. >
  660. 删行
  661. </el-button>
  662. </template>
  663. </el-table-column>
  664. </el-table>
  665. </el-tab-pane>
  666. </el-tabs>
  667. <el-row style="position: absolute; top: 20px; right: 20px">
  668. <el-button size="mini" @click="addTableRow(params[tabName])"
  669. >增行</el-button
  670. >
  671. </el-row>
  672. </el-card>
  673. </el-form>
  674. </el-drawer>
  675. </template>