index.vue 6.7 KB

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