<template>
  <view class="c-layout">
    <StatisticCard :list="list" />

    <view class="card-box">
      <view class="c-tab">
        <text
          v-for="(item, index) in tabList"
          :key="index"
          :class="{ active: currentTab === item.name }"
          @click="handleTab(item)"
        >
          {{ item.name }}
        </text>
      </view>
      <view class="c-grid">
        <view class="box">
          <view v-for="(item, index) in gridList1" :key="index">
            <text>{{ item.name }}：</text><text>{{ item.isBefore ? item.unit : ''}} {{ randomNum(index)}} {{ item.isBefore ? '' : item.unit }} </text>
          </view>
        </view>

        <view class="box">  
          <view v-for="(item, index) in gridList2" :key="index">
            <text v-if="item.name">{{ item.name }}：</text><text v-if="item.num">{{ item.isBefore ? item.unit : ''}} {{ randomNum(index) }} {{ item.isBefore ? '' : item.unit }} </text>
          </view>
        </view>

        <view class="box">
          <view v-for="(item, index) in gridList3" :key="index">
            <text>{{ item.name }}：</text><text>{{ item.isBefore ? item.unit : ''}} {{ randomNum(index) }} {{ item.isBefore ? '' : item.unit }} </text>
          </view>
        </view>
      </view>
    </view>
  </view>
  <TimeRangeFilter :show="isShowTimeDialog" @handleDialog="handleDialog"/>
</template>
<script setup lang="ts">
import StatisticCard from "@/components/StatisticCard/index.vue";
import TimeRangeFilter from './components/TimeRangeFilter.vue'
const list = reactive([
  {
    num: 8923.0,
    name: "客户应收款总额",
  },
  {
    num: 8923.0,
    name: "供应商应付款总额",
  },
]);

const currentTab = ref("昨日");
const tabList = reactive([
  {
    name: "昨日",
  },
  {
    name: "本月",
  },
  {
    name: "本年",
  },
  {
    name: "自定义",
  },
]);
const handleTab = (item: any) => {
  if (item.name === '自定义') {
    handleDialog(true)
  } else {
    currentTab.value = item.name;
  }
};
const randomNum = (index:number) => {
  return Math.floor(Math.random() * (10000 - 1 + 1)) + 1 + index
}

const gridList1 = reactive([
  {
    name: "出货收入",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "实际收入",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "收货支出",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "实际支出",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "杂费支出",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "运费支出",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
]);
const gridList2 = reactive([
{
    name: "出货实收金额",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "出货应收金额",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "出货笔数",
    num: "2",
  },
  {
    name: "",
    num: "",
  },
  {
    name: "出货总重量",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "出货净重（客户）",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "出货重量(已结)",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "结算总重量",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "出货重量(未结)",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "结算重量(已结)",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "净重误差",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "结算总量(未结)",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
]);
const gridList3 = reactive([
  {
    name: "收货总重量",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "收货笔数",
    num: "2",
    unit: '',
    isBefore: false
  },
  {
    name: "收货重量(已付)",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "收货实付金额",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
  {
    name: "收货重量(未付)",
    num: "6000.00",
    unit: 'KG',
    isBefore: false
  },
  {
    name: "收货应付金额",
    num: "6000.00",
    unit: '￥',
    isBefore: true
  },
]);

const isShowTimeDialog = ref(false)
const handleDialog = (v: boolean) => {
  isShowTimeDialog.value = v
}
</script>
<style lang="scss" scoped>
.card-box {
  background: #ffffff;
  box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(5, 68, 37, 0.12);
  border-radius: 13rpx;
  margin-top: 25rpx;
  .c-tab {
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 27rpx;
    color: #999999;
    line-height: 41rpx;
    display: flex;
    align-items: center;
    justify-content: space-around;
    border-bottom: 1rpx solid rgba(233, 233, 233, 0.76);
    text {
      padding: 16rpx;
    }
    .active {
      color: $u-primary;
      border-bottom: 5rpx solid $u-primary;
      border-radius: 5rpx;
    }
  }
  .c-grid {
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 21rpx;
    color: #000000;
    .box {
      padding: 30rpx;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      flex: 1;
      > view {
        line-height: 50rpx;
      }
    }
    .box + .box {
      border-top: 18rpx solid #F8F8F8;
    }
  }
}
</style>
