BusinessListByContact.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <!-- 操作栏 -->
  3. <el-row justify="end">
  4. <el-button @click="openForm">
  5. <Icon class="mr-5px" icon="ep:opportunity" />
  6. 创建商机
  7. </el-button>
  8. <el-button @click="openBusinessLink"> 关联 </el-button>
  9. <el-button @click="deleteBusinessLink"> 解除关联 </el-button>
  10. </el-row>
  11. <!-- 列表 -->
  12. <ContentWrap class="mt-10px">
  13. <el-table
  14. v-loading="loading"
  15. ref="businessRef"
  16. :data="list"
  17. :stripe="true"
  18. :show-overflow-tooltip="true"
  19. >
  20. <el-table-column type="selection" width="55" />
  21. <el-table-column label="商机名称" fixed="left" align="center" prop="name">
  22. <template #default="scope">
  23. <el-link type="primary" :underline="false" @click="openDetail(scope.row.id)">
  24. {{ scope.row.name }}
  25. </el-link>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="商机金额" align="center" prop="price" :formatter="fenToYuanFormat" />
  29. <el-table-column label="客户名称" align="center" prop="customerName" />
  30. <el-table-column label="商机组" align="center" prop="statusTypeName" />
  31. <el-table-column label="商机阶段" align="center" prop="statusName" />
  32. </el-table>
  33. <!-- 分页 -->
  34. <Pagination
  35. :total="total"
  36. v-model:page="queryParams.pageNo"
  37. v-model:limit="queryParams.pageSize"
  38. @pagination="getList"
  39. />
  40. </ContentWrap>
  41. <!-- 表单弹窗:添加 -->
  42. <BusinessForm ref="formRef" @success="getList" />
  43. <!---->
  44. <BusinessLink ref="businessLinkRef" @success="getList" />
  45. </template>
  46. <script setup lang="ts">
  47. import * as ContactBusinessLinkApi from '@/api/crm/contactbusinesslink'
  48. import BusinessForm from '../../business/BusinessForm.vue'
  49. import { BizTypeEnum } from '@/api/crm/permission'
  50. import { fenToYuanFormat } from '@/utils/formatter'
  51. import BusinessLink from './BusinessLinkContactList.vue'
  52. const message = useMessage() // 消息弹窗
  53. // TODO @zyna:这个组件,可以服用 BusinessList,然后根据传入的编号类型,做一些判断?
  54. defineOptions({ name: 'CrmBusinessContactList' })
  55. const props = defineProps<{
  56. bizType: number // 业务类型
  57. bizId: number // 业务编号
  58. }>()
  59. const loading = ref(true) // 列表的加载中
  60. const total = ref(0) // 列表的总页数
  61. const list = ref([]) // 列表的数据
  62. const queryParams = reactive({
  63. pageNo: 1,
  64. pageSize: 10,
  65. contactId: undefined as unknown // 允许 undefined + number
  66. })
  67. /** 查询列表 */
  68. const getList = async () => {
  69. loading.value = true
  70. try {
  71. // 置空参数
  72. queryParams.contactId = undefined
  73. // 执行查询
  74. let data = { list: [], total: 0 }
  75. switch (props.bizType) {
  76. case BizTypeEnum.CRM_CONTACT:
  77. queryParams.contactId = props.bizId
  78. data = await ContactBusinessLinkApi.getBusinessByContactPage(queryParams)
  79. break
  80. default:
  81. return
  82. }
  83. list.value = data.list
  84. total.value = data.total
  85. } finally {
  86. loading.value = false
  87. }
  88. }
  89. /** 搜索按钮操作 */
  90. const handleQuery = () => {
  91. queryParams.pageNo = 1
  92. getList()
  93. }
  94. /** 添加操作 */
  95. const formRef = ref()
  96. const openForm = () => {
  97. formRef.value.open('create')
  98. }
  99. /** 关联操作 */
  100. const businessLinkRef = ref()
  101. const openBusinessLink = () => {
  102. businessLinkRef.value.open(props.bizId)
  103. }
  104. /**解除关联 */
  105. const businessRef = ref()
  106. const deleteBusinessLink = async () => {
  107. if (businessRef.value.getSelectionRows().length === 0) {
  108. message.success('未选择商机')
  109. } else {
  110. const postData = ref<ContactBusinessLinkApi.ContactBusinessLinkVO[]>([])
  111. businessRef.value.getSelectionRows().forEach((element) => {
  112. let data = {
  113. id: undefined,
  114. businessId: element.id,
  115. contactId: props.bizId
  116. }
  117. postData.value.push(data)
  118. })
  119. await ContactBusinessLinkApi.deleteContactBusinessLink(postData.value)
  120. handleQuery()
  121. }
  122. }
  123. /** 打开联系人详情 */
  124. const { push } = useRouter()
  125. const openDetail = (id: number) => {
  126. push({ name: 'CrmBusinessDetail', params: { id } })
  127. }
  128. /** 监听打开的 bizId + bizType,从而加载最新的列表 */
  129. watch(
  130. () => [props.bizId, props.bizType],
  131. () => {
  132. handleQuery()
  133. },
  134. { immediate: true, deep: true }
  135. )
  136. </script>