<template> <div class="md:flex" v-if="exchangeTab === 'tab1'"> <template v-for="(item, index) in growCardList" :key="item.title"> <Card size="small" :loading="loading" :title="item.title" class="md:w-1/4 w-full !md:mt-0" :class="{ '!md:mr-4': index + 1 < 5, '!mt-4': index > 0 }" > <!-- <template #extra> <Tag :color="item.color">{{ item.action }}</Tag> </template> --> <div class="py-4 px-4 flex justify-between items-center"> <CountTo :startVal="1" :endVal="item.value" class="text-2xl" /> <!-- <Icon :icon="item.icon" :size="40" /> --> </div> <!-- <div class="p-2 px-4 flex justify-between"> <span>总{{ item.title }}</span> <CountTo prefix="$" :startVal="1" :endVal="item.total" /> </div> --> </Card> </template> </div> <div class="md:flex" v-if="exchangeTab === 'tab2'"> <template v-for="(item, index) in growCardList2" :key="item.title"> <Card size="small" :loading="loading" :title="item.title" class="md:w-1/4 w-full !md:mt-0" :class="{ '!md:mr-4': index + 1 < 5, '!mt-4': index > 0 }" > <div class="py-4 px-4 flex justify-between items-center" style="font-size: 20px"> {{ item.value }} </div> </Card> </template> </div> </template> <script lang="ts" setup> import { CountTo } from '/@/components/CountTo/index'; import Icon from '@/components/Icon/Icon.vue'; import { Tag, Card } from 'ant-design-vue'; import { growCardList } from '../data'; import { useDataStoreWithOut } from '/@/store/modules/data'; import { computed, onMounted, ref, watch, watchEffect } from 'vue'; import { exchangeTab, businessPersonIn, customerCodeIn, dateTime, period, } from '/@/store/modules/user'; import { number } from 'vue-types'; import { getSalesData, getApiData } from '/@/api/project/global'; import { useOrderStoreWithOut } from '/@/store/modules/order'; const dataStore = useDataStoreWithOut(); const data1 = ref(); watch( [dateTime, period], async ([newDateTime, newPeriod], [oldBusinessPersonIn, oldCustomerCodeIn]) => { console.log('businessPersonIn changed from', oldBusinessPersonIn, 'to', newDateTime); console.log('customerCodeIn changed from', oldCustomerCodeIn, 'to', newPeriod); // 在这里添加你希望在这两个值改变时执行的逻辑 data1.value = await getApiData({ dateTime: newDateTime, period: newPeriod, }); }, ); const growCardList = computed(() => { const data = dataStore.getData; return [ { title: '订单完成', icon: 'visit-count|svg', value: data1.value?.allCount || 0, total: 120000, color: 'green', action: '月', }, { title: '跟单和质检中', icon: 'total-sales|svg', value: data1.value?.trackingAndInspectingList || 0, total: 500000, color: 'blue', action: '月', }, { title: '利润分析表待审核', icon: 'download-count|svg', value: data1.value?.profitList || 0, total: 120000, color: 'orange', action: '周', }, { title: '项目报告书待审核', icon: 'transaction|svg', value: data1.value?.reportList || 0, total: 50000, color: 'purple', action: '年', }, { title: '订单初始化', icon: 'transaction|svg', value: data1.value?.orderInitList || 0, total: 50000, color: 'purple', action: '年', }, ]; }); const data2 = ref(); // watchEffect(async () => { // data2.value = await getSalesData({ // businessPersonIn: businessPersonIn, // customerCodeIn: customerCodeIn, // }); // }); onMounted(async () => { data1.value = await getApiData({ dateTime: dateTime.value, period: period.value, }); data2.value = await getSalesData({ businessPersonIn: businessPersonIn.value, customerCodeIn: customerCodeIn.value, }); }); watch( [businessPersonIn, customerCodeIn], async ([newDateTime, newPeriod], [oldBusinessPersonIn, oldCustomerCodeIn]) => { console.log('businessPersonIn changed from', oldBusinessPersonIn, 'to', newDateTime); console.log('customerCodeIn changed from', oldCustomerCodeIn, 'to', newPeriod); // 在这里添加你希望在这两个值改变时执行的逻辑 const customerCodeParams = newPeriod ? newPeriod.map((code) => `customerCodeIn=${encodeURIComponent(code)}`).join('&') : ''; // 构造完整请求 URL const baseURL = '/basic-api/order/erp/index/totalSalesStatistics'; const fullURL = `${baseURL}?${customerCodeParams}`; // 使用 fetch 或其他请求库发送请求 const response = await fetch(fullURL); const res = await response.json(); data2.value = res.data; // data2.value = await getSalesData({ // businessPersonIn: newDateTime, // customerCodeIn: newPeriod, // }); }, ); const growCardList2 = computed(() => { return [ { title: '总销售额目标', icon: 'visit-count|svg', value: data2.value?.yearlySalesAmountTarget || 0, total: 120000, color: 'green', action: '年', }, { title: '总销售额完成率', icon: 'visit-count|svg', value: data2.value?.yearlySalesAmountCompletionRate || 0, total: 120000, color: 'green', action: '年', }, { title: '每季度销售额目标', icon: 'visit-count|svg', value: data2.value?.quarterlySalesAmountTarget || 0, total: 120000, color: 'green', action: '月', }, { title: '当季度销售额完成率', icon: 'visit-count|svg', value: data2.value?.quarterlySalesAmountCompletionRate || 0, total: 120000, color: 'green', action: '月', }, { title: '当月销售额', icon: 'visit-count|svg', value: data2.value?.monthlySalesAmount || 0, total: 120000, color: 'green', action: '日', }, ]; }); defineProps({ loading: { type: Boolean, }, exchangeTab: { type: String, }, }); </script>