<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" placeholder="请输入姓名"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="身份证号">
                    <el-input v-model="searchFrom.card" placeholder="请输入身份证号"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系电话">
                    <el-input v-model="searchFrom.phone" placeholder="请输入联系电话"></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="24" class="btn">
                  <!-- <el-button type="primary" size="mini" @click="batchMake">批量补考</el-button> -->
                  <el-button type="primary" size="mini" @click="search()">查询</el-button>
                </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"
            @make="toMake"
            :select="true"
            :selected="selected"
            @handleSelect="handleSelect"
          >
          </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: examination_examinee } = createNamespacedHelpers('examination_examinee');
const { mapActions: security_guard_base } = createNamespacedHelpers('security_guard_base');

export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '姓名', model: 'name' },
        { label: '身份证号', model: 'card' },
        { label: '准考证号', model: 'exam_num' },
        { label: '考试日期', model: 'exam_date' },
        { label: '考试成绩', model: 'exam_achieve' },
        { label: '考试类型', model: 'exam_type' },
        { label: '考试等级', model: 'exam_grade' },
        { label: '公安机关', model: 'police_office' },
      ],
      opera: [{ label: '补考', method: 'make', type: 'primary' }],
      list: [],
      total: 0,
      // 批量补考所选列表
      selected: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...examination_examinee(['query', 'update', 'create']),
    ...security_guard_base({ baseUpdate: 'update' }),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      let res = await this.query({ skip, limit, ...condition, status: '-4', ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 补考
    async toMake({ data }) {
      let p1 = await this.update({ id: data.id, status: '5' });
      if (this.$checkRes(p1)) {
        let p2 = await this.baseUpdate({ id: data.security_guard_id, status: '4' });
        if (this.$checkRes(p2)) {
          let p3 = {
            name: data.name,
            gender: data.gender,
            card: data.card,
            phone: data.phone,
            exam_grade: data.exam_grade,
            security_guard_id: data.security_guard_id,
            exam_type: '补考',
          };
          let p4 = await this.create(p3);
          if (this.$checkRes(p4)) {
            this.$message({ type: `success`, message: `操作完成` });
            this.search();
          }
        }
      }
    },
    // 批量选择打印数
    handleSelect(data) {
      this.$set(this, `selected`, data);
    },
    // 批量补考
    batchMake() {
      console.log(this.selected);
    },
  },
  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>
