<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.company"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="法人姓名">
                    <el-input v-model="searchFrom.legal_personal"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="法人身份证号">
                    <el-input v-model="searchFrom.legal_card"></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="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>
    <el-dialog class="dialog" title="信息审核" :visible.sync="show" width="60%" :before-close="close" :close-on-click-modal="false">
      <form-1 :form="form" @close="close" @onSubmit="onSubmit"></form-1>
    </el-dialog>
    <el-dialog class="dialog" title="详细信息" :visible.sync="twoShow" width="60%" :before-close="twoClose" :close-on-click-modal="false">
      <info-1 :info="info" :fileList="fileList"></info-1>
    </el-dialog>
  </div>
</template>

<script>
import form1 from './parts/form-1.vue';
import info1 from './parts/info-1.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: company_legal_change } = createNamespacedHelpers('company_legal_change');
const { mapActions: digital_files } = createNamespacedHelpers('digital_files');
const { mapActions: company_base } = createNamespacedHelpers('company_base');

export default {
  name: 'index',
  props: {},
  components: { form1, info1 },
  data: function () {
    return {
      // 查询表单
      searchFrom: {},
      list: [],
      total: 0,
      fields: [
        { label: '企业名称', model: 'company' },
        { label: '企业类别', model: 'purpose' },
        { label: '法人姓名', model: 'legal_personal' },
        { label: '法人身份证号', model: 'legal_card' },
        { label: '法人联系电话', model: 'legal_phone' },
        { label: '法人代表职务', model: 'legal_zw' },
        { label: '管辖单位名称', model: 'tube_company' },
        { label: '审核结果', model: 'status', format: (i) => (i == '0' ? '待审中' : i == '1' ? '通过' : '拒绝') },
      ],
      opera: [
        { label: '详情', method: 'view' },
        { label: '审核', method: 'check', display: (i) => i.status == '0' },
      ],
      // 审核
      show: false,
      form: {},
      // 详情
      twoShow: false,
      info: {},
      fileList: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...company_legal_change(['query', 'create', 'update']),
    ...digital_files({ fileQuery: 'query', fileCreate: 'create' }),
    ...company_base({ baseUpdate: 'update' }),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      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);
      }
    },
    // 查看
    async toView({ data }) {
      let res = await this.fileQuery({ main_id: data.id });
      if (this.$checkRes(res)) {
        this.$set(this, `fileList`, res.data);
        this.$set(this, `info`, data);
        this.twoShow = true;
      }
    },
    // 关闭详情
    twoClose() {
      this.twoShow = false;
    },
    // 提交审核
    async onSubmit({ data }) {
      let res = await this.update(data);
      if (this.$checkRes(res)) {
        if (data.status == '1') this.updateCompany(data);
        this.search();
        this.close();
      } else {
        this.$message({ type: `error`, message: `${res.errmsg}` });
      }
    },
    // 审核通过更新数据
    async updateCompany(data) {
      let p1 = {
        id: data.company_id,
        legal_personal: data.legal_personal,
        legal_card: data.legal_card,
        legal_phone: data.legal_phone,
        legal_zw: data.legal_zw,
      };
      let p2 = await this.baseUpdate(p1);
      if (this.$checkRes(p2)) {
        this.$message({ type: `success`, message: `操作成功` });
      } else {
        this.$message({ type: `error`, message: `${p2.errmsg}` });
      }
    },
    // 审核
    toCheck({ data }) {
      this.$set(this, `form`, data);
      this.show = true;
    },
    // 关闭
    close() {
      this.show = 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;
        }
      }
    }
  }
}
</style>
