<template>
    <el-dialog title="受理信息" :visible.sync="show" center width="600px">
        <el-form :model="form" :rules="rules" ref="form" label-width="120px" style="padding-right: 120px;">
            <el-form-item label="是否受理" prop="accept">
                <el-radio-group v-model="form.accept">
                    <el-radio :label="true">
                        是
                    </el-radio>
                    <el-radio :label="false">
                        否
                    </el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="缴费通知书" prop="attachment1" v-if="form.accept">
                <attachment-upload
                    v-model="form.attachment1"
                    :fileSize.sync="form.attachment1.size"
                ></attachment-upload>
            </el-form-item>
            <template v-else>
                <el-form-item label="不予受理通知书" prop="attachment2">
                    <attachment-upload
                        v-model="form.attachment2"
                        :fileSize.sync="form.attachment2.size"
                    ></attachment-upload>
                </el-form-item>
                <el-form-item prop="correctionPeriod" label="上传回文补正期限">
                    <el-date-picker
                        v-model="form.correctionPeriod"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期"
                        readonly
                    >
                    </el-date-picker>
                </el-form-item>
            </template>
            <el-form-item>
                <el-button style="width: 150px;" size="normal" type="primary" @click="onSubmit">提交</el-button>
                <el-button style="width: 120px;" size="normal" @click="show = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
import logoPatent from '@/mixins/logoPatent';
export default {
    mixins: [logoPatent],
    props: {
        info: {}
    },
    data() {
        return {
            form: {
                accept: true,
                attachment1: { attachmentName: '缴费通知书', fileName: '', url: '', remark: '', size: '' },
                attachment2: { attachmentName: '不予受理通知书', fileName: '', url: '', remark: '', size: '' }
            },
            show: true,
            rules: {
                accept: { required: true, message: '请输入附件名称', trigger: 'blur' },
                attachment1: {
                    validator: (rule, value, callback) => {
                        if (!value.url) {
                            callback(new Error('请上传缴费通知书'));
                        } else {
                            callback();
                        }
                    },
                    trigger: 'change'
                },
                attachment2: {
                    validator: (rule, value, callback) => {
                        if (!value.url) {
                            callback(new Error('不予受理通知书'));
                        } else {
                            callback();
                        }
                    },
                    trigger: 'change'
                },
                correctionPeriod: { required: true, message: '请输入上传回文补正期限', trigger: 'change' }
            }
        };
    },
    methods: {
        onSubmit() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        cancel() {
            this.$emit('cancel');
        },
        submit() {
            let info = { ...this.info };

            info.accept = this.form.accept;

            if (info.accept) {
                this.$emit('uploadAttement', this.form.attachment1);
                info.logoWorkflow = 'PENDING_REVIEW';
            } else {
                this.$emit('uploadAttement', this.form.attachment1);
                info.logoWorkflow = 'DISMISS';
            }

            this.$emit('submit', info);
        }
    }
};
</script>

<style></style>
