<template>
	<div class="detail-main">
		<el-form label-width="180px" label-position="right" :inline="true">
			<el-row>
				<el-col :span="12">
					<el-form-item label="企业名称" required>
						<el-input v-model="detailForm.qymc" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="统一社会信用代码" required>
						<el-input v-model="detailForm.tyshxydm" disabled></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="12">
					<el-form-item label="所属粮食局" required>
						<el-input v-model="detailForm.sslsxzglbm" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="行政区划编码" required>
						<el-input v-model="detailForm.qyszqybh" disabled></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="12">
					<el-form-item label="所属市" required>
						<el-input v-model="detailForm.shiName" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所属县" required>
						<el-input v-model="detailForm.xianName" disabled></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="12">
					<el-form-item label="企业类型" required>
						<el-input v-model="detailForm.qylxmc" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="法定代表人" required>
						<el-input v-model="detailForm.fddbr" disabled></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="12">
					<el-form-item label="联系人" required>
						<el-input v-model="detailForm.qylxr" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="联系电话" required>
						<el-input v-model="detailForm.bgdh" disabled></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-form-item label="单位主要业务" class="width-100" required>
					<el-input v-model="detailForm.qyzyyw" disabled></el-input>
				</el-form-item>
			</el-row>
		</el-form>
		<el-form
			label-width="180px"
			label-position="right"
			:inline="true"
			:model="audits"
			ref="auditForm"
		>
			<el-row>
				<el-form-item label="审核结果" required>
					<el-radio-group v-model="audits.sfba" :disabled="showType">
						<el-radio :label="1">通过</el-radio>
						<el-radio :label="2">不通过</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-row>
			<el-row>
				<el-form-item label="审核意见" class="width-100" :rules="rules('审核意见')" prop="审核意见">
					<el-input type="textarea" v-model="audits.审核意见" :rows="{minRow:3}" :disabled="showType"></el-input>
				</el-form-item>
			</el-row>
		</el-form>

		<el-row style="text-align:center;">
			<el-button
				type="primary"
				v-if="!showType"
				@click="doAudit"
				size="small"
				class="iconfont iconbaocun"
			>保存</el-button>
			<el-button
				type="primary"
				@click="$router.push('index')"
				size="small"
				class="iconfont iconfanhui"
			>返回</el-button>
		</el-row>
	</div>
</template>
<script>
import {
	company,
	audit,
	orgName,
	coMainBusiness,
	orgAreaCode
} from '@/api/grainCoManage/coInfoAudit/index.js'
export default {
	data() {
		return {
			showType: false,
			detailForm: {
				shjg: 1
			},
			audits: { sfba: 5 }
		}
	},
	created() {
		if (this.$route.query.state == 2) {
			this.showType = true
			this.audits.sfba = ''
		}
		this.getDetail()
	},
	methods: {
		rules(msg) {
			return {
				required: true,
				message: '请填写' + msg,
				trigger: ['change', 'blur']
			}
		},
		getDetail() {
			var dm = this.$route.query.tyshxydm
			if (dm)
				company(dm).then((res) => {
					if (res.infoCode == 200) {
						this.detailForm = res.data
						orgName(res.data.sslsxzglbm).then((resp) => {
							this.detailForm.sslsxzglbm = resp.data
						})
						if (this.detailForm.qyzyyw) {
							coMainBusiness().then((resp) => {
								var list = resp.data
								list = list
									.filter((d) => this.detailForm.qyzyyw.includes(d.dictCode))
									.map((d) => d.dictName)
								this.detailForm.qyzyyw = list.join(',')
							})
						}
						// if (res.data.qyjgdm)
						// 	orgName(res.data.qyjgdm).then((resp) => {
						// 		var orgName = resp.data
						// 		if (orgName) {
						// 			orgAreaCode(orgName).then((response) => {
						// 				this.detailForm.qyszqybh = response.data
						// 			})
						// 		}
						// 	})
						this.detailForm.qylxmc = res.data.tzQylxVOList
							.map((d) => d.qylxmc)
							.join(',')
						let { sfba, bz, id } = res.data
						if (this.$route.query.state == 1) sfba = 5
						this.audits = { sfba, 审核意见: bz || '', id }
						this.$refs.auditForm.resetFields()
					}
				})
		},
		doAudit() {
			this.$refs.auditForm.validate((valid) => {
				if (!valid) {
					this.$message.warning('请先完成必填项')
					return
				}
				audit({ ...this.audits }).then((res) => {
					if (res.infoCode == 200) {
						this.$message.success(res.data)
						this.$router.push('index')
					} else {
						this.$message.error(res.msg)
					}
				})
			})
		}
	}
}
</script>
<style lang="scss" scoped>
.detail-main {
	padding: 20px;
	.width-100 {
		width: 100%;
		/deep/ .el-form-item__content {
			width: 65%;
		}
	}
}
</style>
