<!--考核培训一览-->
<template>
  <div :v-loading="pageLoading" class="app-container">

    <card-table :del-prop="['createTime']" :loading="loading" :modalData="data" :searchParams="queryParams"
                :tableSearch="true" labelWidth="120px" @columnSearch="handleQuery" @pagination="getList"
                @resetList="resetQuery"
    >

      <template #default="{ list }">
        <el-table-column align="center" label="No" type="index" width="50"/>


        <!--培训名称-->
        <Column :label="$t('trainList.trainingName')" :searchParams="queryParams" prop="trainName" show-search/>
        <!--培训类别-->
        <Column :label="$t('trainList.trainingCategory')" :searchDict="dict.type.training_category"
                :searchParams="queryParams" prop="trainType"
                searchType="select" select-more
                select-prop="trainTypes" show-search
        >
        </Column>
        <!--开始时间-->
        <Column :label="$t('trainList.startTime')" :searchParams="queryParams"
                prop="startDate" searchType="dateRange"
        >
        </Column>
        <!--结束时间-->
        <Column :label="$t('trainList.endTime')" :searchParams="queryParams"
                prop="endDate" searchType="dateRange"
        >
        </Column>
        <!--是否考核-->
        <Column :label="$t('trainTarget.needTrain')" :searchDict="dict.type.train_whether_to_assess"
                :searchParams="queryParams"
                prop="assessFlag" searchType="select"
        >
        </Column>
        <!--发布人-->
        <Column :label="$t('trainList.publisher')" :searchParams="queryParams" prop="createByName"/>
        <!--发布时间-->
        <Column :label="$t('trainList.releaseTime')" :searchParams="queryParams"
                prop="createTime" searchType="dateRange"
        >
        </Column>
        <!--培训状态-->
        <Column :label="$t('trainTarget.trainStatus')" :searchDict="dict.type.train_target_train_complete_flag"
                :searchParams="queryParams"
                prop="trainCompleteFlag" searchType="select" select-more
                select-prop="trainCompleteFlags" show-search>
          <template #default="{ row }">
            <ColorDictTag :bgc="statusColorMap[row.trainCompleteFlag].bgc"
                          :label="convertStatus(row.trainCompleteFlag)"
                          :label-color="statusColorMap[row.trainCompleteFlag].color"
            />
          </template>
        </Column>


        <!--考核分数-->
        <Column :label="$t('trainTarget.score')" prop="totalScore"/>

        <!--考核情况-->
        <Column :label="$t('trainTarget.examStatus')" :searchDict="dict.type.train_exam_status"
                :searchParams="queryParams"
                prop="assessCompleteFlag" searchType="select" select-more
                select-prop="passFlags" show-search/>

        <!--备注-->
        <Column :label="$t('common.remark')" prop="remark"/>


        <!--操作-->
        <Column :label="$t('common.operate')" :min-width="250" :showSearch="true" align="center" fixed="right"
                search-type="operate">
          <template #default="{ row }">
            <!--查看 查看考核结果-->
            <el-button v-if=" '0' !== row.assessCompleteFlag" v-hasPermi="['train:trainTarget:view']" icon="el-icon-view" size="mini" type="text"
                       @click="handleView(row)"
            >{{ $t('common.view') }}
            </el-button>
            <!--参与培训-->
            <el-button v-if="'0' === row.assessCompleteFlag || '0' === row.trainCompleteFlag" v-hasPermi="['train:trainTarget:train']" icon="el-icon-reading" size="mini" type="text"
                       @click="handleTrain(row)"
            >{{ $t('trainTarget.participateTrain') }}
            </el-button>
            <!--参与考核-->
            <el-button v-if="'1'===row.assessFlag && '2' !== row.assessCompleteFlag" v-hasPermi="['train:trainTarget:exam']" icon="el-icon-document-checked" size="mini" type="text"
                       @click="handleExam(row)"
            >{{ $t('trainTarget.participateExam') }}
            </el-button>
          </template>
        </Column>

      </template>

    </card-table>

  </div>
</template>

<script>
import { getCurrency } from '@/api/user/currency'
import CardTable from '@/components/element/table/CardTable.vue'
import Column from '@/components/element/table/Column.vue'
import { participantTrainPage } from '@/api/train/train'
import ColorDictTag from "@/views/crmManagement/lead/ColorDictTag/index.vue";
const statusColorMap = {
  '0': {
    color: '#FFC500',
    bgc: 'rgba(255,200,12,0.12)'
  },
  '1': {
    color: '#24CA5D',
    bgc: 'rgba(24,199,84,0.12)'
  },
  '2': {
    color: '#8B71FD',
    bgc: 'rgba(139,113,253,0.12)'
  },
  '3': {
    color: '#D71943',
    bgc: '#FAEDED'
  },
}
export default {
  name: 'Currency',
  components: {ColorDictTag, Column, CardTable },
  dicts: ['training_category', 'train_whether_to_assess', 'train_status', 'train_exam_status','train_target_train_complete_flag'],
  data() {
    return {
      statusColorMap: statusColorMap,
      pageLoading: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 币种汇率表格数据
      data: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
        // currencyName: null,
        // exchangeRate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 是否可编辑
      editAble: false
      // 汇率校验

    }
  },
  created() {
    this.getList()
  },
  methods: {
    convertStatus(status) {
      if (!status) return '-'
      return this.dict.type.train_target_train_complete_flag.filter(item => item.value === status)[0].label
    },
    /** 查询币种汇率列表 */
    async getList() {
      this.loading = true
      try {
        const { trainType, trainStatus, passFlag, createTime, ...params } = this.queryParams
        const response = await participantTrainPage(params)
        console.log("response", response)
        this.data = response.rows
        // this.total = response.total;
        this.queryParams.total = response.total
      } finally {
        this.loading = false
      }
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        currencyId: null,
        currencyName: null,
        exchangeRate: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null,
        dateRange: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        // pageNum: 1,
        // pageSize: 10,
      }

      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.currencyId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleView(row) {
      let query = {
        data:row
      }
      this.$tab.openPage(this.$t('trainTarget.testView'),"/train/trainTarget/detail/resultTestPaper",query)
    },

    // 参与培训
    handleTrain(row) {
      console.log('row::',row)
      if(row.trainStatus === '00'){
        return this.$modal.msgError(this.$t("trainTarget.trainUnStart"))
      }
      if(row.trainStatus === '02'){
        return this.$modal.msgError(this.$t("trainTarget.trainIsEnd"))
      }
      if(row.trainStatus === '03'){
        return this.$modal.msgError(this.$t("trainTarget.trainIsTerminate"))
      }
      console.log('row::',row)
      let query = {
        data: JSON.stringify(row)
      }
      console.log("query::",query)
      this.$tab.openPage('参与培训', `/participate-train/${row.id}`,query)
    },

    // 参与考核
    handleExam(row) {
      console.log('row::',row.trainStatus)
      if(row.trainStatus === '00'){
        return this.$modal.msgError(this.$t("trainTarget.trainUnStart"))
      }
      if(row.trainStatus === '02'){
        return this.$modal.msgError(this.$t("trainTarget.trainIsEnd"))
      }
      if(row.trainStatus === '03'){
        return this.$modal.msgError(this.$t('trainTarget.trainIsTerminate'))
      }
      let query = {
        data: JSON.stringify(row)
      }
      this.$tab.openPage(this.$t('trainTarget.participateExam'),"/train/trainTarget/detail/testPaper",query)
    }

  }
}
</script>


<style lang="scss">
</style>
