<script setup lang="ts">
import { AdminPCIndex, WeekPay } from "@/api";
import { useTimeStore } from "@/stores/index";
const timeStore = useTimeStore();
import { useDataStore } from "@/stores/index";
const dataStore = useDataStore();

// 获取整体数据
const getAdminPCIndex = (params: any) => {
  AdminPCIndex(params).then((res: any) => {
    dataStore.setData(res.data);
  })
};
// 获取缴费人数
// 缴费人数-- 本科 专科 专升本
/* 
 缴费人数---根据学历层次EducationalLevel 获取
*/
/* const payData = () => {
  let params: any = [{
    "EducationalLevel": 3,
    "Year": myDate.value.year || void 0,
    "Month": myDate.value.month || void 0,
    "Day": myDate.value.day || void 0,
  }, {
    "EducationalLevel": 4,
    "Year": myDate.value.year || void 0,
    "Month": myDate.value.month || void 0,
    "Day": myDate.value.day || void 0,
  }, {
    "EducationalLevel": 6,
    "Year": myDate.value.year || void 0,
    "Month": myDate.value.month || void 0,
    "Day": myDate.value.day || void 0,
  }]
  for (let item of params) {
    WeekPay(item).then((res: any) => {
      switch (item.EducationalLevel) {
        case 3:
          dataStore.setBkPay(res.data);
        case 4:
          dataStore.setZkPay(res.data);
        case 6:
          dataStore.setZsbPay(res.data);
      }
    })
  }
} */
/* 
 缴费人数---根据批次去区分
*/
const payData = () => {
  let params: any = {
    "EducationalLevel": 3,
    "Year": myDate.value.year || void 0,
    "Month": myDate.value.month || void 0,
    "Day": myDate.value.day || void 0,
  }
  WeekPay(params).then((res: any) => {
    const bk = res.data.todayPayDto.batchTodayPays?.find((item:any) => item.name === "统招本科");
    const zk = res.data.todayPayDto.batchTodayPays?.find((item:any) => item.name === "统招专科");
    const zsb = res.data.todayPayDto.batchTodayPays?.find((item:any) => item.name === "统招专升本");
    dataStore.setBkPay(bk)
    dataStore.setZkPay(zk)
    dataStore.setZsbPay(zsb)
    dataStore.setTotalPay(res.data.todayPayDto.batchTodayPays?.payNum)
  })
}



// const returnHome = () => {
//   history.go(-1)
// };
const currentDate = new Date()
// 当前选择的日期
const myDate = ref({
  year: currentDate.getFullYear(),
  month: currentDate.getMonth() + 1,
  day: currentDate.getDate(),
})
// 获取选择的日期（年 || 月 ||日）
const getDate = (val: any) => {
  myDate.value = val
  // 根据年、月、日的切换，展示不同的标题  --- 具体问问产品怎么展示 -----待修改
  timeStore.setYears(val.year)
  timeStore.setMounths(val.month)
  timeStore.setDays(val.day)
  let params = {
    "Year": val.year || void 0,
    "Month": val.month || void 0,
    "Day": val.day || void 0,
  }
  getAdminPCIndex(params)
  payData()
}
const dateTitle = computed(() => {
  let { year, month, day } = myDate.value
  return formatDate(year, month, day)
})
/**
 * @description: 将日期返回成中文格式
 * @param {*} year
 * @param {*} month
 * @param {*} day
 * @return {*}
 */
function formatDate(year: number, month: number, day: number) {
  let dateStr = `${year}年`;
  if (month !== 0) {
    dateStr += `${month}月`;
  }
  if (day !== 0) {
    dateStr += `${day}日`;
  }
  return dateStr;
}
</script>

<template>
  <div class="d-flex">
    <div class="top-left">
      <div class="title">
        <span class="title-text">新生报到情况</span>
        <!-- <span style="color: yellow;" @click="returnHome()">返回</span> -->
      </div>
      <div class="en-title">
        <div class="en-line"></div>
        <span>New student registration status</span>
      </div>
    </div>

    <div class="change-time">
      <div class="change-year">
        <DatePicker @getOption="getDate" :myDate="myDate"></DatePicker>
      </div>
      <div class="time-title">选择日期：{{ dateTitle }}</div>

      <!-- <div class="change-year">
        <Dropdown :options="yearOptions" title="切换年份" @getOption="getYear" ref="selectYear"></Dropdown>
      </div>
      <div class="change-year">
        <Dropdown :options="monthOptions" title="切换月份" @getOption="getMonth" ref="selectMonth"></Dropdown>
      </div>
      <div class="change-year" @click="selectNowdays">选择今日</div> -->
    </div>
  </div>
</template>

<style scoped lang="scss">
.d-flex {
  width: 100%;
  display: flex;
  justify-content: space-between;
  z-index: 999;
  height: 60px;
  position: relative;
  margin-bottom: 4px;
}

.top-left {
  display: flex;
}

.title {
  // position: relative;
  width: 300px;
  text-align: left;
  // color: transparent;
  height: 60px;
  line-height: 46px;

  .title-text {
    font-family: 'YouSheBiaoTiHei';
    font-size: 38px;
    font-weight: 400;
    letter-spacing: 6px;
    width: 100%;
    color: #ECEDEE;
  }
}

.en-title {
  width: 300px;
  height: 40px;
  font-family: 'YouSheBiaoTiHei';
  font-weight: 400;
  font-size: 14px;
  color: #ADC0DE;
  opacity: 0.2;
  // line-height: 40px;
  padding-top: 10px;
  text-align: center;

  .en-line {
    width: 80%;
    height: 2px;
    background-color: #ADC0DE;
    margin-left: 30px;
  }
}

.change-time {
  // position: relative;
  // float: right;
  width: 400px;
  height: 60px;
  display: flex;
  // justify-content: space-between;
  flex-direction: row-reverse;
  font-family: 'YouSheBiaoTiHei';
  font-size: 16px;

  .time-title {
    margin-right: 20px;
    height: 35px;
    line-height: 30px;
  }

  .change-year {
    width: 125px;
    height: 35px;
    line-height: 30px;
    text-align: center;
    cursor: pointer;
    background-image: url("@/assets/img/zheke/top_change.png");
    background-size: cover;
    background-position: center center;
  }
}
</style>
