addDialog.vue 17 KB

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