<template>
	<div class="bg">
		<!-- <van-nav-bar
	  title="智慧“和顺”"
	  left-text="民宗干事"
	  left-arrow
	  @click-left="onClickLeft"
	/> -->

		<!-- <van-image
		width="100%"
		height="10rem"
		fit="cover"
		src="https://img1.baidu.com/it/u=2086445453,3056906789&fm=253&fmt=auto&app=138&f=GIF?w=1378&h=400"
		/> -->

		<van-swipe :autoplay="3000" lazy-render>
			<van-swipe-item v-for="image in BannerImgurls" :key="image">
				<van-image width="100%" height="10rem" fit="cover" :src="image" />
			</van-swipe-item>
		</van-swipe>

		<div class="tabtitlelay" @click="goToBeDone">
			<div class="tabtitle1"></div>
			<div class="tabtitle">我的待办</div>
			<div class="tabtitle2">(</div>
			<div class="tabtitle3">{{ sum }}</div>
			<div class="tabtitle4">)</div>
			<van-icon name="ellipsis" class="tabtitle5" />
		</div>

		<div class="flexll">
			<div class="ffl2" id="0" @click="goToBeDone($event)">
				<div class="textRegular">待处理</div>
				<div class="textRed">{{ sum1 ? sum1 : 0 }}</div>
			</div>
			<div class="verticalLine"></div>
			<div class="ffl2" id="1" @click="goToBeDone($event)">
				<div class="textRegular">已处理</div>
				<div class="textBlue">{{ sum2 ? sum2 : 0 }}</div>
			</div>
		</div>
		<div class="hLine"></div>

		<div class="tabtitlelay">
			<div class="tabtitle1"></div>
			<div class="tabtitle">场所管理</div>
		</div>

		<van-grid :border="false">
			<van-grid-item icon="./loginbg/csdj.png" text="场所登记" @click="goPlaceRegister" />
			<van-grid-item icon="./loginbg/csry.png" text="场所人员信息" @click="goPlacePerson" />
			<van-grid-item icon="./loginbg/cspw.png" text="牌位管理" @click="goPlaceTablet" />
		</van-grid>

		<div class="hLine"></div>

		<div class="tabtitlelay">
			<div class="tabtitle1"></div>
			<div class="tabtitle">{{ testshow }}</div>
		</div>

		<van-grid :border="false">
			<van-grid-item icon="./loginbg/hd_cshd.png" @click="placeActivity" text="场所活动" />			
			<van-grid-item icon="./loginbg/hd_jc.png" text="场所检查" @click="tohd_jc" />
			<van-grid-item icon="./loginbg/hd_hy.png" text="负责人会议" @click="tohd_hy" />
		</van-grid>
		
		<div class="tabtitlelay">
			<div class="tabtitle1"></div>
			<div class="tabtitle">{{ testshow2 }}</div>
		</div>
		
		<van-grid :border="false">
			<van-grid-item icon="./loginbg/hd_ssjhd.png" @click="selfMeetingList" text="私设聚会点" />
			<van-grid-item icon="./loginbg/hd_xjqz.png" @click="abnormalCrowd" text="信教群众异常" />
			<van-grid-item icon="./loginbg/hd_af.png" text="安防设施异常" @click="tohd_af" />
			<van-grid-item icon="./loginbg/hd_qt.png" text="其他有害信息" @click="tohd_qt" />
		</van-grid>
	</div>
</template>

