payablesInfo.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <div class="payables-info">
  3. <el-form ref="form" :model="dataForm" :rules="rules" label-width="170px">
  4. <el-row>
  5. <el-col :span="8">
  6. <el-form-item :label="statementAdvanceTotalPriceTitle">
  7. <el-input disabled v-model="statementAdvanceTotalPrice">
  8. <template slot="append">元</template>
  9. </el-input>
  10. </el-form-item>
  11. </el-col>
  12. <el-col :span="8">
  13. <el-form-item label="本次对账应付总金额">
  14. <el-input disabled v-model="receivedTotalPrice">
  15. <template slot="append">元</template>
  16. </el-input>
  17. </el-form-item>
  18. </el-col>
  19. </el-row>
  20. </el-form>
  21. <el-form :model="{ payablesList: localList }" ref="tableForm">
  22. <ele-pro-table
  23. ref="payablesTable"
  24. row-key="id"
  25. :needPage="false"
  26. :columns="columns"
  27. max-height="400px"
  28. :datasource="localList"
  29. :cache-key="cacheKeyUrl"
  30. class="time-form"
  31. >
  32. <template v-slot:fundType="scope">
  33. <el-form-item
  34. :prop="'payablesList.' + scope.$index + '.fundType'"
  35. label-width="0"
  36. >
  37. <el-select
  38. v-model="scope.row.fundType"
  39. placeholder="请选择"
  40. class="ele-block"
  41. :disabled="isView"
  42. @change="(val) => updateRowField(scope.$index, 'fundType', val)"
  43. >
  44. <el-option
  45. v-for="item in paymentTypeOp"
  46. :key="item.value"
  47. :label="item.label"
  48. :value="item.value"
  49. />
  50. </el-select>
  51. </el-form-item>
  52. </template>
  53. <template v-slot:transactionMode="scope">
  54. <el-form-item
  55. :prop="'payablesList.' + scope.$index + '.transactionMode'"
  56. label-width="0"
  57. >
  58. <el-select
  59. v-model="scope.row.transactionMode"
  60. placeholder="请选择"
  61. class="ele-block"
  62. :disabled="isView"
  63. @change="(val) => updateRowField(scope.$index, 'transactionMode', val)"
  64. >
  65. <el-option
  66. v-for="item in transactionMethodsOp"
  67. :key="item.value"
  68. :label="item.label"
  69. :value="item.value"
  70. />
  71. </el-select>
  72. </el-form-item>
  73. </template>
  74. <template v-slot:paymentConditionName="scope">
  75. <el-input
  76. clearable
  77. :value="scope.row.paymentConditionName"
  78. @click.native="openPaymentTerms(scope.$index)"
  79. :placeholder="isView ? '' : '请选择'"
  80. :disabled="isView"
  81. readonly
  82. />
  83. </template>
  84. <template v-slot:nowConfirmedPrepayAmt="scope">
  85. <el-form-item
  86. :prop="'payablesList.' + scope.$index + '.nowConfirmedPrepayAmt'"
  87. :rules="{
  88. validator: (rule, value, cb) =>
  89. validateConfirmAmount(rule, value, cb, scope.row),
  90. trigger: 'change'
  91. }"
  92. >
  93. <el-input
  94. v-model="scope.row.nowConfirmedPrepayAmt"
  95. type="number"
  96. :disabled="true"
  97. @input="handleConfirmAmountChange(scope.row, scope.$index)"
  98. />
  99. </el-form-item>
  100. </template>
  101. <template v-slot:amountDiff="scope">
  102. <el-input
  103. v-model="scope.row.amountDiff"
  104. type="number"
  105. :min="0"
  106. disabled
  107. placeholder="0"
  108. />
  109. </template>
  110. <template v-slot:dealType="scope">
  111. <el-select
  112. v-model="scope.row.dealType"
  113. placeholder="请选择"
  114. class="ele-block"
  115. disabled
  116. >
  117. <el-option
  118. v-for="item in dealTypeOp"
  119. :key="item.value"
  120. :label="item.label"
  121. :value="item.value"
  122. />
  123. </el-select>
  124. </template>
  125. <template v-slot:offsetMode="scope">
  126. <el-select
  127. v-if="scope.row.dealType === 3"
  128. v-model="scope.row.offsetMode"
  129. placeholder="请选择"
  130. class="ele-block"
  131. disabled
  132. >
  133. <el-option
  134. v-for="item in offsetModeOp"
  135. :key="item.value"
  136. :label="item.label"
  137. :value="item.value"
  138. />
  139. </el-select>
  140. <span v-else class="ele-block diff-direction-empty">-</span>
  141. </template>
  142. <template v-slot:offsetRef="scope">
  143. <el-tag
  144. v-if="scope.row.dealType === 3 && isWriteoffMode(scope.row.offsetMode) && (scope.row.writeoffList || []).length"
  145. size="mini"
  146. type="success"
  147. >
  148. 已选{{ (scope.row.writeoffList || []).length }}张/合计{{ sumWriteoff(scope.row) }}
  149. </el-tag>
  150. <span v-else>-</span>
  151. </template>
  152. <template v-slot:exceptionRemark="scope">
  153. <el-input
  154. v-model="scope.row.exceptionRemark"
  155. type="textarea"
  156. :autosize="{ minRows: 1, maxRows: 3 }"
  157. disabled
  158. />
  159. </template>
  160. <template v-slot:action="scope">
  161. <el-link
  162. v-if="!isView"
  163. type="danger"
  164. :underline="false"
  165. icon="el-icon-delete"
  166. @click="removeRow(scope.$index)"
  167. >删除</el-link
  168. >
  169. </template>
  170. <template v-slot:columnRequired="{ column }">
  171. <span class="is-required">{{ column.label }}</span>
  172. </template>
  173. </ele-pro-table>
  174. </el-form>
  175. </div>
  176. </template>
  177. <script>
  178. import {
  179. paymentTypeOp,
  180. transactionMethodsOp,
  181. paymentStatus
  182. } from '@/enum/dict';
  183. export default {
  184. name: 'payablesInfo',
  185. components: { },
  186. props: {
  187. dataForm: {
  188. type: Object,
  189. default: () => ({})
  190. },
  191. // 父组件传入的初始应付明细,仅作为初始化值,修改不再回写父
  192. payablesList: {
  193. type: Array,
  194. default: () => []
  195. },
  196. dialogType: {
  197. type: String,
  198. default: 'add'
  199. },
  200. statementAdvanceTotalPriceTitle: {
  201. type: String,
  202. default: '总对账预付款确收金额'
  203. },
  204. columnsTitle: {
  205. type: String,
  206. default: '本次对账预付款确收金额'
  207. }
  208. },
  209. data() {
  210. return {
  211. // 缓存键变更:强制重建列配置,确保「差异汇总金额」「异常处理」「冲抵处置方式」「冲抵单据」「异常说明」五列在审批页显示
  212. cacheKeyUrl: 'wt-202611172100-purchase-payables-table',
  213. paymentTypeOp,
  214. transactionMethodsOp,
  215. paymentStatusOp: paymentStatus,
  216. // 金额差异异常处理类型(与后端 FinStatDealTypeEnum 一致)
  217. dealTypeOp: [
  218. { value: 1, label: '收款' },
  219. { value: 2, label: '退款' },
  220. { value: 3, label: '冲抵下期' },
  221. { value: 4, label: '不处置' }
  222. ],
  223. // 冲抵处置方式(与后端 FinOffsetModeEnum 一致)
  224. offsetModeOp: [
  225. { value: 1, label: '借向结转(应补未补)' },
  226. { value: 2, label: '贷向结转(应退未退)' },
  227. { value: 3, label: '核销冲抵单据(借向)' },
  228. { value: 4, label: '核销冲抵单据(贷向)' }
  229. ],
  230. rules: {},
  231. // 本地维护的应付明细,避免每次编辑都同步回父组件
  232. localList: [],
  233. columns: [
  234. {
  235. width: 60,
  236. label: '序号',
  237. type: 'index',
  238. columnKey: 'index',
  239. align: 'center',
  240. fixed: 'left'
  241. },
  242. {
  243. minWidth: 140,
  244. prop: 'purchaseCode',
  245. label: '采购订单编码',
  246. align: 'center',
  247. showOverflowTooltip: true
  248. },
  249. {
  250. minWidth: 140,
  251. prop: 'prepayCodes',
  252. label: '预付编码',
  253. align: 'center',
  254. showOverflowTooltip: true
  255. },
  256. // {
  257. // prop: 'fundType',
  258. // minWidth: 140,
  259. // label: '款项类型',
  260. // align: 'center',
  261. // slot: 'fundType',
  262. // headerSlot: 'columnRequired'
  263. // },
  264. {
  265. prop: 'transactionMode',
  266. minWidth: 140,
  267. label: '交易方式',
  268. align: 'center',
  269. slot: 'transactionMode',
  270. headerSlot: 'columnRequired'
  271. },
  272. {
  273. prop: 'paymentConditionName',
  274. minWidth: 160,
  275. label: '付款条件',
  276. align: 'center',
  277. slot: 'paymentConditionName'
  278. },
  279. {
  280. prop: 'prepayTotalAmt',
  281. minWidth: 160,
  282. label: '预付合计金额',
  283. align: 'center',
  284. },
  285. {
  286. prop: 'confirmedPrepayAmt',
  287. minWidth: 160,
  288. label: '累计预付确付金额',
  289. align: 'center',
  290. },
  291. {
  292. prop: 'unpaidPrepayAmt',
  293. minWidth: 160,
  294. label: '未付预付金额',
  295. align: 'center',
  296. },
  297. // {
  298. // minWidth: 170,
  299. // prop: 'unreconciledAdvanceConfirmAmount',
  300. // label: '未对账预付款确收金额',
  301. // align: 'center',
  302. // showOverflowTooltip: true
  303. // },
  304. {
  305. minWidth: 190,
  306. headerSlot: 'columnRequired',
  307. prop: 'nowConfirmedPrepayAmt',
  308. label: this.columnsTitle,
  309. align: 'center',
  310. slot: 'nowConfirmedPrepayAmt'
  311. },
  312. {
  313. minWidth: 160,
  314. prop: 'lastPayableAmt',
  315. label: '上期累计应付金额',
  316. align: 'center'
  317. },
  318. {
  319. minWidth: 120,
  320. prop: 'statementAmount',
  321. label: '本次对账金额',
  322. align: 'center',
  323. showOverflowTooltip: true
  324. },
  325. {
  326. minWidth: 120,
  327. prop: 'statementAmt',
  328. label: '本次对账应付总金额',
  329. align: 'center',
  330. showOverflowTooltip: true
  331. },
  332. {
  333. minWidth: 160,
  334. prop: 'payableAmt',
  335. label: '累计应付金额',
  336. align: 'center',
  337. showOverflowTooltip: true
  338. },
  339. {
  340. minWidth: 140,
  341. prop: 'amountDiff',
  342. label: '差异汇总金额',
  343. align: 'center',
  344. slot: 'amountDiff'
  345. },
  346. {
  347. minWidth: 160,
  348. prop: 'dealType',
  349. label: '异常处理',
  350. align: 'center',
  351. slot: 'dealType'
  352. },
  353. {
  354. minWidth: 180,
  355. prop: 'offsetMode',
  356. label: '冲抵处置方式',
  357. align: 'center',
  358. slot: 'offsetMode'
  359. },
  360. {
  361. minWidth: 220,
  362. prop: 'writeoffList',
  363. label: '冲抵单据',
  364. align: 'center',
  365. slot: 'offsetRef'
  366. },
  367. {
  368. minWidth: 160,
  369. prop: 'exceptionRemark',
  370. label: '异常说明',
  371. align: 'center',
  372. slot: 'exceptionRemark'
  373. }
  374. ]
  375. };
  376. },
  377. computed: {
  378. isView() {
  379. return this.dialogType === 'view';
  380. },
  381. statementAdvanceTotalPrice() {
  382. return this.dataForm?.statPayable?.statementPrepayTotalPrice || 0
  383. // return (
  384. // this.localList.reduce(
  385. // (pre, cur) =>
  386. // pre + Math.round((+cur.confirmedPrepayAmt || 0) * 100),
  387. // 0
  388. // ) / 100
  389. // );
  390. },
  391. receivedTotalPrice() {
  392. return (
  393. // Math.round(
  394. // ((+this.dataForm.amountTotalPrice || 0) -
  395. // this.statementAdvanceTotalPrice) *
  396. // 100
  397. // ) / 100
  398. this.localList.reduce(
  399. (pre, cur) =>
  400. pre + Math.round((+cur.payablePrice || 0) * 100),
  401. 0
  402. ) / 100
  403. );
  404. }
  405. },
  406. watch: {
  407. // 父传入初始值(查询/编辑回填)时同步到本地副本
  408. payablesList: {
  409. handler(val) {
  410. this.localList = (val || []).map((item) => ({ ...item }));
  411. this.recalcAllRows();
  412. },
  413. immediate: true
  414. },
  415. 'dataForm.amountTotalPrice': {
  416. handler() {
  417. this.recalcAllRows();
  418. },
  419. immediate: true
  420. }
  421. },
  422. methods: {
  423. // 是否核销模式(3核销借向 / 4核销贷向)
  424. isWriteoffMode(mode) {
  425. return mode === 3 || mode === 4;
  426. },
  427. // 已选冲抵金额合计
  428. sumWriteoff(row) {
  429. const sum = (row.writeoffList || []).reduce(
  430. (pre, cur) => pre + (+cur.writeoffAmt || 0),
  431. 0
  432. );
  433. return Math.round(sum * 100) / 100;
  434. },
  435. openPaymentTerms(index) {
  436. this.currentRowIndex = index;
  437. this.$refs.receiveTermsDialogRef.open();
  438. },
  439. changeReceiveTerms(row, index) {
  440. const targetIndex = index != null ? index : this.currentRowIndex;
  441. if (targetIndex == null) return;
  442. this.updateRowField(targetIndex, 'collectionConditionId', row.id);
  443. this.updateRowField(targetIndex, 'collectionConditionName', row.name);
  444. },
  445. // 行内字段修改:仅更新本地副本
  446. // 注意:必须用 $set 直接修改原对象属性,保持引用不变,
  447. // 否则 ele-pro-table 内部缓存的 tableData 仍引用旧对象,导致表格不更新
  448. updateRowField(index, key, val) {
  449. const item = this.localList[index];
  450. if (!item) return;
  451. this.$set(item, key, val);
  452. },
  453. // 新增一行空白预付
  454. addRow() {
  455. this.localList.push({
  456. id: 'local_' + Date.now() + '_' + this.localList.length,
  457. purchaseCode: '',
  458. advanceCode: '',
  459. fundType: '',
  460. transactionMode: '',
  461. paymentConditionId: '',
  462. paymentConditionName: '',
  463. unreconciledAdvanceConfirmAmount: 0,
  464. nowConfirmedPrepayAmt: 0,
  465. lastPayableAmt: 0,
  466. statementAmount: 0,
  467. payablePrice: 0,
  468. payableAmt: 0
  469. });
  470. },
  471. // 由父组件预付款选择器回调调用:追加一行已映射好的应付明细(本地维护)
  472. addPayableRow(row) {
  473. this.localList.push({ ...row });
  474. },
  475. removeRow(index) {
  476. if (index < 0 || index >= this.localList.length) return;
  477. this.localList.splice(index, 1);
  478. },
  479. // 本次对账预付款确收金额上限 = min(未对账预付款确收金额, 本次对账金额)
  480. getMaxConfirmAmount(row) {
  481. return Math.min(
  482. +row.unreconciledAdvanceConfirmAmount || 0,
  483. +row.statementAmount || 0
  484. );
  485. },
  486. handleConfirmAmountChange(row, index) {
  487. // 限制本次确收金额不能超过未对账金额和本次对账金额
  488. let val = +row.nowConfirmedPrepayAmt || 0;
  489. const max = this.getMaxConfirmAmount(row);
  490. if (val > max) {
  491. val = max;
  492. // this.$set(row, 'nowConfirmedPrepayAmt', val);
  493. this.$message.warning(
  494. '本次对账预付款确收金额不能超过未对账金额和本次对账金额'
  495. );
  496. }
  497. this.recalcRow(row);
  498. },
  499. // 根据本次对账金额重算单行:
  500. // 确收金额 = min(未对账预付款确收金额, 本次对账金额)
  501. // 本次应付金额 = 本次对账金额 - 确收金额
  502. // 累计应付金额 = 本次对账金额 - 累计预付确付金额 + 上期累计应付金额
  503. recalcRow(row) {
  504. const statementAmount = +row.statementAmount || 0;
  505. let val = +row.nowConfirmedPrepayAmt || 0;
  506. const max = this.getMaxConfirmAmount(row);
  507. if (val > max) val = max;
  508. // this.$set(row, 'nowConfirmedPrepayAmt', val);
  509. // 本次应付金额 = 本次对账金额 - 确收金额
  510. this.$set(
  511. row,
  512. 'payablePrice',
  513. Math.round((statementAmount - val) * 100) / 100
  514. );
  515. // 累计应付金额=本次对账金额-累计预付确付金额+上期累计应付金额
  516. const totalPayableAmount =
  517. statementAmount -
  518. (+row.confirmedPrepayAmt || 0) +
  519. (+row.lastPayableAmt || 0);
  520. this.$set(
  521. row,
  522. 'payableAmt',
  523. Math.round(totalPayableAmount * 100) / 100
  524. );
  525. },
  526. // 明细表按采购单号汇总本次对账金额后,同步到对应采购单号的应付行
  527. syncStatementAmount(summaryMap) {
  528. if (!summaryMap || !Object.keys(summaryMap).length) return;
  529. this.localList.forEach((row) => {
  530. const amount = summaryMap[row.purchaseCode];
  531. if (amount !== undefined) {
  532. this.$set(row, 'statementAmount', amount);
  533. this.recalcRow(row);
  534. }
  535. });
  536. },
  537. recalcAllRows() {
  538. this.localList.forEach((row) => {
  539. this.recalcRow(row);
  540. });
  541. },
  542. validateConfirmAmount(rule, value, callback, row) {
  543. return callback();
  544. const val = +value || 0;
  545. const max = this.getMaxConfirmAmount(row);
  546. if (val < 0) {
  547. callback(new Error('不能小于0'));
  548. } else if (val > max) {
  549. callback(new Error(`不能超过${max}`));
  550. } else {
  551. callback();
  552. }
  553. },
  554. // 提交时由父组件调用,一次性取回整个应付表单(本地明细 + 汇总)
  555. getSubmitData() {
  556. return {
  557. payablesList: this.localList.map((item) => ({ ...item })),
  558. statementAdvanceTotalPrice: this.statementAdvanceTotalPrice,
  559. receivedTotalPrice: this.receivedTotalPrice
  560. };
  561. },
  562. validate() {
  563. return new Promise((resolve, reject) => {
  564. const promises = [this.$refs.form.validate()];
  565. if (this.$refs.tableForm) {
  566. promises.push(this.$refs.tableForm.validate());
  567. }
  568. Promise.all(promises)
  569. .then(() => resolve(true))
  570. .catch(() => reject(false));
  571. });
  572. }
  573. }
  574. };
  575. </script>
  576. <style scoped lang="scss">
  577. .payables-info {
  578. .payables-table-header {
  579. display: flex;
  580. justify-content: flex-end;
  581. margin-bottom: 10px;
  582. }
  583. .el-form-item {
  584. margin-bottom: 0 !important;
  585. }
  586. }
  587. ::v-deep .is-required::before {
  588. content: '*';
  589. color: #f56c6c;
  590. margin-right: 4px;
  591. }
  592. </style>