<template>
  <div>
    <div class="content-head">
      <dataBreadcrumb :breads="breads"></dataBreadcrumb>
      <h3>发布招标公告</h3>
      <h5>发布招标公告</h5>
    </div>
    <div class="content">
      <div class="describe">招标公告</div>
      <div class="form">
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
          <el-form-item label="公告标题" prop="title"><strong></strong>
            <el-input v-model.trim="ruleForm.title" maxlength="30"></el-input>
          </el-form-item>
          <el-form-item label="上传附件" ><strong></strong>
            <singleUpload tip="支持扩展名：.rar .zip .doc .docx .pdf .jpg..." @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>
    </div>
    <div class="bottomButton">
      <el-button @click="back">取消</el-button>
      <el-button type="primary" @click="submit">提交审核</el-button>
    </div>
  </div>
</template>

<script>
	
import { bidMessage } from '@api/purchaser/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 dataBreadcrumb from '@components/dataBreadcrumb.vue'
import singleUpload from '@components/Upload/Upload.vue'
export default {
  components: {
    dataBreadcrumb,
    singleUpload,
    quillEditor
  },
  data() {
	  // 检测文件是否上传
	  let checkupload = (rule, value, callback) => {
	    if (this.justimg.length === 0) {
	      callback(new Error('请上传正面照片'))
	    } else {
	      callback()
	    }
	  }
    return {
      accessoryPOList: [],
      editorOption: {},
      breads: ['招标管理', '招标项目管理', '工作台'],
      ruleForm: {
        title: '',
        content: ''
      },
      rules: {
        title: [{
          required: true,
          message: '请填写',
          trigger: 'blue'
        }],
        content: [{
          required: true,
          message: '请填写',
          trigger: 'blue'
        }]
      }
    }
  },
  methods: {
	  back(){
		this.$router.go(-1)  
	  },
    cancel() {
      this.$router.go(-1)
    },
    getfile(val) {
      for (let item of val) {
        item.accessoryUrl = item.fileUrl
      }
      this.accessoryPOList = val
    },
    //提交表单
    async submit() {
      let ruleForm = this.ruleForm
      ruleForm.projectId = localStorage.getItem("projectId")
      ruleForm.accessoryPOList = this.accessoryPOList
      try {
        const valid = await this.$refs['ruleForm'].validate()
        if (valid) {
          const {
            code,
            msg
          } = await bidMessage(this.ruleForm)
          if (code === 200) {
            this.$message({
              message: msg,
              type: 'success',
			  duration:1500
            })
			setTimeout(()=>{
				 this.$router.go(-1)
			},1500)
          }else if(code == 500){
			  this.$message.error(msg)
		  }
        }
      } catch (err) {
        console.log(err)
      }
    }
  }

}
</script>


<style scoped>

	.ql-editor{
		height:400px;
	}
	.bottomButton{
		margin-top: 20px;
	}
	.form{
		padding-bottom: 80px;
	}
</style>
