<template>
	<view style="overflow: hidden;">
		<page-meta :root-font-size="getFontSizeValue"></page-meta>
		<view class="uni-margin-wrap">
			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
				:duration="duration">
				<swiper-item v-for="item in bannnerData" :key="item.id">
					<image :src="item.imgPath" mode=""></image>
				</swiper-item>
			</swiper>
		</view>

		<view class="orderManage">
			<view class="orderTit" style="padding-left: 15px;color: rgb(126, 131, 125);">
				<text style="width: 4px;background-color: rgb(26, 188, 156);height: 20px;margin-top: 10px;margin-right: 5px;"></text>
				<text>工单模块</text>
			</view>

			<view class="orderCon">
				<view class="orderList" v-for="item in orderListData" :key="item.id" @click="workOrderListClick(item)">
					<image :style="{ background: item.imageBg }" :src="item.imagePath" mode=""></image>
					<text>{{ item.text }}</text>
				</view>
			</view>

			<view class="orderTit" @click="changeStore" v-if="noticState">
				<image style="background: #ff9600" src="/static/icon_noticefi.png"></image>
				<text>公告通知</text>
			</view>

			<view class="notification">
				<view class="notifiList" v-for="item in noticListData" :key="item.id">
					<image :style="{ background: item.imageBg }" :src="item.imagePath" mode=""></image>
					<view class="">
						<text>{{ item.textTit }}</text>
						<text>{{ item.textCon }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import { mapGetters } from "vuex"
	import store from '@/store';
	import { getToken } from '@/utils/auth'
	import pageData from '../myTask/repairList/addRepair/pageData.js'
	export default {
		data() {
			return {
				indicatorDots: true,
				getFontSizeValue:'1rem',
				autoplay: true,
				interval: 2000,
				noticState: false,
				duration: 500,
				bannnerData: [],
				orderListData: [],
				noticListData: [],
			}
		},
		computed: {
			...mapGetters(["State"]),
		},
		onLoad() {
			this.init()
			this.saveDept()
			this.getFontSizeValue = uni.getStorageSync('fontSizeValue')+'rem'
			// this.getFontSizeValue = '1.5rem'
			if(uni.getStorageSync("roleCode") === "APRY"){
				uni.hideTabBar()
			}
			// uni.hideTabBar()
		},
		methods: {
			init() {
				// #ifdef APP-PLUS
				let timer
				timer = setInterval(() => {
					plus.push.getClientInfoAsync((info) => {
						let cid = info["clientid"];
						if (cid) {
							clearInterval(timer)
							this.clienGet(cid) //获取cid 
						}
					});	
				}, 5000)
				
				this.upData()
				// #endif
				this.bannnerData = this.$mConstDataConfig.bannnerData
				this.getMenuPermissions() //获取用户权限
				// if (!getToken()) {
				// 	uni.reLaunch({
				// 		url: '/pages/login/login'
				// 	});
				// } else {
				// 	//banner数据
				// 	this.bannnerData = this.$mConstDataConfig.bannnerData
				// 	this.getMenuPermissions() //获取用户权限
				// 	// 公告数据
				// 	//this.noticListData = this.$mConstDataConfig.noticListData
				// }
			},
			saveDept(){
				pageData.getDet((res, data) => {
					uni.setStorageSync('deptTreeData',JSON.stringify(res))
					uni.setStorageSync('deptAllList',JSON.stringify(data))
				})
			},
			changeStore() {
				this.$mStore.dispatch("STATE", 3)
			},
			workOrderListClick(item) {
				uni.navigateTo({
					url: item.navigateToUrl,
				})
			},
			clienGet(cid) {
			
				let apptype
				if (plus.device.model.indexOf('iPhone') > -1) {
					apptype = 2;
				} else {
					apptype = 1;
				}
				const params = {
					apptype: apptype,
					clientid: cid,
					token: uni.getStorageSync("token"),
				}
				this.$http.get("PushMessage/PutAppClientIdAsync", params).then((response) => {
						if (response.state.toLowerCase() === "success") {
							let data = response.message
						}
			
					})
					.catch((e) => {
						console.log(e)
					})
			
			},
			upData(){
				plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
					uni.setStorageSync('versionCode',wgtinfo.version)
				});
				let typeUp = ''
				if (plus.device.model.indexOf('iPhone') > -1) {
					typeUp=1; 
				}else{
					typeUp=0; 
				}
				const params = {
					type:typeUp,
					isNew: true, 
				}
				this.$http.get('/ApplicationsVersion/GetAndroid', params).then((response) => {
					if (response.state == "success") {
						let data = response.data
						console.log(data)
						//NewCode_ = data.data.F_VersionCode; 
						const nowVersionCode = uni.getStorageSync('versionCode')
						const serveVersionCode = data.F_VersionCode 
						console.log(nowVersionCode + "---" +serveVersionCode)
						if (nowVersionCode !== serveVersionCode) {
							if(typeUp === 0){
								plus.runtime.openURL(data.FileUrl[0].F_FileUrl, err=>{
									plus.runtime.openURL(data.FileUrl[0].F_FileUrl);
								}, 'com.android.browser');
								// uni.showModal({
								// 	title: '更新',
								// 	content: '是否更新',
								// 	success: function (res) {
								// 		if (res.confirm) {
								// 			console.log(data.F_FileUrl)
								// 		} else if (res.cancel) {
								// 			this.$mHelper.toast("取消更新");
								// 		}
								// 	}
								// });
							}else if(typeUp === 1){
								plus.runtime.openURL(data.F_Url);
								// uni.showModal({
								// 	title: '更新',
								// 	content: '是否更新',
								// 	success: function (res) {
								// 		if (res.confirm) {
								// 			plus.runtime.openURL(data.F_Url);
								// 		} else if (res.cancel) {
								// 			this.$mHelper.toast("取消更新");
								// 		}
								// 	}
								// });
								
							}
							
							
						}
						
					}
				}).catch((e) => {
					console.log(e);
				})
			},
			
			getMenuPermissions() { 
				let code = uni.getStorageSync("roleCode")
				this.$http.get("InternalMessages/GetCount").then((response) => {
						if (response.state.toLowerCase() === "success") {
							if(response.IsRead == 1) {
								uni.showTabBarRedDot({
								  index: 2
								})
							}else{
								uni.hideTabBarRedDot({
								  index: 2
								})
							}
						}
				
					})
					.catch((e) => {
						console.log(e)
					})
				/* 
        GLY：管理员
				*/
				if ( code === 'WXY' || code === 'WXBZZ') {
					this.orderListData = this.$mConstDataConfig.roleListData.UnitList 
				}else if(code === "DDZX" ) {
					this.orderListData = this.$mConstDataConfig.roleListData.dispatchList 
				}else if(code === "GQY" ) {
					this.orderListData = this.$mConstDataConfig.roleListData.AttendantList 
				}else if(code === "SJ" ){
					this.orderListData = this.$mConstDataConfig.roleListData.driverList
				}else if(code === 'jcgn'){
					this.orderListData = this.$mConstDataConfig.roleListData.applyRepairList
				}else if(code === 'APRY'){
					this.orderListData = this.$mConstDataConfig.roleListData.driverList
				}else if( code === 'BMXG'){
					this.orderListData = this.$mConstDataConfig.roleListData.applyRepairList
				}else if( code === 'GLY'){
					this.orderListData = this.$mConstDataConfig.roleListData.applyRepairList
				}
			},
		},
	}
