<template>
    <div class="">
        <el-dialog
            :title="titleOption[type]"
            :visible.sync="dialogVisible"
            @closed="$emit('closed')"
        >
            <el-form
              ref="dialogForm"
              :model="form"
              label-width="120px"
              label-position="right"
              :rules="rules"
            >
                <el-form-item label="报告证书编号" >
                    <el-input v-model="form.number"></el-input>
                </el-form-item>
                <el-form-item label="业务受理日期" v-if="type=='add2'||type=='edit2'">
                    <el-date-picker
                        v-model="form.date_accept"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:50%"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="更改后证书编号" v-else>
                    <el-input v-model="form.number_correct"></el-input>
                </el-form-item>
                <el-form-item label="预计发放日期" v-if="type=='add2'||type=='edit2'">
                    <el-date-picker
                        v-model="form.date_expect"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:50%"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="出错原因" v-else>
                    <el-input v-model="form.reason_error"></el-input>
                </el-form-item>
                <el-form-item label="实际发放日期"  v-if="type=='add2'||type=='edit2'">
                    <el-date-picker
                        v-model="form.date_issue"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:50%"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="更改报告发放日期"  v-else>
                    <el-date-picker
                        v-model="form.date_issue"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        style="width:50%"
                    >
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div style="text-align: right">
                <el-button type="danger" @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" :loading="isSaveing" @click="onSubmit('Form')">确认</el-button>
            </div>
        </el-dialog>
    </div>
  </template>
  
  <script>
  import {createRc,updateRc} from "@/api/task";
  export default {
    emits: ["onSubmit", "onCancel"],
    data() {
      return {
        form:{
            number: "",
            date_issue: null,
            reason_error: "",
            date_expect: null,
            date_accept: null,
            number_correct: "",
            etype: 10,
            task2do: 0
        },
        titleOption: {
            add: "新增不准确报告",
            edit: "不准确报告编辑",
            
            add2: "新增超期报告",
            edit2: "超期报告编辑",
        },
        type:10,
        isSaveing:false,
        dialogVisible:false,
        rules: {
        number: [{ required: true, message: "请填入" }],
        vchannel: [{ required: true, message: "请选择视频" }],
      },
      }
    },
    methods: {
        //显示
        open(type = "add",task2do) {
            this.type = type;
            if(task2do){
                this.form.task2do = task2do;
            }
            this.dialogVisible = true;
            return this;
        },
        //表单注入数据
        setData(data) {
            Object.assign(this.form, data);
            debugger;
            console.log(this.form);
        },
        onSubmit() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                this.isSaveing = true;
                try {
                    var res;
                    if (this.type == "add") {
                        this.form.etype=10;
                        createRc(this.form).then(res=>{
                            this.isSaveing = false;
                            if(res.code>=200){
                                debugger;
                                this.dialogVisible = false;
                                this.$emit("success");
                            }else{
                                this.$message.warning(res.data.msg);
                            }
                        })
                    } else if (this.type == "edit") {
                        this.form.etype=10;
                        updateRc(this.form.id,this.form).then(res=>{
                            debugger;
                            this.isSaveing = false;
                            if(res.code>=200){
                                this.dialogVisible = false;
                                this.$emit("success");
                            }else{
                                this.$message.warning(res.data.msg);
                            }
                        })
                    }else if (this.type == "add2") {
                        this.form.etype=20;
                        createRc(this.form).then(res=>{
                            debugger;
                            this.isSaveing = false;
                            if(res.code>=200){
                                this.dialogVisible = false;
                                this.$emit("success");
                            }else{
                                this.$message.warning(res.data.msg);
                            }
                        })
                    }else if (this.type == "edit2") {
                        this.form.etype=20;
                        updateRc(this.form.id,this.form).then(res=>{
                            debugger;
                            this.isSaveing = false;
                            if(res.code>=200){
                                this.dialogVisible = false;
                                this.$emit("success");
                            }else{
                                this.$message.warning(res.data.msg);
                            }
                        })
                    }
                    //return res;
                } catch (err) {
                    //可以处理校验错误
                    this.isSaveing = false;
                    return err;
                }
                }
            });
        },
        onCancel() {
            this.$emit("closed");
        }
    }
  }
  </script>
  
  <style scoped>
  .line{
    text-align: center;
  }
  </style>
  
  