<template>
  <div class="basic-info">
    <cy-info-title>企业信息</cy-info-title>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="formRef"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >
      <el-form-item label="企业类别" prop="companyType">
        <el-select v-model="ruleForm.companyType" placeholder="请选择企业类别" :disabled="disabled">
          <el-option
            :key="1"
            label="企业"
            value="企业">
          </el-option>
          <el-option
            :key="2"
            label="个体工商户"
            value="个体工商户">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input v-model="ruleForm.enterpriseName" placeholder="请输入企业公司名称" disabled />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="socialCreditCode">
        <el-input v-model="ruleForm.socialCreditCode" placeholder="请输入统一社会信用代码" disabled />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    baseInfo: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ruleForm: {
        companyType: '',
        enterpriseName: '',
        socialCreditCode: ''
      },
      rules: {
        companyType: [{ required: true, message: '请选择企业类别', trigger: 'blur' }],
        enterpriseName: [{ required: true, message: '请输入企业名称', trigger: 'blur' }],
        socialCreditCode: [{ required: true, message: '请输入统一社会信用代码', trigger: 'blur' }]
      }
    }
  },
  watch: {
    baseInfo: {
      handler(newV) {
        if (newV && Object.keys(newV)) {
          const { companyType, enterpriseName, socialCreditCode } = JSON.parse(JSON.stringify(newV))
          this.ruleForm = {
            companyType,
            enterpriseName,
            socialCreditCode
          }
        }
      },
      immediate: true
    }
  },
  methods: {
    getPrams(type) {
      return new Promise((resolve) => {
        if (type === 'temp') {
          resolve(this.ruleForm)
        }
        if (type === 'submit') {
          this.$refs.formRef.validate((valid) => {
            if (valid) {
              resolve(this.ruleForm)
            }
          })
        }
      })
    }
  }
}
</script>

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