<template>
  <div class="cmain">
    <el-form ref="form" :model="form" :disabled="param.detail" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="企业名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入公司名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="法定代表人" prop="legalPerson">
            <el-input v-model="form.legalPerson" placeholder="请输入法定代表人" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="企业电话" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入电话" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="企业邮箱" prop="email">
            <el-input v-model="form.email" placeholder="请输入邮箱" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="注册资本" prop="capital">
            <el-input v-model="form.capital" placeholder="请输入注册资本" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="企业地址" prop="address">
            <el-input v-model="form.address" placeholder="请输入地址" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="企业简介" prop="contents">
        <el-input v-model="form.contents" type="textarea" rows="4" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="营业执照" prop="p1">
        <el-image :fit="'contain'" class="sfz" style="max-height: 150px; width: 30%" :z-index="50000" :src="baseUrl + form.p1" :preview-src-list="[baseUrl + form.p1]"></el-image>
      </el-form-item>
    </el-form>
    <div class="mfooter" v-if="form.state == 0">
      <el-button type="primary" @click="submitForm(1)">认证通过</el-button>
      <el-button type="danger" @click="submitForm(2)">认证不通过</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {},
      rules: {}
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      }
    },
    layerid: {
      type: String
    }
  },
  mounted() {
    if (this.param.id) {
      this.ajax({ url: '/work/enterprise/detail/' + this.param.id }).then((response) => {
        this.form = response.data;
      });
    }
  },
  methods: {
    submitForm(state) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$prompt(state == 1 ? '认证通过' : '认证不通过', {
            type: 'warning',
            showInput: state == 1 ? false : true,
            inputType: 'textarea',
            inputPlaceholder: '认证失败',
            inputValidator: (value) => {
              if (!value && state == 2) {
                return '请输入认证失败原因';
              }
            }
          }).then(({ value }) => {
            this.post({ url: '/work/enterprise/edit', data: { id: this.form.id, state: state, msg: value } }).then((response) => {
              this.$modal.msgSuccess('操作成功');
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          });
        }
      });
    }
  }
};
</script>
