<template>
	<view class="fullHeight projectIndexPage" style="background-color: white">
		<scroll-view class="" :class="accountType == 5 || accountType == 6 || accountType == 10 ? 'smallHeight' : ''"
			scroll-y>
			<view class="fixedheader">
				<headers :themeType="true" :showBack="true">
					<view class="headerName">
						应用中心
					</view>
				</headers>
			</view>
			<view class="moudleContent">
				<!-- <view class="moudleTitle"> ·已有产品·</view> -->
				<view class="moudleBox">
					<view @click="goMoudleFn(item)" v-for="(item, index) in list" :key="index">
						<view class="moudleItem"
							v-if="item.operation && (item.moduleType == 2 || item.moduleType == 10) && item.appShow == 1">
							<view class="inner" v-if="COMPANY=='sanjiang'">
								<!-- <view class="imgBox" v-if="iconType == 1">
                <image class="img" :src="'/static/moudleImg/' + item.moduleIcon + '.png'"></image>
              </view> -->
								<view class="imgBox" v-if="item.bigModuleIcon">
									<image class="img" :src="'/static/sjjtIcon/' + item.bigModuleIcon + '.png'"></image>
								</view>
								<view class="desc">
									{{ item.appName || item.moduleName }}
								</view>
							</view>
							<view class="inner" v-else>
								<!-- <view class="imgBox" v-if="iconType == 1">
								<image class="img" :src="'/static/moudleImg/' + item.moduleIcon + '.png'"></image>
							</view> -->
								<!-- v-if="iconType == 2" -->
								<view class="imgBox">
									<image class="img" :src="'/static/bthgIcon/' + item.commonIcon + '.png'"></image>
								</view>
								<view class="desc">
									{{ item.appName || item.moduleName }}
								</view>
							</view>
						</view>
					</view>
					<!-- <view class="moudleItem" @click="goMoudleFnTest()">
					<view class="inner">
					  <view class="imgBox">
						<image class="img" src=""></image>
					  </view>
					  <view class="desc">
						培训计划
					  </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>
		<levitatedsphere :x="100" :y="80"></levitatedsphere>
	</view>
</template>

