<template>
  <view class="p-20 min-height">
    <uv-empty v-if="!list.length" text="暂无打分任务"></uv-empty>
    <view v-for="(item, index) in list" :key="index" class="border p-20 m-20 text-25 rounded">
      <view>{{ item.title }}</view>
      <view class="mt-15 text-gray">考试时长: {{ item.examTime }}分钟</view>
      <view class="mt-15 text-gray">考试企业: {{ item.orgName }}</view>
      <view class="mt-15 text-gray">{{ item.level }}</view>
      <view class="mt-15 text-gray flex justify-start items-start">
        <text>试卷:</text>
        <view class="ml-10 flex flex-col justify-start items-start">
          <text class="mb-10" v-if="item.paperList[0].operatePaper">{{ item.paperList[0].operatePaper.title }}</text>
        </view>
      </view>
      <view class="mt-15 text-main pb-15" @click="item.showPeople = !item.showPeople">
        {{ item.showPeople ? '收起' : '查看考试人员' }}
      </view>
      <template v-if="item.showPeople">
        <view class="flex flex-col justify-start items-start py-15 border-top text-main text-25"
              v-for="(people, peopleIndex) in item.peopleList" :key="peopleIndex">
          <view class="flex justify-between items-center w-100p">
            <text>{{ people.userDetail.realname }}</text>
            <uv-button v-if="!people.staffHasScore && item.staffTypeList.includes('考评人员')" shape="circle"
                       type="primary"
                       @click="jump('/pages/exam/makeScore', item, people)"
                       size="mini">去打分
            </uv-button>
            <text v-if="people.staffHasScore">总分: {{ people.operateScore }}分</text>
          </view>
          <template v-if="people.staffHasScore && item.staffTypeList.includes('督导人员')">
            <view class="flex justify-between items-center w-100p py-15 border-bottom text-gray"
                  v-for="(score, scoreIndex) in people.scoreList" :key="scoreIndex">
              <view class="flex justify-start items-center">
                <text>打分人:{{ score.scoreUserName }}</text>
                <text class="ml-10">评分:{{ score.totalScore }}</text>
              </view>
              <uv-button v-if="!score.checkUserName" shape="circle"
                         type="primary"
                         @click="jump('/pages/exam/checkScore', item, people, score)"
                         size="mini">核分
              </uv-button>
              <text v-else>核分人:{{ score.checkUserName }}</text>
            </view>
          </template>
        </view>
      </template>
    </view>
  </view>
</template>

<script setup>
import {ref} from 'vue'
import {trainExamStaffListReq} from "@/api/exam";
import {onShow} from "@dcloudio/uni-app";

const list = ref([])
const getList = async () => {
  const {data} = await trainExamStaffListReq()
  list.value = data.map(item => {
    item.showPeople = false
    return item
  })
}

onShow(() => {
  getList()
})

const jump = (url, item, people, score = null) => {
  url += `?examId=${item.id}&paperId=${item.paperList[0].operatePaperId}&userId=${people.userId}`
  url += `&idCard=${people.userDetail.idCard}&realname=${people.userDetail.realname}`
  if (score) {
    url += `&scoreUserId=${score.scoreUserId}&scoreUserName=${score.scoreUserName}`
  }
  uni.navigateTo({url})
}
</script>