<script>
import tool from "@/tool";
import qs from "qs";
import userSets from "@/api/sys/userSets";
import toBeDone from '@/api/toBeDone/toBeDone';
import $base from "@/utils/config";
export default {
	data() {
		return {
			title: '民宗干事',
			username: "",
			sms: "",
			password: "",
			password2: "",
			con1: 0,
			con2: 0,
			testshow: "活动管理",
			testshow2: "异常监管",
			sum: "0",
			sum1: "0",
			sum2: "0",
			BannerImgurls: ['https://img1.baidu.com/it/u=2086445453,3056906789&fm=253&fmt=auto&app=138&f=GIF?w=1378&h=400', 'https://img1.baidu.com/it/u=2086445453,3056906789&fm=253&fmt=auto&app=138&f=GIF?w=1378&h=400']
		}
	},

	created() {
		let id = this.$route.query.id;
		window.xm.setNavigationBarTitle({ title: '宗教和顺' })
		this.TokenLogin2();
		this.$dictUtils.refreshDictList();
	},

	methods: {
		// 待办跳转
		goToBeDone(e) {
			let value = JSON.stringify(e.currentTarget.id)
			// console.log(e.currentTarget.id);
			this.$router.push({
				path: "/toBeDone",
				query: { "name": value }
			});
		},
		// 场所登记跳转
		goPlaceRegister() {
			this.$router.push("/placeRegisterList");
		},
		// 人员档案跳转
		goPlacePerson() {
			this.$router.push("/placePerson");
		},
		// 牌位管理跳转
		goPlaceTablet() {
			this.$router.push("/placeTablet");
		},
		//待办数据获取
		dataNumber() {
			new toBeDone().list().then((res) => {
				this.sum1 = res.records.length;
				this.sum = this.sum1 + this.sum2;
			})
			new toBeDone().list2().then((res1) => {
				this.sum2 = res1.records.length;
				this.sum = this.sum1 + this.sum2;

			})

		},
		onClickLeft() {
			history.back();
		},
		tohd_jc() {
			//this.onlineXm.xmNavTo("../activityMan\siteInspection\siteInspectionList");
			this.$router.push("/siteInspectionList");
		},
		tohd_af() {
			this.$router.push("/securityFacilitiesErrList");
		},
		tohd_hy() {
			this.$router.push("/religiousConferenceList");
		},
		tohd_qt() {
			this.$router.push("/nonReligiousInformationList");
		},
		// 活动场所
		placeActivity() {
			this.$router.push("/placeActivityList")
		},
		selfMeetingList() {
			this.$router.push("/selfMeetingList")
		},
		abnormalCrowd() {
			this.$router.push("/differentbelieversList")
		},
		async TokenLogin() {
			let that = this;
			//添加PCtoken过期判断,(请求拦截到token过期,会设置PCtoken为空,为空的时候再调用免登功能)
			if (this.$store.state.pctoken == "" || this.$store.state.pctoken == undefined) {

				//SDK中 getToken() 方法获取免登token
				//window.xm.getToken().then(async function(token){//上线取消注释
				let token = "test";//上线注释

				const inputForm = qs.stringify({
					'token': token
				}, { allowDots: true, arrayFormat: 'indices' })
				var res = await this.$API.yin.TokenLogin.get(inputForm);
				//存PCtoken
				this.$store.commit('setPcToken', res.PcToken);
				this.$store.commit('setUser', res.account);

				//})//上线取消注释

			}

		},

		TokenLogin2() {
			let that = this;
			//添加PCtoken过期判断,(请求拦截到token过期,会设置PCtoken为空,为空的时候再调用免登功能)
			if (this.$store.state.pctoken == "" || this.$store.state.pctoken == undefined) {

				//SDK中 getToken() 方法获取免登token
				window.xm.getToken().then(async function (token) {//上线取消注释
					// let token = "test";//上线注释	


					new userSets()
						.TokenLogin({
							token: token
						})
						.then((res) => {
							that.$store.commit('setPcToken', res.PcToken);
							that.$store.commit('setUser', res.account);
							that.getBannerImg();//获取轮播图
							that.getSelectColor();//获取主题颜色
							that.dataNumber();//获取待办事项数
						});

				})//上线取消注释

			} else {
				that.getBannerImg();//获取轮播图
				that.getSelectColor();//获取主题颜色
				that.dataNumber();//获取待办事项数
			}


		},

		getStatistics() {
			let that = this;
			new userSets()
				.Statistics()
				.then((res) => {
					if (res[0].sum != undefined && res[0].sum != null && res[0].sum != "") {
						that.sum = res[0].sum;
					}
					if (res[0].sum1 != undefined && res[0].sum1 != null && res[0].sum1 != "") {
						that.sum1 = res[0].sum1;
					}
					if (res[0].sum2 != undefined && res[0].sum2 != null && res[0].sum2 != "") {
						that.sum2 = res[0].sum2;
					}
				});
		},

		getBannerImg() {
			new userSets()
				.BannerImg({
					'current': 1,
					'size': 5,
					'orders': [],
				})
				.then((res) => {
					let bs = [];

					res.records[0].bannerImg.split("|").forEach((item) => {
						if (item.trim().length > 0) {
							bs.push($base + item.replace('程序附件//', '程序附件/'),
							);
						}
					});
					this.BannerImgurls = bs;
				});
		},

		getSelectColor() {
			let that = this;
			new userSets()
				.SelectColor()
				.then((res) => {
					//console.log(res.records[0].selectColor.substring(1, 7));
					//存PCtoken
					that.$store.commit('setSelectColor', res.默认);
				});
		},



		//测试接口,可删除
		async gettest() {
			let that = this;

			//SDK中 getToken() 方法获取免登token
			// window.xm.getToken().then(function(token){
			// 	console.log(token);

			// 	that.con1="哈哈"+token;
			// 	window.xm.showToast({
			// 		message:that.con1
			// 	})

			// })

			//测试数据同步接口的
			const inputForm = {
				'iamRequestId': '120010',
				'iamRemoteUser': 'admin12022',
				'iamRemotePwd': ''
			}
			var res = await this.$API.yin.SchemaService.post(inputForm);
			if (res.type == 1) {
				this.$router.replace({
					path: "/main",
				});
			} else {
				Toast.fail(res.message);
			}

		},

		//测试接口,可删除
		async gettest2() {
			var datas = {
				username: "admin",
			};
			var res = await this.$API.my.OrderDetails.get(datas);
			this.con1 = res;
			console.log(res);
		},


		//用户数据同步测试用(用户保存)
		async gettestUser1() {
			const inputForm = {
				'iamRequestId': '120010',
				'iamRemoteUser': 'admin',
				'iamRemotePwd': '11',
				'loginName': 'yzt2',
				'name': '同步用户2',
				'password': '111',
				'idcard': '320911199010000002',
				'email': '818166662@qq.com',
				'phone': '88868882',
				'mobile': '1829999992',
				'loginFlag': '1',
				'photo': '',
				'sign': '个性签名2',
			}
			var res = await this.$API.yin.UserCreateService.post(inputForm);
			console.log(res);
		},
		//(用户更新)
		async gettestUser2() {
			const inputForm = {
				'iamRequestId': '120010',
				'iamRemoteUser': 'admin',
				'iamRemotePwd': '11',
				'uid': '1639158103696228354',
				'loginName': 'yzt222',
				'name': '11',
				// 'password': '',
				// 'idcard': '',
				// 'email': '',
				// 'phone': '',
				// 'mobile': '',
				// 'loginFlag': '',
				// 'photo': '',
				// 'sign': '',
			}
			var res = await this.$API.yin.UserUpdateService.post(inputForm);
			console.log(res);

		},
		//(用户删除)
		async gettestUser3() {
			const inputForm = {
				'iamRequestId': '120010',
				'iamRemoteUser': 'admin',
				'iamRemotePwd': '111',
				'uid': '1639158103696228354',
			}
			var res = await this.$API.yin.UserDeleteService.post(inputForm);
			console.log(res);
		},

	},

};
</script>

<style>
.bg {
	height: 100%;
	background: #ffffff;
}
</style>