index.vue 5.4 KB

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