<template>
  <div class="supplementary-info">
    <cy-info-title type="center">其它补充资料</cy-info-title>
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >
      <el-form-item label="从业人数" prop="peopleEngaged">
        <el-input
          v-model="ruleForm.peopleEngaged"
          :disabled="disabled"
          placeholder="请输入从业人数"
        />
      </el-form-item>
      <el-form-item label="营业收入（元）" prop="operatingRevenue">
        <cy-amount-input
          v-model="ruleForm.operatingRevenue"
          :disabled="disabled"
          placeholder="请输入营业收入"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    detailInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        peopleEngaged: '',
        operatingRevenue: ''
      },
      rules: {
        peopleEngaged: [{ required: true, message: '请输入从业人数', trigger: 'blur' }],
        operatingRevenue: [{ required: true, message: '请输入营业收入', trigger: 'blur' }]
      }
    }
  },
  watch: {
    detailInfo: {
      handler(newV) {
        console.log('detailInfo-----')
        console.log(newV)
        if (newV === undefined) return
        if (newV && Object.keys(newV).length) {
          this.ruleForm.peopleEngaged = newV.peopleEngaged
          this.ruleForm.operatingRevenue = newV.operatingRevenue
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getParams(type) {
      const params = {
        peopleEngaged: this.ruleForm.peopleEngaged,
        operatingRevenue: this.ruleForm.operatingRevenue
      }
      return new Promise((resolve, reject) => {
        if (type === 'submit') {
          this.$refs.ruleFormRef.validate(valid => {
            if (valid) {
              resolve(params)
            } else {
              reject()
              return false
            }
          })
        } else {
          resolve(params)
        }
      })
    }
  }
}
</script>
