<template>
  <div id="baseInfo">
    <view-form :data="info" :fields="finalFields"></view-form>
  </div>
</template>

<script>
import viewForm from './util/view-form.vue';
const _ = require('lodash');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: dept } = createNamespacedHelpers('police_department');
export default {
  name: 'baseInfo',
  props: {
    data: { type: Object, required: true },
  },
  components: { viewForm },
  data: function () {
    return {
      info: {},
      tube_companyList: [],
      fields: [
        {
          label: '企业类型',
          model: 'purpose',
        },
        {
          label: '账号名称',
          model: 'name',
        },
        {
          label: '设置账号',
          model: 'phone',
        },
        // {
        //   label: '安全邮箱',
        //   model: 'email',
        // },
        {
          label: '企业名称',
          model: 'company',
        },
        {
          label: '详细地址',
          model: 'addres',
        },
        {
          label: '所属区县',
          model: 'belong_city',
        },
        {
          label: '管辖单位',
          model: 'tube_company',
        },
        {
          label: '法人代表人姓名',
          model: 'legal_personal',
        },
        {
          label: '法人代表人联系方式',
          model: 'legal_phone',
        },
        {
          label: '法人代表人公民身份号码',
          model: 'legal_card',
        },
        {
          label: '法人户籍地详址',
          model: 'legal_hjd',
        },
        {
          label: '法人现住地详址',
          model: 'legal_xzd',
        },
        // {
        //   label: '法人代表人职务',
        //   model: 'legal_zw',
        // },
        {
          label: '保安服务类型',
          model: 'baoan_sevicetype',
        },
        // {
        //   label: '申请报告',
        //   model: 'apply_report',
        // },
        {
          label: '企业组织机构代码',
          model: 'zhjgdm',
        },
        {
          label: '类型',
          model: 'money_type',
        },
        {
          label: '邮政编码',
          model: 'post_num',
        },
        // {
        //   label: '传真',
        //   model: 'fax',
        // },
        {
          label: '统一社会信用代码',
          model: 'company_yyzzzch',
        },
        // {
        //   label: '保安服务许可证号',
        //   model: 'company_xkzpzwh',
        // },
        {
          label: '注册资金',
          model: 'register_money',
        },
        {
          label: '分管保安负责人姓名',
          model: 'charge_personal',
        },
        {
          label: '分管保安负责人身份号码',
          model: 'charge_card',
        },
        {
          label: '分管保安负责人联系电话',
          model: 'charge_phone',
        },
        {
          label: '分管保安负责人微信联系方式',
          model: 'charge_wx',
        },
        {
          label: '分管保安负责人户籍地详址',
          model: 'charge_hjd',
        },
        {
          label: '分管保安负责人现住地详址',
          model: 'charge_xzd',
        },
        // {
        //   label: '分管保安负责人职务',
        //   model: 'charge_zw',
        // },
        {
          label: '营业执照经营范围',
          model: 'company_yyzzjyfw',
        },
        // {
        //   label: '营业执照发证机关',
        //   model: 'company_yyzzfzjg',
        // },
        // {
        //   label: '成立日期',
        //   model: 'establish_date',
        // },
        // {
        //   label: '营业执照截止日期',
        //   model: 'company_yyzzjzrq',
        // },
        // {
        //   label: '单位性质',
        //   model: 'company_nature',
        // },
        // {
        //   label: '单位组织机构类型',
        //   model: 'zhjglx',
        // },
      ],
      finalFields: [],
      companyType: {
        保安服务公司申请设立: {
          fields: [{ label: '场地面积', model: 'land_rice' }],
          rules: { land_rice: [{ required: false, message: '请填写场地面积', trigger: 'change' }] },
        },
        保安培训单位设立审批: {
          fields: [
            {
              label: '发起人类型',
              model: 'initiator_type',
            },
            {
              label: '培训规模',
              model: 'train_num',
            },
            {
              label: '校长或院长姓名',
              model: 'school_personal',
            },
            {
              label: '校长或院长身份证号',
              model: 'school_card',
            },
            {
              label: '校长或院长联系电话',
              model: 'school_phone',
            },
            {
              label: '师资人数',
              model: 'teache_num',
            },
            {
              label: '保安专业师资人数',
              model: 'major_teanum',
            },
            {
              label: '校园面积',
              model: 'campus_area',
            },
            {
              label: '校舍面积',
              model: 'schoolhouse_area',
            },
            {
              label: '固定资产',
              model: 'fixed_money',
            },
            {
              label: '是否提供住宿',
              model: 'is_stay',
            },
            {
              label: '培训目标',
              model: 'train_target',
            },
          ],
        },
        自行招用保安员单位申请备案: {
          // fields: [{ label: '保安主管部门名称', model: 'zxzy_depart' }],
        },
      },
    };
  },
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    ...dept(['fetch']),

    async init() {
      const info = _.cloneDeep(this.data);
      if (_.get(info, 'purpose')) {
        const keys = Object.keys(this.companyType);
        const r = keys.find((f) => _.get(info, 'purpose').includes(f));
        const mid = this.companyType[r];
        if (mid) {
          const { fields } = mid;
          if (_.isArray(fields)) {
            let dup = _.cloneDeep(this.fields);
            dup = [...dup, ...fields];
            this.$set(this, `finalFields`, dup);
          } else this.$set(this, `finalFields`, _.cloneDeep(this.fields));
        } else this.$set(this, `finalFields`, _.cloneDeep(this.fields));
      }
      if (_.get(info, 'tube_company')) {
        const r = await this.getTubeCompany(_.get(info, 'tube_company'));
        if (r) info.tube_company = r;
      }
      this.$set(this, `info`, info);
    },
    async getTubeCompany(id) {
      const res = await this.fetch({ id });
      if (this.$checkRes(res)) {
        return _.get(res.data, 'name');
      }
    },
  },
  computed: {},
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped></style>
