<template>
    <el-form label-position="left" :model="ruleForm" :rules="rules" ref="ruleForm" size="mini" label-width="80px">
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="ruleForm.status" placeholder="审核状态" style="width:500px">
          <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="customer_id">
        <search-customer :value.sync="ruleForm.customer_id" style="width:500px" />
      </el-form-item>

      <el-form-item label="审核备注" prop="remark">
        <el-input v-model="ruleForm.remark" type="textarea" placeholder="审核备注" style="width:500px" />
      </el-form-item>

      <el-form-item class="flex-end" style="width:570px">
        <el-button type="primary" @click="onSubmit" :loading="loading">保存</el-button>
      </el-form-item>
    </el-form>
</template>

<script>
import asyncRequest from "@/apis/service/customerService/demandOrder";
  // status //审核状态
  // customer_id //客户公司
  // remark //审核备注

export default {
  props:['sitem'],
  data(){
    return {
      loading:false,
      statusList:[
        {value:'6', label:'通过'},
        {value:'8', label:'驳回'}
      ],
      ruleForm:{
        customer_id:"",
        status:"",
        remark:""
      }
    }
  },
  computed:{
    rules(){
      return {
      customer_id:[
        {
          required:this.ruleForm.status !== '8',
          trigger:'change',
          message:'请选择客户公司'
        }
      ],
      status:[
        {
          required:true,
          trigger:'change',
          message:'请选择审核状态'
        }
      ],
      remark:[
        {
          required:this.ruleForm.status === '8',
          trigger:'change',
          message:'请输入审核备注'
        }
      ],
     }
    }
  },
  methods:{
        async onSubmit(){
          try {
            await this.$refs.ruleForm.validate()
            const { customer_id,status,remark} = this.ruleForm
            this.loading = true
            const { code } = await asyncRequest.status({
              id: this.sitem.id,
              customer_id,
              status,
              remark
            })
            this.loading = false
            if(code !== 1) return
            this.$emit('refresh')
          }catch(err){
            console.log(err)
          }
      }
    }
}
</script>
