ContactList.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <!-- 操作栏 -->
  3. <el-row justify="end">
  4. <el-button>
  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">
  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-column label="操作" align="center" fixed="right" width="200">
  28. <template #default="scope">
  29. <el-button
  30. plain
  31. type="primary"
  32. @click="openForm('update', scope.row.id)"
  33. v-hasPermi="['crm:contact:update']"
  34. >
  35. 编辑
  36. </el-button>
  37. <el-button
  38. plain
  39. type="danger"
  40. @click="handleDelete(scope.row.id)"
  41. v-hasPermi="['crm:contact:delete']"
  42. >
  43. 删除
  44. </el-button>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. <!-- 分页 -->
  49. <Pagination
  50. :total="total"
  51. v-model:page="queryParams.pageNo"
  52. v-model:limit="queryParams.pageSize"
  53. @pagination="getList"
  54. />
  55. </ContentWrap>
  56. <!-- 表单弹窗:添加/修改 -->
  57. <ContactForm ref="formRef" @success="getList" />
  58. </template>
  59. <script setup lang="ts">
  60. import * as ContactApi from '@/api/crm/contact'
  61. import ContactForm from './../ContactForm.vue'
  62. import { DICT_TYPE } from '@/utils/dict'
  63. import { BizTypeEnum } from '@/api/crm/permission'
  64. defineOptions({ name: 'CrmContactList' })
  65. const props = defineProps<{
  66. bizType: number // 业务类型
  67. bizId: number // 业务编号
  68. }>()
  69. const message = useMessage() // 消息弹窗
  70. const { t } = useI18n() // 国际化
  71. const loading = ref(true) // 列表的加载中
  72. const total = ref(0) // 列表的总页数
  73. const list = ref([]) // 列表的数据
  74. const queryParams = reactive({
  75. pageNo: 1,
  76. pageSize: 10,
  77. customerId: undefined as unknown // 允许 undefined + number
  78. })
  79. /** 查询列表 */
  80. const getList = async () => {
  81. loading.value = true
  82. try {
  83. // 置空参数
  84. queryParams.customerId = undefined
  85. // 执行查询
  86. let data = { list: [], total: 0 }
  87. switch (props.bizType) {
  88. case BizTypeEnum.CRM_CUSTOMER:
  89. queryParams.customerId = props.bizId
  90. data = await ContactApi.getContactPageByCustomer(queryParams)
  91. break
  92. default:
  93. return
  94. }
  95. list.value = data.list
  96. total.value = data.total
  97. } finally {
  98. loading.value = false
  99. }
  100. }
  101. /** 搜索按钮操作 */
  102. const handleQuery = () => {
  103. queryParams.pageNo = 1
  104. getList()
  105. }
  106. /** 添加/修改操作 */
  107. const formRef = ref()
  108. const openForm = (type: string, id?: number) => {
  109. formRef.value.open(type, id)
  110. }
  111. /** 删除按钮操作 */
  112. const handleDelete = async (id: number) => {
  113. try {
  114. // 删除的二次确认
  115. await message.delConfirm()
  116. // 发起删除
  117. await ContactApi.deleteContact(id)
  118. message.success(t('common.delSuccess'))
  119. // 刷新列表
  120. await getList()
  121. } catch {}
  122. }
  123. /** 打开客户详情 */
  124. const { push } = useRouter()
  125. const openDetail = (id: number) => {
  126. push({ name: 'CrmContactDetail', 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>