addDialog.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" :rules="rules" label-width="120px" >
  4. <headerTitle title="基本信息"></headerTitle>
  5. <el-row>
  6. <el-col :span="12">
  7. <el-form-item
  8. label="采购计划单名称"
  9. prop="planCode"
  10. style="margin-bottom: 22px"
  11. >
  12. <el-input
  13. @click.native="handParent"
  14. v-model="form.planName"
  15. placeholder="请选择"
  16. :disabled="isView"
  17. ></el-input>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="12">
  21. <el-form-item
  22. label="询价单名称"
  23. prop="inquiryName"
  24. style="margin-bottom: 22px"
  25. >
  26. <el-input v-model="form.inquiryName" :disabled="isView"></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="12">
  30. <el-form-item prop="remark" label="是否接受拆单" label-width="120px">
  31. <el-select
  32. v-model="form.acceptUnpack"
  33. clearable
  34. style="width: 100%"
  35. disabled
  36. >
  37. <el-option
  38. v-for="item in acceptUnpackList"
  39. :key="item.value"
  40. :label="item.label"
  41. :value="item.value"
  42. >
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="12">
  48. <el-form-item prop="files" label="附件">
  49. <fileMain v-model="form.files" :type="isView?'view':'add'"></fileMain>
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="12">
  53. <el-form-item prop="remark" label="备注">
  54. <el-input
  55. type="textarea"
  56. resize="none"
  57. v-model="form.remark"
  58. :rows="2"
  59. placeholder="请输入" :disabled="isView"
  60. size="small"
  61. maxlength="200"
  62. ></el-input>
  63. </el-form-item>
  64. </el-col>
  65. </el-row>
  66. </el-form>
  67. <headerTitle title="物品清单" style="margin-top: 15px"></headerTitle>
  68. <el-button type="primary" @click="openSupplier" v-if="!isView">新增供应商</el-button>
  69. <el-button
  70. type="primary"
  71. style="margin-bottom: 10px"
  72. @click="supplierSelectAll"
  73. v-click-once
  74. >批量生成报价单</el-button
  75. >
  76. <inventoryTable
  77. ref="inventoryTable"
  78. @delList="delList"
  79. :acceptUnpack="form.acceptUnpack"
  80. @supplierSelect="supplierSelect"
  81. :status="isView?'Detail':''"
  82. ></inventoryTable>
  83. <headerTitle title="报价清单" style="margin-top: 15px"></headerTitle>
  84. <inquiryManageList
  85. ref="inquiryManageRef"
  86. @changeInquiryManageList="changeInquiryManageList"
  87. @supplierSelect="supplierSelect"
  88. @supplierManageChange="supplierManageChange"
  89. ></inquiryManageList>
  90. <supplierManageDialog
  91. ref="supplierManageDialogRef"
  92. @supplierManageChange="supplierManageChange"
  93. ></supplierManageDialog>
  94. <inquiryTable
  95. @removeSupplier="removeSupplier"
  96. :ref="'inquiryTable' + item.supplierId"
  97. v-for="item in supplierList"
  98. :key="item.supplierId"
  99. style="margin-top: 15px"
  100. :obj="item"
  101. :isUpdate="isUpdate"
  102. @deliveryDateChange="deliveryDateChange"
  103. :status="isView?'Detail':'edit'"
  104. ></inquiryTable>
  105. </div>
  106. </template>
  107. <script>
  108. import inventoryTable from './inventoryTable.vue';
  109. import inquiryTable from './inquiryTable.vue';
  110. import inquiryManageList from './inquiryManage-list.vue';
  111. import supplierManageDialog from './supplierManageDialog.vue';
  112. import fileUpload from '@/components/upload/fileUpload';
  113. import dictMixins from '@/mixins/dictMixins';
  114. import { deepClone } from '@/utils';
  115. import { getplanDetail } from '@/api/bpm/components/purchasingManage/purchasePlanManage';
  116. import {
  117. getpurchaseinquiry,
  118. chooseWinner
  119. } from '@/api/bpm/components/purchasingManage/inquiryManage';
  120. import { copyObj } from '@/utils/util';
  121. import { getFile } from '@/api/system/file';
  122. import { contactQueryByCategoryIdsAPI } from '@/api/bpm/components/supplierManage/contact';
  123. import { contactDetail } from '@/api/bpm/components/saleManage/contact';
  124. // import fileMain from '@/components/addDoc/index.vue';
  125. export default {
  126. mixins: [dictMixins],
  127. components: {
  128. // fileMain,
  129. fileUpload,
  130. inventoryTable,
  131. inquiryManageList,
  132. supplierManageDialog,
  133. inquiryTable
  134. },
  135. props: {
  136. businessId: {
  137. default: ''
  138. },
  139. isView:''
  140. },
  141. data() {
  142. let formDef = {
  143. id: '',
  144. planCode: null,
  145. planName: null,
  146. inquiryName: null,
  147. remark: null,
  148. planId: '',
  149. detailList: '',
  150. resultList: [],
  151. supplierName: '',
  152. files: [],
  153. acceptUnpack: ''
  154. };
  155. return {
  156. visible: false,
  157. supplierVisible: false,
  158. title: '',
  159. supplierList: [],
  160. detailList: [],
  161. list: [],
  162. delDetailIds: [],
  163. supplierProducts: {},
  164. formDef,
  165. rawList: [],
  166. outputList: [],
  167. acceptUnpackList: [
  168. {
  169. label: '接受',
  170. value: 1
  171. },
  172. {
  173. label: '不接受',
  174. value: 0
  175. }
  176. ],
  177. form: copyObj(formDef),
  178. rules: {
  179. responsibleName: [
  180. { required: true, message: '请选择负责人', trigger: 'change' }
  181. ],
  182. requireDeptId: [
  183. { required: true, message: '请选择需求部门', trigger: 'change' }
  184. ],
  185. inquiryName: [
  186. { required: true, message: '请输入询价单名称', trigger: 'blur' }
  187. ]
  188. },
  189. // 提交状态
  190. loading: false,
  191. // 是否是修改
  192. isUpdate: false
  193. };
  194. },
  195. created() {
  196. this.requestDict('产地');
  197. this.requestDict('质保期单位');
  198. this.requestDict('生产类型');
  199. this.requestDict('结算方式');
  200. this.getDetailData(this.businessId, 'init');
  201. },
  202. methods: {
  203. openSupplier() {
  204. if (this.list.length == 0) {
  205. this.$message.warning('请先选择采购计划');
  206. return;
  207. }
  208. this.$refs.supplierManageDialogRef.open();
  209. },
  210. //获取询价详情
  211. async getDetailData(id, type) {
  212. this.loading = true;
  213. let data = await getpurchaseinquiry(id);
  214. this.loading = false;
  215. if (data) {
  216. this.form = data;
  217. this.supplierList = data.supplierList;
  218. let supplierObj = await this.getSupplierObj(
  219. data.detailList,
  220. 'productId'
  221. );
  222. data.detailList.forEach((item) => {
  223. item.supplierList = supplierObj[item.productId] || [];
  224. });
  225. this.list = [...data.detailList, ...data.rawList, ...data.outputList];
  226. this.rawList = data.rawList;
  227. this.outputList = data.outputList;
  228. this.supplierList = data.supplierList;
  229. this.$nextTick(() => {
  230. this.$refs.inventoryTable &&
  231. this.$refs.inventoryTable.putTableValue(data.detailList);
  232. // this.setIsInquiry()
  233. });
  234. if (type == 'init') {
  235. this.getplanData(data.planId, type);
  236. }
  237. // console.log(this.form, 'this.form');
  238. // this.$nextTick(() => {
  239. // });
  240. }
  241. },
  242. deliveryDateChange(fn) {
  243. let data = this.$refs.inventoryTable.getTableValue() || [];
  244. fn(data);
  245. },
  246. setIsInquiry(supplierList) {
  247. // let supplierList = [];
  248. this.$nextTick(() => {
  249. // this.supplierList.forEach((item) => {
  250. // supplierList.push(
  251. // this.$refs['inquiryTable' + item.supplierId][0].getTableValue()
  252. // );
  253. // });
  254. this.$refs.inventoryTable.setIsInquiry(supplierList);
  255. });
  256. },
  257. //获取计划详情
  258. async getplanData(id, type) {
  259. this.loading = true;
  260. let data = await getplanDetail(id);
  261. this.rawList = data.rawDetailList;
  262. this.outputList = data.outputDetailList;
  263. this.loading = false;
  264. if (data) {
  265. let supplierObj = await this.getSupplierObj(
  266. data.detailList,
  267. 'productId'
  268. );
  269. data.detailList.forEach((item) => {
  270. if (item.arrivalWay == 2 && item.arrivalBatch.length > 0) {
  271. item.expectReceiveDate =
  272. item.arrivalBatch[item.arrivalBatch.length - 1].arriveDate;
  273. }
  274. item.supplierList = supplierObj[item.productId] || [];
  275. if (item.supplierList.length === 1) {
  276. item.supplierIds = [item.supplierList[0].id];
  277. // this.supplierSelect(item)
  278. }
  279. });
  280. this.$set(this.form, 'acceptUnpack', data.acceptUnpack);
  281. this.form.planId = data.id;
  282. this.form.planCode = data.planCode;
  283. this.form.planName = data.planName;
  284. // if (type == 'change') {
  285. // this.supplierList.forEach((item) => {
  286. // this.$refs['inquiryTable' + item.supplierId][0].putTableValue(
  287. // data.detailList
  288. // );
  289. // });
  290. // }
  291. if (type == 'init') {
  292. return;
  293. }
  294. this.list = [
  295. ...data.detailList,
  296. ...data.rawDetailList,
  297. ...data.outputDetailList
  298. ];
  299. this.$nextTick(() => {
  300. this.$refs.inventoryTable &&
  301. this.$refs.inventoryTable.putTableValue(data.detailList);
  302. });
  303. }
  304. },
  305. async getSupplierObj(productList, queryName) {
  306. try {
  307. let categoryIds = productList.map((item) => item[queryName]);
  308. return await contactQueryByCategoryIdsAPI({ categoryIds });
  309. } catch (e) {
  310. return Promise.resolve({});
  311. }
  312. },
  313. getValidate() {
  314. let promises = [];
  315. this.supplierList.forEach((item) => {
  316. promises.push(
  317. new Promise((resolve, reject) => {
  318. this.$refs['inquiryTable' + item.supplierId][0].validateForm(
  319. (valid) => {
  320. if (!valid) {
  321. reject(false);
  322. } else {
  323. resolve(true);
  324. }
  325. }
  326. );
  327. })
  328. );
  329. });
  330. return Promise.all([
  331. new Promise((resolve, reject) => {
  332. this.$refs.form.validate((valid) => {
  333. if (!valid) {
  334. reject(false);
  335. } else {
  336. resolve(true);
  337. }
  338. });
  339. }),
  340. ...promises
  341. ]);
  342. },
  343. //计划删除
  344. delList(productCode) {
  345. this.supplierList.forEach((item) => {
  346. this.$refs['inquiryTable' + item.supplierId][0].remove(productCode);
  347. });
  348. },
  349. removeSupplier(supplierId) {
  350. this.supplierList = this.supplierList.filter(
  351. (item) => item.supplierId != supplierId
  352. );
  353. // this.setIsInquiry()
  354. },
  355. //选择产品
  356. handParent() {
  357. this.$refs.inquiryManageRef.open(this.form.planCode);
  358. },
  359. changeInquiryManageList(data) {
  360. this.getplanData(data.id, 'change');
  361. },
  362. supplierSelectAll() {
  363. if (!this.$refs.inventoryTable.selection.length)
  364. return this.$message.warning('请选择产品');
  365. this.$refs.inventoryTable.selection.forEach((item) => {
  366. this.supplierSelect(item);
  367. });
  368. },
  369. async supplierSelect(row) {
  370. let supplierIds = Object.keys(this.supplierProducts);
  371. const promises = [];
  372. row.supplierIds.forEach((item) => {
  373. if (!supplierIds.includes(item)) {
  374. promises.push(contactDetail(item));
  375. } else {
  376. this.productSetSupplier(this.supplierProducts[item], row);
  377. }
  378. });
  379. Promise.all(promises).then((results) => {
  380. results.forEach((data, index) => {
  381. this.supplierProducts[data.base.id] = data;
  382. this.productSetSupplier(this.supplierProducts[data.base.id], row);
  383. });
  384. });
  385. },
  386. productSetSupplier(data, row) {
  387. let obj = deepClone(row);
  388. obj.supplierProductName = data.productList.find(
  389. (item) => item.productCode == row.productCode
  390. )?.productName;
  391. obj.supplierProductCode = data.productList.find(
  392. (item) => item.productCode == row.productCode
  393. )?.productCode;
  394. obj.supplierName = data.base.name;
  395. obj.reqTotalCount=obj.totalCount
  396. let params = {
  397. ...data.base,
  398. supplierId: data.base.id,
  399. supplierName: data.base.name,
  400. supplierCode: data.base.code,
  401. files: [],
  402. preferentialPrice: '',
  403. settlementMode: '4',
  404. settlementModeName: '分期付款',
  405. taxRate: '',
  406. totalPrice: '',
  407. resultList: [obj]
  408. };
  409. let supplierIds = this.supplierList.map((item) => item.supplierId);
  410. let supplierIndex = supplierIds.indexOf(data.base.id);
  411. if (supplierIndex == -1) {
  412. this.supplierList.push(params);
  413. } else {
  414. let isHave = this.supplierList[supplierIndex].resultList.some(
  415. (item) => item.productCode == obj.productCode
  416. );
  417. if (!isHave) {
  418. // putTableValue
  419. //this.supplierList[supplierIndex].resultList.push(obj)
  420. this.$set(this.supplierList[supplierIndex], 'resultList', [
  421. ...this.supplierList[supplierIndex].resultList,
  422. obj
  423. ]);
  424. this.$nextTick(() => {
  425. this.$refs['inquiryTable' + data.base.id][0]?.putTableValue(
  426. this.supplierList[supplierIndex].resultList
  427. );
  428. this.$refs['inquiryTable' + data.base.id][0]?.getSpanArr();
  429. });
  430. }
  431. }
  432. },
  433. //供应商回调
  434. supplierManageChange(data) {
  435. let supplierIds = this.supplierList.map((item) => item.supplierId);
  436. data.forEach((item) => {
  437. item['files'] = [];
  438. item['supplierName'] = item.name;
  439. item['preferentialPrice'] = '';
  440. item['settlementMode'] = '4';
  441. item['settlementModeName'] = '分期付款';
  442. item['taxRate'] = '';
  443. item['totalPrice'] = '';
  444. item['resultList'] = copyObj(this.$refs.inventoryTable.selection);
  445. item['resultList'].forEach((val) => {
  446. val['remark'] = '';
  447. item['deliveryDate'] = val.expectReceiveDate;
  448. val.supplierName = item.name;
  449. reqTotalCount=val.totalCount
  450. });
  451. let supplierIndex = supplierIds.indexOf(item.supplierId);
  452. if (supplierIndex == -1) {
  453. this.supplierList.push(item);
  454. } else {
  455. item['resultList'].forEach((val) => {
  456. let isHave = this.supplierList[supplierIndex].resultList.some(
  457. (i) => i.productCode == val.productCode
  458. );
  459. console.log(isHave, supplierIndex);
  460. if (!isHave) {
  461. this.$set(this.supplierList[supplierIndex], 'resultList', [
  462. ...this.supplierList[supplierIndex].resultList,
  463. val
  464. ]);
  465. this.$refs['inquiryTable' + item.id][0]?.putTableValue(
  466. this.supplierList[supplierIndex].resultList
  467. );
  468. this.$nextTick(() => {
  469. this.$refs['inquiryTable' + item.id][0]?.getSpanArr();
  470. });
  471. }
  472. });
  473. }
  474. });
  475. },
  476. async getTableValue() {
  477. try {
  478. await this.getValidate();
  479. let supplierList = [];
  480. this.supplierList.forEach((item) => {
  481. supplierList.push(
  482. this.$refs['inquiryTable' + item.supplierId][0].getTableValue()
  483. );
  484. });
  485. this.setIsInquiry(supplierList);
  486. let is = false;
  487. supplierList.forEach((item) => {
  488. item.resultList.forEach((val) => {
  489. val['technicalDrawings'] = [];
  490. if (val.minimumOrderQuantity > val.totalCount) {
  491. is = true;
  492. }
  493. });
  494. });
  495. if (is) {
  496. this.$message.warning('购买数量不能小于最低订购量!');
  497. return;
  498. }
  499. this.form.detailList = this.list;
  500. this.form.supplierList = supplierList;
  501. // 表单验证通过,执行保存操作
  502. this.loading = true;
  503. if (this.$refs.inventoryTable.getTableValue().length == 0) {
  504. this.$message.warning('物品清单不能为空');
  505. return;
  506. }
  507. this.form.supplierList.forEach((item) => {
  508. item.resultList = [
  509. ...item.resultList,
  510. ...this.rawList,
  511. ...this.outputList
  512. ];
  513. });
  514. this.form.files = this.form.files || [];
  515. return this.form;
  516. } catch (error) {
  517. console.log(error);
  518. // 表单验证未通过,不执行保存操作
  519. }
  520. },
  521. downloadFile(file) {
  522. getFile({ objectName: file.storePath }, file.name);
  523. }
  524. }
  525. };
  526. </script>
  527. <style scoped lang="scss">
  528. .TotalAmount {
  529. font-size: 16px;
  530. padding-right: 30px;
  531. }
  532. </style>