index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. <el-tab-pane label="销售漏斗分析" lazy name="funnelRef">
  84. <FunnelBusiness ref="funnelRef" :query-params="queryParams" />
  85. </el-tab-pane>
  86. <el-tab-pane label="新增商机分析" lazy name="businessSummaryRef">
  87. <BusinessSummary ref="businessSummaryRef" :query-params="queryParams" />
  88. </el-tab-pane>
  89. <el-tab-pane label="商机转化率分析" lazy name="sourceRef" />
  90. </el-tabs>
  91. </el-col>
  92. </template>
  93. <script lang="ts" setup>
  94. import * as DeptApi from '@/api/system/dept'
  95. import * as UserApi from '@/api/system/user'
  96. import { useUserStore } from '@/store/modules/user'
  97. import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
  98. import { defaultProps, handleTree } from '@/utils/tree'
  99. import FunnelBusiness from './components/FunnelBusiness.vue'
  100. import BusinessSummary from './components/BusinessSummary.vue'
  101. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  102. defineOptions({ name: 'CrmStatisticsFunnel' })
  103. const queryParams = reactive({
  104. interval: 2, // WEEK, 周
  105. deptId: useUserStore().getUser.deptId,
  106. userId: undefined,
  107. times: [
  108. // 默认显示最近一周的数据
  109. formatDate(beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7))),
  110. formatDate(endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24)))
  111. ]
  112. })
  113. const queryFormRef = ref() // 搜索的表单
  114. const deptList = ref<Tree[]>([]) // 部门树形结构
  115. const userList = ref<UserApi.UserVO[]>([]) // 全量用户清单
  116. /** 根据选择的部门筛选员工清单 */
  117. const userListByDeptId = computed(() =>
  118. queryParams.deptId
  119. ? userList.value.filter((u: UserApi.UserVO) => u.deptId === queryParams.deptId)
  120. : []
  121. )
  122. const activeTab = ref('funnelRef') // 活跃标签
  123. const funnelRef = ref() // 销售漏斗
  124. const businessSummaryRef = ref() // 新增商机分析
  125. const sourceRef = ref() // 客户来源
  126. /** 搜索按钮操作 */
  127. const handleQuery = () => {
  128. switch (activeTab.value) {
  129. case 'funnelRef':
  130. funnelRef.value?.loadData?.()
  131. break
  132. case 'businessSummaryRef':
  133. businessSummaryRef.value?.loadData?.()
  134. break
  135. case 'sourceRef':
  136. sourceRef.value?.loadData?.()
  137. break
  138. }
  139. }
  140. /** 当 activeTab 改变时,刷新当前活动的 tab */
  141. watch(activeTab, () => {
  142. handleQuery()
  143. })
  144. /** 重置按钮操作 */
  145. const resetQuery = () => {
  146. queryFormRef.value.resetFields()
  147. handleQuery()
  148. }
  149. /** 初始化 */
  150. onMounted(async () => {
  151. deptList.value = handleTree(await DeptApi.getSimpleDeptList())
  152. userList.value = handleTree(await UserApi.getSimpleUserList())
  153. })
  154. </script>