index.vue 22 KB

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