addDialog.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <!-- 预付款新增/编辑弹窗 -->
  2. <template>
  3. <ele-modal
  4. width="1100px"
  5. :visible="visible"
  6. :append-to-body="true"
  7. :close-on-click-modal="false"
  8. custom-class="ele-dialog-form"
  9. :title="isDetail ? '预付款详情' : (isUpdate ? '修改预付款' : '新增预付款')"
  10. @update:visible="updateVisible"
  11. >
  12. <div class="switch_left" v-if="isDetail">
  13. <ul>
  14. <li
  15. v-for="item in tabOptions"
  16. :key="item.key"
  17. :class="{ active: activeComp == item.key }"
  18. @click="activeComp = item.key"
  19. >
  20. {{ item.name }}
  21. </li>
  22. </ul>
  23. </div>
  24. <el-form
  25. ref="form"
  26. :model="form"
  27. :rules="rules"
  28. label-width="120px"
  29. v-show="activeComp == 'main'"
  30. >
  31. <!-- 基本信息 -->
  32. <headerTitle title="基本信息" size="16px"></headerTitle>
  33. <el-row :gutter="20">
  34. <el-col :span="8">
  35. <el-form-item label="预付日期:" prop="prepayDate">
  36. <el-date-picker
  37. v-model="form.prepayDate"
  38. type="date"
  39. placeholder="请选择"
  40. value-format="yyyy-MM-dd"
  41. style="width: 100%"
  42. :disabled="isDetail"
  43. />
  44. </el-form-item>
  45. </el-col>
  46. <el-col :span="8">
  47. <el-form-item label="预付金额:" prop="prepayTotalPrice">
  48. <el-input
  49. v-model="form.prepayTotalPrice"
  50. placeholder="请输入"
  51. :disabled="isDetail"
  52. >
  53. <template slot="append">元</template>
  54. </el-input>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="8">
  58. <el-form-item label="会计科目:" prop="accountingSubjectId">
  59. <ele-tree-select
  60. clearable
  61. :disabled="isDetail"
  62. filterable
  63. ref="treeSelect"
  64. :data="accountingSubjectList"
  65. v-model="form.accountingSubjectId"
  66. valueKey="id"
  67. labelKey="name"
  68. placeholder="请选择"
  69. @change="changeSubjectInfo"
  70. default-expand-all
  71. />
  72. </el-form-item>
  73. </el-col>
  74. </el-row>
  75. <el-row :gutter="20">
  76. <el-col :span="8">
  77. <el-form-item label="供应商名称:" prop="contactName">
  78. <el-input
  79. clearable
  80. v-model="form.contactName"
  81. @click.native="$refs.parentRef.open()"
  82. placeholder="请选择"
  83. readonly
  84. :disabled="isDetail"
  85. />
  86. </el-form-item>
  87. </el-col>
  88. <el-col :span="8">
  89. <el-form-item label="来源类型:" prop="sourceType">
  90. <el-select
  91. v-model="form.sourceType"
  92. placeholder="请选择"
  93. style="width: 100%"
  94. :disabled="isDetail"
  95. >
  96. <el-option label="采购订单" :value="3"></el-option>
  97. <el-option label="合同" :value="2"></el-option>
  98. </el-select>
  99. </el-form-item>
  100. </el-col>
  101. <el-col :span="8">
  102. <el-form-item label="来源编码:" prop="sourceCode">
  103. <!-- <el-select
  104. v-model="form.sourceCode"
  105. placeholder="请选择"
  106. style="width: 100%"
  107. :disabled="isDetail"
  108. filterable
  109. >
  110. <el-option
  111. v-for="item in sourceCodeOptions"
  112. :key="item.value"
  113. :label="item.label"
  114. :value="item.value"
  115. />
  116. </el-select> -->
  117. <el-input
  118. clearable
  119. v-model="form.sourceCode"
  120. @click.native="openSource"
  121. placeholder="请选择"
  122. :disabled="isDetail"
  123. readonly
  124. />
  125. </el-form-item>
  126. </el-col>
  127. </el-row>
  128. <el-row :gutter="20">
  129. <el-col :span="8">
  130. <el-form-item label="款项类型:" prop="fundType">
  131. <DictSelection
  132. dictName="预收款款项类型"
  133. clearable
  134. v-model="form.fundType"
  135. :disabled="isDetail"
  136. >
  137. </DictSelection>
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="8">
  141. <el-form-item label="付款条件:" prop="paymentConditionName">
  142. <!-- <el-select
  143. v-model="form.paymentConditionName"
  144. placeholder="请选择"
  145. style="width: 100%"
  146. :disabled="isDetail"
  147. >
  148. <el-option
  149. v-for="item in paymentTermsOptions"
  150. :key="item.value"
  151. :label="item.label"
  152. :value="item.value"
  153. />
  154. </el-select> -->
  155. <el-input
  156. clearable
  157. v-model="form.paymentConditionName"
  158. @click.native="openReceiveTerms"
  159. placeholder="请选择"
  160. :disabled="isDetail"
  161. readonly
  162. />
  163. </el-form-item>
  164. </el-col>
  165. </el-row>
  166. <el-row :gutter="20">
  167. <el-col :span="8">
  168. <el-form-item label="备注:" prop="remark">
  169. <el-input
  170. v-model="form.remark"
  171. placeholder="请输入"
  172. :disabled="isDetail"
  173. />
  174. </el-form-item>
  175. </el-col>
  176. <el-col :span="8">
  177. <el-form-item label="附件:" prop="files">
  178. <fileMain v-model="form.files" :type="isDetail ? 'view' : 'add'"></fileMain>
  179. </el-form-item>
  180. </el-col>
  181. </el-row>
  182. <!-- 物品清单 -->
  183. <headerTitle title="物品清单" size="16px" style="margin-top: 20px"></headerTitle>
  184. <inventoryTableDetails
  185. ref="inventoryTableDetailsRef"
  186. :isAllPrice="true"
  187. :showSummary="true"
  188. :isSelected="false"
  189. :isDiscountTotalPrice="true"
  190. cacheKeyUrl="eos-prepayment-inventoryTableDetails"
  191. :countObj="countObj"
  192. ></inventoryTableDetails>
  193. <!-- 付款信息 -->
  194. <div style="margin-top: 20px" v-if="isDetail">
  195. <headerTitle title="付款信息"></headerTitle>
  196. <div style="margin: 10px 0; font-size: 14px; color: #606266;">
  197. <span>预付金额:{{ form.amount || 0 }} 元</span>
  198. <span style="margin-left: 20px;">已付金额:{{ paidAmount }} 元</span>
  199. <span style="margin-left: 20px;">未付金额:{{ unpaidAmount }} 元</span>
  200. </div>
  201. <ele-pro-table
  202. ref="table"
  203. :needPage="false"
  204. :columns="columns"
  205. :datasource="form.detailList"
  206. :toolkit="[]"
  207. >
  208. <template v-slot:files="{ row: r }">
  209. <fileMain v-model="r.files" type="view" :limit="1"></fileMain>
  210. </template>
  211. </ele-pro-table>
  212. </div>
  213. </el-form>
  214. <template v-slot:footer>
  215. <template v-if="isDetail">
  216. <el-button @click="updateVisible(false)">关闭</el-button>
  217. </template>
  218. <template v-else>
  219. <el-button type="primary" :loading="loading" @click="save(0)">
  220. 保存
  221. </el-button>
  222. <el-button type="primary" :loading="loading" @click="save(1)">
  223. 提交
  224. </el-button>
  225. <el-button @click="updateVisible(false)">取消</el-button>
  226. </template>
  227. </template>
  228. <contractListDialog
  229. ref="selectContractRef"
  230. @changeParent="changeContract"
  231. :isChange="true"
  232. :type="2"
  233. :contactData="{
  234. id: form.contactId
  235. }"
  236. ></contractListDialog>
  237. <!-- 采购订单 -->
  238. <orderListDialog
  239. ref="orderListDialogRef"
  240. :isMy="true"
  241. :contactData="{
  242. id: form.contactId
  243. }"
  244. @changeParent="changeOrder"
  245. ></orderListDialog>
  246. <!-- 供应商 -->
  247. <parentList
  248. ref="parentRef"
  249. @changeParent="changeParent"
  250. :classType="2"
  251. ></parentList>
  252. <!-- 付款条件 -->
  253. <receiveTermsDialog ref="receiveTermsDialogRef" conditionType="terms" @changeParent="changeReceiveTerms"></receiveTermsDialog>
  254. <bpmDetail
  255. v-if="activeComp === 'bpm' && form.processInstanceId"
  256. :id="form.processInstanceId"
  257. ></bpmDetail>
  258. <process-submit-dialog
  259. :isNotNeedProcess="false"
  260. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  261. v-if="processSubmitDialogFlag"
  262. ref="processSubmitDialogRef"
  263. @reload="reload"
  264. ></process-submit-dialog>
  265. </ele-modal>
  266. </template>
  267. <script>
  268. import headerTitle from '@/components/header-title';
  269. import inventoryTableDetails from '@/BIZComponents/inventoryTableDetails.vue';
  270. import fileMain from '@/components/addDoc/index.vue';
  271. import { addPrepayment, updatePrepayment, getPrepaymentInfo } from '@/api/financialManage/prepayment';
  272. import { getTreeByPid } from '@/api/classifyManage';
  273. import parentList from '@/views/purchasingManage/supplierManage/components/parentList.vue';
  274. import contractListDialog from '@/views/saleManage/saleOrder/components/contractListDialog.vue';
  275. import orderListDialog from '@/views/purchasingManage/purchaseOrder/invoice/components/orderListDialog.vue';
  276. import { getByIdCondition } from '@/api/purchasingManage/purchaseOrder';
  277. import receiveTermsDialog from '@/views/financialManage/advanceReceipt/components/receiveTermsDialog.vue';
  278. import bpmDetail from '@/views/bpm/processInstance/detail.vue';
  279. import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  280. export default {
  281. components: {
  282. headerTitle,
  283. inventoryTableDetails,
  284. fileMain,
  285. parentList,
  286. contractListDialog,
  287. orderListDialog,
  288. receiveTermsDialog,
  289. bpmDetail,
  290. processSubmitDialog
  291. },
  292. data() {
  293. return {
  294. activeComp: 'main',
  295. visible: false,
  296. loading: false,
  297. isUpdate: false,
  298. isDetail: false,
  299. processSubmitDialogFlag: false,
  300. supplierOptions: [],
  301. sourceCodeOptions: [],
  302. paymentTermsOptions: [],
  303. accountingSubjectList: [],
  304. businessId: '',
  305. countObj: {
  306. countKey: 'purchaseCount',
  307. unitKey: 'purchaseUnit',
  308. unitIdKey: 'purchaseUnitId'
  309. },
  310. tabOptions: [
  311. { key: 'main', name: '预付款项' },
  312. { key: 'bpm', name: '流程详情' }
  313. ],
  314. form: {
  315. id: null,
  316. code: '',
  317. prepayDate: '',
  318. prepayTotalPrice: '',
  319. accountingSubjectId: '1779719367139791007',
  320. accountingSubjectCode: '1123',
  321. accountingSubjectName: '预付账款',
  322. contactName: '',
  323. contactId: '',
  324. sourceType: 3,
  325. sourceCode: '',
  326. sourceId: '',
  327. fundType: 1,
  328. paymentConditionName: '',
  329. paymentConditionId: '',
  330. remark: '',
  331. files: []
  332. },
  333. rules: {
  334. prepayDate: [{ required: true, message: '请选择预付日期', trigger: 'change' }],
  335. prepayTotalPrice: [{ required: true, message: '请输入预付金额', trigger: 'blur' }],
  336. accountingSubjectId: [{ required: true, message: '请选择会计科目', trigger: 'change' }],
  337. contactName: [{ required: true, message: '请选择供应商名称', trigger: 'change' }],
  338. sourceType: [{ required: true, message: '请选择来源类型', trigger: 'change' }],
  339. sourceCode: [{ required: true, message: '请选择来源编码', trigger: 'change' }],
  340. fundType: [{ required: true, message: '请选择款项类型', trigger: 'change' }]
  341. },
  342. columns: [
  343. {
  344. type: 'index',
  345. label: '序号',
  346. width: 55,
  347. align: 'center',
  348. fixed: 'left'
  349. },
  350. {
  351. prop: 'paidDate',
  352. label: '付款时间',
  353. align: 'center',
  354. minWidth: 160
  355. },
  356. {
  357. prop: 'paidTotalPrice',
  358. label: '已付金额',
  359. align: 'center',
  360. minWidth: 140
  361. },
  362. {
  363. prop: 'paymentTypeName',
  364. label: '支付类型',
  365. align: 'center',
  366. minWidth: 140
  367. },
  368. {
  369. prop: 'files',
  370. label: '附件',
  371. align: 'center',
  372. minWidth: 120,
  373. slot: 'files'
  374. },
  375. {
  376. prop: 'remark',
  377. label: '备注',
  378. align: 'center',
  379. minWidth: 140
  380. }
  381. ]
  382. };
  383. },
  384. computed: {
  385. paidAmount() {
  386. return this.form.tableData.reduce((sum, item) => {
  387. const val = parseFloat(item.paidAmount);
  388. return sum + (isNaN(val) ? 0 : val);
  389. }, 0).toFixed(2);
  390. },
  391. unpaidAmount() {
  392. const total = parseFloat(this.row.prepayTotalPrice) || 0;
  393. const paid = parseFloat(this.paidAmount) || 0;
  394. return (total - paid).toFixed(2);
  395. }
  396. },
  397. methods: {
  398. generateCode() {
  399. const now = new Date();
  400. const year = now.getFullYear();
  401. const month = String(now.getMonth() + 1).padStart(2, '0');
  402. const day = String(now.getDate()).padStart(2, '0');
  403. const random = String(Math.floor(Math.random() * 900) + 100);
  404. this.form.code = `YFK${year}${month}${day}${random}`;
  405. },
  406. async open(type, row) {
  407. this.visible = true;
  408. await this.getClassifyList(24, 'accountingSubjectList');
  409. this.isUpdate = type === 'edit';
  410. this.isDetail = type === 'detail';
  411. if ((this.isUpdate || this.isDetail) && row) {
  412. this.form = await getPrepaymentInfo(row.id);
  413. this.form.totalAmount = this.form.productList.reduce((sum, item) => {
  414. const val = parseFloat(item.totalPrice);
  415. return sum + (isNaN(val) ? 0 : val);
  416. }, 0);
  417. this.form.discountTotalPrice = this.form.productList.reduce((sum, item) => {
  418. const val = parseFloat(item.discountTotalPrice);
  419. return sum + (isNaN(val) ? 0 : val);
  420. }, 0);
  421. this.businessId = row.id;
  422. this.$nextTick(() => {
  423. this.$refs.inventoryTableDetailsRef &&
  424. this.$refs.inventoryTableDetailsRef.putTableValue(this.form || []);
  425. });
  426. } else {
  427. this.resetForm();
  428. // this.generateCode();
  429. this.$nextTick(() => {
  430. this.$refs.inventoryTableDetailsRef &&
  431. this.$refs.inventoryTableDetailsRef.putTableValue([]);
  432. });
  433. this.form.accountingSubjectId = '1779719367139791007';
  434. this.form.accountingSubjectCode = '1123';
  435. this.form.accountingSubjectName = '预付账款';
  436. }
  437. this.$nextTick(() => {
  438. this.$refs.form && this.$refs.form.clearValidate();
  439. });
  440. },
  441. openReceiveTerms() {
  442. this.$refs.receiveTermsDialogRef.open();
  443. },
  444. changeReceiveTerms(row, index) {
  445. console.log('changeReceiveTerms~~~', row)
  446. this.form.paymentConditionId = row.id;
  447. this.form.paymentConditionName = row.name;
  448. console.log('changeReceiveTerms!!!', this.form)
  449. this.$forceUpdate()
  450. },
  451. async changeContract(row) {
  452. console.log(row, 'dadas');
  453. this.form.sourceCode = row.contractNumber;
  454. this.form.sourceId = row.id;
  455. const { productList, receiptPaymentList, contractVO } = await getDetail(
  456. row.id
  457. );
  458. this.$refs.inventoryTableDetailsRef.putTableValue({ productList });
  459. this.form.prepayTotalPrice = contractVO.discountTotalPrice;
  460. },
  461. async changeOrder(row) {
  462. this.form.sourceCode = row.orderNo;
  463. this.form.sourceId = row.id;
  464. const { productList, receiptPaymentList, payAmount } =
  465. await getByIdCondition(row.id, 2);
  466. this.$refs.inventoryTableDetailsRef.putTableValue({ productList });
  467. this.form.prepayTotalPrice = payAmount;
  468. },
  469. openSource() {
  470. if (!this.form.contactName) {
  471. this.$message.error('请选择供应商');
  472. return;
  473. }
  474. if (!this.form.sourceType) {
  475. this.$message.error('请选择来源类型');
  476. return;
  477. }
  478. if (this.form.sourceType == 3) {
  479. this.$refs.orderListDialogRef.open()
  480. } else {
  481. this.$refs.selectContractRef.open();
  482. }
  483. },
  484. //获取分类管理中的数据
  485. async getClassifyList(id, listName) {
  486. let res = await getTreeByPid(id);
  487. this[listName] = res.data;
  488. },
  489. changeSubjectInfo(val) {
  490. const { code, name } = this.$refs.treeSelect.getNodeByValue(val);
  491. this.form.accountingSubjectCode = code;
  492. this.form.accountingSubjectName = name;
  493. },
  494. async changeParent(obj) {
  495. this.form.contactName = obj.name;
  496. this.form.contactId = obj.id;
  497. },
  498. resetForm() {
  499. this.form = {
  500. id: null,
  501. code: '',
  502. prepayDate: '',
  503. prepayTotalPrice: '',
  504. accountingSubjectId: '1779719367139791007',
  505. accountingSubjectCode: '1123',
  506. accountingSubjectName: '预付账款',
  507. contactName: '',
  508. contactId: '',
  509. sourceType: 3,
  510. sourceCode: '',
  511. sourceId: '',
  512. fundType: 1,
  513. paymentConditionName: '',
  514. paymentConditionId: '',
  515. remark: '',
  516. files: []
  517. };
  518. },
  519. save(type) {
  520. this.$refs.form.validate((valid) => {
  521. if (!valid) return;
  522. this.loading = true;
  523. const productList = this.$refs.inventoryTableDetailsRef
  524. ? this.$refs.inventoryTableDetailsRef.getTableValue()
  525. : [];
  526. const params = { ...this.form, productList };
  527. const saveOrUpdate = this.isUpdate ? updatePrepayment : addPrepayment;
  528. saveOrUpdate(params)
  529. .then((res) => {
  530. this.loading = false;
  531. this.$message.success(this.isUpdate ? '修改成功' : '新增成功');
  532. console.log('sub', type)
  533. if(type == 1) {
  534. console.log('提交', res)
  535. this.sub(res);
  536. }
  537. this.updateVisible(false);
  538. this.$emit('done');
  539. })
  540. .catch(() => {
  541. this.loading = false;
  542. });
  543. });
  544. },
  545. async sub(res) {
  546. const data = await getPrepaymentInfo(
  547. this.businessId || res
  548. );
  549. this.processSubmitDialogFlag = true;
  550. let key = 'fin_prepay_approve';
  551. this.$nextTick(() => {
  552. let params = {
  553. businessId: data.id,
  554. businessKey: key,
  555. formCreateUserId: data.createUserId,
  556. variables: {
  557. businessCode: data.code,
  558. businessName: data.contactName,
  559. fundType: data.fundTypeName,
  560. sourceType: data.sourceType,
  561. businessType: '预付款项'
  562. }
  563. };
  564. this.$refs.processSubmitDialogRef.init(params);
  565. });
  566. // submit({
  567. // businessId: this.businessId || res,
  568. // receiveType: this.form.receiveType,
  569. // sourceType,
  570. // variables: {
  571. // storemanIds
  572. // }
  573. // }).then((res) => {
  574. // this.cancel();
  575. // this.$emit('done');
  576. // });
  577. },
  578. reload() {
  579. this.updateVisible(false);
  580. this.$emit('done');
  581. },
  582. updateVisible(value) {
  583. this.visible = value;
  584. if (!value) {
  585. this.resetForm();
  586. }
  587. }
  588. }
  589. };
  590. </script>