index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. />
  52. </el-form-item>
  53. <el-form-item label="员工" prop="userId">
  54. <el-select
  55. v-model="queryParams.userId"
  56. class="!w-240px"
  57. clearable
  58. placeholder="员工"
  59. @change="handleQuery"
  60. >
  61. <el-option
  62. v-for="(user, index) in userListByDeptId"
  63. :key="index"
  64. :label="user.nickname"
  65. :value="user.id"
  66. />
  67. </el-select>
  68. </el-form-item>
  69. <el-form-item>
  70. <el-button @click="handleQuery">
  71. <Icon class="mr-5px" icon="ep:search" />
  72. 查询
  73. </el-button>
  74. <el-button @click="resetQuery">
  75. <Icon class="mr-5px" icon="ep:refresh" />
  76. 重置
  77. </el-button>
  78. </el-form-item>
  79. </el-form>
  80. </ContentWrap>
  81. <!-- 客户统计 -->
  82. <el-col>
  83. <el-tabs v-model="activeTab">
  84. <!-- 客户总量分析 -->
  85. <el-tab-pane label="客户总量分析" lazy name="customerSummary">
  86. <CustomerSummary ref="customerSummaryRef" :query-params="queryParams" />
  87. </el-tab-pane>
  88. <!-- 客户跟进次数分析 -->
  89. <el-tab-pane label="客户跟进次数分析" lazy name="followUpSummary">
  90. <CustomerFollowUpSummary ref="followUpSummaryRef" :query-params="queryParams" />
  91. </el-tab-pane>
  92. <!-- 客户跟进方式分析 -->
  93. <el-tab-pane label="客户跟进方式分析" lazy name="followUpType">
  94. <CustomerFollowUpType ref="followUpTypeRef" :query-params="queryParams" />
  95. </el-tab-pane>
  96. <!-- 客户转化率分析 -->
  97. <el-tab-pane label="客户转化率分析" lazy name="conversionStat">
  98. <CustomerConversionStat ref="conversionStatRef" :query-params="queryParams" />
  99. </el-tab-pane>
  100. <!-- 公海客户分析 -->
  101. <el-tab-pane label="公海客户分析" lazy name="poolSummary">
  102. <PoolSummary ref="poolSummaryRef" :query-params="queryParams" />
  103. </el-tab-pane>
  104. <!-- 成交周期分析 -->
  105. <el-tab-pane label="成交周期分析" lazy name="dealCycle">
  106. <CustomerDealCycle ref="dealCycleRef" :query-params="queryParams" />
  107. </el-tab-pane>
  108. </el-tabs>
  109. </el-col>
  110. </template>
  111. <script lang="ts" setup>
  112. import * as DeptApi from '@/api/system/dept'
  113. import * as UserApi from '@/api/system/user'
  114. import { useUserStore } from '@/store/modules/user'
  115. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  116. import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
  117. import { defaultProps, handleTree } from '@/utils/tree'
  118. import CustomerConversionStat from './components/CustomerConversionStat.vue'
  119. import CustomerDealCycle from './components/CustomerDealCycle.vue'
  120. import CustomerFollowUpSummary from './components/CustomerFollowUpSummary.vue'
  121. import CustomerFollowUpType from './components/CustomerFollowUpType.vue'
  122. import CustomerSummary from './components/CustomerSummary.vue'
  123. import PoolSummary from './components/PoolSummary.vue'
  124. defineOptions({ name: 'CrmStatisticsCustomer' })
  125. const queryParams = reactive({
  126. interval: 2, // WEEK, 周
  127. deptId: useUserStore().getUser.deptId,
  128. userId: undefined,
  129. times: [
  130. // 默认显示最近一周的数据
  131. formatDate(beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7))),
  132. formatDate(endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24)))
  133. ]
  134. })
  135. const queryFormRef = ref() // 搜索的表单
  136. const deptList = ref<Tree[]>([]) // 部门树形结构
  137. const userList = ref<UserApi.UserVO[]>([]) // 全量用户清单
  138. /** 根据选择的部门筛选员工清单 */
  139. const userListByDeptId = computed(() =>
  140. queryParams.deptId
  141. ? userList.value.filter((u: UserApi.UserVO) => u.deptId === queryParams.deptId)
  142. : []
  143. )
  144. const activeTab = ref('customerSummary') // 活跃标签
  145. const customerSummaryRef = ref() // 1. 客户总量分析
  146. const followUpSummaryRef = ref() // 2. 客户跟进次数分析
  147. const followUpTypeRef = ref() // 3. 客户跟进方式分析
  148. const conversionStatRef = ref() // 4. 客户转化率分析
  149. const poolSummaryRef = ref() // 5. 客户公海分析
  150. const dealCycleRef = ref() // 6. 成交周期分析
  151. /** 搜索按钮操作 */
  152. const handleQuery = () => {
  153. switch (activeTab.value) {
  154. case 'customerSummary': // 客户总量分析
  155. customerSummaryRef.value?.loadData?.()
  156. break
  157. case 'followUpSummary': // 客户跟进次数分析
  158. followUpSummaryRef.value?.loadData?.()
  159. break
  160. case 'followUpType': // 客户跟进方式分析
  161. followUpTypeRef.value?.loadData?.()
  162. break
  163. case 'conversionStat': // 客户转化率分析
  164. conversionStatRef.value?.loadData?.()
  165. break
  166. case 'poolSummary': // 公海客户分析
  167. poolSummaryRef.value?.loadData?.()
  168. break
  169. case 'dealCycle': // 成交周期分析
  170. dealCycleRef.value?.loadData?.()
  171. break
  172. }
  173. }
  174. /** 当 activeTab 改变时,刷新当前活动的 tab */
  175. watch(activeTab, () => {
  176. handleQuery()
  177. })
  178. /** 重置按钮操作 */
  179. const resetQuery = () => {
  180. queryFormRef.value.resetFields()
  181. handleQuery()
  182. }
  183. /** 初始化 */
  184. onMounted(async () => {
  185. deptList.value = handleTree(await DeptApi.getSimpleDeptList())
  186. userList.value = handleTree(await UserApi.getSimpleUserList())
  187. })
  188. </script>