index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!-- 数据统计 - 员工客户分析 -->
  2. <template>
  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="orderDate">
  13. <el-date-picker
  14. v-model="queryParams.times"
  15. :shortcuts="defaultShortcuts"
  16. class="!w-240px"
  17. end-placeholder="结束日期"
  18. start-placeholder="开始日期"
  19. type="daterange"
  20. value-format="YYYY-MM-DD HH:mm:ss"
  21. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  22. />
  23. </el-form-item>
  24. <el-form-item label="归属部门" prop="deptId">
  25. <el-tree-select
  26. v-model="queryParams.deptId"
  27. class="!w-240px"
  28. :data="deptList"
  29. :props="defaultProps"
  30. check-strictly
  31. node-key="id"
  32. placeholder="请选择归属部门"
  33. @change="queryParams.userId = undefined"
  34. />
  35. </el-form-item>
  36. <el-form-item label="员工" prop="userId">
  37. <el-select v-model="queryParams.userId" class="!w-240px" placeholder="员工" clearable>
  38. <el-option
  39. v-for="(user, index) in userListByDeptId"
  40. :label="user.nickname"
  41. :value="user.id"
  42. :key="index"
  43. />
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item>
  47. <el-button @click="handleQuery"> <Icon icon="ep:search" class="mr-5px" /> 搜索 </el-button>
  48. <el-button @click="resetQuery"> <Icon icon="ep:refresh" class="mr-5px" /> 重置 </el-button>
  49. </el-form-item>
  50. </el-form>
  51. </ContentWrap>
  52. <!-- 客户统计 -->
  53. <el-col>
  54. <el-tabs v-model="activeTab">
  55. <!-- 客户总量分析 -->
  56. <el-tab-pane label="客户总量分析" name="customerSummary" lazy>
  57. <CustomerSummary :query-params="queryParams" ref="customerSummaryRef" />
  58. </el-tab-pane>
  59. <!-- 客户跟进次数分析 -->
  60. <el-tab-pane label="客户跟进次数分析" name="followupSummary" lazy>
  61. <CustomerFollowupSummary :query-params="queryParams" ref="followupSummaryRef" />
  62. </el-tab-pane>
  63. <!-- 客户跟进方式分析 -->
  64. <el-tab-pane label="客户跟进方式分析" name="followupType" lazy>
  65. <CustomerFollowupType :query-params="queryParams" ref="followupTypeRef" />
  66. </el-tab-pane>
  67. <!-- 客户转化率分析 -->
  68. <el-tab-pane label="客户转化率分析" name="conversionStat" lazy>
  69. <CustomerConversionStat :query-params="queryParams" ref="conversionStatRef" />
  70. </el-tab-pane>
  71. <!-- 成交周期分析 -->
  72. <el-tab-pane label="成交周期分析" name="dealCycle" lazy>
  73. <CustomerDealCycle :query-params="queryParams" ref="dealCycleRef" />
  74. </el-tab-pane>
  75. </el-tabs>
  76. </el-col>
  77. </template>
  78. <script lang="ts" setup>
  79. import * as DeptApi from '@/api/system/dept'
  80. import * as UserApi from '@/api/system/user'
  81. import { useUserStore } from '@/store/modules/user'
  82. import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
  83. import { defaultProps, handleTree } from '@/utils/tree'
  84. import CustomerSummary from './components/CustomerSummary.vue'
  85. import CustomerFollowupSummary from './components/CustomerFollowupSummary.vue'
  86. import CustomerFollowupType from './components/CustomerFollowupType.vue'
  87. import CustomerConversionStat from './components/CustomerConversionStat.vue'
  88. import CustomerDealCycle from './components/CustomerDealCycle.vue'
  89. defineOptions({ name: 'CrmStatisticsCustomer' })
  90. const queryParams = reactive({
  91. deptId: useUserStore().getUser.deptId,
  92. userId: undefined,
  93. times: [
  94. // 默认显示最近一周的数据
  95. formatDate(beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7))),
  96. formatDate(endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24)))
  97. ]
  98. })
  99. const queryFormRef = ref() // 搜索的表单
  100. const deptList = ref<Tree[]>([]) // 部门树形结构
  101. const userList = ref<UserApi.UserVO[]>([]) // 全量用户清单
  102. // 根据选择的部门筛选员工清单
  103. const userListByDeptId = computed(() =>
  104. queryParams.deptId
  105. ? userList.value.filter((u: UserApi.UserVO) => u.deptId === queryParams.deptId)
  106. : []
  107. )
  108. // 活跃标签
  109. const activeTab = ref('customerSummary')
  110. // 1.客户总量分析
  111. const customerSummaryRef = ref()
  112. // 2.客户跟进次数分析
  113. const followupSummaryRef = ref()
  114. // 3.客户跟进方式分析
  115. const followupTypeRef = ref()
  116. // 4.客户转化率分析
  117. const conversionStatRef = ref()
  118. // 5.公海客户分析
  119. // 缺 crm_owner_record 表
  120. // 6.成交周期分析
  121. const dealCycleRef = ref()
  122. /** 搜索按钮操作 */
  123. const handleQuery = () => {
  124. switch (activeTab.value) {
  125. case 'customerSummary':
  126. customerSummaryRef.value?.loadData?.()
  127. break
  128. case 'followupSummary':
  129. followupSummaryRef.value?.loadData?.()
  130. break
  131. case 'followupType':
  132. followupTypeRef.value?.loadData?.()
  133. break
  134. case 'conversionStat':
  135. conversionStatRef.value?.loadData?.()
  136. break
  137. case 'dealCycle':
  138. dealCycleRef.value?.loadData?.()
  139. break
  140. }
  141. }
  142. // 当 activeTab 改变时,刷新当前活动的 tab
  143. watch(activeTab, () => {
  144. handleQuery()
  145. })
  146. /** 重置按钮操作 */
  147. const resetQuery = () => {
  148. queryFormRef.value.resetFields()
  149. handleQuery()
  150. }
  151. // 加载部门树
  152. onMounted(async () => {
  153. deptList.value = handleTree(await DeptApi.getSimpleDeptList())
  154. userList.value = handleTree(await UserApi.getSimpleUserList())
  155. })
  156. </script>