addDialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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
  26. v-model="form.inquiryName"
  27. ></el-input>
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="12">
  31. <el-form-item prop="remark" label="是否接受拆单" label-width="120px">
  32. <el-select
  33. v-model="form.acceptUnpack"
  34. clearable
  35. style="width: 100%"
  36. disabled
  37. >
  38. <el-option
  39. v-for="item in acceptUnpackList"
  40. :key="item.value"
  41. :label="item.label"
  42. :value="item.value"
  43. >
  44. </el-option>
  45. </el-select>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="12">
  49. <el-form-item prop="files" label="附件">
  50. <fileUpload
  51. v-model="form.files"
  52. module="main"
  53. :showLib="false"
  54. :limit="1"
  55. />
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item prop="remark" label="备注">
  60. <el-input
  61. type="textarea"
  62. resize="none"
  63. v-model="form.remark"
  64. :rows="2"
  65. placeholder="请输入"
  66. size="small"
  67. maxlength="200"
  68. ></el-input>
  69. </el-form-item>
  70. </el-col>
  71. </el-row>
  72. </el-form>
  73. <headerTitle title="产品清单" style="margin-top: 15px"></headerTitle>
  74. <inventoryTable
  75. ref="inventoryTable"
  76. @delList="delList"
  77. :acceptUnpack="form.acceptUnpack"
  78. ></inventoryTable>
  79. <headerTitle title="报价清单" style="margin-top: 15px"></headerTitle>
  80. <el-button type="primary" @click="openSupplier">新增供应商</el-button>
  81. <inquiryManageList
  82. ref="inquiryManageRef"
  83. @changeInquiryManageList="changeInquiryManageList"
  84. ></inquiryManageList>
  85. <supplierManageDialog
  86. ref="supplierManageDialogRef"
  87. @supplierManageChange="supplierManageChange"
  88. ></supplierManageDialog>
  89. <inquiryTable
  90. @removeSupplier="removeSupplier"
  91. @setSupplierId="setSupplierId"
  92. :ref="'inquiryTable' + item.supplierId"
  93. :radio="form.winnerId"
  94. v-for="item in supplierList"
  95. :key="item.supplierId"
  96. style="margin-top: 15px"
  97. :obj="item"
  98. :isUpdate="isUpdate"
  99. ></inquiryTable>
  100. </div>
  101. </template>
  102. <script>
  103. import inventoryTable from './inventoryTable.vue';
  104. import inquiryTable from './inquiryTable.vue';
  105. import inquiryManageList from './inquiryManage-list.vue';
  106. import supplierManageDialog from './supplierManageDialog.vue';
  107. import fileUpload from '@/components/upload/fileUpload';
  108. import dictMixins from '@/mixins/dictMixins';
  109. import { getplanDetail } from '@/api/bpm/components/purchasingManage/purchasePlanManage';
  110. import {
  111. getpurchaseinquiry,
  112. chooseWinner
  113. } from '@/api/bpm/components/purchasingManage/inquiryManage';
  114. import { copyObj } from '@/utils/util';
  115. import { getFile } from '@/api/system/file';
  116. export default {
  117. mixins: [dictMixins],
  118. components: {
  119. fileUpload,
  120. inventoryTable,
  121. inquiryManageList,
  122. supplierManageDialog,
  123. inquiryTable
  124. },
  125. props: {
  126. businessId: {
  127. default: ''
  128. }
  129. },
  130. data() {
  131. let formDef = {
  132. id: '',
  133. planCode: null,
  134. planName: null,
  135. inquiryName: null,
  136. remark: null,
  137. planId: '',
  138. detailList: '',
  139. resultList: [],
  140. // supplierList: [],
  141. supplierName: '',
  142. files: [],
  143. acceptUnpack: ''
  144. };
  145. return {
  146. visible: false,
  147. supplierVisible: false,
  148. title: '',
  149. supplierList: [],
  150. detailList: [],
  151. list: [],
  152. delDetailIds: [],
  153. formDef,
  154. acceptUnpackList: [
  155. {
  156. label: '接受',
  157. value: 1
  158. },
  159. {
  160. label: '不接受',
  161. value: 0
  162. }
  163. ],
  164. form: copyObj(formDef),
  165. rules: {
  166. responsibleName: [
  167. { required: true, message: '请选择负责人', trigger: 'change' }
  168. ],
  169. requireDeptId: [
  170. { required: true, message: '请选择需求部门', trigger: 'change' }
  171. ],
  172. inquiryName: [
  173. { required: true, message: '请输入询价单名称', trigger: 'blur' }
  174. ],
  175. },
  176. // 提交状态
  177. loading: false,
  178. // 是否是修改
  179. isUpdate: false
  180. };
  181. },
  182. created() {
  183. this.getDetailData(this.businessId, 'init');
  184. },
  185. methods: {
  186. openSupplier() {
  187. if (this.list.length == 0) {
  188. this.$message.warning('请先选择采购计划');
  189. return;
  190. }
  191. this.$refs.supplierManageDialogRef.open();
  192. },
  193. setSupplierId(data) {
  194. this.form.winnerId = data.supplierId;
  195. this.form.winnerName = data.supplierName;
  196. chooseWinner(this.form);
  197. },
  198. //获取询价详情
  199. async getDetailData(id, type) {
  200. this.loading = true;
  201. let data = await getpurchaseinquiry(id);
  202. this.loading = false;
  203. if (data) {
  204. this.form = data;
  205. this.list = data.detailList;
  206. this.supplierList = data.supplierList;
  207. this.$nextTick(() => {
  208. this.$refs.inventoryTable &&
  209. this.$refs.inventoryTable.putTableValue(data.detailList);
  210. });
  211. if (type == 'init') {
  212. this.getplanData(data.planId, type);
  213. }
  214. // console.log(this.form, 'this.form');
  215. // this.$nextTick(() => {
  216. // });
  217. }
  218. },
  219. //获取计划详情
  220. async getplanData(id, type) {
  221. this.loading = true;
  222. let data = await getplanDetail(id);
  223. this.loading = false;
  224. if (data) {
  225. this.$set(this.form, 'acceptUnpack', data.acceptUnpack);
  226. this.form.planId = data.id;
  227. this.form.planCode = data.planCode;
  228. this.form.planName = data.planName;
  229. if (type == 'change') {
  230. this.supplierList.forEach((item) => {
  231. this.$refs['inquiryTable' + item.supplierId][0].putTableValue(
  232. data.detailList
  233. );
  234. });
  235. }
  236. if (type == 'init') {
  237. return;
  238. }
  239. this.list = data.detailList;
  240. this.$nextTick(() => {
  241. this.$refs.inventoryTable &&
  242. this.$refs.inventoryTable.putTableValue(data.detailList);
  243. });
  244. }
  245. },
  246. getValidate() {
  247. let promises = [];
  248. this.supplierList.forEach((item) => {
  249. promises.push(
  250. new Promise((resolve, reject) => {
  251. this.$refs['inquiryTable' + item.supplierId][0].validateForm(
  252. (valid) => {
  253. if (!valid) {
  254. reject(false);
  255. } else {
  256. resolve(true);
  257. }
  258. }
  259. );
  260. })
  261. );
  262. });
  263. return Promise.all([
  264. new Promise((resolve, reject) => {
  265. this.$refs.form.validate((valid) => {
  266. if (!valid) {
  267. reject(false);
  268. } else {
  269. resolve(true);
  270. }
  271. });
  272. }),
  273. ...promises
  274. ]);
  275. },
  276. //计划删除
  277. delList(productCode) {
  278. this.supplierList.forEach((item) => {
  279. this.$refs['inquiryTable' + item.supplierId][0].remove(productCode);
  280. });
  281. },
  282. removeSupplier(supplierId) {
  283. if(supplierId == this.form.winnerId){
  284. this.form.winnerId = ''
  285. this.form.winnerName = ''
  286. }
  287. this.supplierList = this.supplierList.filter(
  288. (item) => item.supplierId != supplierId
  289. );
  290. },
  291. //选择产品
  292. handParent() {
  293. this.$refs.inquiryManageRef.open(this.form.planCode);
  294. },
  295. changeInquiryManageList(data) {
  296. // this.form.planId = data.id;
  297. // this.form.planCode = data.planCode;
  298. this.getplanData(data.id, 'change');
  299. },
  300. //供应商回调
  301. supplierManageChange(data) {
  302. let supplierIds = this.supplierList.map((item) => item.supplierId);
  303. data.forEach((item) => {
  304. item['files'] = [];
  305. item['preferentialPrice'] = '';
  306. item['settlementMode'] = '';
  307. item['settlementModeName'] = '';
  308. item['taxRate'] = '';
  309. item['totalPrice'] = '';
  310. item['resultList'] = copyObj(this.list);
  311. item['resultList'].forEach((val) => {
  312. val['remark'] = '';
  313. });
  314. if (!supplierIds.includes(item.supplierId)) {
  315. this.supplierList.push(item);
  316. }
  317. });
  318. },
  319. async getTableValue() {
  320. let supplierList = [];
  321. this.supplierList.forEach((item) => {
  322. supplierList.push(
  323. this.$refs['inquiryTable' + item.supplierId][0].getTableValue()
  324. );
  325. });
  326. supplierList.forEach((item) => {
  327. item.resultList.forEach((val) => {
  328. val['technicalDrawings'] = [];
  329. });
  330. });
  331. this.form.detailList = this.list;
  332. this.form.supplierList = supplierList;
  333. try {
  334. await this.getValidate();
  335. // 表单验证通过,执行保存操作
  336. this.loading = true;
  337. if (this.$refs.inventoryTable.getTableValue().length == 0) {
  338. this.$message.warning('产品清单不能为空');
  339. return;
  340. }
  341. this.form.files = this.form.files || [];
  342. return this.form;
  343. } catch (error) {
  344. console.log(error);
  345. // 表单验证未通过,不执行保存操作
  346. }
  347. },
  348. downloadFile(file) {
  349. getFile({ objectName: file.storePath }, file.name);
  350. }
  351. }
  352. };
  353. </script>
  354. <style scoped lang="scss">
  355. .TotalAmount {
  356. font-size: 16px;
  357. padding-right: 30px;
  358. }
  359. </style>