BusinessLinkContactList.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <Dialog :title="dialogTitle" v-model="dialogVisible">
  3. <!-- 搜索工作栏 -->
  4. <ContentWrap>
  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. <!-- TODO @zyna:字段按照他们对齐下 -->
  32. <ContentWrap class="mt-10px">
  33. <el-table
  34. v-loading="loading"
  35. ref="businessRef"
  36. :data="list"
  37. :stripe="true"
  38. :show-overflow-tooltip="true"
  39. >
  40. <el-table-column type="selection" width="55" />
  41. <el-table-column label="商机名称" fixed="left" align="center" prop="name">
  42. <template #default="scope">
  43. <el-link type="primary" :underline="false" @click="openDetail(scope.row.id)">
  44. {{ scope.row.name }}
  45. </el-link>
  46. </template>
  47. </el-table-column>
  48. <el-table-column
  49. label="商机金额"
  50. align="center"
  51. prop="price"
  52. :formatter="fenToYuanFormat"
  53. />
  54. <el-table-column label="客户名称" align="center" prop="customerName" />
  55. <el-table-column label="商机组" align="center" prop="statusTypeName" />
  56. <el-table-column label="商机阶段" align="center" prop="statusName" />
  57. </el-table>
  58. <!-- 分页 -->
  59. <Pagination
  60. :total="total"
  61. v-model:page="queryParams.pageNo"
  62. v-model:limit="queryParams.pageSize"
  63. @pagination="getList"
  64. />
  65. </ContentWrap>
  66. <template #footer>
  67. <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
  68. <el-button @click="dialogVisible = false">取 消</el-button>
  69. </template>
  70. <!-- 表单弹窗:添加 -->
  71. <BusinessForm ref="formRef" @success="getList" />
  72. </Dialog>
  73. </template>
  74. <script setup lang="ts">
  75. import * as BusinessApi from '@/api/crm/business'
  76. import BusinessForm from '../../business/BusinessForm.vue'
  77. import { fenToYuanFormat } from '@/utils/formatter'
  78. // TODO @zyna:下面这个拼接,要注意大小写哈
  79. import * as ContactbusinesslinkApi from '@/api/crm/contactbusinesslink'
  80. const message = useMessage() // 消息弹窗
  81. defineOptions({ name: 'CrmBusinessLinkContactList' })
  82. const dialogVisible = ref(false) // 弹窗的是否展示
  83. const dialogTitle = ref('') // 弹窗的标题 TODO @zyna:是不是搞个标题?
  84. const loading = ref(true) // 列表的加载中
  85. const total = ref(0) // 列表的总页数
  86. const list = ref([]) // 列表的数据
  87. const queryFormRef = ref() // 搜索的表单
  88. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  89. const queryParams = reactive({
  90. pageNo: 1,
  91. pageSize: 10,
  92. // TODO @zyna:是不是要根据 customerId 筛选?
  93. name: undefined
  94. })
  95. const contactIdProp = ref(0) // 联系人编号
  96. /** 打开弹窗 */
  97. const open = async (contactId: number) => {
  98. dialogVisible.value = true
  99. contactIdProp.value = contactId
  100. // TODO @zyna:下面要 await 下;一般 idea 如果有黄色警告,最好都看看哈
  101. getList()
  102. }
  103. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  104. /** 查询列表 */
  105. const getList = async () => {
  106. loading.value = true
  107. try {
  108. const data = await BusinessApi.getBusinessPage(queryParams)
  109. list.value = data.list
  110. total.value = data.total
  111. } finally {
  112. loading.value = false
  113. }
  114. }
  115. /** 搜索按钮操作 */
  116. const handleQuery = () => {
  117. queryParams.pageNo = 1
  118. getList()
  119. }
  120. /** 重置按钮操作 */
  121. const resetQuery = () => {
  122. queryFormRef.value.resetFields()
  123. handleQuery()
  124. }
  125. /** 添加操作 */
  126. const formRef = ref()
  127. const openForm = () => {
  128. formRef.value.open('create')
  129. }
  130. /** 关联商机提交 */
  131. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  132. const businessRef = ref()
  133. const submitForm = async () => {
  134. // TODO @zyna:可以 if return,这样括号层级简单一点
  135. if (businessRef.value.getSelectionRows().length === 0) {
  136. message.success('未选择商机')
  137. } else {
  138. // TODO @zyna:这里 postData 应该不用 ref,搞个 数组就好了?
  139. const postData = ref<ContactbusinesslinkApi.ContactBusinessLinkVO[]>([])
  140. businessRef.value.getSelectionRows().forEach((element) => {
  141. // TODO @zyna:可以直接 push,不用声明 data
  142. let data = {
  143. id: undefined,
  144. businessId: element.id,
  145. contactId: contactIdProp.value
  146. }
  147. postData.value.push(data)
  148. })
  149. await ContactbusinesslinkApi.createContactBusinessLinkBatch(postData.value)
  150. dialogVisible.value = false
  151. emit('success')
  152. }
  153. }
  154. /** 打开联系人详情 */
  155. const { push } = useRouter()
  156. const openDetail = (id: number) => {
  157. push({ name: 'CrmBusinessDetail', params: { id } })
  158. }
  159. </script>