<template>
	<div>
		<div class="content-head">
			<dataBreadcrumb :breads="breads"></dataBreadcrumb>
			<h3>新增问题</h3>
			<h5>专家评审向投标方提出问题</h5>
		</div>
		<div class="content">
			<div class="flex-arround">
				<div>项目编号：{{projectCode}}</div>
				<div>项目名称：{{projectName}}</div>
			</div>
			<div class="form">
				<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="160px" 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="type">
						<el-input v-model.trim="ruleForm.type" maxlength="30"></el-input>
					</el-form-item>
					<el-form-item label="澄清质询回复截止时间" prop="cutOffTime">
						<el-date-picker v-model="ruleForm.cutOffTime" type="datetime" placeholder="选择日期时间" format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss">
						</el-date-picker>
					</el-form-item>
					<el-form-item label="选择投标人" prop="CompanyId">
						<el-radio v-model="ruleForm.CompanyId" v-for="(item,index) in CompanyIds" :label="item.companyId" :key="item.companyId">{{item.companyName}}</el-radio>
					</el-form-item>
					<el-form-item label="澄清质询问题内容" prop="content">
						<el-input v-model.trim="ruleForm.content" :rows="2" type="textarea" maxlength="300"></el-input>
					</el-form-item>
					<el-form-item label="澄清质询问题文件" prop="file">
						<singleUpload :limit="1" :max="10" tip="最多上传一份，大小不超过10M." @input="getfile"></singleUpload>
					</el-form-item>
				</el-form>
			</div>
			<div class="button">
				<el-button @click="back">取消</el-button>
				<el-button type="primary" @click="submit">提交</el-button>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		addQuestion,
		bidsupplyList
	} from '@api/purchaser/bid'
	import dataBreadcrumb from '@components/dataBreadcrumb.vue'
	import singleUpload from '@components/Upload/Upload.vue'
	export default {
		components: {
			singleUpload,
			dataBreadcrumb
		},
		data() {
			return {
				fileUrl:"",
				fileName:"",
				projectCode: "",
				projectName: "",
				CompanyIds: [],
				projectId: "",
				breads: ['招标管理', '招标项目管理', '工作台'],
				ruleForm: {
					title: '',
					type: '',
					cutOffTime: '',
					CompanyId: '',
					content: ''
				},
				file: [],
				rules: {
					title: [{
						required: true,
						message: '请填写标题',
						trigger: 'blur'
					}],
					type: [{
						required: true,
						message: '请填写类型',
						trigger: 'blur'
					}],
					cutOffTime: [{
						required: true,
						message: '请选择时间',
						trigger: 'blur'
					}],
					CompanyId: [{
						required: true,
						message: '请选择投标人',
						trigger: 'blur'
					}],
					content: [{
						required: true,
						message: '请填写内容',
						trigger: 'blur'
					}]
				}
			}
		},
		methods: {
			getfile(val) {
				this.file = val
			},
			back(){
				this.$router.go(-1)
			},
			//提交表单
			async submit() {
				try {
					const valid = await this.$refs['ruleForm'].validate()
					if (valid) {
						let ruleForm = this.ruleForm;
						let file=this.file;
						if(file.length>0){
							ruleForm.fileUrl = file[0].fileUrl
							ruleForm.fileName = file[0].fileName
						}
						ruleForm.projectId = localStorage.getItem("projectId");
						console.log(ruleForm)
						const {
							code,
							msg
						} = await addQuestion(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) {}
			},
			async getbidsupplyList() {
				try {
					let projectId = localStorage.getItem("projectId");
					const {
						data,
						code
					} = await bidsupplyList(projectId)
					if (code === 200) {
						this.CompanyIds = data
					}
				} catch (e) {
					console.log(e)
				}
			}
		},
		created() {
			this.getbidsupplyList()
			this.projectCode = localStorage.getItem("projectCode")
			this.projectName = localStorage.getItem("projectName")
		}
	}
</script>


<style scoped>
	.form {
		width: 60%;
		margin-top: 30px;
	}

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