paymentCollection.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="flex flex-col h-full paymentCollection">
  3. <div class="info flex-1 overflow-y-auto cellnormall">
  4. <template v-if="paymentPlanList.length">
  5. <div class="bg-white py-2 mb-4" v-for="item in paymentPlanList" :key="item.id">
  6. <van-cell-group inset>
  7. <van-cell title="回款时间" :value="item.createTime" />
  8. <van-cell title="操作人">
  9. <template #default>
  10. <TranslationComponent :openId="item.creatorName"></TranslationComponent>
  11. </template>
  12. </van-cell>
  13. <van-cell title="回款金额" :value="item.money" />
  14. <van-cell title="未回款金额" :value="item.unReceivedPayment" />
  15. <van-cell title="操作">
  16. <template #default>
  17. <div class="flex justify-end">
  18. <div class="mr-3 themeTextColor" @click="editPaymentCollection(item)">编辑</div>
  19. <div class="text-[red]" @click="deletePaymentCollection(item)">删除</div>
  20. </div>
  21. </template>
  22. </van-cell>
  23. </van-cell-group>
  24. </div>
  25. </template>
  26. <template v-else>
  27. <van-empty description="暂无数据" />
  28. </template>
  29. </div>
  30. <div class="bottomButton">
  31. <van-button type="primary" class="w-full block" @click="addPaymentCollection">添加回款</van-button>
  32. </div>
  33. <!-- 添加回款 -->
  34. <van-dialog v-model:show="showDialog" :title="`${dialogNumberVal.rowId ? '编辑' : '新增'}回款金额`" show-cancel-button
  35. @confirm="addEditReceipt" :before-close="dialogCloseBefo">
  36. <van-field v-model="dialogNumberVal.val" type="digit" label="回款金额" placeholder="请输入回款金额" />
  37. </van-dialog>
  38. </div>
  39. </template>
  40. <script setup>
  41. import { ref, watch } from 'vue';
  42. import { showConfirmDialog } from 'vant';
  43. import { useLifecycle } from '@hooks/useCommon.js';
  44. import { OBTAIN_SALES_ORDER_RECEIPTS, NEW_SALES_ORDER_PAYMENT_COLLECTION, SALES_ORDER_COLLECTION_EDITING, DELETE_SALES_ORDER_PAYMENT_RECORDS } from '@hooks/useApi'
  45. import requests from "@common/requests";
  46. import useShowToast from '@hooks/useToast'
  47. const { toastSuccess, toastFail, toastText } = useShowToast()
  48. const props = defineProps({
  49. info: {
  50. type: Object,
  51. required: true,
  52. default: () => ({})
  53. }
  54. })
  55. const paymentPlanList = ref([])
  56. const showDialog = ref(false);
  57. const dialogNumberVal = ref({
  58. rowId: null,
  59. val: null
  60. })
  61. watch(() => props.info, (newValue) => {
  62. processingData(newValue.id)
  63. })
  64. function deletePaymentCollection(row) {
  65. showConfirmDialog({
  66. message: `确定删除该回款记录吗?`,
  67. }).then(() => {
  68. requests.post(DELETE_SALES_ORDER_PAYMENT_RECORDS, { paymentId: row.id }).then(() => {
  69. toastSuccess('操作成功')
  70. processingData(props.info.id)
  71. }).catch((err) => {
  72. toastFail(err.msg ? err.msg : '删除失败')
  73. })
  74. })
  75. }
  76. function addEditReceipt() {
  77. const { rowId, val } = dialogNumberVal.value
  78. if (!val || val <= 0) {
  79. toastText('请填写回款金额并且不能为负数')
  80. return
  81. }
  82. const url = rowId ? SALES_ORDER_COLLECTION_EDITING : NEW_SALES_ORDER_PAYMENT_COLLECTION
  83. const arrList = paymentPlanList.value.filter(item => item.id !== rowId)
  84. const totalMoney = arrList.reduce((acc, item) => acc + item.money, 0);
  85. const orderAmount = props.info.price
  86. const formVal = {
  87. [rowId ? 'paymentId' : 'orderId']: rowId ? rowId : props.info.id,
  88. money: val,
  89. }
  90. if ((+totalMoney + val) > orderAmount) {
  91. toastText('回款金额不能大于订单金额')
  92. return
  93. }
  94. requests.post(url, formVal).then(() => {
  95. toastSuccess('操作成功')
  96. processingData(props.info.id)
  97. showDialog.value = false
  98. })
  99. }
  100. function addPaymentCollection() {
  101. dialogNumberVal.value = { rowId: null, val: null }
  102. showDialog.value = true
  103. }
  104. function editPaymentCollection(row) {
  105. const { id, money } = row
  106. dialogNumberVal.value = { rowId: id, val: money }
  107. showDialog.value = true
  108. }
  109. function processingData(id) {
  110. requests.post(OBTAIN_SALES_ORDER_RECEIPTS, { orderId: id }).then((res) => {
  111. paymentPlanList.value = res.data.reverse()
  112. })
  113. }
  114. function dialogCloseBefo(val) {
  115. if (val == 'confirm' && showDialog.value) {
  116. return false
  117. }
  118. return true
  119. }
  120. useLifecycle({
  121. init: () => {
  122. processingData(props.info.id)
  123. }
  124. });
  125. </script>
  126. <style lang='scss' scoped>
  127. .paymentCollection {
  128. .bottomButton {
  129. margin: 0 14px;
  130. padding-bottom: 30px;
  131. :deep(.van-button) {
  132. margin-bottom: 20px;
  133. }
  134. }
  135. .info {
  136. margin: 8px 4px 30px 4px;
  137. padding: 10px
  138. }
  139. }
  140. </style>