<template>
  <el-form ref="ruleForm" :rules="rules" :model="ruleForm" label-position="left" size="mini" label-width="80px">
    <el-form-item label="审核状态" :prop="'status'">
      <el-select style="width:400px" v-model="ruleForm['status']">
        <el-option v-for="status in statusList" :key="status.value" :value="status.value" :label="status.label" />
      </el-select>
    </el-form-item>

    <el-form-item label="审核备注" :prop="'remark'">
      <el-input style="width:400px" type="textarea" v-model="ruleForm['remark']" />
    </el-form-item>

    <el-form-item style="display:flex;justify-content:flex-end;width:470px">
       <el-button type="primary" size="mini" @click="onSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name:'NormalNode',
  props:{
    passValue:{
      type:String,
      default:() => "1"
    },
    rejectValue:{
      type:String,
      default:() => '0'
    }
  },
  data(){
      return {
          ruleForm:{
            ['status']:"",
            ['remark']:""
          }
      }
  },
  computed:{
    statusList(){
      return [
       {label:'通过',value:this.passValue},
       {label:'驳回',value:this.rejectValue}
      ]
    },
    rules(){
      return ({
        ['status']:[
          {
            required:true,
            trigger:'change',
            message:'请选择审核状态'
          }
        ],
        ['remark']:[
          {
            required:this.ruleForm['status'] === this.rejectValue,
            trigger:'change',
            message:'请输入备注'
          }
        ]
      })
    }
  },
  methods:{
    async onSubmit(){
      try {
        await this.$refs.ruleForm.validate()
        this.$emit('confirm',this.ruleForm)
      }catch(err){
        console.log(err)
      }
    }
  }
}
</script>
