<template>
	<div>
		<h1 style="text-align:center;margin:20px;font-weight:bold;">停歇业登记</h1>
		<table width="80%" cellspacing="1" border="2">
			<tr>
				<td width="120px">单位名称</td>
				<td>{{ tabledata.qymc }}</td>
			</tr>
			<tr>
				<td>经营项目</td>
				<td>{{ tabledata.jyfw }}</td>
			</tr>
			<tr>
				<td>通讯地址</td>
				<td>{{ tabledata.qytxdz }}</td>
			</tr>
			<tr>
				<td>法人代表</td>
				<td>{{ tabledata.fddbr }}</td>
			</tr>

			<tr>
				<td>手机号码</td>
				<td>{{ tabledata.frsjh }}</td>
			</tr>
			<tr>
				<td>电子信箱</td>
				<td>{{ tabledata.qydzyx }}</td>
			</tr>
			<tr>
				<td>企业性质</td>
				<td>{{ tabledata.qyxz }}</td>
			</tr>
			<tr>
				<td>主营业务</td>
				<td>{{ tabledata.qyzyyw }}</td>
			</tr>

			<tr>
				<td>有效仓容</td>
				<td>{{ tabledata.kdyxcr }}</td>
			</tr>
			<tr>
				<td>有效罐容</td>
				<td>{{ tabledata.kdyxcr }}</td>
			</tr>
			<tr>
				<td>备案编号</td>
				<td>{{ tabledata.qybabh }}</td>
			</tr>

			<tr>
				<td>申请原因</td>
				<td colspan="2">
					本单位因<el-input placeholder="请输入" disabled v-model="tabledata.sqyy"></el-input
					>原因，暂时停止（或者终止）粮油仓储经营业务，特此申报。
				</td>
			</tr>
			<tr>
				<td>联系电话</td>
				<td><el-input v-model="tabledata.bgdh" disabled></el-input></td>
			</tr>
			<tr>
				<td>停歇业日期</td>
				<td>
					<el-date-picker
						type="date"
						value-format="yyyy-MM-dd"
						format="yyyy-MM-dd"
						v-model="tabledata.txyrq"
						disabled
					></el-date-picker>
				</td>
			</tr>
		</table>

		<el-row class="sub_title">
			企业备案变更审核
		</el-row>
		<table width="90%" cellspacing="1" border="2" class="audit">
			<tr>
				<th width="20%">审核部门</th>
				<th width="10%">审核人</th>
				<th width="20%">审核结果</th>
				<th width="20%">审核日期</th>
				<th width="30%">申请意见</th>
			</tr>
			<tr v-for="(item, index) in audits" :key="index">
				<td>{{ item.qymc }}</td>
				<td>{{ item.qybashr }}</td>
				<td>
					<el-radio-group v-model="item.shjg" :disabled="auditData.qybm != item.qybm">
						<el-radio label="1">通过</el-radio><el-radio label="0">驳回</el-radio></el-radio-group
					>
				</td>
				<td>{{ item.shrq && item.shrq.slice(0, 10) }}</td>
				<td>
					<el-input
						type="text"
						clearable
						v-model="item.shyj"
						:disabled="auditData.qybm != item.qybm"
					></el-input>
				</td>
			</tr>
		</table>

		<el-row class="footer_btn">
			<el-button type="primary" size="small" class="iconfont icontijiao" @click="handleSubmit">提交</el-button>
			<el-button type="primary" size="small" class="iconfont iconfanhui" @click="handleReturn">返回</el-button>
		</el-row>
	</div>
</template>
<script>
import { subDetail, audit } from '@/api/grainCoManage/warehousingLogistics/dynamicFiling/index.js'
import { getNowDate } from '@/utils'
function compare(property) {
	return function(a, b) {
		var value1 = a[property]
		var value2 = b[property]
		return value1 - value2
	}
}
export default {
	data() {
		return {
			tabledata: {},
			auditData: {
				lx: 's',
				lxId: '',
				qybashr: sessionStorage.userName,
				shrq: getNowDate(),
				qybm: '1', //区域编码（1：县，2：市，3：省）
				qymc: '',
				shyj: '',
				shjg: ''
			},
			shbm: ['旗县粮食局', '盟市粮食局', '自治区粮食局'],
			audits: [
				{
					qymc: '旗县粮食局',
					shyj: '',
					shjg: '1',
					qybashr: sessionStorage.userName,
					qybm: '1',
					shrq: getNowDate()
				}
				// { qymc: '盟市粮食局', shyj: '', shjg: '', qybashr: '', qybm: '2' },
				// { qymc: '自治区粮食局', shyj: '', shjg: '', qybashr: '', qybm: '3' }
			]
		}
	},
	created() {
		let { id } = this.$route.query
		this.id = id
		this.auditData.qybabh = id
		var codelen = String(sessionStorage.orgCode).length
		if (codelen == 5) this.auditData.qybm = 3
		if (codelen == 8) this.auditData.qybm = 2
		if (codelen == 11) this.auditData.qybm = 1
		// this.auditData.qybm = 3
		this.getDetail()
	},
	methods: {
		getDetail() {
			subDetail(this.id, 's').then((res) => {
				if (res.infoCode == 200) {
					this.tabledata = res.data
					this.tabledata.sqyy = res.data.stopIndustryVO.sqyy
					this.tabledata.bgdh = res.data.stopIndustryVO.lxdh
					this.tabledata.txyrq = res.data.stopIndustryVO.txyrq
					this.auditData.lxId = res.data.stopIndustryVO.id
					if (res.data.stopIndustryVO.auditList) {
						this.audits = [
							...res.data.stopIndustryVO.auditList,
							{
								qymc: this.shbm[this.auditData.qybm - 1],
								shyj: '',
								shjg: '1',
								shrq: getNowDate(),
								qybashr: sessionStorage.userName,
								qybm: this.auditData.qybm
							}
						].sort(compare('qybm'))
					}
				}
			})
		},
		handleReturn() {
			this.$router.push('index')
		},
		handleSubmit() {
			var cur = this.audits.filter((d) => d.qybm == this.auditData.qybm)[0]
			audit({
				...this.auditData,
				...cur
			}).then((res) => {
				if (res.infoCode == 200) {
					this.$message.success('审核成功')
					this.handleReturn()
				} else {
					this.$message.error('审核失败')
				}
			})
		}
	}
}
</script>
<style lang="scss" scoped>
$content_width: 90%;
table {
	border-collapse: collapse;
	margin: 0 auto;
	text-align: center;
	width: $content_width;
	tr {
		th {
			text-align: center;
			padding: 8px 0;
			font-weight: 500;
		}
		td:first-child {
			text-align: right;
			padding-right: 10px;
		}
		td {
			padding: 8px;
		}
	}
	&.audit {
		td {
			padding: 8px 0;
			&:first-child {
				text-align: center;
			}
		}
	}
}
.footer_btn {
	text-align: center;
	margin: 20px;
}
.sub_title {
	height: 2.5em;
	line-height: 2.5em;
	color: white;
	text-align: center;
	margin: 20px auto;
	width: $content_width;
	background-color: #49a2fa;
}
</style>
