<template>
	<div>
		<div class="content-head">
			<dataBreadcrumb :breads="breads"></dataBreadcrumb>
			<h3>{{ title }}</h3>
			<h5>{{ title }}</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" placeholder="请输入" 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">
						<quill-editor ref="text" v-model="ruleForm.content" :options="editorOption" class="myQuillEditor" />
					</el-form-item>
				</el-form>
				<div class="button">
					<el-button @click="cancle">取消</el-button>
					<el-button type="primary" @click="submit">提交审核</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		createAbortive
	} 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 {
				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 type = this.$route.query.type
			console.log(type)
			if (type === 'modify') {
				this.ruleForm = {
					title: '修改',
					content: '大修改'
				}
				this.title = '修改流标公告'
			}
		},
		methods: {
			getfile(val){
				this.ruleForm.accessoryPOList=val
			},
			cancle() {
				this.$router.go(-1)
			},
			//提交表单
			async submit() {
				let ruleForm = this.ruleForm
				ruleForm.projectId = 1
				let type = this.$route.query.type
				if (type === 'modify') {
					ruleForm.changeId = 1
				}
				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)
				}
			}
		}

	}
</script>


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

	.button {
		width: 200px;
		margin: 150px auto 0
	}
</style>
