BusinessLinkContactList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <Dialog :title="dialogTitle" v-model="dialogVisible">
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="商机名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入商机名称"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  23. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  24. <el-button type="primary" @click="openForm()" v-hasPermi="['crm:business:create']">
  25. <Icon icon="ep:plus" class="mr-5px" /> 新增
  26. </el-button>
  27. </el-form-item>
  28. </el-form>
  29. </ContentWrap>
  30. <!-- 列表 -->
  31. <ContentWrap class="mt-10px">
  32. <el-table v-loading="loading" ref="businessRef" :data="list" :stripe="true" :show-overflow-tooltip="true">
  33. <el-table-column type="selection" width="55" />
  34. <el-table-column label="商机名称" fixed="left" align="center" prop="name">
  35. <template #default="scope">
  36. <el-link type="primary" :underline="false" @click="openDetail(scope.row.id)">
  37. {{ scope.row.name }}
  38. </el-link>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="商机金额" align="center" prop="price" :formatter="fenToYuanFormat" />
  42. <el-table-column label="客户名称" align="center" prop="customerName" />
  43. <el-table-column label="商机组" align="center" prop="statusTypeName" />
  44. <el-table-column label="商机阶段" align="center" prop="statusName" />
  45. </el-table>
  46. <!-- 分页 -->
  47. <Pagination
  48. :total="total"
  49. v-model:page="queryParams.pageNo"
  50. v-model:limit="queryParams.pageSize"
  51. @pagination="getList"
  52. />
  53. </ContentWrap>
  54. <template #footer>
  55. <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
  56. <el-button @click="dialogVisible = false">取 消</el-button>
  57. </template>
  58. <!-- 表单弹窗:添加 -->
  59. <BusinessForm ref="formRef" @success="getList" />
  60. </Dialog>
  61. </template>
  62. <script setup lang="ts">
  63. import * as BusinessApi from '@/api/crm/business'
  64. import BusinessForm from '../../business/BusinessForm.vue'
  65. import { BizTypeEnum } from '@/api/crm/permission'
  66. import { fenToYuanFormat } from '@/utils/formatter'
  67. import * as ContactbusinesslinkApi from '@/api/crm/contactbusinesslink'
  68. const message = useMessage() // 消息弹窗
  69. defineOptions({ name: 'CrmBusinessLinkContactList' })
  70. const dialogVisible = ref(false) // 弹窗的是否展示
  71. const dialogTitle = ref('') // 弹窗的标题
  72. const loading = ref(true) // 列表的加载中
  73. const total = ref(0) // 列表的总页数
  74. const list = ref([]) // 列表的数据
  75. const queryFormRef = ref() // 搜索的表单
  76. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  77. const contactIdProp = ref(undefined)
  78. const queryParams = reactive({
  79. pageNo: 1,
  80. pageSize: 10,
  81. name: undefined as unknown, // 允许 undefined + number
  82. })
  83. /** 打开弹窗 */
  84. const open = async (contactId?: number) => {
  85. dialogVisible.value = true
  86. contactIdProp.value = contactId
  87. getList()
  88. }
  89. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  90. /** 查询列表 */
  91. const getList = async () => {
  92. loading.value = true
  93. try {
  94. const data = await BusinessApi.getBusinessPage(queryParams)
  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 resetQuery = () => {
  108. queryFormRef.value.resetFields()
  109. handleQuery()
  110. }
  111. /** 添加操作 */
  112. const formRef = ref()
  113. const openForm = () => {
  114. formRef.value.open('create')
  115. }
  116. /**关联商机提交 */
  117. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  118. const businessRef = ref()
  119. const submitForm = async () =>{
  120. if(businessRef.value.getSelectionRows().length === 0){
  121. message.success('未选择商机')
  122. }else{
  123. const postData = ref<ContactbusinesslinkApi.ContactBusinessLinkVO[]>([])
  124. businessRef.value.getSelectionRows().forEach(element => {
  125. let data = {
  126. id:undefined,
  127. businessId : element.id,
  128. contactId : contactIdProp.value
  129. }
  130. postData.value.push(data)
  131. });
  132. await ContactbusinesslinkApi.createContactBusinessLinkBatch(postData.value)
  133. dialogVisible.value = false
  134. emit('success')
  135. }
  136. }
  137. /** 打开联系人详情 */
  138. const { push } = useRouter()
  139. const openDetail = (id: number) => {
  140. push({ name: 'CrmBusinessDetail', params: { id } })
  141. }
  142. </script>