index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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";
  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(this.params.status) ?
  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. },
  238. // 子表参照改变之后
  239. async handleTabReferChange(val, type, source) {
  240. // 触发物料参照
  241. if (type == "MATERIAL_PARAM" && source.qty && source.qty != "") {
  242. source['qty'] = 0;
  243. source['whetherCompleteInquiry'] = false;
  244. source['taxPrice'] = 0;
  245. source['money'] = 0;
  246. source['taxDeductMoneya'] = 0;
  247. source['price'] = 0;
  248. source['notaxMoney'] = 0;
  249. source['tax'] = 0;
  250. this.params['qty'] = 0;
  251. this.params['originalQty'] = 0;
  252. this.params['money'] = 0;
  253. this.params['originalMoney'] = 0;
  254. this.params['notaxMoney'] = 0;
  255. source.isDrug = val.materialMedcine.isDrug == '0' ? 'Y' : 'N';
  256. // await this.handleGetPrice();
  257. }
  258. },
  259. // 子表Select改变之后
  260. handleSelectChange(val,typeName){
  261. if(val === 'billType'){
  262. this.params['billTypeName'] = this.dict.type[typeName].find(item => item.value == this.params[val]).label;
  263. }
  264. },
  265. // 子表下拉框改变
  266. handleTabSelectChange(type,row){
  267. if(type == 'priceType' && row.material && row.qty && row.qty != ""){
  268. row['whetherCompleteInquiry'] = false;
  269. this.handleGetPrice();
  270. }
  271. },
  272. // 子表inputNumber
  273. handleInputChange(row, type) {
  274. // 物料数量变化----询价
  275. if (type == 'qty' && row.material) {
  276. row['whetherCompleteInquiry'] = false;
  277. row.qty && this.handleGetPrice();
  278. }
  279. },
  280. // 子表多选框改变
  281. handleTabCheckbox(type,source){
  282. // 勾选赠品,价税合计更新为0,含税单价、无税单价更新为0
  283. if(type === 'isGift' && source.material && source.qty && source.qty != ""){
  284. source['whetherCompleteInquiry'] = false;
  285. this.handleGetPrice()
  286. }
  287. },
  288. // 询价 getPrice
  289. async handleGetPrice() {
  290. try {
  291. // let { puOrg, priceType, customer, assignSupplier, material, } = data;
  292. let { code, data } = await orderApi.getPrice({ ...this.params })
  293. if (code == 200) {
  294. this.params = data;
  295. }
  296. } catch (error) {
  297. } finally {
  298. }
  299. },
  300. // 判断修订还是编辑
  301. handleIsRevise(status) {
  302. return status == '2';
  303. },
  304. },
  305. created() {},
  306. mounted() { },
  307. destroyed() { },
  308. };
  309. </script>
  310. <template>
  311. <el-drawer
  312. direction="btt"
  313. size="100%"
  314. :with-header="false"
  315. :visible.sync="visible"
  316. @open="beforeOpen"
  317. @close="$emit('close')"
  318. >
  319. <el-form
  320. :key="count"
  321. v-loading="loading"
  322. :size="size"
  323. ref="orderEditForm"
  324. label-position="right"
  325. label-width="140px"
  326. :model="params"
  327. :rules="rules"
  328. >
  329. <el-card :body-style="{
  330. padding: '20px',
  331. display: 'flex',
  332. 'flex-wrap': 'wrap',
  333. }" style="margin: 10px">
  334. <div slot="header" style="
  335. display: flex;
  336. justify-content: space-between;
  337. align-items: center;
  338. ">
  339. <h3>{{ handleIsRevise(params.status) ? '修订' : '编辑' }}</h3>
  340. <div style="text-align: right">
  341. <el-button :size="size" @click="handleCancel">取 消</el-button>
  342. <el-button :size="size" type="danger" @click="handleSava">更 新</el-button>
  343. </div>
  344. </div>
  345. <el-row style="display:flex; flex-wrap: wrap;">
  346. <el-col
  347. v-for="(column, index) in columns"
  348. :key="index"
  349. :span="column.span || 6"
  350. >
  351. <el-form-item :prop="column.key" :label="column.title" v-if="column.isShow">
  352. <el-input v-if="column.inputType === 'Input'"
  353. v-model="params[column.key]"
  354. :placeholder="column.placeholder"
  355. :clearable="column.clearable"
  356. :disabled="column.disabled"
  357. style="width: 100%"
  358. ></el-input>
  359. <dr-popover-select v-if="column.inputType === 'PopoverSelect'"
  360. v-model="params[column.key]"
  361. size="mini"
  362. :value-key="column.valueKey"
  363. :source.sync="params"
  364. :title="column.title"
  365. :type="column.referName"
  366. :multiple="column.multiple"
  367. :placeholder="column.placeholder"
  368. :data-mapping="column.dataMapping"
  369. :disabled="column.disabled"
  370. :query-params="column.queryParams"
  371. @change="handleReferChange"
  372. ></dr-popover-select>
  373. <el-input v-if="column.inputType === 'Textarea'"
  374. v-model="params[column.key]"
  375. type="textarea"
  376. :placeholder="column.placeholder"
  377. :clearable="column.clearable"
  378. :disabled="column.disabled"
  379. style="width: 100%"
  380. ></el-input>
  381. <el-input-number v-if="column.inputType === 'InputNumber'"
  382. v-model="params[column.key]"
  383. :max="handleIsRevise(params.status) ? params[column.key] : Infinity"
  384. :controls-position="column.controlsPosition"
  385. :placeholder="column.placeholder"
  386. :clearable="column.clearable"
  387. :disabled="column.disabled"
  388. style="width: 100%"
  389. ></el-input-number>
  390. <el-select v-if="column.inputType === 'Select'"
  391. v-model="params[column.key]"
  392. :disabled="column.disabled"
  393. :clearable="column.clearable"
  394. :placeholder="column.placeholder"
  395. style="width: 100%"
  396. @change="handleSelectChange(column.key,column.referName)"
  397. >
  398. <el-option
  399. v-for="item in dict.type[column.referName]"
  400. :key="item.value"
  401. :label="item.label"
  402. :value="item.value"
  403. ></el-option>
  404. </el-select>
  405. <el-select v-if="column.inputType === 'TagSelect'"
  406. v-model="params[column.key]"
  407. multiple
  408. clearable
  409. collapse-tags
  410. :placeholder="column.placeholder"
  411. :clearable="column.clearable"
  412. :disabled="column.disabled"
  413. style="width: 100%"
  414. >
  415. <template #prefix>
  416. <el-icon class="el-icon-view" style="cursor: pointer" @click.stop="$message.info(234)"></el-icon>
  417. </template>
  418. <el-option
  419. v-for="item in options"
  420. :key="item.value"
  421. :label="item.label"
  422. :value="item.value"
  423. ></el-option>
  424. </el-select>
  425. <el-date-picker v-if="column.inputType === 'DatePicker'"
  426. v-model="params[column.key]"
  427. :type="column.type"
  428. :placeholder="column.placeholder"
  429. :clearable="column.clearable"
  430. :disabled="column.disabled"
  431. :picker-options="column.pickerOptions"
  432. style="width: 100%"
  433. ></el-date-picker>
  434. <el-checkbox v-if="column.inputType === 'Checkbox'"
  435. v-model="params[column.key]"
  436. :disabled="column.disabled"
  437. true-label="Y"
  438. false-label="N"
  439. > </el-checkbox>
  440. <file-upload-center v-if="column.inputType === 'Upload'"
  441. v-model="params[column.key]"
  442. :file-type="column.fileType"
  443. :disabled="handleIsRevise(params.status)"
  444. ></file-upload-center>
  445. </el-form-item>
  446. </el-col>
  447. </el-row>
  448. </el-card>
  449. <el-card :body-style="{
  450. padding: '20px',
  451. display: 'flex',
  452. 'flex-wrap': 'wrap',
  453. position: 'relative',
  454. }" style="margin: 10px">
  455. <el-tabs v-model="tabName" style="width: 100%">
  456. <el-tab-pane
  457. v-for="(column, index) in tabColumns"
  458. :key="index"
  459. :label="column.title"
  460. :name="column.key"
  461. >
  462. <el-table
  463. :data="params[column.key].filter(item => item.delFlag === '0')"
  464. style="width: 100%"
  465. :height="params[column.key].filter(item => item.delFlag === '0').length ? 300 : 100"
  466. >
  467. <el-table-column label="序号">
  468. <template slot-scope="scope">
  469. {{ scope.$index + 1 }}
  470. </template>
  471. </el-table-column>
  472. <el-table-column
  473. v-for="(cColumn, cIndex) in column.tableColumns"
  474. :key="cIndex"
  475. :prop="cColumn.key"
  476. :label="cColumn.title"
  477. :width="cColumn.width"
  478. >
  479. <template slot-scope="scope">
  480. <el-form-item
  481. label-width="0"
  482. :prop="`${column.key}.${scope.$index}.${[cColumn.key]}`"
  483. :rules="{ required: cColumn.require || false, message: `${cColumn.title}不能为空`, trigger: 'change' }"
  484. >
  485. <span v-if="!cColumn.inputType">
  486. {{ scope.row[cColumn.key] }}
  487. </span>
  488. <el-input v-if="cColumn.inputType === 'Input'"
  489. v-model="scope.row[cColumn.key]"
  490. :placeholder="cColumn.placeholder"
  491. :clearable="cColumn.clearable"
  492. :disabled="cColumn.disabled"
  493. :size="size"
  494. style="width: 100%"
  495. ></el-input>
  496. <dr-popover-select v-if="cColumn.inputType === 'PopoverSelect'"
  497. v-model="scope.row[cColumn.key]"
  498. :source.sync="scope.row"
  499. :title="cColumn.title"
  500. :value-key="cColumn.valueKey"
  501. :disabled="cColumn.disabled"
  502. :type="cColumn.referName"
  503. :multiple="cColumn.multiple"
  504. :placeholder="cColumn.placeholder"
  505. :data-mapping="cColumn.dataMapping"
  506. :query-params="cColumn.queryParams"
  507. size="mini"
  508. @change="handleTabReferChange"
  509. ></dr-popover-select>
  510. <el-select v-if="cColumn.inputType === 'Select'"
  511. v-model="scope.row[cColumn.key]" size="mini"
  512. :disabled="cColumn.disabled"
  513. :clearable="cColumn.clearable"
  514. :placeholder="cColumn.placeholder"
  515. style="width: 100%"
  516. @change="handleTabSelectChange(cColumn.key,scope.row)"
  517. >
  518. <el-option
  519. v-for="item in dict.type[cColumn.referName]"
  520. :key="item.value"
  521. :label="item.label"
  522. :value="item.value"
  523. ></el-option>
  524. </el-select>
  525. <el-checkbox v-if="cColumn.inputType === 'Checkbox'"
  526. v-model="scope.row[cColumn.key]"
  527. :disabled="cColumn.disabled"
  528. true-label="Y"
  529. false-label="N"
  530. @change="handleTabCheckbox(cColumn.key,scope.row)"
  531. ></el-checkbox>
  532. <el-input-number v-if="cColumn.inputType === 'InputNumber'"
  533. v-model="scope.row[cColumn.key]"
  534. :controls-position="cColumn.controlsPosition"
  535. :max="handleIsRevise(params.status) ? scope.row[cColumn.key] : Infinity"
  536. @change="handleInputChange(scope.row, cColumn.key)"
  537. :placeholder="cColumn.placeholder"
  538. :clearable="cColumn.clearable"
  539. :disabled="cColumn.disabled"
  540. :size="size"
  541. style="width: 100%"
  542. ></el-input-number>
  543. </el-form-item>
  544. </template>
  545. </el-table-column>
  546. <!-- 修订:不可删除、增行
  547. 编辑:自制:可删可增 -->
  548. <el-table-column fixed="right" label="操作" width="120">
  549. <template slot-scope="scope">
  550. <el-button
  551. v-if="params.source == '3' && !handleIsRevise(params.status)"
  552. @click.native.prevent="delTableRow(params[tabName], scope.$index)"
  553. type="text"
  554. size="small"
  555. > 删行
  556. </el-button>
  557. </template>
  558. </el-table-column>
  559. </el-table>
  560. </el-tab-pane>
  561. </el-tabs>
  562. <el-row style="position: absolute; top: 20px; right: 20px">
  563. <el-button v-if="params.source == '3' && !handleIsRevise(params.status)" :size="size"
  564. @click="addTableRow(params[tabName])">增行</el-button>
  565. </el-row>
  566. </el-card>
  567. </el-form>
  568. </el-drawer>
  569. </template>