<script>
	import levitatedsphere from "@/components/levitatedsphere/levitatedsphere.vue"
	import headers from '../../../components/headers/headers.vue'
	import footers from '../../../components/footers/footers.vue'
	import checkVersion from '@/pages/lq-upgrade/checkVersion.js'
	import {
		closeBle
	} from '@/static/js/BLEConn.js'
	import {
		getBottomLevelData
	} from "@/utils/tool.js"

	export default {
		components: {
			headers,
			footers
		},
		data() {
			return {
				qrCode: {},
				projectDetail: {
					projectName: '',
					contractPeriodEndTime: '',
					contractPeriodStartTime: '', //-.-.-
					contractPeriodType: 1, //1是正常  2是已延期
					periodRatio: 0
				},
				userInfo: {},
				searchsn: '',
				accountType: 1,
				list: [],
				weatherInfo: {
					city: '--',
					weather: '-',
					temperature: '--',
					winddirection: '--',
					windpower: '--',
					humidity: '--'
				},
				iconType: '1',
				systemInfo: {
					statusBarHeight: 0
				},
				styType: '',
				//天气
				imgUrl: '',
				date: '', //现在时间
				// weatherInfo: '--',
				adressDetail: '--',
				city: '',
				url: '',
				versionData: '',
				haveModuleList: "",
			}
		},
		mounted() {},
		onShow() {

		},
		onLoad(options) {
			var userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'));
			console.log('userInfo===========', userInfo)
			this.userInfo = userInfo
			this.accountType = userInfo.accountType
			this.styType = userInfo.styleType
			this.systemInfo = uni.getStorageSync('systemInfo')
			this.getAllModule();
			this.haveModuleList = uni.getStorageSync("haveModuleList")
		},
		methods: {
			toDept() {
				uni.navigateTo({
					url: "/pages/deptList/deptList"
				})
			},
			goMoudleFnTest() {
				uni.navigateTo({
					url: '/pages/projectEnd/trainPlan/list'
				})
			},
			goMoudleFn(item) {
				//添加虚拟模块 报警提示
				// if(item.moduleName=="预警播报"){
				// 	uni.navigateTo({
				// 		url: '/pages/alarmPage/index'
				// 	})
				// 	return false;
				// }
				console.log('item=======item.plugin', item, item.plugin)
				switch (item.plugin) {
					// case 'markRoom':
					//   uni.navigateTo({
					//     url: '../markRoom/markRoom'
					//   })
					//   break
					case "standardScheduleAg":
						uni.navigateTo({
							url: '/pages/standardScheduleNews/home'
						})
						break;
					case "inspectRoute":
						uni.navigateTo({
							url: '../../projectEnd/InspectionRoute/inspection'
						})
						break;
					case 'educationExam':
						uni.navigateTo({
							url: '../trainPlan/list'
						})
						break
					case 'markRoom':
						uni.navigateTo({
							url: '../markRoom/markRoom'
						})
						break
					case 'videoMonitor':
						// uni.navigateTo({
						// 	url: '../../videoManage/videoList?sn=' +
						// 		this.projectDetail.projectSn +
						// 		'&pageType=backEnd'
						// })
						uni.navigateTo({
							url: '../../videoManage/videoGroup'
						})
						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/indexPage'
						})
						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 'safeManageAG':
						uni.navigateTo({
							url: '../safeSame/index'
						})
						break
					case 'fileManage':
						uni.navigateTo({
							url: '../../fileManage/fileManage'
						})
						break
					case 'materialsManage':
						uni.navigateTo({
							url: '../../projectEnd/materialsManage/materialsManage'
						})
						break
					case 'ukashManage':
						uni.navigateTo({
							url: '../../projectEnd/ukashManage/ukashManage'
						})
						break
					case 'ekashManage':
						uni.navigateTo({
							url: '../../projectEnd/ekashManage/ekashManage'
						})
						break
					case 'visitorsManage':
						uni.navigateTo({
							url: '../../projectEnd/visitorsManage/visitorsManage'
						})
						break
					case 'betonManage':
						uni.navigateTo({
							url: '../betonManage/index'
						})
						break
					case 'progressManage':
						uni.navigateTo({
							url: '../progressManagement/index'
						})
						break
						// case 'dangerBroadcast':
						// 	uni.navigateTo({
						// 		url: '../../alarmPage/index'
						// 	})
						// 	break
					case 'dangerBroadcast':
						// uni.navigateTo({
						// 	url: '../../alarmPage/indexTwo'
						// })
						uni.navigateTo({
							url: '../../alarmPage/pageIndex'
						})
						break
					case 'carViolation':
						// uni.navigateTo({
						// 	url: '../../alarmPage/indexTwo'
						// })
						uni.navigateTo({
							url: '../../carViolation/pageIndex'
						})
						break

					case 'standardSchedule':
						uni.navigateTo({
							url: '../standardSchedule/index',
						})
						break
					case 'smartBeamField':
						uni.navigateTo({
							url: '../smartBeamField/beamMenu',
						})
						break
					case 'specialOperations':
						uni.navigateTo({
							url: '../../projectEnd/specialOperations/specialOperations'
						})
						break
					case 'operationManage':
						uni.navigateTo({
							url: '../../projectEnd/operationManage/operationManage'
						})
						break
					case 'emergencyDisposal':
						uni.navigateTo({
							url: '../../projectEnd/emergencyDisposal/index'
						})
						break
					case 'pouringOrderLedger':
						uni.navigateTo({
							// url: '../qualityManage/pouringOrderLedger/work'
							url: '../../projectEnd/workflowTable/pouringOrderApplyfor/index'
						})
						break
					case 'testingManage':
						uni.navigateTo({
							url: '../../projectEnd/testingManage/operationManage'
						})
						break
					case 'startReportApproveManage':
						uni.navigateTo({
							url: '../../projectEnd/startReportApproveManage/index'
						})
						break
					case 'controlPointGrading':
						uni.navigateTo({
							url: '../../projectEnd/controlPointGrading/index'
						})
						break
					case 'buildUnqualifiedReport':
						uni.navigateTo({
							url: '../../projectEnd/workflowTable/buildUnqualifiedReport/index'
						})
						break
					case 'welderAssessmentRequest':
						uni.navigateTo({
							url: '../../projectEnd/workflowTable/welderAssessmentRequest/index'
						})
						break
					case 'unitProjectDivideReport':
						uni.navigateTo({
							url: '../../projectEnd/workflowTable/unitProjectDivideReport/index'
						})
						break
					case 'engineeringSurveyRetest':
						uni.navigateTo({
							url: '../../projectEnd/workflowTable/engineeringSurveyRetest/index'
						})
						break
					case 'waterElectricityRecordSettlement':
						uni.navigateTo({
							url: '../../projectEnd/workflowTable/waterElectricityRecordSettlement/index'
						})
						break
					case 'roadUseApproval':
						uni.navigateTo({
							url: '../../projectEnd/workflowTable/roadUseApproval/index'
						})
						break
					case 'centralizeAntisepticEntrust':
						uni.navigateTo({
							url: '../../projectEnd/centralizeAntisepticEntrust/index'
						})
						break
					case 'pipelineWelding':
						uni.navigateTo({
							url: '../../projectEnd/pipelineWelding/index'
						})
						break

					case 'guidancePartyBuilding':
						uni.navigateTo({
							url: '../../projectEnd/guidancePartyBuilding/index'
						})
						break
					case 'sunshineProject':
						uni.navigateTo({
							url: '../../projectEnd/sunshineProject/index'
						})
						break
					case 'videoLedger':
						uni.navigateTo({
							url: '../../projectEnd/videoLedger/index'
						})
						break
					case 'buildEquipToolManage':
						uni.navigateTo({
							url: '../../projectEnd/buildEquipToolManage/index'
						})
						break
					case 'schemeLedger':
						uni.navigateTo({
							url: '../../projectEnd/schemeLedger/index'
						})
						break
					case 'winterConstructionManage':
						uni.navigateTo({
							url: '../../projectEnd/winterConstructionManage/index'
						})
						break
					case 'firstModelManage':
						uni.navigateTo({
							url: '../../projectEnd/firstModelManage/index'
						})
						break
					case 'civilConstruction':
						uni.navigateTo({
							url: '../../projectEnd/civilConstruction/index'
						})
						break
					case 'qualitySurveillance':
						uni.navigateTo({
							url: '../../projectEnd/qualitySurveillance/index'
						})
						break
					case 'contractors':
						uni.navigateTo({
							url: '../../contractors/index'
						})
						break
					case 'saosao':
						console.log('打开saosao')
						// let that = this;
						uni.scanCode({
							scanType: ['qrCode'],
							success: function(res) {
								console.log('扫一扫得到的数据：' + res.result)
								// uni.navigateTo({
								// 	url: '../scan/saoSao?data=' + res.result
								// })
								uni.navigateTo({
									url: `${res.result}`
								})

								// let qrcodeVal=JSON.parse(res.result)
								// let param={
								// 	checkingPointId:qrcodeVal.checkingPointId,
								// 	checkingPointName:qrcodeVal.checkingPointName,
								// 	checkingPointUserId:that.userInfo.userId,
								// 	checkingPointUserName:that.userInfo.realName||that.userInfo.account,
								// 	position:qrcodeVal.position
								// }

								// that.sendRequest({
								// 	url: "xmgl/checkingPointInfo/add",
								// 	data:param,
								// 	method: "POST",
								// 	success(res) {
								// 		console.log(res,'res');
								// 		console.log(param,'===')
								// 		that.qrCode=param;
								// 		that.$refs.popupqrcode.open();
								// 		setTimeout(item=>{
								// 			that.$refs.popupqrcode.close();
								// 		},5000)
								// 	}
								// })
							}
						})
						break
					default:
						uni.showToast({
							icon: 'none',
							title: '该产品暂未开放，敬请期待！'
						})
				}
			},
			getProjectDetail() {
				var that = this
				this.sendRequest({
					url: 'xmgl/project/getProjectInfoBySn',
					data: {
						projectSn: this.projectDetail.projectSn
						// 获取存储数组最底层的projectSn
					},
					method: 'POST',
					success(res) {
						that.projectDetail = res.result
						uni.setStorageSync('projectDetail', JSON.stringify(res.result))
					}
				})
			},

			getAllModule(arr) {
				console.log('获取的模块', arr)

				var that = this
				this.sendRequest({
					url: 'xmgl/baseModule/getModuleAndMenuList',
					data: {
						projectSn: this.projectDetail.projectSn,
						userId: this.userInfo.userId,
						moduleType: 2,
						isApp: 1
					},
					method: 'POST',
					success(res) {
						if (res.success) {
							console.log(uni.getStorageSync("userInfo"), 777888)
							var all = res.result.moduleList;
							console.log("all", all);
							all.forEach((element, index) => {
								all[index].operation = true;
								// res.result.menuList.forEach((element2) => {
								// 	if (element2.moduleId == element.moduleId) {
								// 		all[index].operation = true;
								// 	}
								// });
							});
							console.log("all111", all);
							console.log(all, that.haveModuleList)

							// const newList = that.$recursiveSearchFn(all);
							// console.log(111, newList)
							that.list = all.filter(item => {
								if (that.haveModuleList.length > 0) {
									const path = item.path ? item.path : item.modulePath;
									const res = that.$recursiveSearch(that.haveModuleList, path)
									return res ? true : false
								}


								// console.log(5555555, res);
								// debugger
								return res;
							}).reduce((prev, item) => {
								const findIndex = prev.findIndex(ele => ele.plugin == item.plugin);
								if (findIndex == -1) {
									prev.push(item);
								}
								return prev
							}, []);
							console.log("我是", that.list)
						}
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.qrcodeItem {
		padding: 40rpx 30rpx;
		width: 480rpx;

		background-color: #fff;
		border-radius: 8rpx;

		.title {
			text-align: center;
			margin-bottom: 12rpx;
		}
	}

	.topBoxContent {
		color: white;
		font-size: 28rpx;
		// background: linear-gradient(360deg, #A59FFF 0%, #3258FF 100%);
		height: 520rpx;
		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: 300rpx;
		height: 300rpx;
		position: relative;
		text-align: center;
		margin: 0px auto 50rpx;

		.title1 {
			padding-top: 48rpx;
		}

		.title2 {
			font-size: 66rpx;
			margin: 12rpx 0;

			.unit {
				font-size: 40rpx;
			}
		}

		.status {
			width: 104rpx;
			height: 104rpx;
			background: #8fda5c;
			border-radius: 24rpx;
			display: inline-block;
			line-height: 50rpx;
		}

		.redStatus {
			background: #ea6868;
		}

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

	.weatherBox {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
		text-align: center;

		.top {
			font-size: 54rpx;
			display: flex;
			align-items: center;
		}

		.weatherIcon {
			width: 72rpx;
			height: 72rpx;
		}

		.bottom {
			font-size: 20rpx;
		}
	}

	.projectIndexPage {

		:deep(.uni-scroll-view-content) {
			background-image: url(@/static/bthgIcon/prjectIndex_bg3.png);
			background-repeat: no-repeat;
			background-size: 100%;
		}

		:deep(.headerBox) {
			background-color: transparent;
			border-bottom: none;
		}
	}

	.progressBox {
		width: 300rpx;
		height: 300rpx;
		position: relative;
		text-align: center;
		margin: 0px auto 48rpx;

		.title1 {
			padding-top: 48rpx;
		}

		.title2 {
			font-size: 66rpx;
			margin: 12rpx 0;

			.unit {
				font-size: 40rpx;
			}
		}

		.status {
			width: 104rpx;
			height: 50rpx;
			background: #8fda5c;
			border-radius: 24rpx;
			display: inline-block;
			line-height: 50rpx;
		}

		.redStatus {
			background: #ea6868;
		}

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

	.weatherBox {
		position: absolute;
		top: 20rpx;
		right: 30rpx;
		text-align: center;

		.top {
			font-size: 54rpx;
			display: flex;
			align-items: center;
		}

		.weatherIcon {
			width: 72rpx;
			height: 72rpx;
		}

		.bottom {
			font-size: 20rpx;
		}
	}

	.moudleBox2 {
		opacity: 0.6;
	}

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

	.moudleItem {
		float: left;
		width: 33.33%;
		font-size: 26rpx;
		text-align: center;
		margin-bottom: 20rpx;

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

		.img {
			// width: 80rpx;
			// height: 80rpx;
			// width: 64rpx;
			// height: 64rpx;
			width: 88rpx;
			height: 88rpx;
			color: red;
		}

		.desc {
			margin-top: 12rpx;
			color: rgba(38, 45, 71, 0.77);
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
	}

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

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

	.moudleContent {
		// box-shadow: 0px 8rpx 32rpx 0px rgba(212, 220, 236, 0.59);
		border-radius: 16rpx;
		padding: 30rpx;
		margin: 110rpx 30rpx 30rpx;
		position: relative;
		z-index: 2;
	}

	.projectIndexBG {
		width: 100%;
		height: 714rpx !important;
		position: absolute;
		top: 0;
		left: 0;
	}
</style>