<template>
  <div class="basic-info">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px" label-position="top" class="rule-form-orange">
      <el-form-item label="审批结论：" prop="conclusion">
        <el-radio-group v-model="ruleForm.conclusion" :disabled="isView">
          <el-radio label="pass">通过</el-radio>
          <el-radio label="back">退回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="审批意见："
        style="width: 100%;"
        class="textarea-content"
        prop="suggestion"
        :rules="[
          { required: ruleForm.conclusion === 'back', message: '请输入审批意见', trigger: 'blur' }
        ]"
      >
        <el-input v-model="ruleForm.suggestion" type="textarea" style="width: 100%;" rows="3" clearable :disabled="isView" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        conclusion: 'pass',
        suggestion: ''
      },
      rules: {
        conclusion: [
          { required: true, message: '请选择审批结论', trigger: 'change' }
        ]
      }
    }
  },
  props: ["info", "isView"],
  methods: {
    confirm() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(flag => {
          if(flag) {
            let data = { ...this.ruleForm }
            resolve(data)
          } else {
            reject()
          }
        })
      })
    }
  },
  watch: {
    'info.id': {
      handler: function(val) {
        if(val) {
          Object.keys(this.ruleForm).forEach(key => {
            if(this.info[key] || this.info[key] === 0) {
              this.ruleForm[key] = this.info[key]
            }
          })
        }
      },
      immediate: true
    }
  }
}
</script>

<style lang="scss" scoped>
.basic-info {

}

</style>
