<template>
	<view class="fullHeight projectIndexPage" style="background-color: white;">
		<scroll-view class="" :class="(accountType==5||accountType==6)?'smallHeight':''" scroll-y>
			<headers :showBack="(accountType==5||accountType==6)?false:true" :themeType="'white'">
				<view class="headerName">
					{{projectDetail.projectName}}
				</view>
			</headers>
			<image src="/static/projectIndexBG.png" class="projectIndexBG"
				:style="{height:(systemInfo.statusBarHeight+357)+'px'}"></image>
			<view class="topBoxContent">

				<view class="" style="height: 20px;">

				</view>
				<view class="progressBox">
					<image src="/static/progressLine.png" class="progressLine"></image>
					<view class="title1">
						工程进度
					</view>
					<view class="title2">
						<text>{{projectDetail.periodRatio?projectDetail.periodRatio:'--'}}</text><text
							class="unit">%</text>
					</view>
					<text class="status"
						:class="projectDetail.contractPeriodType==2?'redStatus':''">{{projectDetail.contractPeriodType==1?'正常':'已延期'}}</text>
				</view>
				<view class="weatherBox">
					<view class="top">
						{{weatherInfo.temperature}}℃<image class="weatherIcon"
							:src="'/static/weatherIcon/'+weatherIcon(weatherInfo.weather)+'.png'"></image>
					</view>
					<view class="bottom">
						<!-- {{weatherInfo.reporttime.split(' ')[0]}} -->
						{{weatherInfo.winddirection}}风 {{weatherInfo.windpower}}级
					</view>
				</view>
				<view class="dateBox">
					<view class="item">
						<view class="">
							{{projectDetail.contractPeriodStartTime?projectDetail.contractPeriodStartTime:'—.—.—'}}
						</view>
						<view class="">
							项目开工日期
						</view>
					</view>
					<view class="item item2">
						<view class="">
							{{projectDetail.contractPeriodEndTime?projectDetail.contractPeriodEndTime:'—.—.—'}}
						</view>
						<view class="">
							要求完成日期
						</view>
					</view>
					<!-- <view class="item">
						<view class="">
							—.—.—
						</view>
						<view class="">
							预计完成日期
						</view>
					</view> -->
				</view>
			</view>
			<view class="moudleContent">
				<view class="moudleTitle">
					·已有产品·
				</view>
				<view class="moudleBox">
					<view class="moudleItem" @click="goMoudleFn(item)" v-for="(item,index) in list" :key="index"
						v-if="item.operation&&item.moduleType==2&&item.appShow==1">
						<view class="inner">
							<view class="imgBox" v-if="iconType == 1">
								<image class="img" :src="'/static/moudleImg/'+item.moduleIcon+'.png'"></image>
							</view>
							<view class="imgBox" v-if="iconType == 2">
								<image class="img" :src="'/static/moudleImg/'+item.bigModuleIcon+'.png'"></image>
							</view>
							<view class="desc">
								{{item.appName}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="moudleTitle">
			未解锁模块
		</view>
		<view class="moudleBox moudleBox2">
			<view class="moudleItem" v-for="(item,index) in list" :key="index" v-if="!item.operation&&item.moduleType==2&&item.appShow==1">
				<view class="inner">
					<view class="imgBox">
						<image class="img" :src="'/static/moudleImg/'+item.moduleIcon+'.png'"></image>
					</view>
					<view class="desc">
						{{item.appName}}
					</view>
				</view>
			</view>
		</view> -->
		</scroll-view>
		<footers :activeTab="'projectEnd'" v-if="accountType==5||accountType==6"></footers>
	</view>
</template>

<script>
	import headers from "../../../components/headers/headers.vue"
	import footers from '../../../components/footers/footers.vue'
	import {
			closeBle
		} from '@/static/js/BLEConn.js';
	export default {
		components: {
			headers,
			footers
		},
		data() {
			return {
				projectDetail: {
					projectName: '',
					contractPeriodEndTime: '-.-.-',
					contractPeriodStartTime: '-.-.-',
					contractPeriodType: 1, //1是正常  2是已延期
					periodRatio: 0,
				},
				searchsn: '',
				accountType: 1,
				list: [],
				weatherInfo: {
					city: "--",
					weather: "-",
					temperature: "--",
					winddirection: "--",
					windpower: "--",
					humidity: "--"
				},
				iconType: "1",
				systemInfo: {
					statusBarHeight: 0
				}
			}
		},
		onShow() {
			this.getSystemLogoConfig()
			closeBle().then(res => {
				// this.closeDiv = false
				// this.clear()
				// uni.hideLoading()
				console.log('断开蓝牙成功')
			}).catch(err => {
				// uni.hideLoading()
				console.log('断开蓝牙失败')
			})
			if(uni.getStorageSync('oldObj')){
				uni.removeStorageSync('oldObj');
			}
			if(uni.getStorageSync('buildObj')){
				uni.removeStorageSync('buildObj');
			}
		},
		onLoad() {
			var userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.accountType = userInfo.accountType
			var arr = userInfo.menuAuthority.moduleList
			this.systemInfo = uni.getStorageSync('systemInfo')
			this.getSystemLogoConfig()
			this.getAllModule(arr)
			if (this.accountType == 5 || this.accountType == 6) {
				this.searchsn = userInfo.sn
				this.getProjectDetail()
			} else {
				this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'))
				this.loadWeather()
			}
			this.viewVersionInfo()
			
		},
		methods: {
			viewVersionInfo() {
			
				var that = this
				// console.log('viewVersionInfo',that.url_config)
				// uni.navigateTo({
				// 	url:'versionInfo'
				// })
			
				if (this.systemInfo.platform.indexOf('android') != -1 && typeof plus !== "undefined") {
					//获取最新版本
					that.sendRequest({
						url: "xmgl/appVersion/getAppVersion",
						data: {},
						method: "POST",
						success(res2) {
							console.log('最新版本', res2)
							//获取当前应用版本
							console.log('plus.runtime.version', plus.runtime.version)
							if (res2.result && (res2.result.versionNo != plus.runtime.version)) {
								uni.showModal({
									title: '版本更新',
									content: '更新内容：' + res2.result.versionDescribe,
									// confirmText: '更新',
									showCancel: false,
									success(res) {
										if (res.confirm) {
											console.log('用户点击确定');
											var url = that.url_config + 'image/' + JSON.parse(res2.result
												.downloadUrl)[0].url
											console.log('apk地址', url)
											uni.showModal({
												title: '提示',
												content: '正在后台下载更新资源，请耐心等待。。。',
												showCancel: false
											})
											uni.downloadFile({
												url: url,
												success: (res) => {
													// uni.hideLoading()
													console.log('res', res)
													if (res.statusCode === 200) {
														console.log('下载成功33');
														var fileSaveUrl = plus.io
															.convertLocalFileSystemURL(res
																.tempFilePath);
														plus.runtime.openFile(res
														.tempFilePath); //选择软件打开文件
													}
												}
											});
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								})
							} else {
								// uni.showToast({
								// 	title: '您已经是最新版本啦！',
								// 	icon: 'none'
								// })
							}
						}
					})
				}
			},
			weatherIcon(index) {
				if (index == "晴") {
					return "w_sun";
				} else if (index == "多云") {
					return "w_cloud";
				} else if (index == "阴") {
					return "w_overcast";
				} else if (index.indexOf("雨")) {
					return "w_rain";
				} else if (index.indexOf("雷")) {
					return "w_thunder";
				} else if (index.indexOf("雪")) {
					return "w_snow";
				} else if (index.indexOf("雾")) {
					return "w_fog";
				} else {
					return "w_sun";
				}
			},
			getSystemLogoConfig(){
				var that = this
				this.sendRequest({
					url: "xmgl/systemLogoConfig/selectSystemLogoConfig",
					data:{},
					method: "GET",
					success(res) {
						console.log(res.result.iconType)
						that.iconType = res.result.iconType ? res.result.iconType : "1"
					}
				})
			},
			loadWeather() {
				uni.request({
					url: 'http://restapi.amap.com/v3/weather/weatherInfo', //仅为示例，并非真实接口地址。
					data: {
						key: "a3217cf9335d333c307abee2fce600b5",
						city: this.projectDetail.cityCode,
						extensions: "base",
						output: "JSON"
					},
					// header: {
					//     'custom-header': 'hello' //自定义请求头信息
					// },
					success: (res) => {
						if (res.data.status == "1") {
							if (res.data.lives[0]) {
								this.weatherInfo = res.data.lives[0];
							}

							// localStorage.setItem(
							//   "weatherInfo",
							//   JSON.stringify(this.weatherInfo)
							// );
						}
					}
				});
			},
			goMoudleFn(item) {
				console.log('item.plugin', item.plugin)
				switch (item.plugin) {
					case 'markRoom':
						uni.navigateTo({
							url: '../markRoom/markRoom'
						})
						break;
					case 'videoMonitor':
						uni.navigateTo({
							url: '../../videoManage/videoList?sn=' + this.projectDetail.projectSn +
								'&pageType=backEnd'
						})
						break;
					case 'projectInfo':
						uni.navigateTo({
							url: '../project/projectInfo'
						})
						break;
					case 'environmentMonitor':
						uni.navigateTo({
							url: '../environment/menu'
						})
						break;
					case 'laborManage':
						uni.navigateTo({
							url: '../laborManage/index'
						})
						break;
					case 'constructionLog':
						uni.navigateTo({
							url: '../constructionLog/list'
						})
						break;
					case 'electricBoxMange':
						uni.navigateTo({
							url: '../electricBox/index'
						})
						break;
					case 'lifterManage':
						uni.navigateTo({
							url: '../lifterMonitoring/index'
						})
						break;
					case 'carManage':
						uni.navigateTo({
							url: '../carManage/index'
						})
						break;
					case 'towerManage':
						uni.navigateTo({
							url: '../towerManage/index'
						})
						break;
					case 'dailyInspection':
						uni.navigateTo({
							url: '../dailyCheck/index'
						})
						break;
					case 'qualitySpringback':
						uni.navigateTo({
							url: '../qualitySpringback/index'
						})
						break;
					case 'unloadManage':
						uni.navigateTo({
							url: '../unload/index'
						})
						break;
					case 'concreteMonitoring':
						uni.navigateTo({
							url: '../concreteMonitoring/index'
						})
						break;
					case 'safeManage':
						// uni.navigateTo({
						// 	url: '../safeManage/index'
						// })
						uni.navigateTo({
							url: '../safeManage/safeIndex'
						})
						break;
						// uni.navigateTo({
						// 	url: '../safeManage/addExamine'
						// })
						break;
					case 'qualityManage':
						uni.navigateTo({
							url: '../qualityManage/index'
						})
						break;
					case 'carWashManage':
						uni.navigateTo({
							url: '../carWashManage/index'
						})
						break;
					case 'dangerBigProject':
						uni.navigateTo({
							url: '../dangerBigProject/index'
						})
						break;
                    case 'fileManage':
						uni.navigateTo({
							url: '../../fileManage/fileManage'
						})
						break;
					case 'betonManage':
						uni.navigateTo({
							url: '../betonManage/index'
						})
						break;
					default:
						uni.showToast({
							icon: 'none',
							title: '该产品暂未开放，敬请期待！'
						})
				}

			},
			getProjectDetail() {
				var that = this
				this.sendRequest({
					url: "xmgl/project/getProjectInfoBySn",
					data: {
						projectSn: this.searchsn
					},
					method: "POST",
					success(res) {
						that.projectDetail = res.result
						uni.setStorageSync('projectDetail', JSON.stringify(res.result))
						that.loadWeather()
					}
				})
			},
			getAllModule(half) {
				var that = this
				this.sendRequest({
					url: "xmgl/baseModule/list",
					data: {},
					method: "POST",
					success(res) {
						var all = res.result
						all.forEach((element, index) => {
							all[index].operation = false
							half.forEach(element2 => {
								if (element2.moduleId == element.moduleId) {
									all[index].operation = true
									all[index].menuList = element2.menuList
								}
							});
						});
						that.list = all
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.topBoxContent {
		color: white;
		font-size: 14px;
		// background: linear-gradient(360deg, #A59FFF 0%, #3258FF 100%);
		height: 260px;
		position: relative;

		.dateBox {
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			z-index: 2;

			.item {
				flex: 1;
				text-align: center;
			}

			.item2 {
				border-left: 1px dashed white;
				// border-right: 1px dashed white;
			}
		}
	}

	.progressBox {
		width: 150px;
		height: 150px;
		position: relative;
		text-align: center;
		margin: 0px auto 25px;

		.title1 {
			padding-top: 24px;
		}

		.title2 {
			font-size: 33px;
			margin: 6px 0;

			.unit {
				font-size: 20px;
			}
		}

		.status {
			width: 52px;
			height: 25px;
			background: #8FDA5C;
			border-radius: 12px;
			display: inline-block;
			line-height: 25px;
		}

		.redStatus {
			background: #ea6868;
		}

		.progressLine {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
		}
	}

	.weatherBox {
		position: absolute;
		top: 15px;
		right: 15px;
		text-align: center;

		.top {
			font-size: 27px;
			display: flex;
			align-items: center;
		}

		.weatherIcon {
			width: 36px;
			height: 36px;
		}

		.bottom {
			font-size: 10px;
		}
	}

	.projectIndexPage {
		/deep/.headerBox {
			background-color: transparent;
			border-bottom: none;
		}
	}

	.progressBox {
		width: 150px;
		height: 150px;
		position: relative;
		text-align: center;
		margin: 0px auto 24px;

		.title1 {
			padding-top: 24px;
		}

		.title2 {
			font-size: 33px;
			margin: 6px 0;

			.unit {
				font-size: 20px;
			}
		}

		.status {
			width: 52px;
			height: 25px;
			background: #8FDA5C;
			border-radius: 12px;
			display: inline-block;
			line-height: 25px;
		}

		.redStatus {
			background: #ea6868;
		}

		.progressLine {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
		}
	}

	.weatherBox {
		position: absolute;
		top: 10px;
		right: 15px;
		text-align: center;

		.top {
			font-size: 27px;
			display: flex;
			align-items: center;
		}

		.weatherIcon {
			width: 36px;
			height: 36px;
		}

		.bottom {
			font-size: 10px;
		}
	}

	.moudleBox2 {
		opacity: 0.6;
	}

	.moudleBox {
		overflow: hidden;
		// margin: 20px 11px;
	}

	.moudleItem {
		float: left;
		width: 33.33%;
		font-size: 13px;
		text-align: center;
		margin-bottom: 10px;

		.inner {
			border: 1px solid rgba(18, 41, 75, 0.06);
			padding: 15px 0 15px;
			margin: 0 5px;
			border-radius: 5px;
		}

		.img {
			width: 40px;
			height: 40px;
		}

		.desc {
			margin-top: 6px;
			color: rgba(38, 45, 71, 0.77);
		}
	}

	.moudleTitle {
		color: rgba(42, 43, 91, 0.5);
		font-size: 13px;
		margin: 0px 0 15px;
		text-align: center;
	}

	.smallHeight {
		// padding-bottom: 63px;
		height: calc(100% - 63px);
	}

	.moudleContent {
		box-shadow: 0px 4px 16px 0px rgba(212, 220, 236, 0.59);
		border-radius: 8px;
		padding: 15px 15px;
		margin: 55px 15px 15px;
		position: relative;
		z-index: 2;
	}

	.projectIndexBG {
		width: 100%;
		height: 357px;
		position: absolute;
		top: 0;
		left: 0;
	}
</style>
