<template>
  <div id="companyPersonCharge">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-form :model="info" ref="info" label-width="130px">
            <el-col :span="8" class="one_1">
              <el-form-item label="姓名" prop="name">
                <el-input v-model="info.name" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="性别" prop="gender">
                <el-input v-model="info.gender" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="公民身份证号" prop="card">
                <el-input v-model="info.card" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="民族" prop="nation">
                <el-input v-model="info.nation" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="出生日期" prop="birth">
                <el-input v-model="info.birth" readonly></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8" class="one_1">
              <el-form-item label="学历" prop="education">
                <el-input v-model="info.education" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="政治面貌" prop="politics">
                <el-input v-model="info.politics" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="法人联系电话" prop="legal_phone">
                <el-input v-model="info.legal_phone" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="职务" prop="zw">
                <el-input v-model="info.zw" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="户籍地省市县" prop="household">
                <el-input v-model="info.household" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="户籍地详址" prop="household_detailed">
                <el-input v-model="info.household_detailed" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="现住地省市县" prop="onhouse_city">
                <el-input v-model="info.onhouse_city" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="现住址详址" prop="onaddress_detailed">
                <el-input v-model="info.onaddress_detailed" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="保安职业等级代码" prop="exam_grade">
                <el-input v-model="info.exam_grade" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="保安员证编号" prop="baoan_num">
                <el-input v-model="info.baoan_num" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="one_1">
              <el-form-item label="保安员发证日期" prop="baoan_cert_date">
                <el-input v-model="info.baoan_cert_date" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" class="one_1">
              <el-form-item label="简历" prop="resume">
                <el-input v-model="info.resume" type="textarea" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-col>
        <el-col :span="24" class="two">
          <data-table :fields="filefields" :opera="fileopera" :data="filelist" :usePage="false" @download="toDownload"> </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('company_person_charge');
const { mapActions: mapfiles } = createNamespacedHelpers('digital_files');

export default {
  name: 'companyPersonCharge',
  props: {},
  components: {},
  data: function () {
    return {
      info: {},
      filefields: [
        { label: '电子材料类型', model: 'type' },
        { label: '电子材料名称', model: 'name' },
        { label: '文件地址', model: 'el_img' },
      ],
      fileopera: [{ label: '下载', method: 'download' }],
      filelist: [],
    };
  },
  async created() {
    if (this.id) await this.search();
  },
  methods: {
    ...mapActions(['fetch', 'update', 'create']),
    ...mapfiles({ filesQuery: 'query' }),
    async search() {
      const res = await this.fetch({ company_id: this.id });
      if (this.$checkRes(res)) {
        if (res.data) this.$set(this, 'info', res.data);
        this.searchFiles();
      }
    },
    async searchFiles() {
      let res = await this.filesQuery({ main_id: this.info.id });
      if (this.$checkRes(res)) {
        this.$set(this, `filelist`, res.data);
      }
    },
    // 下载
    toDownload({ data }) {
      window.open(`${process.env.VUE_APP_HOST}${data.el_img}`, '_blank');
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .one_1 {
      padding: 0 10px;
    }
  }
}
</style>
