index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. />
  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. class="!w-240px"
  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" clearable placeholder="员工">
  38. <el-option
  39. v-for="(user, index) in userListByDeptId"
  40. :key="index"
  41. :label="user.nickname"
  42. :value="user.id"
  43. />
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item>
  47. <el-button @click="handleQuery">
  48. <Icon class="mr-5px" icon="ep:search" />
  49. 搜索
  50. </el-button>
  51. <el-button @click="resetQuery">
  52. <Icon class="mr-5px" icon="ep:refresh" />
  53. 重置
  54. </el-button>
  55. </el-form-item>
  56. </el-form>
  57. </ContentWrap>
  58. <!-- 客户统计 -->
  59. <el-col>
  60. <el-tabs v-model="activeTab">
  61. <!-- 城市分布分析 -->
  62. <el-tab-pane label="城市分布分析" lazy name="areaRef">
  63. <PortraitCustomerArea ref="areaRef" :query-params="queryParams" />
  64. </el-tab-pane>
  65. <!-- 客户级别分析 -->
  66. <el-tab-pane label="客户级别分析" lazy name="levelRef">
  67. <PortraitCustomerLevel ref="levelRef" :query-params="queryParams" />
  68. </el-tab-pane>
  69. <!-- 客户来源分析 -->
  70. <el-tab-pane label="客户来源分析" lazy name="sourceRef">
  71. <PortraitCustomerSource ref="sourceRef" :query-params="queryParams" />
  72. </el-tab-pane>
  73. <!-- 客户行业分析 -->
  74. <el-tab-pane label="客户行业分析" lazy name="industryRef">
  75. <PortraitCustomerIndustry ref="industryRef" :query-params="queryParams" />
  76. </el-tab-pane>
  77. </el-tabs>
  78. </el-col>
  79. </template>
  80. <script lang="ts" setup>
  81. import * as DeptApi from '@/api/system/dept'
  82. import * as UserApi from '@/api/system/user'
  83. import { useUserStore } from '@/store/modules/user'
  84. import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
  85. import { defaultProps, handleTree } from '@/utils/tree'
  86. import PortraitCustomerArea from './components/PortraitCustomerArea.vue'
  87. import PortraitCustomerIndustry from './components/PortraitCustomerIndustry.vue'
  88. import PortraitCustomerSource from './components/PortraitCustomerSource.vue'
  89. import PortraitCustomerLevel from './components/PortraitCustomerLevel.vue'
  90. defineOptions({ name: 'CrmStatisticsPortrait' })
  91. const queryParams = reactive({
  92. deptId: useUserStore().getUser.deptId,
  93. userId: undefined,
  94. times: [
  95. // 默认显示最近一周的数据
  96. formatDate(beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7))),
  97. formatDate(endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24)))
  98. ]
  99. })
  100. const queryFormRef = ref() // 搜索的表单
  101. const deptList = ref<Tree[]>([]) // 部门树形结构
  102. const userList = ref<UserApi.UserVO[]>([]) // 全量用户清单
  103. /** 根据选择的部门筛选员工清单 */
  104. const userListByDeptId = computed(() =>
  105. queryParams.deptId
  106. ? userList.value.filter((u: UserApi.UserVO) => u.deptId === queryParams.deptId)
  107. : []
  108. )
  109. const activeTab = ref('areaRef') // 活跃标签
  110. const areaRef = ref() // 客户地区分布
  111. const levelRef = ref() // 客户级别
  112. const sourceRef = ref() // 客户来源
  113. const industryRef = ref() // 客户行业
  114. /** 搜索按钮操作 */
  115. const handleQuery = () => {
  116. switch (activeTab.value) {
  117. case 'areaRef':
  118. areaRef.value?.loadData?.()
  119. break
  120. case 'levelRef':
  121. levelRef.value?.loadData?.()
  122. break
  123. case 'sourceRef':
  124. sourceRef.value?.loadData?.()
  125. break
  126. case 'industryRef':
  127. industryRef.value?.loadData?.()
  128. break
  129. }
  130. }
  131. /** 当 activeTab 改变时,刷新当前活动的 tab */
  132. watch(activeTab, () => {
  133. handleQuery()
  134. })
  135. /** 重置按钮操作 */
  136. const resetQuery = () => {
  137. queryFormRef.value.resetFields()
  138. handleQuery()
  139. }
  140. /** 初始化 */
  141. onMounted(async () => {
  142. deptList.value = handleTree(await DeptApi.getSimpleDeptList())
  143. userList.value = handleTree(await UserApi.getSimpleUserList())
  144. })
  145. </script>