<template>
	<view>
		<view class="barBox" :style="{'height': barBoxHeight + 'px'}">
			<headers class="fixedheader" :themeType="'white'" :showBack="true">
				<view class="headerName">
					基本信息
				</view>
			</headers>
		</view>
		<view class="tabBox">
			<view :class="{'enterprise-tab':true,'active-tab': checked == 1}" @click="handleTab(1)">企业信息</view>
			<view :class="{'project-tab':true,'active-tab': checked == 2}" @click="handleTab(2)">项目信息</view>
		</view>
		<scroll-view :scroll-y="true" class="scrollBox" :style="{height: scrollHeight + 'px'}" v-if="checked == 1">
			<view class="property-item">
				<view class="item-top">企业名称</view>
				<view class="item-bottom">{{enterpriseInfo.enterpriseName || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">企业类型</view>
				<view class="item-bottom">{{enterpriseInfo.companyTypeName || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">统一社会信用代码</view>
				<view class="item-bottom">{{enterpriseInfo.socialCode || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">法定代表人</view>
				<view class="item-bottom">{{enterpriseInfo.enterpriseLegalPerson || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">法人电话</view>
				<view class="item-bottom">{{enterpriseInfo.legalPersonTel || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">注册人申请电话</view>
				<view class="item-bottom">{{enterpriseInfo.registerPersonPhoneTel || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">开户行</view>
				<view class="item-bottom">{{enterpriseInfo.bankname || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">银行账号</view>
				<view class="item-bottom">{{enterpriseInfo.bankcardnumber || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">营业执照截止日期</view>
				<text class="item-bottom">{{enterpriseInfo.businessLicenseEndDate || '--'}}</text>
			</view>
			<view class="property-item">
				<view class="item-top">资质照片</view>
				<view class="item-bottom" v-if="enterpriseInfo.enterpriseQualificationUrl">
					<image :src="enterpriseInfo.enterpriseQualificationUrl"
						@click="previewImage(enterpriseInfo.enterpriseQualificationUrl)" class="icon-image"></image>
					<!-- <image :src="enterpriseInfo.enterpriseQualificationUrl[0].url" 
					@click="previewImage(enterpriseInfo.enterpriseQualificationUrl[0].url)"
					class="icon-image"></image> -->
				</view>
				<view class="item-bottom" v-else>
					<text>--</text>
				</view>
			</view>
		</scroll-view>
		<scroll-view :scroll-y="true" class="scrollBox" :style="{height: scrollHeight + 'px'}" v-if="checked == 2">
			<div class="conProjectItem" v-for="item in conProjectList" :key="item.id">
				<view class="property-item">
					<view class="item-top">承包商名称</view>
					<view class="item-bottom">{{item.cbsName || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">项目施工区域</view>
					<view class="item-bottom">{{item.projectBuildArea || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">项目经理</view>
					<view class="item-bottom">{{item.projectManage || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">项目类型</view>
					<view class="item-bottom">{{item.cbsProjectTypeName || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">施工阶段</view>
					<view class="item-bottom">{{item.constructionStageName || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">经度位置</view>
					<view class="item-bottom">{{item.longitude || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">纬度位置</view>
					<view class="item-bottom">{{item.latitude || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">项目编号</view>
					<view class="item-bottom">{{item.projectNumber || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">结构类型</view>
					<view class="item-bottom">{{item.structureTypeName || '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">项目面积(㎡)</view>
					<view class="item-bottom">{{item.projectAcreage ? item.projectAcreage + '㎡' : '--'}}</view>
				</view>
				<view class="property-item">
					<view class="item-top">工程状态</view>
					<view class="item-bottom">{{
						item.bulidStatus == 0 ? '未开工' : 
						item.bulidStatus == 1 ? '在建' : 
						item.bulidStatus == 2 ? '停工' : 
						item.bulidStatus == 3 ? '竣备' : '--'
					}}</view>
				</view>
			</div>
			<!-- <view class="property-item">
				<view class="item-top">承包商名称</view>
				<view class="item-bottom">{{conProjectInfo.cbsName || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">项目施工区域</view>
				<view class="item-bottom">{{conProjectInfo.projectBuildArea || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">项目经理</view>
				<view class="item-bottom">{{conProjectInfo.projectManage || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">项目类型</view>
				<view class="item-bottom">{{conProjectInfo.cbsProjectTypeName || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">施工阶段</view>
				<view class="item-bottom">{{conProjectInfo.constructionStageName || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">经度位置</view>
				<view class="item-bottom">{{conProjectInfo.longitude || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">纬度位置</view>
				<view class="item-bottom">{{conProjectInfo.latitude || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">项目编号</view>
				<view class="item-bottom">{{conProjectInfo.projectNumber || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">结构类型</view>
				<view class="item-bottom">{{conProjectInfo.structureTypeName || '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">项目面积(㎡)</view>
				<view class="item-bottom">{{conProjectInfo.projectAcreage ? conProjectInfo.projectAcreage + '㎡' : '--'}}</view>
			</view>
			<view class="property-item">
				<view class="item-top">工程状态</view>
				<view class="item-bottom">{{
					conProjectInfo.bulidStatus == 0 ? '未开工' : 
					conProjectInfo.bulidStatus == 1 ? '在建' : 
					conProjectInfo.bulidStatus == 2 ? '停工' : 
					conProjectInfo.bulidStatus == 3 ? '竣备' : '--'
				}}</view>
			</view> -->
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				projectId: '',
				checked: 1,
				barBoxHeight: '',
				scrollHeight: '',
				enterpriseInfo: '',
				conProjectInfo: '',
				conProjectList: [],
			};
		},
		onReady() {
			this.getHeight()
		},
		onLoad(option) {
			this.id = option.id
			this.projectId = option.projectId
			this.getDetailInfo()
			this.supplierInfoList();
		},
		methods: {
			async getHeight() {
				const query = uni.createSelectorQuery().in(this);

				let fixedheaderHeight = 0
				const fixedHeaderPromise = new Promise((resolve) => {
					query.select('.fixedheader').boundingClientRect(data => {
						fixedheaderHeight = data.height
						console.log('fixedheaderHeight：', data.height);
						resolve();
					}).exec();
				});

				let mobileTopHeight = 0
				const systemInfoPromise = new Promise((resolve) => {
					uni.getSystemInfo({
						success(res) {
							mobileTopHeight = res.statusBarHeight ? res.statusBarHeight : 0;
							resolve();
						}
					});
				});

				await fixedHeaderPromise;
				await systemInfoPromise;

				this.barBoxHeight = fixedheaderHeight + mobileTopHeight;
				console.log('this.barBoxHeight', this.barBoxHeight);

				let screenHeight = uni.getSystemInfoSync().screenHeight;
				console.log('screenHeight', screenHeight);

				this.scrollHeight = screenHeight - this.barBoxHeight - 44 - 20;
				console.log('this.scrollHeight', this.scrollHeight);
			},
			handleTab(val) {
				this.checked = val
			},
			supplierInfoList() {
				let data = {
					type: 2,
					enterpriseId: this.id,
					projectSn: JSON.parse(uni.getStorageSync('projectDetail')).projectSn,
				}
				let that = this
				this.sendRequest({
					url: 'xmgl/projectEnterpriseSupplierInfo/list',
					method: 'get',
					data: data,
					success: res => {
						console.log("enterpriseInfo", res);
						that.conProjectList = res.result;
					}
				})
			},
			getDetailInfo() {
				let data = {
					enterpriseId: this.id,
					projectSn: JSON.parse(uni.getStorageSync('projectDetail')).projectSn,
				}
				let that = this
				this.sendRequest({
					url: 'xmgl/enterpriseInfo/getEnterpriseInfoById',
					method: 'post',
					data: data,
					success: res => {
						console.log("enterpriseInfo", res);
						this.enterpriseInfo = res.result

						if (this.enterpriseInfo.enterpriseQualificationUrl) {
							// pc处理方式
							this.enterpriseInfo.enterpriseQualificationUrl =
								res.result.enterpriseQualificationUrl && res.result.enterpriseQualificationUrl
								.split(',').length > 1 ?
								res.result.enterpriseQualificationUrl.split(',').map(item => {
									return {
										name: item.split('*')[0],
										url: that.url_config + 'image/' + item.split('*')[1],
									}
								}) : res.result.enterpriseQualificationUrl.indexOf('http://') >= 0 ? res.result
								.enterpriseQualificationUrl :
								url_config + 'image/' + res.result.enterpriseQualificationUrl;
							console.log(this.enterpriseInfo.enterpriseQualificationUrl)
						}

						//如果app有图片但没加载出来，就切换成上面pc处理方式
						// if(this.enterpriseInfo.enterpriseQualificationUrl){
						// 	this.enterpriseInfo.enterpriseQualificationUrl = this.enterpriseInfo.enterpriseQualificationUrl.split('*')[1]
						// }

						this.conProjectInfo = res.result.projectEnterprise
					}
				})
			},
			//预览图片
			previewImage(url) {
				console.log('url', url);
				uni.previewImage({
					urls: [url]
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.conProjectItem {
		border: 2rpx solid #EBECF0;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-top: 20rpx;
	}

	.barBox {
		// background-color: #5181F6;
		background-color: #f6f6f6;
		min-height: 100%;
		height: 44px;

		.fixedheader {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			z-index: 999;

			.headerName {
				z-index: 1;
			}
		}
	}

	.tabBox {
		width: 100%;
		height: 44px;
		display: flex;

		.enterprise-tab {
			width: 50%;
			height: 100%;
			border: 1rpx solid #e5e5e5;
			// border-top: none;
			// border-left: none;
			line-height: 44px;
			text-align: center;
		}

		.project-tab {
			width: 50%;
			height: 100%;
			border: 1rpx solid #e5e5e5;
			// border-top: none;
			// border-right: none;
			line-height: 44px;
			text-align: center;
		}

		.active-tab {
			background-color: #2b8df3;
			color: #fff;
		}
	}

	.scrollBox {
		height: 100%;
		width: calc(100% - 20rpx);
		// background-color: darkred;
		margin: 0 10px;
		word-break: break-all;
		padding-bottom: 20rpx;

		.property-item {
			// line-height: 25px;
			margin-bottom: 15px;

			.item-top {
				color: #878787;
			}

			.item-bottom {
				margin-top: 5px;
				width: auto;
				height: auto;

				.icon-image {
					width: 50px;
					height: 50px;
				}
			}
		}
	}
</style>