<template>
    <div>
        <div class="content-head">
            <dataBreadcrumb :breads="breads"></dataBreadcrumb>
            <h3>{{ title }}</h3>
            <h5>{{ title }}</h5>
            <div class="abs">
              <div>拒绝原因：{{ruleForm.reason}}</div>
            </div>
        </div>
        <div class="content">
            <div class="describe">流标公告</div>
            <div class="form">
                <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="120px" class="demo-ruleForm">
                    <el-form-item label="公告标题" prop="title">
                        <el-input v-model.trim="ruleForm.title" placeholder="请输入" maxlength="30"></el-input>
                    </el-form-item>
                    <el-form-item label="上传附件">
                        <singleUpload tip="支持扩展名：.rar .zip .doc .docx .pdf .jpg..."  :fileList="ruleForm.accessoryVOList" @input="getfile"></singleUpload>
                    </el-form-item>
                    <el-form-item label="公告内容" prop="content">
                        <quill-editor ref="text" v-model="ruleForm.content" :options="editorOption" class="myQuillEditor" />
                    </el-form-item>
                </el-form>
                 <div class="centerButton">
                    <el-button @click="cancle">取消</el-button>
                     <el-button type="primary" @click="submit" v-if="!state">提交审核</el-button>
                    <el-button type="primary" @click="change" v-else>提交修改</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { createAbortive, noticeAbortive,editabortive } from '@api/purchaser/bid';
import dataBreadcrumb from '@components/dataBreadcrumb.vue';
import singleUpload from '@components/Upload/Upload.vue';
import { quillEditor } from 'vue-quill-editor';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
export default {
    components: {
        dataBreadcrumb,
        singleUpload,
        quillEditor
    },
    data() {
        return {
            state:false,
            editorOption: {},
            title: '发布流标公告',
            breads: ['招标管理', '招标项目管理', '工作台'],
            ruleForm: {
                title: '',
                content: '',
                accessoryPOList: []
            },
            rules: {
                title: [
                    {
                        required: true,
                        message: '请输入',
                        trigger: 'blue'
                    }
                ],
                release: [
                    {
                        required: true,
                        message: '请输入',
                        trigger: 'blue'
                    }
                ],
                content: [
                    {
                        required: true,
                        message: '请输入',
                        trigger: 'blue'
                    }
                ]
            }
        };
    },
    created() {
        let id = this.$route.query.id;
        this.id = id;
        if (id) {
            this.title = '修改流标公告';
            this.abortiveDetail(id);
            this.state=true
        }
    },
    methods: {
        getfile(val) {
            this.ruleForm.accessoryPOList = val;
        },
        cancle() {
            this.$router.go(-1);
        },
        //提交表单
        async submit() {
            let ruleForm = this.ruleForm;
            ruleForm.projectId = localStorage.getItem('projectId');
            if (this.id) {
                ruleForm.changeId = this.id
            }
            try {
                const valid = await this.$refs['ruleForm'].validate();
                if (valid) {
                    const { code, msg } = await createAbortive(this.ruleForm);
                    if (code === 200) {
                        this.$message({
                            message: msg,
                            type: 'success',
                            duration: 1500
                        });
                        setTimeout(() => {
                            this.$router.go(-1);
                        }, 1500);
                    } else {
                        this.$message.error(msg);
                    }
                }
            } catch (err) {
                console.log(err);
            }
		},
		async abortiveDetail(id) {
            try {
                const { data, code } = await noticeAbortive(id);
                if (code === 200) {
                     for (let item of data.accessoryVOList) {
                        console.log(item);
                        item.name = item.fileName;
                        item.fileUrl = item.accessoryUrl;
                        item.url = item.accessoryUrl
                    }
                     data.accessoryPOList=data.accessoryVOList
                    this.ruleForm = data; 
                }
            } catch (e) {
                console.log(e);
            }
        },
        // 修改
          async  change(){
             try {
                const valid = await this.$refs['ruleForm'].validate();
                if (valid) {
                   let ruleForm = this.ruleForm;
                  ruleForm.projectId = localStorage.getItem('projectId');
                    if (this.id) {
                        ruleForm.id = this.id;
                    }
                    const { code, msg } = await editabortive(this.ruleForm);
                    if (code === 200) {
                        this.$message({
                            message: msg,
                            type: 'success',
                            duration: 1500
                        });
                        setTimeout(() => {
                            this.$router.go(-1);
                        }, 1500);
                    }
                }
            } catch (err) {
                console.log(err);
            }
        },
    }
};
</script>


<style scoped>
.content {
    padding: 0;
    padding-bottom: 100px;
}

.button {
    width: 200px;
    margin: 150px auto 0;
}
.content-head{
  position: relative;
}
.content-head>.abs{
  position: absolute;
  right:10px;
  bottom: 10px;
}
</style>
