<script setup lang="ts">
import StaticConstant from "@/utils/StaticConstant";
import { reactive, ref, toRefs } from 'vue';
import axiosInstance from '@/utils/http';
import apiConstant from "@/utils/ApiConstant";
import { AxiosResponse } from "axios";
import { Search } from '@element-plus/icons-vue';
import LeftNav from "@/components/LeftNav.vue";
document.title = '轻松查排名|' + import.meta.env.VITE_PROGRAM_TYPE;
const state = reactive({
  dataList: null as any,
  categoryList: ['文科', '理科'] as any,
  professionalCategoryList: [...StaticConstant.professionalCategoryList] as any,
  yearList: ['2024', '2023', '2022'] as any,
  selectForm: {
    professionalScore: 0,//统考成绩
    professionalCategory: '美术与设计类',
    category: '文科',
  },//查位次表单
  flag: true,

  queryForm: {
    professionalCategory: '美术与设计类',
    year: '2024',
  },// 五分一段表查询表单
  professionalCategoryList2: [
      {value: '美术与设计类', label: '美术与设计类'},
      {value: '播音与主持类', label: '播音与主持类'},
      {value: '服装表演',label: '服装表演类'},
      {value: '戏剧影视导演',label: '戏剧影视导演类'},
      {value: '戏剧影视表演',label: '戏剧影视表演类'},
      {value: '音乐表演声乐',label: '音乐表演声乐类'},
      {value: '音乐表演器乐',label: '音乐表演器乐类'},
      {value: '音乐教育',label: '音乐教育类'},
      {value: '舞蹈类', label: '舞蹈类'},
      {value: '书法类', label: '书法类'}
    ] as any,
  scoreTableDialogVisible: false,//显示成绩表弹框判断
  fiveScoreTableData:[] as any,//五分一段表数据
})

//选择文理科
function checkboxCategory(e: string) {
  if (state.selectForm.category !== e) {
    state.selectForm.category = e
  }
}
//专业类别
function checkboxProfessionalCategory(e: string) {
  if (state.selectForm.professionalCategory !== e) {
    state.selectForm.professionalCategory = e
  }
  
}

//获取排名
function getList() {
  axiosInstance({
    url: apiConstant.Score.scoreSegmentSearchByScore,
    method: 'get',
    params: {
      province: '河南',
      score: state.selectForm.professionalScore,
      professionalCategory: state.selectForm.professionalCategory
    },
    //showLoading: false,//是否显示加载图标
  }).then((response: AxiosResponse) => {
    return response?.data
  }).then((data) => {
    if (data.success) {
      console.log(data)
      if (data.result && data.result.length > 0) {
        state.dataList = data.result
      } else {
        state.dataList = null
      }
    }
  }).catch((error: any) => {
    console.log(error);
  }).finally(() => {
    state.flag = false
  });
}
function handleNumberChange(v: string) {
  console.log(v)
}


// 选择年份
const checkboxYear = (e: string) => {
  if(state.queryForm.year != e){
    state.queryForm.year = e
    if (e === '2024') {
    state.professionalCategoryList2 = [
      {value: '美术与设计类', label: '美术与设计类'},
      {value: '播音与主持类', label: '播音与主持类'},
      {value: '服装表演',label: '服装表演类'},
      {value: '戏剧影视导演',label: '戏剧影视导演类'},
      {value: '戏剧影视表演',label: '戏剧影视表演类'},
      {value: '音乐表演声乐',label: '音乐表演声乐类'},
      {value: '音乐表演器乐',label: '音乐表演器乐类'},
      {value: '音乐教育',label: '音乐教育类'},
      {value: '舞蹈类', label: '舞蹈类'},
      {value: '书法类', label: '书法类'},
    ]
  } else if (e === '2023') {
    state.professionalCategoryList2 = [
      { value: '美术与设计类', label: '美术与设计类' },
      {value: '播音与主持类', label: '播音与主持类'},
      { value: '国际标准舞', label: '国际标准舞类' },
      { value: '艺术舞蹈', label: '艺术舞蹈类' },
      { value: '表演类', label: '表演类' },
      { value: '音乐类', label: '音乐类' },
      { value: '书法类', label: '书法类' }
    ]
  } else if (e === '2022') {
    state.professionalCategoryList2 = [
      { value: '美术与设计类', label: '美术与设计类' },
      { value: '播音与主持类', label: '播音与主持类' },
      { value: '国际标准舞', label: '国际标准舞类' },
      { value: '艺术舞蹈', label: '艺术舞蹈类' },
      { value: '表演类', label: '表演类' },
      { value: '音乐类', label: '音乐类' },
      { value: '书法类', label: '书法类' }
    ]
  }
  state.queryForm.professionalCategory = state.professionalCategoryList2[0].value
  getScoreList()
  console.log(state.professionalCategoryList2)
  }
  
}
// 选择专业类别
const checkboxProfessionalCategory2 = (e:string) =>{
  if (state.queryForm.professionalCategory !== e) {
    state.queryForm.professionalCategory = e
    getScoreList()
  }
}
// 获取五分一段表
const getScoreList = ()=>{
  axiosInstance({
    url: apiConstant.Score.scoreSegmentList,
    method: 'get',
    params: {
      year:state.queryForm.year,
      professionalCategory: state.queryForm.professionalCategory
    },
    //showLoading: false,//是否显示加载图标
  }).then((response: AxiosResponse) => {
    return response?.data
  }).then((data) => {
    if (data.success) {
      state.fiveScoreTableData = data.result
      console.log(data)
    }
  }).catch((error: any) => {
    console.log(error);
  }).finally(() => {
    state.flag = false
  });
}

