<template>
  <div id="examrecord-1">
    <el-row>
      <el-col :span="24" class="main">
        <data-table :fields="fields" :opera="opera" :data="list" :usePage="false">
          <template #custom="{ item, row }">
            <template v-if="item.model === 'exam_num'">
              <el-link size="mini" type="primary" :underline="false" @click="viewCard(row)">{{ row.exam_num }}</el-link>
            </template>
          </template>
        </data-table>
      </el-col>
    </el-row>
    <el-dialog class="cardDialog" title="准考证信息" :visible.sync="cardDialog" width="50%" :before-close="close" :close-on-click-modal="false">
      <card-info :info="cardInfo"></card-info>
    </el-dialog>
  </div>
</template>

<script>
import cardInfo from './card-1.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: examination_examinee } = createNamespacedHelpers('examination_examinee');
export default {
  name: 'examrecord-1',
  props: { basic_id: { type: String } },
  components: { cardInfo },
  data: function () {
    return {
      fields: [
        { label: '考试日期', model: 'exam_date' },
        { label: '准考证号', model: 'exam_num', custom: true },
        { label: '考试类型', model: 'exam_type' },
        { label: '准考证打印日期', model: 'exam_printdate' },
        { label: '考试成绩', model: 'exam_achieve' },
        { label: '体能', model: 'stamina' },
        { label: '考试地点', model: 'exam_addr' },
        { label: '公安机关', model: 'police_office' },
      ],
      opera: [],
      list: [],
      // 准考证信息
      cardDialog: false,
      cardInfo: {},
    };
  },
  created() {},
  methods: {
    ...examination_examinee(['query']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      info.security_guard_id = this.basic_id;
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
      }
    },
    // 考试记录
    viewCard(data) {
      this.$set(this, `cardInfo`, data);
      this.cardDialog = true;
    },
    // 关闭
    close() {
      this.cardDialog = false;
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    basic_id: {
      deep: true,
      immediate: true,
      handler(val) {
        if (val) this.search();
      },
    },
  },
};
</script>

<style lang="less" scoped></style>
