ReceivableList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <!-- 操作栏 -->
  3. <el-row justify="end">
  4. <el-button @click="openForm('create')">
  5. <Icon class="mr-5px" icon="icon-park:income-one" />
  6. 创建回款
  7. </el-button>
  8. </el-row>
  9. <!-- 列表 -->
  10. <ContentWrap class="mt-10px">
  11. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  12. <el-table-column align="center" label="回款编号" prop="no" />
  13. <el-table-column align="center" label="客户" prop="customerName" />
  14. <el-table-column align="center" label="合同" prop="contract.no" />
  15. <el-table-column
  16. :formatter="dateFormatter2"
  17. align="center"
  18. label="回款日期"
  19. prop="returnTime"
  20. width="150px"
  21. />
  22. <el-table-column align="center" label="回款方式" prop="returnType" width="130px">
  23. <template #default="scope">
  24. <dict-tag :type="DICT_TYPE.CRM_RECEIVABLE_RETURN_TYPE" :value="scope.row.returnType" />
  25. </template>
  26. </el-table-column>
  27. <el-table-column
  28. align="center"
  29. label="回款金额(元)"
  30. prop="price"
  31. :formatter="erpPriceTableColumnFormatter"
  32. />
  33. <el-table-column align="center" label="负责人" prop="ownerUserName" />
  34. <el-table-column align="center" label="备注" prop="remark" />
  35. <el-table-column align="center" fixed="right" label="操作" width="130px">
  36. <template #default="scope">
  37. <el-button
  38. v-hasPermi="['crm:receivable:update']"
  39. link
  40. type="primary"
  41. @click="openForm('update', scope.row.id)"
  42. >
  43. 编辑
  44. </el-button>
  45. <el-button
  46. v-hasPermi="['crm:receivable:delete']"
  47. link
  48. type="danger"
  49. @click="handleDelete(scope.row.id)"
  50. >
  51. 删除
  52. </el-button>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <!-- 分页 -->
  57. <Pagination
  58. v-model:limit="queryParams.pageSize"
  59. v-model:page="queryParams.pageNo"
  60. :total="total"
  61. @pagination="getList"
  62. />
  63. </ContentWrap>
  64. <!-- 表单弹窗:添加 -->
  65. <ReceivableForm ref="formRef" @success="getList" />
  66. </template>
  67. <script lang="ts" setup>
  68. import * as ReceivablePlanApi from '@/api/crm/receivable/plan'
  69. import * as ReceivableApi from '@/api/crm/receivable'
  70. import ReceivableForm from './../ReceivableForm.vue'
  71. import { dateFormatter2 } from '@/utils/formatTime'
  72. import { DICT_TYPE } from '@/utils/dict'
  73. import { erpPriceTableColumnFormatter } from '@/utils'
  74. defineOptions({ name: 'CrmReceivableList' })
  75. const props = defineProps<{
  76. customerId?: number // 客户编号
  77. contractId?: number // 合同编号
  78. }>()
  79. const message = useMessage() // 消息弹窗
  80. const { t } = useI18n() // 国际化
  81. const loading = ref(true) // 列表的加载中
  82. const total = ref(0) // 列表的总页数
  83. const list = ref([]) // 列表的数据
  84. const queryParams = reactive({
  85. pageNo: 1,
  86. pageSize: 10,
  87. customerId: undefined as unknown, // 允许 undefined + number
  88. contractId: undefined as unknown // 允许 undefined + number
  89. })
  90. /** 查询列表 */
  91. const getList = async () => {
  92. loading.value = true
  93. try {
  94. if (props.customerId && !props.contractId) {
  95. queryParams.customerId = props.customerId
  96. } else if (props.customerId && props.contractId) {
  97. // 如果是合同的话客户编号也需要带上因为权限基于客户
  98. queryParams.customerId = props.customerId
  99. queryParams.contractId = props.contractId
  100. }
  101. const data = await ReceivableApi.getReceivablePageByCustomer(queryParams)
  102. list.value = data.list
  103. total.value = data.total
  104. } finally {
  105. loading.value = false
  106. }
  107. }
  108. /** 搜索按钮操作 */
  109. const handleQuery = () => {
  110. queryParams.pageNo = 1
  111. // 置空参数
  112. queryParams.customerId = undefined
  113. queryParams.contractId = undefined
  114. getList()
  115. }
  116. /** 添加/修改操作 */
  117. const formRef = ref()
  118. const openForm = (type: string, id?: number) => {
  119. formRef.value.open(type, id, {
  120. customerId: props.customerId,
  121. contractId: props.contractId
  122. })
  123. }
  124. /** 删除按钮操作 */
  125. const handleDelete = async (id: number) => {
  126. try {
  127. // 删除的二次确认
  128. await message.delConfirm()
  129. // 发起删除
  130. await ReceivableApi.deleteReceivable(id)
  131. message.success(t('common.delSuccess'))
  132. // 刷新列表
  133. await getList()
  134. } catch {}
  135. }
  136. /** 从回款计划创建回款 */
  137. const createReceivable = (planData: any) => {
  138. const data = planData as unknown as ReceivablePlanApi.ReceivablePlanVO
  139. formRef.value.open('create', undefined, data)
  140. }
  141. defineExpose({ createReceivable })
  142. /** 监听打开的 customerId + contractId,从而加载最新的列表 */
  143. watch(
  144. () => [props.customerId, props.contractId],
  145. (newVal) => {
  146. // 保证至少客户编号有值
  147. if (!newVal[0]) {
  148. return
  149. }
  150. handleQuery()
  151. },
  152. { immediate: true, deep: true }
  153. )
  154. </script>