<template>
  <div class="home-content">
    <el-row :gutter="20">
      <el-col :span="12" style="margin-bottom: 20px;">
        <el-card shadow="never">
          <div class="card-header">
            <h3 class="card-title">订单总览</h3>
            <el-radio-group v-model="queryKey" style="margin-bottom: 30px" @change="init">
        <el-radio-button v-for="item in btns" :key="item.key" :value="item.key">{{ item.name }}</el-radio-button>
      </el-radio-group>
          </div>
          <el-row>
            <el-col :span="6" v-for="item in orderReview" :key="item.key">
              <el-statistic :value="data[item.key]">
                <template #title>
                  <div>
                    {{ item.name }}
                  </div>
                </template>
              </el-statistic>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="never">
          <div class="card-header">
            <h3 class="card-title">人员总览</h3>
            <el-radio-group v-model="userKey" style="margin-bottom: 30px" @change="init">
              <el-radio-button v-for="item in userbtns" :key="item.key" :value="item.key">{{ item.name }}</el-radio-button>
            </el-radio-group>
          </div>
          <el-row>
            <el-col :span="6" v-for="item in userReview" :key="item.key">
              <el-statistic :value="data[item.key]">
                <template #title>
                  <div>
                    {{ item.name }}
                  </div>
                </template>
              </el-statistic>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="never">
          <div class="card-header">
            <h3 class="card-title">区县收入排名</h3>
          </div>
          <el-row>
            <el-col :span="24" v-for="item in data.orgAmountVos" :key="item.key">
              <div class="phStyle">
                <div class="phStyle-left">{{ item.orgName }}</div>
                <div class="progress"><el-progress :percentage="(item.orderAmount/data.orgAmountVos[0].orderAmount) * 100">
                <span>{{ item.orderAmount  }}</span>
               </el-progress></div>
              </div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="never">
          <div class="card-header">
            <h3 class="card-title">区县订单总量排名</h3>
          </div>
          <el-row>
            <el-col :span="24" v-for="item in data.orgOrderVos" :key="item.key">
              <div class="phStyle">
                <div class="phStyle-left">{{ item.orgName }}</div>
                <div class="progress"><el-progress :percentage="(item.orderTotal/data.orgOrderVos[0].orderTotal) * 100">
                <span>{{ item.orderTotal  }}</span>
               </el-progress></div>
              </div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
    </el-row>




  </div>
</template>

<script setup>
import { orderSummary, userSummary, orgRank } from '@/api/index'
import { computed } from 'vue'
import { onMounted } from 'vue'
import {formatDate} from '@/utils/index'

const queryKey = ref('4')
const userKey = ref(1)

// const queryparmasTimes = computed(() => {
//   if(queryKey.value === 'today'){
//     return getToday();
//   }
//   if(queryKey.value === 'yesterday'){
//     return getYesterday();
//   }
//   if(queryKey.value === 'week'){
//     return getThisWeek();
//   }
//   return ''
// })

const btns = [
  {
    name: '今日',
    key: '2'
  },
  {
    name: '昨日',
    key: '1'
  },
  {
    name: '本月',
    key: '3'
  },
  {
    name: '全部',
    key: '4'
  },
]
const userbtns = [
  {
    name: '用户',
    key: 1
  },
  {
    name: '志愿者',
    key: 2
  },
]
const orderReview = [
  {
    name: '订单总量',
    key: 'orderTotal'
  },
  {
    name: '取消单量',
    key: 'orderCancelTotal'
  },
  {
    name: '总金额',
    key: 'orderTotalAmount'
  },
  {
    name: '完成单量',
    key: 'orderFinishTotal	'
  },
]

const userReview = [
  {
    name: '用户总量',
    key: 'userTotal'
  },
  {
    name: '今日新增',
    key: 'todayAdd'
  },
  {
    name: '昨日新增',
    key: 'yesterdayAdd'
  },
  {
    name: '本月新增',
    key: 'monthAdd'
  },
]

const data = ref({
  order: 388
})


const init = async () => {
  try {
    const parmas = {
      pageType:queryKey.value
    }
    const res1 = await orderSummary(parmas)
    const res2 = await userSummary({...parmas,userType: userKey.value})
    const res3 = await orgRank({})
    data.value = {
      ...res1.data,
      ...res2.data,
      ...res3.data,
    }
    console.log('data.value');
    
  } catch (error) {

  }
}

onMounted(() => {
  init()
})

</script>

<style lang="scss" scoped>
.home-content {
  padding: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.phStyle {
  // display: flex;
  // align-items: center;
  // flex-direction: column;
  .phStyle-left {
    // width: 200px;
    // text-align: right;
  }
  .progress {
    flex: 1;
  }
}
</style>

<style scoped>
.el-statistic {
  --el-statistic-content-font-size: 28px;
  text-align: center;
}

.statistic-card {
  height: 100%;
  padding: 20px;
  border-radius: 4px;
  background-color: var(--el-bg-color-overlay);
}

.statistic-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--el-text-color-regular);
  margin-top: 16px;
}

.statistic-footer .footer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.statistic-footer .footer-item span:last-child {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.green {
  color: var(--el-color-success);
}

.red {
  color: var(--el-color-error);
}
.el-radio-group {
  margin-bottom: 0px !important;
}
</style>