<template>
    <el-dialog title="驳回处理" :visible.sync="show" center width="600px">
        <el-form
            hide-required-asterisk
            :model="form"
            :rules="rules"
            ref="form"
            label-width="120px"
            style="padding-right: 120px;"
        >
            <el-form-item label="是否复审" prop="rehear">
                <el-radio-group v-model="form.rehear">
                    <el-radio :label="true">
                        是
                    </el-radio>
                    <el-radio :label="false">
                        否
                    </el-radio>
                </el-radio-group>
                <div class="el-form-tips" v-if="!form.rehear && info.rejectAll">
                    注：商标全部驳回，选择不再复审，则此商标注册终止
                </div>
            </el-form-item>
            <el-form-item label="缴费通知书" prop="attachment1" v-if="!form.rehear && !info.rejectAll">
                <div slot="label" style="line-height: 22px;">
                    <div>初步审定公告</div>
                    <div>通知书</div>
                </div>
                <attachment-upload
                    v-model="form.attachment1"
                    :fileSize.sync="form.attachment1.size"
                ></attachment-upload>

                <div class="el-form-tips">注：商标部分驳回，选择不再复审，则驳回部分终止，其他部分生效</div>
            </el-form-item>
            <template v-else-if="form.rehear">
                <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="attachment3" label="收款回执">
                    <attachment-upload
                        v-model="form.attachment3"
                        :fileSize.sync="form.attachment3.size"
                    ></attachment-upload>
                </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: {
                rehear: true,
                attachment1: { attachmentName: '初步审定公告通知书', fileName: '', url: '', remark: '', size: '' },
                attachment2: { attachmentName: '复审合同', fileName: '', url: '', remark: '', size: '' },
                attachment3: { attachmentName: '收款回执', fileName: '', url: '', remark: '', size: '' },
                rejectAll: true
            },
            show: false,
            rules: {
                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'
                },
                attachment3: {
                    validator: (rule, value, callback) => {
                        if (!value.url) {
                            callback(new Error('请上传收款回执'));
                        } else {
                            callback();
                        }
                    },
                    trigger: 'change'
                }
            }
        };
    },
    methods: {
        onSubmit() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        submit() {
            let info = { ...this.info };

            info.rehear = this.form.rehear;

            if (!info.rehear) {
                if (this.info.rejectAll) {
                    info.logoWorkflow = 'NO_REVIEW';
                } else {
                    info.logoWorkflow = 'ANNOUNCEMENTS';
                    this.$emit('uploadAttement', this.form.attachment1);
                }
            } else {
                info.rejectAll = this.form.rejectAll;
                if (info.rejectAll) {
                    this.$emit('uploadAttement', this.form.attachment2);
                } else {
                    this.$emit('uploadAttement', this.form.attachment3);
                }

                info.logoWorkflow = 'REVIEW_MATERIALS';
                info.rejectContent = this.form.rejectContent;
            }

            this.$emit('submit', info);
            this.show = false;
        }
    }
};
</script>
<style lang="less" scoped>
.el-form-tips {
    font-size: 12px;
    color: #d7ab41;
    line-height: 17px;
    margin-top: 18px;
}
</style>
