<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="80px">
              <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-select v-model="searchFrom.grade" clearable placeholder="请选择">
                      <el-option v-for="(item, index) in exam_gradeList" :key="index" :label="item" :value="item"></el-option>
                    </el-select>
                  </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="search()">查询</el-button>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
        </el-col>
        <el-col :span="24" class="thr">
          <data-table @query="search" :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @check="toCheck"> </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const { exam_grade } = require('@common/src/layout/deploy/dict');
import { mapGetters, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('system_account');
const { mapActions: security_guard_base } = createNamespacedHelpers('security_guard_base');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 用户信息
      user: {},
      // 查询表单
      searchFrom: {},
      list: [],
      total: 0,
      fields: [
        { label: '姓名', model: 'name' },
        { label: '身份证号', model: 'card' },
        { label: '性别', model: 'gender' },
        { label: '保安员等级', model: 'grade' },
        { label: '出生日期', model: 'birth' },
        { label: '采集照片', model: 'collect_photo' },
        { label: '采集指纹', model: 'collect_fingerprint' },
        { label: '审核结果', model: 'examine_status' },
        { label: '审批结果', model: 'approve_status' },
        { label: '受理时间', model: 'acceptance_date' },
        { label: '受理公安机关', model: 'acceptance_police' },
      ],
      opera: [
        { label: '详情', method: 'view', type: 'info' },
        { label: '资格审核', method: 'check', type: 'primary' },
      ],
      // 保安员等级
      exam_gradeList: exam_grade,
    };
  },
  async created() {},
  mounted() {
    this.init();
  },
  methods: {
    ...mapActions(['fetch']),
    ...security_guard_base(['query', 'delete', 'update']),
    async init() {
      if (!_.get(this.tokenInfo, 'id')) return;
      const res = await this.fetch({ id: this.tokenInfo.id });
      if (this.$checkRes(res)) {
        let data = _.cloneDeep(res.data);
        this.$set(this, `user`, data);
        this.search();
      }
    },
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      let res = await this.query({ skip, limit, ...condition, ...this.searchFrom, status: '2', house_police: this.user.department_name, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 详情
    toView({ data }) {
      this.$router.push({ path: '/adminPolice/security/bmzgsh/info', query: { id: data.id } });
    },
    // 资格审核
    toCheck({ data }) {
      this.$router.push({ path: '/adminPolice/security/bmzgsh/check', query: { id: data.id } });
    },
  },
  computed: {
    ...mapGetters(['tokenInfo']),
  },
  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>
