index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. isEnd:'N',
  115. status: "0",
  116. source: "3",
  117. isClose:'N',
  118. closeTime:'',
  119. isInvoice:'N',
  120. isSendWms:'N',
  121. rebateMoney:'',
  122. invoiceMoney:'',
  123. paymentMoney:'',
  124. applyPaymentMoney:'',
  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(!_this.params[tableTwo][index]){
  193. const arr = _this.tabColumns.find(
  194. (element) => element.key === tableTwo
  195. ).tableColumns;
  196. _this.params[tableTwo].push(initParams(arr, "key", "value"));
  197. }
  198. if (key in _this.params[tableTwo][index]) {
  199. _this.params[tableTwo][index].material = item.material;
  200. key !== 'id' && ( _this.params[tableTwo][index][key] = item[key]);
  201. }
  202. }
  203. });
  204. },
  205. // 取消
  206. handleCancel() {
  207. this.params = {
  208. ...initParams(this.columns),
  209. puOrderItemList: [],
  210. puOrderExecuteList: [],
  211. };
  212. this.setVisible(false);
  213. },
  214. // 判断保存条件
  215. judgeSaveCondition(cb){
  216. this.$refs['orderAddForm'].validate(async (valid) => {
  217. if (valid) {
  218. if(!this.params['puOrderItemList'].length || !this.params['puOrderExecuteList'].length){
  219. this.$message.error('请填写订单行!');
  220. return false;
  221. }
  222. // puOrderItemList
  223. let isPrice = this.params.puOrderItemList.filter(item => !item.whetherCompleteInquiry);
  224. if(isPrice.length){
  225. this.$message.error('询价失败!');
  226. return false
  227. }
  228. console.log(isPrice,'isPrice');
  229. cb();
  230. } else {
  231. this.$message.error('存在必填项未填写');
  232. console.log('error submit!!');
  233. return false;
  234. }
  235. });
  236. },
  237. // 保存
  238. handleSava() {
  239. console.log(this.params,'this.params---------');
  240. this.judgeSaveCondition(async()=>{
  241. try {
  242. this.loading = true;
  243. const { code, msg } = await orderApi.create(this.params);
  244. if (code === 200) {
  245. this.handleCancel();
  246. }
  247. } catch (err) {
  248. //
  249. } finally {
  250. this.loading = false;
  251. }
  252. })
  253. },
  254. // 保存并新增
  255. async handleSubmit() {
  256. this.judgeSaveCondition(async()=>{
  257. try {
  258. const createById = this.params.buyer;
  259. const createByName = this.params.buyerName;
  260. const updateById = this.$store.state.user.id;
  261. const updateByName = this.$store.state.user.name;
  262. const { code, msg } = await orderApi.create({
  263. createById,
  264. createByName,
  265. updateById,
  266. updateByName,
  267. ...this.params,
  268. });
  269. if (code === 200) {
  270. this.setVisible(false);
  271. }
  272. } catch (err) {
  273. this.$notify.error({ title: "error", message: err });
  274. } finally {
  275. // this.setVisible(false);
  276. }
  277. })
  278. },
  279. // 主表参照改变之后
  280. async handleReferChange(val, type, source){
  281. // 供应商选择
  282. if( type === 'SUPPLIER_PARAM' ){
  283. let page = { pageNum: 1 , pageSize: 10 };
  284. let relevanceRefer = [
  285. {
  286. // 供应商联系人
  287. key:'supplierContacts',
  288. params:{
  289. type:'SUPPLIERCONTACTS_PARAM',
  290. supplierId:val.id,
  291. }
  292. },
  293. {
  294. // 供应商业务员
  295. key:'supplierPersonal',
  296. params:{
  297. type:'PSNLICENSE_PARAM',
  298. supplierId:val.id,
  299. pkOrg: source.puOrg,
  300. }
  301. }
  302. ]
  303. await relevanceRefer.forEach(async (refer) =>{
  304. try {
  305. const { code, rows} = await orderApi.REFER(
  306. {
  307. ...refer.params,
  308. search: "",
  309. isPage: true,
  310. }, page );
  311. if (code === 200) {
  312. source[refer.key] = rows[0]? rows[0].id :'';
  313. source[`${refer.key}Name`] = rows[0] ? rows[0].name :'';
  314. }
  315. } catch (error) {}
  316. })
  317. }
  318. },
  319. // 下拉框选择改变
  320. handleSelectChange(val,typeName){
  321. if(val === 'billType'){
  322. this.params['billTypeName'] = this.dict.type[typeName].find(item => item.value == this.params[val]).label;
  323. }
  324. },
  325. // 子表参照改变之后
  326. async handleTabReferChange(val, type, source) {
  327. // 触发物料参照询价 && source.qty && source.qty != ""
  328. if (type == "MATERIAL_PARAM" && source.qty && source.qty != "") {
  329. source['qty'] = 0;
  330. source['whetherCompleteInquiry'] = false;
  331. source['taxPrice'] = 0;
  332. source['money'] = 0;
  333. source['taxDeductMoneya'] = 0;
  334. source['price'] = 0;
  335. source['notaxMoney'] = 0;
  336. source['tax'] = 0;
  337. this.params['qty'] = 0;
  338. this.params['originalQty'] = 0;
  339. this.params['money'] = 0;
  340. this.params['originalMoney'] = 0;
  341. this.params['notaxMoney'] = 0;
  342. source.isDrug = val.materialMedcine.isDrug == '0' ? 'Y' : 'N';
  343. // await this.handleGetPrice();
  344. }
  345. },
  346. // 子表下拉框改变
  347. async handleTabSelectChange(type,row){
  348. if(type == 'priceType' && row.material && row.qty && row.qty != ""){
  349. row['whetherCompleteInquiry'] = false;
  350. await this.handleGetPrice();
  351. }
  352. },
  353. // 子表inputNumber
  354. handleInputChange(row, type) {
  355. // 物料数量变化----询价
  356. if (type == "qty" && row.material) {
  357. row['whetherCompleteInquiry'] = false;
  358. row.qty && this.handleGetPrice();
  359. }
  360. },
  361. // 子表多选框改变
  362. handleTabCheckbox(type,source){
  363. // 勾选赠品,价税合计更新为0,含税单价、无税单价更新为0
  364. if(type === 'isGift' && source.material && source.qty && source.qty != ""){
  365. source['whetherCompleteInquiry'] = false;
  366. this.handleGetPrice()
  367. }
  368. },
  369. // 询价 getPrice
  370. async handleGetPrice() {
  371. try {
  372. // let { puOrg, priceType, customer, assignSupplier, material, } = data;
  373. let { code, data } = await orderApi.getPrice({ ...this.params });
  374. if (code == 200) {
  375. this.params = data;
  376. }
  377. } catch (error) {
  378. } finally {
  379. }
  380. },
  381. },
  382. created() {
  383. console.log("ADD CREATED", this.params);
  384. },
  385. mounted() {},
  386. destroyed() {},
  387. };
  388. </script>
  389. <template>
  390. <el-drawer
  391. direction="btt"
  392. size="100%"
  393. :with-header="false"
  394. :visible.sync="visible"
  395. @open="beforeOpen"
  396. @close="$emit('close')"
  397. >
  398. <el-form
  399. size="mini"
  400. label-position="right"
  401. ref="orderAddForm"
  402. label-width="140px"
  403. :model="params"
  404. :rules="rules"
  405. >
  406. <el-card
  407. :body-style="{
  408. padding: '20px',
  409. display: 'flex',
  410. 'flex-wrap': 'wrap',
  411. }"
  412. style="margin: 10px"
  413. >
  414. <div
  415. slot="header"
  416. style="
  417. display: flex;
  418. justify-content: space-between;
  419. align-items: center;
  420. "
  421. >
  422. <h3>新增</h3>
  423. <div style="text-align: right">
  424. <el-button size="mini" @click="handleCancel">取消</el-button>
  425. <el-button
  426. size="mini"
  427. type="danger"
  428. @click="handleSava"
  429. >保存</el-button>
  430. <!-- <el-button size="mini" type="info" @click="handleSubmit">
  431. 保存并新增
  432. </el-button> -->
  433. </div>
  434. </div>
  435. <el-row style="display: flex; flex-wrap: wrap">
  436. <el-col
  437. v-for="(column, index) in columns"
  438. :key="index"
  439. :span="column.span || 6"
  440. >
  441. <el-form-item
  442. :prop="column.key"
  443. :label="column.title"
  444. v-if="column.isShow"
  445. >
  446. <el-input
  447. v-if="column.inputType === 'Input'"
  448. v-model="params[column.key]"
  449. :placeholder="column.placeholder"
  450. :clearable="column.clearable"
  451. :disabled="column.disabled"
  452. style="width: 100%"
  453. >
  454. </el-input>
  455. <dr-popover-select
  456. v-if="column.inputType === 'PopoverSelect'"
  457. v-model="params[column.key]"
  458. :value-key="column.valueKey"
  459. :source.sync="params"
  460. :title="column.title"
  461. :type="column.referName"
  462. :disabled="column.disabled"
  463. :multiple="column.multiple"
  464. :placeholder="column.placeholder"
  465. :data-mapping="column.dataMapping"
  466. :query-params="column.queryParams"
  467. @change="handleReferChange"
  468. ></dr-popover-select>
  469. <el-input
  470. v-if="column.inputType === 'Textarea'"
  471. v-model="params[column.key]"
  472. type="textarea"
  473. :placeholder="column.placeholder"
  474. :clearable="column.clearable"
  475. :disabled="column.disabled"
  476. style="width: 100%"
  477. ></el-input>
  478. <el-input-number
  479. v-if="column.inputType === 'InputNumber'"
  480. v-model="params[column.key]"
  481. :controls-position="column.controlsPosition"
  482. :placeholder="column.placeholder"
  483. :clearable="column.clearable"
  484. :disabled="column.disabled"
  485. style="width: 100%"
  486. >
  487. </el-input-number>
  488. <el-select
  489. v-if="column.inputType === 'Select'"
  490. v-model="params[column.key]"
  491. :disabled="column.disabled"
  492. :clearable="column.clearable"
  493. :placeholder="column.placeholder"
  494. style="width: 100%"
  495. @change="handleSelectChange(column.key,column.referName)"
  496. >
  497. <el-option
  498. v-for="item in dict.type[column.referName]"
  499. :key="item.value"
  500. :label="item.label"
  501. :value="item.value"
  502. ></el-option>
  503. </el-select>
  504. <el-select
  505. v-if="column.inputType === 'TagSelect'"
  506. v-model="params[column.key]"
  507. multiple
  508. clearable
  509. collapse-tags
  510. :placeholder="column.placeholder"
  511. :clearable="column.clearable"
  512. :disabled="column.disabled"
  513. style="width: 100%"
  514. >
  515. <template #prefix>
  516. <el-icon
  517. class="el-icon-view"
  518. style="cursor: pointer"
  519. @click.stop="$message.info(234)"
  520. >
  521. </el-icon>
  522. </template>
  523. <el-option
  524. v-for="item in options"
  525. :key="item.value"
  526. :label="item.label"
  527. :value="item.value"
  528. ></el-option>
  529. </el-select>
  530. <el-date-picker
  531. v-if="column.inputType === 'DatePicker'"
  532. v-model="params[column.key]"
  533. :type="column.type"
  534. :placeholder="column.placeholder"
  535. :clearable="column.clearable"
  536. :disabled="column.disabled"
  537. :picker-options="column.pickerOptions"
  538. style="width: 100%"
  539. ></el-date-picker>
  540. <el-checkbox
  541. v-if="column.inputType === 'Checkbox'"
  542. v-model="params[column.key]"
  543. :disabled="column.disabled"
  544. true-label="Y"
  545. false-label="N"
  546. ></el-checkbox>
  547. <file-upload-center
  548. v-if="column.inputType === 'Upload'"
  549. v-model="params[column.key]"
  550. :file-type="column.fileType"
  551. ></file-upload-center>
  552. </el-form-item>
  553. </el-col>
  554. </el-row>
  555. </el-card>
  556. <el-card
  557. :body-style="{
  558. padding: '20px',
  559. display: 'flex',
  560. 'flex-wrap': 'wrap',
  561. position: 'relative',
  562. }"
  563. style="margin: 10px"
  564. >
  565. <el-tabs v-model="tabName" style="width: 100%">
  566. <el-tab-pane
  567. v-for="(column, index) in tabColumns"
  568. :key="index"
  569. :label="column.title"
  570. :name="column.key"
  571. >
  572. <el-table
  573. :data="params[column.key]"
  574. style="width: 100%"
  575. :height="params[column.key].length ? 300 : 100"
  576. >
  577. <el-table-column
  578. v-for="(cColumn, cIndex) in column.tableColumns"
  579. :key="cIndex"
  580. :label="cColumn.title"
  581. :width="cColumn.width || 80"
  582. >
  583. <template slot-scope="scope">
  584. <el-form-item
  585. label-width="0"
  586. :prop="`${column.key}.${scope.$index}.${[cColumn.key]}`"
  587. :rules="{ required: cColumn.require || false, message: `${cColumn.title}不能为空`, trigger: 'change' }"
  588. >
  589. <el-tag v-if="cColumn.key === 'index'" >
  590. {{ scope.$index + 1 }}
  591. </el-tag>
  592. <el-input
  593. v-if="cColumn.inputType === 'Input'"
  594. v-model="scope.row[cColumn.key]"
  595. :placeholder="cColumn.placeholder"
  596. :clearable="cColumn.clearable"
  597. :disabled="cColumn.disabled"
  598. size="mini"
  599. style="width: 100%"
  600. ></el-input>
  601. <!-- -->
  602. <dr-popover-select
  603. v-if="cColumn.inputType === 'PopoverSelect'"
  604. v-model="scope.row[cColumn.key]"
  605. :source.sync="scope.row"
  606. :title="cColumn.title"
  607. :value-key="cColumn.valueKey"
  608. :type="cColumn.referName"
  609. :disabled="cColumn.disabled"
  610. :multiple="cColumn.multiple"
  611. :placeholder="cColumn.placeholder"
  612. :data-mapping="cColumn.dataMapping"
  613. :query-params="cColumn.queryParams"
  614. @change="handleTabReferChange"
  615. size="mini"
  616. >
  617. </dr-popover-select>
  618. <el-input-number
  619. v-if="cColumn.inputType === 'InputNumber'"
  620. v-model="scope.row[cColumn.key]"
  621. :controls-position="cColumn.controlsPosition"
  622. :placeholder="cColumn.placeholder"
  623. @change="handleInputChange(scope.row, cColumn.key)"
  624. :clearable="cColumn.clearable"
  625. :disabled="cColumn.disabled"
  626. size="mini"
  627. style="width: 100%"
  628. ></el-input-number>
  629. <el-select
  630. v-if="cColumn.inputType === 'Select'"
  631. v-model="scope.row[cColumn.key]"
  632. size="mini"
  633. :disabled="cColumn.disabled"
  634. :clearable="cColumn.clearable"
  635. :placeholder="cColumn.placeholder"
  636. style="width: 100%"
  637. @change="handleTabSelectChange(cColumn.key,scope.row)"
  638. >
  639. <el-option
  640. v-for="item in dict.type[cColumn.referName]"
  641. :key="item.value"
  642. :label="item.label"
  643. :value="item.value"
  644. ></el-option>
  645. </el-select>
  646. <el-checkbox
  647. v-if="cColumn.inputType === 'Checkbox'"
  648. v-model="scope.row[cColumn.key]"
  649. :disabled="cColumn.disabled"
  650. true-label="Y"
  651. false-label="N"
  652. @change="handleTabCheckbox(cColumn.key,scope.row)"
  653. ></el-checkbox>
  654. </el-form-item>
  655. </template>
  656. </el-table-column>
  657. <el-table-column fixed="right" label="操作" width="80">
  658. <template slot-scope="scope">
  659. <el-button
  660. @click.native.prevent="
  661. delTableRow(params[tabName], scope.$index)
  662. "
  663. type="text"
  664. size="small"
  665. >
  666. 删行
  667. </el-button>
  668. </template>
  669. </el-table-column>
  670. </el-table>
  671. </el-tab-pane>
  672. </el-tabs>
  673. <el-row style="position: absolute; top: 20px; right: 20px">
  674. <el-button size="mini" @click="addTableRow(params[tabName])"
  675. >增行</el-button
  676. >
  677. </el-row>
  678. </el-card>
  679. </el-form>
  680. </el-drawer>
  681. </template>