<template>
  <div class="core-enterprise">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >
      <el-form-item label="公司名称" prop="corporateName">
        <el-input v-model="ruleForm.corporateName" placeholder="请输入公司名称" disabled />
      </el-form-item>
      <el-form-item label="集采平台" prop="centralizedProcurementPlatform">
        <el-radio-group v-model="ruleForm.centralizedProcurementPlatform" :disabled="disabled">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="与供应商存在历史合作" prop="historicalCooperation">
        <el-radio-group v-model="ruleForm.historicalCooperation" :disabled="disabled" @change="historicalCooperationChange">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    details: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ruleForm: {
        id: '',
        cEnterpriseHistoryId: '',
        cProjectInformationId: '',
        corporateName: '',
        centralizedProcurementPlatform: '',
        historicalCooperation: ''
      },
      rules: {
        centralizedProcurementPlatform: [
          { required: true, message: '请选择是否是集采平台', trigger: 'change' }
        ],
        historicalCooperation: [
          { required: true, message: '请选择是否与供应商存在历史合作', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    details: {
      handler(newV) {
        if (newV && Object.keys(newV)) {
          const details = JSON.parse(JSON.stringify(newV))
          this.ruleForm = {
            ...details
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    historicalCooperationChange() {
      this.$emit('isHistoricalCooperation', this.ruleForm.historicalCooperation)
    },
    passData(submitType) {
      return new Promise((resolve, reject) => {
        if (submitType === 'submit' || submitType === 'assess') {
          this.$refs.ruleFormRef.validate(valid => {
            if (valid) {
              return resolve(this.ruleForm)
            } else {
              reject()
              return false
            }
          })
        } else {
          resolve(this.ruleForm)
        }
      })
    }
  }

}
</script>

<style lang="scss" scoped>
.core-enterprise {
.el-form {
  padding: 10px 20px;
}
}
</style>
