index.vue 21 KB

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