<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="120px" 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="上传附件">
            <singleUpload tip="支持扩展名：.rar .zip .doc .docx .pdf .jpg..." @input="getfile"></singleUpload>
          </el-form-item>
          <el-form-item label="投标邀请书内容" prop="content">
            <!-- <el-button style="margin-bottom: 30px;">插入邀请投标单位名称</el-button> -->
            <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="cancel">取消</el-button>
      <el-button type="primary" @click="submit">提交审核</el-button>
    </div>
  </div>
</template>

<script>
import {
  inviteMessage
} 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() {
    return {
      editorOption: {},
      breads: ['招标管理', '招标项目管理', '工作台'],
      ruleForm: {
        title: '',
        content: ''
      },
      rules: {
        title: [{
          required: true,
          message: '请填写',
          trigger: 'blur'
        }],
        content: [{
          required: true,
          message: '请填写',
          trigger: 'blur'
        }]
      }
    }
  },
  methods: {
    cancel() {
      this.$router.go(-1)
    },
    getfile(val) {
      console.log(val)
      for (let item of val) {
        item.accessoryUrl = item.fileUrl
      }
      this.accessoryPOList = val
    },
    //提交表单
    async submit() {
      let ruleForm = this.ruleForm
      ruleForm.projectId = '1'
      ruleForm.accessoryPOList = this.accessoryPOList
      try {
        const valid = await this.$refs['ruleForm'].validate()
        if (valid) {
          const {
            code,
            msg
          } = await inviteMessage(this.ruleForm)
          if (code === 200) {
            this.$message({
              message: msg,
              type: 'success'
            })
            this.$router.go(-1)
          }else{
			   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>