//打开分段表
const openScoreTableDialog = () => {
  state.scoreTableDialogVisible = true
}
//关闭分段表
const closeScoreTableDialog = () => {
  state.scoreTableDialogVisible = false
}

</script>

<template>
  <LeftNav />
  <div class="main-container wrap main-fullScreen">
    <el-row :gutter="20">
      <el-col :span="24">
        <div class="filterBody">
          <div class="flexWrap">
            <div class="flex-item-1">专业类别</div>
            <div class="flex-item-9 tags">
              <span class="tag" :class="state.selectForm.professionalCategory === item.value ? 'tag-active' : ''"
                v-for="(item, index) in state.professionalCategoryList" :key="index"
                @click="checkboxProfessionalCategory(item.value)">
                {{ item.label }}
              </span>
              <span style="padding: 0 30px">
                <el-button type="primary" @click="openScoreTableDialog">五分一段表</el-button>
              </span>
            </div>
          </div>
          <div class="flexWrap">
            <div class="flex-item-1">统考分数</div>
            <div class="flex-item-9 tags">
              <el-input-number v-model="state.selectForm.professionalScore" :min="0" :max="600"
                @change="handleNumberChange" />
              <el-button type="primary" :icon="Search" @click="getList">查询</el-button>
            </div>
          </div>
        </div>
        <div class="dataList">
          <div class="item" v-if="state.dataList && state.dataList.length > 0">
            <div class="flexWrap" v-for="(item, index) in state.dataList" :key="index">
              <div v-if="item.type == 1">
                <div class="year">{{ item.year }}年</div>
                <div class="t1">
                  <span v-if="item.beginScore && item.endScore">
                    {{ item.beginScore }}分~{{ item.endScore }}分
                  </span>
                  <span v-else-if="item.beginScore">
                    {{ item.beginScore }}分~{{ item.endScore }}分
                  </span>
                  <span v-else>
                    最低分{{ item.endScore }}分
                  </span>
                </div>
                <div class="t2">
                  超越全省<span class="orange fw-6">{{ item.rate }}%</span>的考生
                </div>
                <div class="t3">
                  排名
                  <span v-if="item.startRank && item.endRank">
                    介于{{ item.startRank }}名~{{ item.endRank }}名之间
                  </span>
                  <span v-else-if="item.startRank">
                    大于{{ item.startRank }}&nbsp;名
                  </span>
                  <span v-else>
                    小于{{ item.endRank }}名
                  </span>
                </div>
              </div>
              <div v-else>
                您的分数已低于{{ item.year }}公布的最低分{{ item.beginScore }}分
              </div>
            </div>
          </div>
          <div class="item" v-else-if="state.flag">
            请输入统考成绩查询
          </div>
          <div class="item" v-else>
            暂未查询到结果
          </div>
        </div>
      </el-col>
    </el-row>
  </div>

  <!--五分一段表弹框-->
  <el-dialog v-model="state.scoreTableDialogVisible" title="" width="60em" :closeOnClickModal="false"
    :show-close="false">
    <template #header>
      <div style="display: flex; justify-content: space-between; align-items: center;">
        <h3 style="margin: 0;">五分一段表</h3>
        <el-icon @click="closeScoreTableDialog" class="el-dialog__headerbtn">
          <Close />
        </el-icon>
      </div>
    </template>
    <!--筛选内容-->
    <div class="filterBody">
      <div class="flexWrap">
        <div class="flex-item-1">年份</div>
        <div class="flex-item-9 tags">
          <span class="tag" :class="state.queryForm.year === item ? 'tag-active' : ''"
            v-for="(item, index) in state.yearList" :key="index" @click="checkboxYear(item)">
            {{ item }}
          </span>
        </div>
      </div>
      <div class="flexWrap">
        <div class="flex-item-1">专业类别</div>
        <div class="flex-item-9 tags">
          <span class="tag" :class="state.queryForm.professionalCategory === item.value ? 'tag-active' : ''"
            v-for="(item, index) in state.professionalCategoryList2" :key="index"
            @click="checkboxProfessionalCategory2(item.value)">
            {{ item.label }}
          </span>
        </div>
      </div>
      <div class="flexWrap">
        <div class="flex-item-9 tags">
          <el-button type="primary" :icon="Search" @click="getScoreList">查询</el-button>
        </div>
      </div>
    </div>
    <div>
      <el-table :data="state.fiveScoreTableData" border style="width: 100%">
        <el-table-column prop="year" label="年份" align="center"/>
        <el-table-column prop="score" label="分数" align="center"/>
        <el-table-column prop="num" label="人数" align="center"/>
        <el-table-column prop="personNum" label="累计人数" align="center"/>
      </el-table>
    </div>
  </el-dialog>

</template>

<style scoped lang="scss">
root {
  width: 100%;
}

.dataList {
  min-height: 650px;
  background-color: white;
  border-radius: 0 0 5px 0;
  padding: 15px;
  //color: $color-black-60;
  border-bottom: 1px solid #ebeef5;
  line-height: 30px;
  font-size: 30px;
  color: black;

  .year {
    font-weight: 600;
  }

  .item {
    padding-bottom: 20px;
    border-bottom: 1px solid #ebeef5;
  }
}
</style>
