paymentCollection.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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, index) 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" v-if="index == 0" @click="editPaymentCollection(item)">编辑</div>
  19. <div class="text-[red]" v-if="index == 0" @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 emit = defineEmits()
  49. const props = defineProps({
  50. info: {
  51. type: Object,
  52. required: true,
  53. default: () => ({})
  54. }
  55. })
  56. const paymentPlanList = ref([])
  57. const showDialog = ref(false);
  58. const dialogNumberVal = ref({
  59. rowId: null,
  60. val: null
  61. })
  62. watch(() => props.info, (newValue) => {
  63. processingData(newValue.id)
  64. })
  65. function deletePaymentCollection(row) {
  66. showConfirmDialog({
  67. message: `确定删除该回款记录吗?`,
  68. }).then(() => {
  69. requests.post(DELETE_SALES_ORDER_PAYMENT_RECORDS, { paymentId: row.id }).then(() => {
  70. toastSuccess('操作成功')
  71. emit('changePaymentCollection', props.info.id)
  72. processingData(props.info.id)
  73. }).catch((err) => {
  74. toastFail(err.msg ? err.msg : '删除失败')
  75. })
  76. })
  77. }
  78. function addEditReceipt() {
  79. const { rowId, val } = dialogNumberVal.value
  80. if (!val || val <= 0) {
  81. toastText('请填写回款金额并且不能为负数')
  82. return
  83. }
  84. const url = rowId ? SALES_ORDER_COLLECTION_EDITING : NEW_SALES_ORDER_PAYMENT_COLLECTION
  85. const arrList = paymentPlanList.value.filter(item => item.id !== rowId)
  86. const totalMoney = arrList.reduce((acc, item) => acc + item.money, 0);
  87. const orderAmount = props.info.price
  88. const formVal = {
  89. [rowId ? 'paymentId' : 'orderId']: rowId ? rowId : props.info.id,
  90. money: val,
  91. }
  92. if ((+totalMoney + +val) > orderAmount) {
  93. toastText('回款金额不能大于订单金额')
  94. return
  95. }
  96. requests.post(url, formVal).then(() => {
  97. toastSuccess('操作成功')
  98. emit('changePaymentCollection', props.info.id)
  99. processingData(props.info.id)
  100. showDialog.value = false
  101. })
  102. }
  103. function addPaymentCollection() {
  104. dialogNumberVal.value = { rowId: null, val: null }
  105. showDialog.value = true
  106. }
  107. function editPaymentCollection(row) {
  108. const { id, money } = row
  109. dialogNumberVal.value = { rowId: id, val: money }
  110. showDialog.value = true
  111. }
  112. function processingData(id) {
  113. requests.post(OBTAIN_SALES_ORDER_RECEIPTS, { orderId: id }).then((res) => {
  114. paymentPlanList.value = res.data.reverse()
  115. })
  116. }
  117. function dialogCloseBefo(val) {
  118. if (val == 'confirm' && showDialog.value) {
  119. return false
  120. }
  121. return true
  122. }
  123. useLifecycle({
  124. init: () => {
  125. processingData(props.info.id)
  126. }
  127. });
  128. </script>
  129. <style lang='scss' scoped>
  130. .paymentCollection {
  131. .bottomButton {
  132. margin: 0 14px;
  133. padding-bottom: 30px;
  134. :deep(.van-button) {
  135. margin-bottom: 20px;
  136. }
  137. }
  138. .info {
  139. margin: 8px 4px 30px 4px;
  140. padding: 10px
  141. }
  142. }
  143. </style>