<template>
	<div>
		<div class="content">
			<dataBreadcrumb :breads="breads"></dataBreadcrumb>
			<changeNav :navs="navs"></changeNav>
			<dataTable :table-data="tableData" :columns="columns" :is-pageobj="false">
				<el-table-column slot="code" label="中标通知书编号" align="center" fixed="right">
					<template slot-scope="scope">
						<div v-if="scope.row.code"></div>
						<div v-else>(空)</div>
					</template>
				</el-table-column>
				<el-table-column slot="operate" label="操作" align="center" fixed="right" width="150">
					<template slot-scope="scope">
						<el-button type="text" size="small" @click="edit(scope.row)">通知书编辑</el-button>
					</template>
				</el-table-column>
			</dataTable>
			<div class="button flex-center">
				<el-button @click="back">返回</el-button>
				<el-button type="primary" @click="submitData">提交审核</el-button>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		sentBookList,
		sentBookAduit
	} from '@api/purchaser/bid'
	import dataTable from '@components/nopageTable.vue'
	import dataBreadcrumb from '@components/dataBreadcrumb.vue'
	import changeNav from '@components/changeNav.vue'
	export default {
		components: {
			dataTable,
			dataBreadcrumb,
			changeNav
		},
		data() {
			return {
				projectId: 2,
				navs: ['中标通知书'],
				breads: ['招标管理', '招标项目管理', '工作台'],
				tableData: [],
				columns: [{
						label: '投标人',
						prop: 'companyName'
					},
					{
						slot: 'code'
					},
					{
						label: '状态',
						prop: 'state'
					},
					{
						label: '接收人',
						prop: 'companyName'
					},
					{
						slot: 'operate'
					}
				], // 操作列
			}
		},
		created() {
			this.getsentBookList();
		},
		methods: {
			edit(row) {
				this.$router.push(`/purchaser/bid/bidSure/winBid/edit?id=${row.id}&winDate=${row.winDate}&money=${row.money}`)
			},
			back() {
				this.$router.go(-1)
			},
			// 获取列表
			async getsentBookList() {
				try {
					let projectId = localStorage.getItem("projectId");
					const {
						data,
						code
					} = await sentBookList(projectId)
					if (code === 200) {
						for (let item of data) {
							if (item.status == 0) {
								item.state = "未审核"
							} else if (item.status == 1) {
								item.state = "通过审核"
							} else if (item.status == 2) {
								item.state = "未通过审核"
							} else if (item.status == -1) {
								item.state = "暂存本地"
							}
						}
						this.tableData = data
					}
				} catch (e) {
					console.log(e)
				}
			},
			async submitData() {
				try {
					let projectId = localStorage.getItem("projectId")
					const {
						msg,
						code
					} = await sentBookAduit(projectId)
					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>
	.button {
		width: 100%;
		height: 400px;
	}
</style>
