BusinessListModal.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <Dialog title="关联商机" 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. <ContentWrap class="mt-10px">
  32. <el-table
  33. v-loading="loading"
  34. ref="businessRef"
  35. :data="list"
  36. :stripe="true"
  37. :show-overflow-tooltip="true"
  38. >
  39. <el-table-column type="selection" width="55" />
  40. <el-table-column label="商机名称" fixed="left" align="center" prop="name">
  41. <template #default="scope">
  42. <el-link type="primary" :underline="false" @click="openDetail(scope.row.id)">
  43. {{ scope.row.name }}
  44. </el-link>
  45. </template>
  46. </el-table-column>
  47. <el-table-column
  48. label="商机金额"
  49. align="center"
  50. prop="totalPrice"
  51. :formatter="erpPriceTableColumnFormatter"
  52. />
  53. <el-table-column label="客户名称" align="center" prop="customerName" />
  54. <el-table-column label="商机组" align="center" prop="statusTypeName" />
  55. <el-table-column label="商机阶段" align="center" prop="statusName" />
  56. </el-table>
  57. <!-- 分页 -->
  58. <Pagination
  59. :total="total"
  60. v-model:page="queryParams.pageNo"
  61. v-model:limit="queryParams.pageSize"
  62. @pagination="getList"
  63. />
  64. </ContentWrap>
  65. <template #footer>
  66. <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
  67. <el-button @click="dialogVisible = false">取 消</el-button>
  68. </template>
  69. <!-- 表单弹窗:添加 -->
  70. <BusinessForm ref="formRef" @success="getList" />
  71. </Dialog>
  72. </template>
  73. <script setup lang="ts">
  74. import * as BusinessApi from '@/api/crm/business'
  75. import BusinessForm from '../BusinessForm.vue'
  76. import { erpPriceTableColumnFormatter } from '@/utils'
  77. const message = useMessage() // 消息弹窗
  78. const props = defineProps<{
  79. customerId: number
  80. }>()
  81. defineOptions({ name: 'BusinessListModal' })
  82. const dialogVisible = ref(false) // 弹窗的是否展示
  83. const loading = ref(true) // 列表的加载中
  84. const total = ref(0) // 列表的总页数
  85. const list = ref([]) // 列表的数据
  86. const queryFormRef = ref() // 搜索的表单
  87. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  88. const queryParams = reactive({
  89. pageNo: 1,
  90. pageSize: 10,
  91. name: undefined,
  92. customerId: props.customerId
  93. })
  94. /** 打开弹窗 */
  95. const open = async () => {
  96. dialogVisible.value = true
  97. queryParams.customerId = props.customerId // 解决 props.customerId 没更新到 queryParams 上的问题
  98. await getList()
  99. }
  100. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  101. /** 查询列表 */
  102. const getList = async () => {
  103. loading.value = true
  104. try {
  105. const data = await BusinessApi.getBusinessPageByCustomer(queryParams)
  106. list.value = data.list
  107. total.value = data.total
  108. } finally {
  109. loading.value = false
  110. }
  111. }
  112. /** 搜索按钮操作 */
  113. const handleQuery = () => {
  114. queryParams.pageNo = 1
  115. getList()
  116. }
  117. /** 重置按钮操作 */
  118. const resetQuery = () => {
  119. queryFormRef.value.resetFields()
  120. handleQuery()
  121. }
  122. /** 添加操作 */
  123. const formRef = ref()
  124. const openForm = () => {
  125. formRef.value.open('create')
  126. }
  127. /** 关联商机提交 */
  128. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  129. const businessRef = ref()
  130. const submitForm = async () => {
  131. const businessIds = businessRef.value
  132. .getSelectionRows()
  133. .map((row: BusinessApi.BusinessVO) => row.id)
  134. if (businessIds.length === 0) {
  135. return message.error('未选择商机')
  136. }
  137. dialogVisible.value = false
  138. emit('success', businessIds, businessRef.value.getSelectionRows())
  139. }
  140. /** 打开商机详情 */
  141. const { push } = useRouter()
  142. const openDetail = (id: number) => {
  143. push({ name: 'CrmBusinessDetail', params: { id } })
  144. }
  145. </script>