ContactList.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <!-- 操作栏 -->
  3. <el-row justify="end">
  4. <el-button @click="openForm">
  5. <Icon class="mr-5px" icon="system-uicons:contacts" />
  6. 创建联系人
  7. </el-button>
  8. </el-row>
  9. <!-- 列表 -->
  10. <ContentWrap class="mt-10px">
  11. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  12. <el-table-column label="姓名" fixed="left" align="center" prop="name">
  13. <template #default="scope">
  14. <el-link type="primary" :underline="false" @click="openDetail(scope.row.id)">
  15. {{ scope.row.name }}
  16. </el-link>
  17. </template>
  18. </el-table-column>
  19. <el-table-column label="手机号" align="center" prop="mobile" />
  20. <el-table-column label="职位" align="center" prop="post" />
  21. <el-table-column label="直属上级" align="center" prop="parentName" />
  22. <el-table-column label="是否关键决策人" align="center" prop="master" min-width="100">
  23. <template #default="scope">
  24. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.master" />
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. <!-- 分页 -->
  29. <Pagination
  30. :total="total"
  31. v-model:page="queryParams.pageNo"
  32. v-model:limit="queryParams.pageSize"
  33. @pagination="getList"
  34. />
  35. </ContentWrap>
  36. <!-- 表单弹窗:添加 -->
  37. <ContactForm ref="formRef" @success="getList" />
  38. </template>
  39. <script setup lang="ts">
  40. import * as ContactApi from '@/api/crm/contact'
  41. import ContactForm from './../ContactForm.vue'
  42. import { DICT_TYPE } from '@/utils/dict'
  43. import { BizTypeEnum } from '@/api/crm/permission'
  44. defineOptions({ name: 'CrmContactList' })
  45. const props = defineProps<{
  46. bizType: number // 业务类型
  47. bizId: number // 业务编号
  48. customerId: number // 特殊:客户编号;在【商机】详情中,可以传递客户编号,默认新建的联系人关联到该客户
  49. businessId: number // 特殊:商机编号;在【商机】详情中,可以传递商机编号,默认新建的联系人关联到该商机
  50. }>()
  51. const loading = ref(true) // 列表的加载中
  52. const total = ref(0) // 列表的总页数
  53. const list = ref([]) // 列表的数据
  54. const queryParams = reactive({
  55. pageNo: 1,
  56. pageSize: 10,
  57. customerId: undefined as unknown // 允许 undefined + number
  58. })
  59. /** 查询列表 */
  60. const getList = async () => {
  61. loading.value = true
  62. try {
  63. // 置空参数
  64. queryParams.customerId = undefined
  65. // 执行查询
  66. let data = { list: [], total: 0 }
  67. switch (props.bizType) {
  68. case BizTypeEnum.CRM_CUSTOMER:
  69. queryParams.customerId = props.bizId
  70. data = await ContactApi.getContactPageByCustomer(queryParams)
  71. break
  72. case BizTypeEnum.CRM_BUSINESS:
  73. queryParams.businessId = props.bizId
  74. data = await ContactApi.getContactPageByBusiness(queryParams)
  75. break
  76. default:
  77. return
  78. }
  79. list.value = data.list
  80. total.value = data.total
  81. } finally {
  82. loading.value = false
  83. }
  84. }
  85. /** 搜索按钮操作 */
  86. const handleQuery = () => {
  87. queryParams.pageNo = 1
  88. getList()
  89. }
  90. /** 添加操作 */
  91. const formRef = ref()
  92. const openForm = () => {
  93. formRef.value.open('create', undefined, props.customerId, props.businessId)
  94. }
  95. /** 打开联系人详情 */
  96. const { push } = useRouter()
  97. const openDetail = (id: number) => {
  98. push({ name: 'CrmContactDetail', params: { id } })
  99. }
  100. /** 监听打开的 bizId + bizType,从而加载最新的列表 */
  101. watch(
  102. () => [props.bizId, props.bizType],
  103. () => {
  104. handleQuery()
  105. },
  106. { immediate: true, deep: true }
  107. )
  108. </script>