Bläddra i källkod

feat: 添加本年获客统计功能,优化主页数据展示逻辑

EvilDragon 1 månad sedan
förälder
incheckning
761956d624

+ 10 - 0
packages/app/src/core/libs/requests.ts

@@ -765,6 +765,16 @@ export const reserveDesigner = (data: {
   appointmentPhone: string
 }) => httpPost<any>('/app-api/member/designer/reserveDesigner', data)
 /**
+ * 本年获客统计
+ */
+export const countThisYear = (data: { year: number; userId: number }) =>
+  httpPost<
+    {
+      bizType: string
+      quantity: number
+    }[]
+  >('/app-api/member/designer/countThisYear', data)
+/**
  * 创建设计师主页浏览记录
  */
 export const createBrowseHistory = (data: {

+ 49 - 4
packages/app/src/pages/mine/homepage/statistics/index.vue

@@ -7,6 +7,7 @@ import {
   getDesignerInfo,
   getBrowseHistories,
   getReserveHistory,
+  countThisYear,
 } from '../../../../core/libs/requests'
 import { useUserStore } from '../../../../store'
 import { storeToRefs } from 'pinia'
@@ -17,7 +18,12 @@ import PageHelperEvo from '@/components/page-helper-evo.vue'
 
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
-const { data, run: setData } = useRequest(() => getDesignerInfo(userInfo.value.userId))
+const current = ref('累计')
+const request =
+  ref<
+    () => Promise<IResData<{ shareCount: number; viewCount: number; winCustomerCount: number }>>
+  >()
+const data = ref()
 const info = computed(() => [
   { label: '分享', value: data.value?.shareCount || 0, unit: '次' },
   { label: '浏览', value: data.value?.viewCount || 0, unit: '次' },
@@ -29,10 +35,45 @@ const tabs = ref([
   { label: '浏览明细', value: '浏览' },
   { label: '获客明细', value: '获客' },
 ])
-const current = ref('累计')
 const query = computed(() => ({}))
+const setData = async ({ value }) => {
+  console.log(1111)
+  console.log(value)
+
+  request.value = {
+    累计: () =>
+      getDesignerInfo(userInfo.value.userId).then((res) => ({
+        code: res.code,
+        msg: res.msg,
+        data: {
+          shareCount: res.data.shareCount,
+          viewCount: res.data.viewCount,
+          winCustomerCount: res.data.winCustomerCount,
+        },
+      })),
+    本年: () =>
+      countThisYear({ userId: userInfo.value.userId, year: new Date().getFullYear() }).then(
+        (res) => ({
+          code: res.code,
+          msg: res.msg,
+          data: {
+            shareCount: res.data.find((it) => it.bizType === '1')?.quantity || 0,
+            viewCount: res.data.find((it) => it.bizType === '2')?.quantity || 0,
+            winCustomerCount: res.data.find((it) => it.bizType === '3')?.quantity || 0,
+          },
+        }),
+      ),
+  }[value]
+  const { data: resData } = await request.value()
+  data.value = resData
+  console.log(data.value)
+}
 onMounted(async () => {
-  await setData()
+  console.log(1111)
+
+  await setData({ value: current.value })
+  console.log(data.value)
+  // await countThisYear({ userId: userInfo.value.userId, year: new Date().getFullYear() })
 })
 </script>
 <template>
@@ -41,7 +82,11 @@ onMounted(async () => {
       <SectionHeading title="主页数据">
         <template #append>
           <div>
-            <wd-segmented v-model:value="current" :options="['累计']"></wd-segmented>
+            <wd-segmented
+              v-model:value="current"
+              :options="['累计', '本年']"
+              @change="setData"
+            ></wd-segmented>
           </div>
         </template>
       </SectionHeading>