<template>
  <view class="page-box">
    <view class="module-placeholder" />

    <ShopCard :shop-vo="businessVo" />
    <!-- 经营数据 -->
    <BusinessData :value-label="BusinessDataValue" :business-id="businessId" />
    <!-- 今日订单 -->
    <TodayOrder :business-id="businessId" />
    <!-- 近七日交易趋势 -->
    <LineChart :vo="DealTrendData" title="近七日交易趋势" />
    <!-- 近七日订单趋势 -->
    <!-- :yAxisConfig="{allowNegative:false,min: 0}" -->
    <LineChart :vo="OrderTrendData" title="近七日订单趋势" />
  </view>
</template>

<script lang="ts" setup>
import { SevenDay } from "@/hooks/SevenDay.ts";
import BusinessData from "@/components/ShopData/BusinessData.vue";
import TodayOrder from "@/components/ShopData/TodayOrder.vue";
import LineChart from "@/components/ShopData/LineChart.vue";
import { add } from "@/util/decimal.js";
import { getBusinessInfoId_Api } from "@/api/shop";
import { ref, watch } from "vue";

const $Props = defineProps({
  businessId: {
    type: Number,
    default: null,
  },
});
const businessVo = ref({});
const { DealTrendData, OrderTrendData, getLineChart } = SevenDay($Props.businessId);

watch(
  () => $Props.businessId,
  () => {
	  getBusinessInfo();
	  getLineChart($Props.businessId)
  }
);

const getBusinessInfo = async () => {
  try {
	const res = await getBusinessInfoId_Api($Props.businessId);
    businessVo.value = res.data || {};
  } catch (error) {
	
  }
};

getBusinessInfo();

const BusinessDataValue = [
  {
    label: "交易额",
    tag: "￥",
    key: "actualReceivePayment",
  },
  // {
  // 	label: '实际结算',
  // 	tag: '￥',
  // 	key: 'actualCredited'
  // },
  {
    label: "订单数",
    fn: (row: any) => {
      const { onlineOrderNum, shopOrderNum } = row || {};
      return add(onlineOrderNum || 0, shopOrderNum || 0);
    },
  },
  // {
  // 	label: '退款金额',
  // 	fn: (row : any) => {
  // 		const { onlineRefundOrderAmount, shopRefundOrderAmount } = row || {};
  // 		return add(onlineRefundOrderAmount || 0, shopRefundOrderAmount || 0)
  // 	}
  // },
  {
    label: "退款订单",
    fn: (row: any) => {
      const { shopRefundOrderNum, onlineRefundOrderNum } = row || {};
      return add(shopRefundOrderNum || 0, onlineRefundOrderNum || 0);
    },
  },
  {
    label: "积分订单",
    key: "pointVerifiedOrderNum",
  },
  {
    label: "积分消费",
    key: "userUsePoint",
  },
  {
    label: "积分核销订单",
    key: "pointVerifiedOrderNum",
  },
];
</script>

<style lang="scss" scoped>
.page-box {
  padding: 0 30rpx;
}
.module-placeholder {
  width: 100%;
  height: 20rpx;
}
</style>
