<template>
  <el-form ref="formRef" size="mini" label-width="120px" :model="formData" :rules="rules">
    <el-row>
      <el-col :span="12">
        <el-form-item label="审核状态" prop="exam_status">
          <el-select placeholder="审核状态" style="width:100%" v-model="formData.exam_status">
            <el-option value="3" label="通过" />
            <el-option value="7" label="驳回" />
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="12">
        <el-form-item label="平台商品编号" prop="plat_code">
          <el-input placeholder="平台商品编号" v-model="formData.plat_code" />
        </el-form-item>
      </el-col>

      
      <el-col :span="24">
        <el-form-item label="审核备注" prop="exam_remark">
          <el-input type="textarea" placeholder="审核备注" v-model="formData.exam_remark" />
        </el-form-item>
      </el-col>

      <el-col :span="24">
        <el-form-item style="display: flex;justify-content: flex-end;">
           <el-button type="primary" @click="submitForm" :loading="loading">保存</el-button>
        </el-form-item>
      </el-col>
    </el-row>
 </el-form>
</template>

<script>
import asyncRequest from "@/apis/service/bbc";
export default {
  props: ["id"],
  data(){
    return {
      formData:{
        exam_status:"",
        exam_remark:"",
        plat_code:""
      },
      loading:false
    }
  },
  computed:{
    rules() {
      const { exam_status} = this.formData;
      return {
        exam_status:[{trigger:'change', required: true, message:'请选择审核状态'}],
        plat_code:[{trigger:'change', required:true, message:'请输入平台商品编号'}],
        exam_remark:[{trigger:'change', required: exam_status === '7', message:'请输入审核备注'}]
      }
    }
  },
  methods:{
    async submitForm(){
      this.loading = true
      try{
        await this.$refs.formRef.validate();
        const response = await asyncRequest.status({
          skuCode: this.id,
          ...this.formData
        });
        if(Number(response.code) === 0){
          this.$emit("refresh")
        }else{
          this.$message.warning(response.message);
        }
      }catch(err){
        console.log(err);
      }finally{
        this.loading = false;
      }
    }
  }
}
</script>
