<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">
            <search-1 :form="searchForm" @onSubmit="search"></search-1>
          </el-col>
        </el-col>
        <el-col :span="24" class="two">
          <data-table @query="search" :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @check="toCheck"> </data-table>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog class="dialog" title="信息详情" :visible.sync="show" width="60%" :before-close="close" :close-on-click-modal="false">
      <info-1 :info="info"></info-1>
    </el-dialog>
    <el-dialog class="dialog" title="领取登记" :visible.sync="twoShow" width="60%" :before-close="twoClose" :close-on-click-modal="false">
      <check-1 :form="form" @reseatBtn="twoClose" @onSubmit="onSubmit"></check-1>
    </el-dialog>
  </div>
</template>

<script>
import info1 from './parts/info-1.vue';
import check1 from './parts/check-1.vue';
import search1 from './parts/search-1.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: company_keep_grant } = createNamespacedHelpers('company_keep_grant');
export default {
  name: 'index',
  props: {},
  components: {
    info1,
    check1,
    search1,
  },
  data: function () {
    return {
      // 查询
      searchForm: {},
      // 列表
      fields: [
        { label: '企业名称', model: 'company' },
        { label: '企业类别', model: 'purpose' },
        { label: '法人姓名', model: 'legal_personal' },
        { label: '法人代表身份证号', model: 'legal_card' },
        { label: '备案证明编号', model: 'licence_num' },
        { label: '管辖单位', model: 'tube_company' },
        { label: '保安备案证明发证日期', model: 'cert_date' },
        { label: '打印日期', model: 'print_date' },
        { label: '证件状态', model: 'cert_status', format: (i) => (i == '0' ? '正常' : '注销') },
      ],
      opera: [
        { label: '详情', method: 'view' },
        { label: '登记', method: 'check', display: (i) => i.status == '0' },
      ],
      list: [],
      total: 0,
      // 详情
      show: false,
      info: {},
      // 领取登记
      twoShow: false,
      form: {},
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...company_keep_grant(['query', 'update', 'fetch']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchForm);
      let res = await this.query({ skip, limit, ...condition, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 详情
    toView({ data }) {
      this.$set(this, `info`, data);
      this.show = true;
    },
    // 关闭详情
    close() {
      this.show = false;
    },
    // 登记
    async toCheck({ data }) {
      this.$set(this, `form`, data);
      this.twoShow = true;
    },
    // 提交登记
    async onSubmit(data) {
      data.status = '1';
      let res = await this.update(data);
      if (this.$checkRes(res)) {
        this.$message({ type: `success`, message: `操作成功` });
        this.search();
        this.twoClose();
      } else {
        this.$message({ type: `error`, message: `${res.errmsg}` });
      }
    },
    // 关闭登记
    twoClose() {
      this.twoShow = false;
    },
  },
  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;
        }
      }
    }
  }
}
/deep/.el-dialog__body {
  padding: 10px;
}
</style>
