<template>
	<div>
		<div class="content-head">
			<dataBreadcrumb :breads="breads"></dataBreadcrumb>
			<h3>招标结果通知书辑</h3>
			<h5>招标结果通知书辑</h5>
		</div>
		<div class="content ">
			<div class="message flex-colunm">
				<div class="flex-between">
					<div>项目编号：{{projectCode}}</div>
					<div>项目名称：{{projectName}}</div>
				</div>
				<div class="flex-between">
					<div style="margin-bottom: 23px;">日期：{{ winDate}}</div>
					<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="200px" class="demo-ruleForm">
						<el-form-item label="招标结果通知书编号" prop="number">
							<el-input v-model.trim="ruleForm.number" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
						</el-form-item>
					</el-form>
				</div>
				<div class="flex-between">
					<div class="flex">
						<div>上传附件：</div>
						<singleUpload :limit='1' tip="支持上传一个pdf格式文件，大小不超过100M。" accept='.pdf' @input="getfile"></singleUpload>
					</div>
				</div>
				<div class="flex-center button">
					<el-button @click="back">取消</el-button>
					<el-button type="primary" @click="submitData">保存</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	 import {generateNumber} from '@api/common/list'
	import {
		editResultBook
	} from '@api/purchaser/bid'
	import dataBreadcrumb from '@components/dataBreadcrumb.vue'
	import dataTable from '@components/dataTable.vue'
	import singleUpload from '@components/Upload/singleUpload.vue'
	export default {
		name: 'bidingList',
		components: {
			dataTable,
			singleUpload,
			dataBreadcrumb
		},
		data() {
			return {
				money: "",
				winDate: "",
				projectCode: "",
				projectName: "",
				ruleForm: {
					number: '',
					fileList: [],
					resultId: ""
				},
				rules: {
					number: [{
						required: true,
						message: '请填写编号',
						trigger: 'blur'
					}]
				},
				date: '',
				breads: ['招标管理', '招标项目管理', '工作台']
			}
		},
		created() {
			this.getGenerateNumber();
			this.ruleForm.resultId = this.$route.query.id;
			this.winDate = this.$route.query.winDate
			this.projectCode = localStorage.getItem("projectCode")
			this.projectName = localStorage.getItem("projectName")
		},
		methods: {
			async getGenerateNumber() {
			    try {
			      const {
			        data,
			        code
			      } = await generateNumber(5)
				  this.ruleForm.number=data
			    } catch (e) {
			      console.log(e)
			    }
			  },
			back() {
				this.$router.go(-1)
			},
			getfile(val) {
				this.ruleForm.fileList = val
			},
			//提交表单
			async submitData() {
				try {
					const valid = await this.$refs['ruleForm'].validate()
					if (valid) {
						let ruleForm = this.ruleForm;
						ruleForm.projectId = localStorage.getItem("projectId")
						ruleForm.companyId = localStorage.getItem("companyId")
						const {
							code,
							msg
						} = await editResultBook(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) {
					console.log(e)
				}
			}
		}

	}
</script>


<style scoped>
	.message {
		/* 	width:60%; */
	}

	.message>div {
		margin-bottom: 30px;
		width: 50%;
	}

	.message>.button {
		margin: 100px
	}
</style>
