<template>
  <ElForm size="mini" label-width="110px" :model="formData" :rules="rules" ref="formRef" v-loading="loading">
    <ElRow>
      <ElCol :span="12">
        <ElFormItem label="是否合规" prop="status">
          <ElSelect style="width:100%" v-model="formData.status">
            <ElOption label="合规" value="1" />
            <ElOption label="不合规" value="2" />
          </ElSelect>
        </ElFormItem>
      </ElCol>

      <ElCol :span="12">
        <ElFormItem label="平台商品编号" prop="platCode">
          <ElInput v-model="formData.platCode" placeholder="平台商品编号" />
        </ElFormItem>
      </ElCol>
        
      <ElCol :span="24">
        <ElFormItem label="备注" prop="remark">
          <ElInput v-model="formData.remark" type="textarea" placeholder="请输入备注" />
        </ElFormItem>
      </ElCol>

      <ElCol :span="24">
        <ElFormItem style="display:flex;justify-content:flex-end;width:100%">
          <ElButton type="primary" @click="onSubmit">保存</ElButton>
        </ElFormItem>
      </ElCol>
    </ElRow>
  </ElForm>
</template>

<script>
import asyncRequest from "@/apis/service/sellOut/businessFiling";
export default {
  props: ["id"],
  data() {
    return {
      loading: false,
      formData:{
        status: "1",
        platCode: "",
        remark:""
      }
    }
  },
  computed: {
     rules(){
        const { status }  = this.formData;
        return { 
          status:[{required:true, message:"请选择是否合规", trigger: "change"}],
          platCode:[{required:status === "1", message:"请输入平台订单号", trigger: "change"}],
          remark:[{required:status === "2", message: "请输入备注", trigger:"change" }]
        }
      }
  },
  methods: {
    async onSubmit(){
      this.loading = true
      try{
        await this.$refs.formRef.validate();
        const { status :is_compliance, platCode: plat_code, remark: compliance_remark } = this.formData;
        const model = {is_compliance, plat_code, compliance_remark, id: this.id };
        const response = await asyncRequest.compliance(model)
        if(response.code === 0){
          this.$emit("refresh")
          this.formData = { status: "1", platCode: "", remark:"" }
        }else{
          this.$message.warning(response.message)
        }
      }catch(err){
        console.error(err)
      } finally{
        this.loading = false;
      }
    }
  }
}
</script>
