<template>
	<view class="content">
		<view class="tabBox">
			<u-subsection :list="list" :current="queryData.type" @change="sectionChange"></u-subsection>
		</view>
		<u-form :model="pageData" ref="uForm" label-align="right">
			<u-form-item label="企业名称" label-width="150px">
				<u-input readonly v-model="pageData.enterpriseName" type="text" />
			</u-form-item>
			<u-form-item label="统一社会信用代码" label-width="150px">
				<u-input readonly v-model="pageData.creditCode" type="text" />
			</u-form-item>
			<u-form-item label="成立时间" label-width="150px">
				<u-input readonly v-model="pageData.establishmentTime" type="text" />
			</u-form-item>
			<u-form-item label="法人姓名" label-width="150px">
				<u-input readonly v-model="pageData.legalRepresentative" type="text" />
			</u-form-item>
			<u-form-item label="法人联系方式" label-width="150px">
				<u-input readonly v-model="pageData.legalContact" type="text" />
			</u-form-item>
			<u-form-item label="所属市州" label-width="150px">
				<u-input readonly v-model="pageData.cityState" type="text" />
			</u-form-item>
			<u-form-item label="企业性质" label-width="150px">
				<u-input readonly v-model="pageData.enterpriseNature" type="text" />
			</u-form-item>
			<u-form-item label="企业类型" label-width="150px">
				<u-input readonly v-model="pageData.enterpriseType" type="text" />
			</u-form-item>
			<u-form-item label="生产状态" label-width="150px">
				<u-input readonly v-model="pageData.productionText" type="text" />
			</u-form-item>
			<u-form-item label="应急级别" label-width="150px">
				<u-input readonly v-model="pageData.emergencyLevel" type="text" />
			</u-form-item>
			<u-form-item label="归口管理地区" label-width="150px">
				<u-input readonly v-model="pageData.region" type="text" />
			</u-form-item>
			<u-form-item label="实际经营地址" label-width="150px">
				<u-input readonly v-model="pageData.actualBusinessAddress" type="text" />
			</u-form-item>
			<u-form-item label="经度" label-width="150px">
				<u-input readonly v-model="pageData.longitude" type="text" />
			</u-form-item>
			<u-form-item label="纬度" label-width="150px">
				<u-input readonly v-model="pageData.latitude" type="text" />
			</u-form-item>
		</u-form>

		<view class="bottomBox">
			<view class="detailsBox">
				<emergencyBranch :pageData="pageData" v-show="queryData.type == 0" />
				<processingEnterprise :pageData="pageData" v-show="queryData.type == 1" />
				<distributionEnterprise :pageData="pageData" v-show="queryData.type == 2" />
				<storageEnterprise :pageData="pageData" v-show="queryData.type == 3" />
			</view>
		</view>
	</view>
</template>

<script>
	import * as api from "@/api/statisticalQuery.js"
	import emergencyBranch from "./emergencyBranch.vue"
	import storageEnterprise from "./storageEnterprise.vue"
	import processingEnterprise from "./processingEnterprise.vue"
	import distributionEnterprise from "./distributionEnterprise.vue"
	export default {
		components: {
			emergencyBranch,
			storageEnterprise,
			processingEnterprise,
			distributionEnterprise
		},
		data() {
			return {
				queryData: {
					id: '',
					type: 0,
					current: 1,
					size: 1000,
				},
				pageData: {},
				list: [{
						name: '应急网点'
					},
					{
						name: '应急加工企业'
					},
					{
						name: '应急配送企业'
					},
					{
						name: '应急仓储企业'
					}
				],

			}
		},
		onLoad(option) {
			this.queryData.id = option.id
			this.queryData.enterpriseName = option.name
			this.getDrtails()
		},
		methods: {
			getDrtails() {
				let obj = Object.assign({}, this.queryData)
				obj.type = obj.type + 1;

				api.getEsNetworkEntryDetails(obj).then(res => {

					if (this.queryData.type == 0) { // 应急供应网点
						this.pageData = res.data.esNetworkEntry || {}
					} else if (this.queryData.type == 1) { // 应急加工企业
						this.pageData = res.data.esProcessEnterprise || {}
					} else if (this.queryData.type == 2) { // 应急配送企业
						this.pageData = res.data.esDeliveryEnterprise || {}
					} else { // 应急仓储企业
						this.pageData = res.data.esStorageEnterprise || {}
					}
					this.pageData.region = this.pageData.actualAddressProvinceName + this.pageData
						.actualAddressCityName + this.pageData.actualAddressCountyName || ''
					this.pageData.productionText = this.pageData.productionStatus == 0 ? '停产' : '生产'
					this.pageData.emergencyLevel = this.returnEmergencyLevel(this.pageData)
				})
			},
			// 返回应急级别文字
			returnEmergencyLevel(data) {
				let str = ''
				if (data.isNationalLevel || data.isNational) {
					str = '国家级、'
				}
				if (data.isProvincialLevel || data.isProvincial) {
					str = str + '省级、'
				}
				if (data.isCityLevel || data.isCity) {
					str = str + '市级、'
				}
				if (data.isCountyLevel || data.isCounty) {
					str = str + '县级'
				}
				if (str.endsWith('、')) {
					return str.slice(0, -1);
				}
				return str;
			},
			sectionChange(data) {
				this.queryData.type = data
				this.getDrtails()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		margin: 10px 20px;

		.tabBox {
			margin: 10px 0 30px 0;

			.u-subsection__bar {
				width: 25%;
			}
		}

		.u-form {
			overflow: hidden;

			.u-form-item {
				float: left;
				margin-right: 10px;
				width: calc(100%/ 2 - 10px);
			}
		}
	}
</style>