</script>

<style lang="scss">
	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
	}

	.swiper {
		height: 225px;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.orderManage {
		.orderTit {
			margin-top: 15rpx;
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			background: #ffffff;
			display: flex;
			border-bottom: 1rpx solid #eeeeee;

			text {
				font-size: 1rem;
			}

			image {
				width: 24rpx;
				height: 24rpx;
				padding: 8rpx;
				border-radius: 12px;
				background: #1972c2;
				margin: 20rpx 10rpx 20rpx 26rpx;
			}
		}

		.orderCon {
			background: #ffffff;
			display: flex;
			flex-wrap: wrap;

			.orderList {
				width: 186rpx;
				height: 206rpx;
				text-align: center;
				border-right: 2rpx solid #eeeeee;
				border-bottom: 2rpx solid #eeeeee;

				image {
					width: 40rpx;
					height: 40rpx;
					margin: 0 auto;
					display: block;
					border-radius: 35rpx;
					padding: 15rpx;
					margin-top: 45rpx;
				}

				text {
					line-height: 60rpx;
				}
			}

			.orderList:nth-child(4n + 4) {
				border-right: none;
			}

			.orderList:last-child {
				border-right: none;
			}
		}

		.notification {
			background: #ffffff;
			margin-bottom: 100rpx;
			display: flex;
			flex-wrap: wrap;
			border-bottom: 1rpx solid #eeeeee;

			.notifiList {
				width: 375rpx;
				height: 172rpx;
				padding: 46rpx 30rpx 46rpx 30rpx;
				text-align: left;
				border-right: 1rpx solid #eeeeee;
				border-bottom: 1rpx solid #eeeeee;
				box-sizing: border-box;
				display: flex;

				image {
					width: 48rpx;
					height: 48rpx;
					box-sizing: border-box;
					border-radius: 24rpx;
					padding: 10rpx;
					margin: 19rpx;
				}

				text {
					font-size: 24rpx;
					line-height: 30rpx;
				}
			}

			.notifiList:nth-child(2n + 2) {
				border-right: none;
			}
		}
	}
</style>
