<template>
	<div>
		<div class="content">
			<dataBreadcrumb :breads="breads"></dataBreadcrumb>
			<changeNav :navs="navs"></changeNav>
			<div>
				<div class="message form">
					<div class="flex-between">
						<div>项目编号：{{projectCode}}</div>
						<div style="margin-right: 100px;">项目名称：{{projectName}}</div>
					</div>
					<div class="flex-between">
						<div>项目分类：{{classify}}</div>
						<div class="flex">
							<div class="adjustment">上传附件：</div>
							<singleUpload :limit="1" tip="支持上传1个附件,不超过20M" @input="getfile"></singleUpload>
						</div>
					</div>
				</div>
				<div class="form">
					<h3><span>*</span>确定中标人</h3>
					<el-radio-group v-model="companyId">
						<el-radio :label="item.companyId" v-for="(item,index) in tableData" :key="index">{{item.companyName}}</el-radio>
					</el-radio-group>
					<h3 style="margin-top:30px">说明</h3>
					<el-input :rows="3" v-model.trim="content" type="textarea" placeholder="请输入内容" maxlength="300">
					</el-input>
				</div>
				<div class="button flex-center">
					<el-button @click="back">返回</el-button>
					<el-button type="primary" @click="submitData">完成</el-button>
				</div>
			</div>

		</div>
	</div>
</template>

<script>
	import {
		candidate,
		winnerSave
	} from '@api/purchaser/bid'
	import {
		projectClassify
	} from '@api/common/list'
	import dataTable from '@components/nopageTable.vue'
	import dataBreadcrumb from '@components/dataBreadcrumb.vue'
	import changeNav from '@components/changeNav.vue'
	import singleUpload from '@components/Upload/Upload.vue'
	export default {
		components: {
			dataBreadcrumb,
			changeNav,
			singleUpload,
			dataTable
		},
		data() {
			return {
				classify: "",
				projectCode: "",
				projectName: "",
				file: [],
				companyId: "",
				projectId: "",
				content: '',
				navs: ['确认中标人'],
				breads: ['招标管理', '招标项目管理', '工作台'],
				tableData: [],
				columns: [{
						label: '中标候选人',
						prop: 'companyName'
					},
					{
						label: '联系人',
						prop: 'contacts'
					},

					{
						label: '手机号',
						prop: 'phone'
					},
					{
						slot: 'operate'
					}
				] // 
			}
		},
		created() {
			this.getcandidate();
			this.getprojectClassify();
			this.projectCode = localStorage.getItem("projectCode")
			this.projectName = localStorage.getItem("projectName")
		},
		methods: {
			getfile(val) {
				this.file = val
			},
			back() {
				this.$router.go(-1)
			},
			examine() {
				this.$router.push('/admin/bid/bidingDetail')
			},
			check(index) {
				console.log(index);
			},
			// 获取中标人列表
			async getcandidate() {
				let projectId = localStorage.getItem("projectId");
				const {
					data,
					code
				} = await candidate(projectId)
				if (code === 200) {
					this.tableData = data
				}
			},
			// 获取项目分类
			async getprojectClassify() {
				let projectId = localStorage.getItem("projectId");
				try {
					const {
						data,
						code
					} = await projectClassify(projectId)
					this.classify = data;
				} catch (e) {
					console.log(e)
				}
			},
			// 提交中标人
			async submitData() {
				try {
					let data = {};
					data.projectId = localStorage.getItem("projectId")
					data.companyId = this.companyId
					data.remark = this.remark;
					data.fileList = this.file;
					const {
						msg,
						code
					} = await winnerSave(data)
					if (code === 200) {
						this.$message({
							message: "提交完成",
							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: 80%;
		margin:0 auto
	}

	.message>div {
		margin-bottom: 20px;
	}

	.form>h3 {
		font-weight: bold;
		margin-bottom: 30px;
	}

	.button {
		width: 100%;
		height: 50px;

	}

	span {
		color: #B21F2D
	}
</style>
