<route lang="json">
{ "style": { "navigationBarTitleText": "销售明细", "navigationBarBackgroundColor": "#fff" } }
</route>
<script setup lang="ts">
import SectionHeading from '@/components/section-heading.vue'
// import {
//   getDesignerInfo,
//   getBrowseHistories,
//   getReserveHistory,
//   countThisYear,
// } from '../../../../core/libs/requests'
import { storeToRefs } from 'pinia'
import Card from '@/components/card.vue'
import PageHelper from '@/components/page-helper.vue'
import dayjs from 'dayjs'
import PageHelperEvo from '@/components/page-helper-evo.vue'
import { useUserStore } from '@/store'
import { getSalesOrders } from '@/core/libs/agent-requests'

const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore)
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: '¥' },
])
const tab = ref('分享')
const tabs = ref([
  { label: '分享明细', value: '分享' },
  { label: '浏览明细', value: '浏览' },
  { label: '获客明细', value: '获客' },
])
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 () => {
  console.log(1111)

  await setData({ value: current.value })
  console.log(data.value)
  // await countThisYear({ userId: userInfo.value.userId, year: new Date().getFullYear() })
})
</script>
<template>
  <div class="flex-grow flex flex-col gap-5 px-3.5 py-6">
    <Card>
      <SectionHeading title="销售数据">
        <template #append>
          <div>
            <wd-segmented
              v-model:value="current"
              :options="['累计', '本年']"
              @change="setData"
            ></wd-segmented>
          </div>
        </template>
      </SectionHeading>
      <div class="flex mt-7">
        <template v-for="(it, i) in info" :key="i">
          <div class="flex-1 flex flex-col items-center gap-2">
            <div class="flex items-end flex-row-reverse gap-0.5">
              <div class="text-black text-2xl font-medium font-['DIN'] leading-6">
                {{ it.value }}
              </div>
              <div class="text-[#333333] text-sm font-normal font-['PingFang_SC']">
                {{ it.unit }}
              </div>
            </div>
            <div class="text-black/40 text-xs font-normal font-['PingFang_SC'] leading-normal">
              {{ it.label }}
            </div>
          </div>
        </template>
      </div>
    </Card>
    <PageHelperEvo :request="getSalesOrders">
      <template #default="{ source }">
        <template v-for="(it, index) in source?.list" :key="index">
          <Card>{{ it }}</Card>
        </template>
      </template>
    </PageHelperEvo>
  </div>
</template>
