ContactTableSelect.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!-- 联系人的选择列表 TODO 芋艿:后面看看要不要搞到统一封装里 -->
  2. <template>
  3. <Dialog v-model="dialogVisible" :appendToBody="true" title="选择联系人" width="700">
  4. <el-table
  5. ref="multipleTableRef"
  6. v-loading="loading"
  7. :data="list"
  8. :show-overflow-tooltip="true"
  9. :stripe="true"
  10. @selection-change="handleSelectionChange"
  11. >
  12. <el-table-column type="selection" width="55" />
  13. <el-table-column align="center" fixed="left" label="姓名" prop="name" width="140" />
  14. <el-table-column
  15. align="center"
  16. fixed="left"
  17. label="客户名称"
  18. prop="customerName"
  19. width="120"
  20. />
  21. <el-table-column align="center" label="手机" prop="mobile" width="120" />
  22. <el-table-column align="center" label="电话" prop="telephone" width="120" />
  23. <el-table-column align="center" label="邮箱" prop="email" width="120" />
  24. <el-table-column align="center" label="职位" prop="post" width="120" />
  25. </el-table>
  26. <template #footer>
  27. <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
  28. <el-button @click="dialogVisible = false">取 消</el-button>
  29. </template>
  30. </Dialog>
  31. </template>
  32. <script lang="ts" setup>
  33. import * as ContactApi from '@/api/crm/contact'
  34. import { ElTable } from 'element-plus'
  35. defineOptions({ name: 'ContactTableSelect' })
  36. withDefaults(defineProps<{ modelValue: number[] }>(), { modelValue: () => [] })
  37. const list = ref<ContactApi.ContactVO[]>([]) // 列表的数据
  38. const loading = ref(false) // 列表的加载中
  39. const dialogVisible = ref(false) // 弹窗的是否展示
  40. const formLoading = ref(false)
  41. // 确认选择时的触发事件
  42. const emits = defineEmits<{
  43. (e: 'update:modelValue', v: number[]): void
  44. }>()
  45. const multipleTableRef = ref<InstanceType<typeof ElTable>>()
  46. const multipleSelection = ref<ContactApi.ContactVO[]>([])
  47. const handleSelectionChange = (val: ContactApi.ContactVO[]) => {
  48. multipleSelection.value = val
  49. }
  50. /** 触发 */
  51. const submitForm = () => {
  52. formLoading.value = true
  53. try {
  54. emits(
  55. 'update:modelValue',
  56. multipleSelection.value.map((item) => item.id)
  57. )
  58. } finally {
  59. formLoading.value = false
  60. // 关闭弹窗
  61. dialogVisible.value = false
  62. }
  63. }
  64. const getList = async () => {
  65. loading.value = true
  66. try {
  67. list.value = await ContactApi.getSimpleContactList()
  68. } finally {
  69. loading.value = false
  70. }
  71. }
  72. /** 打开弹窗 */
  73. const open = async () => {
  74. dialogVisible.value = true
  75. await nextTick()
  76. if (multipleSelection.value.length > 0) {
  77. multipleTableRef.value!.clearSelection()
  78. }
  79. await getList()
  80. }
  81. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  82. </script>