<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="one_1"> 保安员考试信息导出 </el-col>
          <el-col :span="24" class="one_2">
            <el-form ref="searchFrom" :model="searchFrom" label-width="100px">
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="姓名">
                    <el-input v-model="searchFrom.name"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="公民身份号码">
                    <el-input v-model="searchFrom.card"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="准考证号">
                    <el-input v-model="searchFrom.exam_num"></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="考点编号">
                    <el-input v-model="searchFrom.testsite_num"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="16" class="btn">
                  <el-button type="primary" size="mini" @click="search()">查询</el-button>
                  <download-excel :data="selected" :fields="excel_fields.fields" :name="excel_fields.name" style="display: inline; margin: 0 0 0 10px">
                    <el-button type="primary" size="mini">批量导出</el-button>
                  </download-excel>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
        </el-col>
        <el-col :span="24" class="two">
          <data-table
            @query="search"
            :fields="fields"
            :opera="opera"
            :data="list"
            :total="total"
            :select="true"
            @check="toCheck"
            :selected="selected"
            @handleSelect="handleSelect"
          >
          </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const { exam_grade, baoan_exam } = require('@common/src/layout/deploy/dict');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: examination_examinee } = createNamespacedHelpers('examination_examinee');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '姓名', model: 'name' },
        { label: '性别', model: 'gender' },
        { label: '身份号码', model: 'card' },
        { label: '准考证号', model: 'exam_num' },
        { label: '考试等级', model: 'exam_grade' },
        { label: '考点编号', model: 'testsite_num' },
        { label: '考试日期', model: 'exam_date' },
        { label: '考试时间', model: 'exam_time' },
        { label: '考试地点', model: 'exam_addr' },
        { label: '准考证打印日期', model: 'exam_printdate' },
        { label: '准考证打印人', model: 'exam_printper' },
        { label: '公安机关', model: 'police_office' },
      ],
      // 考试考生信息导出头
      excel_fields: baoan_exam,
      opera: [
        // { label: '导出', method: 'check' }
      ],
      list: [],
      total: 0,
      // 考试等级
      exam_gradeList: exam_grade,
      // 批量导出列表
      selected: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...examination_examinee(['query']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      let res = await this.query({ skip, limit, status: '2', ...condition, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 批量选择打印数
    handleSelect(data) {
      this.$set(this, `selected`, data);
    },
    // 批量导出
    toExport() {
      console.log(this.selected);
    },
    // 单个导出
    toCheck({ data }) {
      console.log(data);
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .one_1 {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #ccc;
      margin: 0 0 10px 0;
      font-size: 18px;
      font-weight: bold;
    }
    .one_2 {
      .one_2txt {
        border: 1px solid #ccc;
        /deep/.el-form-item {
          margin: 0;
        }
        /deep/.el-date-editor.el-input,
        .el-date-editor.el-input__inner {
          width: 100%;
        }
        /deep/.el-select {
          width: 100%;
        }
        .btn {
          text-align: right;
          padding: 5px 5px;
        }
      }
    }
  }
}
</style>
