<template>
    <div>
        <div class="content-head">
            <dataBreadcrumb :breads="breads"></dataBreadcrumb>
            <h3>{{ title }}中标候选人公示</h3>
            <h5>{{ title }}中标候选人公示</h5>
            <div v-if="type == 1" class="abs">
                <div>拒绝原因：{{ ruleForm.reason }}</div>
            </div>
        </div>
        <candidate v-if="type == 2"></candidate>
        <div class="content" v-else>
            <div class="message form">
                <div class="flex-between">
                    <div>项目编号：{{ projectCode }}</div>
                    <div>项目名称：{{ projectName }}</div>
                </div>
                <div class="flex-between">
                    <div class="flex">
                        <div class="adjustment">上传附件：</div>
                        <singleUpload
                            :limit="1"
                            tip="支持上传1个附件,不超过100M"
                            @input="getfile"
                            :max="20"
                            :fileList="ruleForm.accessoryPOList"
                        ></singleUpload>
                    </div>
                    <div>发布媒体：捷安采官网</div>
                </div>
                <div class="flex-item">
                    <div style="width: 50px">备注：</div>
                    <el-input :rows="4" v-model.trim="remark" type="textarea" placeholder="请输入备注" maxlength="300"> </el-input>
                </div>
            </div>
            <div class="form">
                <h3 style="margin-top: 30px">中标候选人公示内容</h3>
                <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="公告标题" prop="title">
                        <el-input v-model.trim="ruleForm.title" maxlength="30"></el-input>
                    </el-form-item>
                    <el-form-item label="公告内容" prop="content">
                        <quill-editor ref="text" v-model.trim="ruleForm.content" :options="editorOption" class="myQuillEditor" />
                    </el-form-item>
                </el-form>
            </div>
            <div class="bottomButton flex-center">
                <el-button @click="back">返回</el-button>
                <el-button type="primary" @click="submitData" v-if="type !== 2">提交审批</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import { createcadidate, editcadidate } from '@api/purchaser/bid';
import { cadidate } from '@api/supply/bid';
import { quillEditor } from 'vue-quill-editor';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
import dataTable from '@components/dataTable.vue';
import dataBreadcrumb from '@components/dataBreadcrumb.vue';
import singleUpload from '@components/Upload/Upload.vue';
import candidate from '@components/detail/candidate.vue';
export default {
    components: {
        dataTable,
        dataBreadcrumb,
        singleUpload,
        quillEditor,
        candidate
    },
    data() {
        return {
            projectCode: '',
            projectName: '',
            editorOption: {},
            file: [],
            ruleForm: {
                title: '',
                content: '',
                accessoryPOList: []
            },
            rules: {
                title: [
                    {
                        required: true,
                        message: '请填写标题',
                        trigger: 'blue'
                    }
                ],
                content: [
                    {
                        required: true,
                        message: '请填写内容',
                        trigger: 'blue'
                    }
                ]
            },
            form: {
                price: ''
            },
            remark: '',
            breads: ['招标管理', '招标项目管理', '工作台'],
            title: ''
        };
    },
    methods: {
        back() {
            this.$router.go(-1);
        },
        getfile(val) {
            this.ruleForm.accessoryPOList = val;
        },
        // 详情
        async getcadidate() {
            let projectId = localStorage.getItem('projectId');
            const { data, code, msg } = await cadidate(projectId);
            if (code == 200) {
                for (let item of data.accessoryVOList) {
                    item.name = item.fileName;
                    item.url = item.accessoryUrl;
                }
                data.accessoryPOList = data.accessoryVOList;
                this.ruleForm = data;
            }
        },
        async submitData() {
            try {
                const valid = await this.$refs['ruleForm'].validate();
                if (valid) {
                    let ruleForm = this.ruleForm;
                    ruleForm.projectId = localStorage.getItem('projectId');
                    if (this.type == 1) {
                        var { code, msg } = await editcadidate(ruleForm);
                    } else {
                        var { code, msg } = await createcadidate(ruleForm);
                    }
                    if (code === 200) {
                        this.$message({
                            message: msg,
                            type: 'success',
                            duration: 1500
                        });
                        setTimeout(() => {
                            this.$router.go(-1);
                        }, 1500);
                    } else {
                        this.$message.error(msg);
                    }
                }
            } catch (e) {
                console.log(e);
            }
        }
    },
    created() {
        this.projectCode = localStorage.getItem('projectCode');
        this.projectName = localStorage.getItem('projectName');
        let type = this.$route.query.type;
        this.type = type;
        if (type == 1) {
            this.getcadidate();
            this.title = '编辑';
        } else if (type == 2) {
            this.title = '查看';
        } else {
            this.title = '发布';
        }
    }
};
</script>


<style scoped>
.message {
    width: 80%;
    margin:0 auto
}

.message > div {
    margin-bottom: 20px;
}

.form > h3 {
    font-weight: bold;
    margin-bottom: 30px;
}

.bottomButton {
    margin-top: 50px;
}
</style>
