<template>
	<view class="storemanagement">
		<view class="storemanagement-header">
			<view class="storemanagement-header-text">
				服务中心
			</view>
			<view class="storemanagement-list">
				<view class="storemanagement-list-yi" v-for="(item,index) in mnu" :key="index" @click="jinru(item.pages,item.name)" v-if="item.show">
					<view class="storemanagement-list-yi-text">
						{{item.name}}
					</view>
					<view class="storemanagement-list-yi-image">
						<image :src="item.url" mode="widthFix"></image>
					</view>
				</view>
			</view>
			<view class="listadd-annkiu" @click="logoutAction" v-if="uid">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	import { emConnect } from '@/EaseIM/emApis';
	import readAppInfo from '@/utils/readAppInfo.js';
	const { loginWithPassword,closeEaseIM } = emConnect();
	export default {
		data() {
			return {
				mnu: [{
						name: "分润设置",
						url: "https://cdn.bjtdba.com/vod/image/2022-08-12/20220812161807687.png",
						pages:"/shop/services/setting",
						show:true,
						id: "3",
					},
					{
						name: "我的音响",
						url: "https://cdn.bjtdba.com/vod/image/2022-08-12/20220812161749139.png",
						pages:"/shop/services/mystereo",
						show:true,
						id: "0",
					},
					{
						name: "锁定用户",
						url: "https://cdn.bjtdba.com/vod/image/2022-08-12/20220812161733260.png",
						pages:"/shop/services/lockuser",
						show:true,
						id: "0",
					}
				],
				uid: '',
				authorization: ''
			}
		},
		async onLoad() {
			console.log('进了我的页面了')
			// uni.showLoading({
			// 	title: '加载中',
			// 	mask: true
			// });
			
			await readAppInfo();
			
			let jurisdiction = uni.getStorageSync('jurisdiction')
			console.log('jurisdiction', jurisdiction)
			let mnuList = this.mnu
			if (jurisdiction!=null) {
				jurisdiction.forEach((res, index) => {
					mnuList.forEach((result, i) => {
						if (res == result.id) {
							result.show = true
						}
						return result
					})
					return res
				})
				this.mnu = mnuList
			}
			
			console.log(this.mnu)
			
			setTimeout(function() {
				uni.hideLoading();
			}, 700);
			
			
			console.log('我的show===>>>>>>')
				
			
			this.authorization = uni.getStorageSync('authorization')
			let userinfo = uni.getStorageSync('userinfo')
			this.uid = userinfo.uid
			console.log('onshow')
			
			let authorization = uni.getStorageSync('authorization')
			// let userinfo = uni.getStorageSync('userinfo')
			let selectmerchant = uni.getStorageSync('selectmerchant')
			let uid = userinfo.uid
			console.log(selectmerchant, authorization, userinfo)
			if (authorization && uid) {
				if (selectmerchant.merId >= 0 && selectmerchant.status == -1) {
					uni.redirectTo({
						url: "/openmerchant/guide/index" //有或者没有商户 没有金额支付and激活码支付
					});
					return
				} else if (selectmerchant.merId > 0 && (selectmerchant.status == 1 || selectmerchant.status == 5)) {
					
					return
				} else if (selectmerchant.merId >= 0 && (selectmerchant.status == 3 || selectmerchant.status == 4)) {
					uni.redirectTo({
						url: '/openmerchant/shopentry/process?mer_id=' + selectmerchant.merId //已开通商户未填写资料
					});
					return
				} else if (selectmerchant.merId > 0 && selectmerchant.status == 0) {
					uni.redirectTo({
						url: '/openmerchant/shopentry/processaudit?submitCode=' + 3 //已开通商户待审核
					});
					return
				} else if (selectmerchant.merId > 0 && selectmerchant.status == 2) {
					uni.redirectTo({
						url: '/openmerchant/shopentry/processaudit?submitCode=' + 2 //已开通商户审核拒绝
					});
					return
				}
			
			} 
		},
		onShow() {
			return;
			
			// 以下逻辑在onload处理
			
			this.authorization = uni.getStorageSync('authorization')
			let userinfo = uni.getStorageSync('userinfo')
			this.uid = userinfo.uid
			
			let authorization = uni.getStorageSync('authorization')
			// let userinfo = uni.getStorageSync('userinfo')
			let selectmerchant = uni.getStorageSync('selectmerchant')
			let uid = userinfo.uid
			console.log(selectmerchant, authorization, userinfo)
			if (authorization && uid) {
				if (selectmerchant.merId >= 0 && selectmerchant.status == -1) {
					uni.redirectTo({
						url: "/openmerchant/guide/index" //有或者没有商户 没有金额支付and激活码支付
					});
					return
				} else if (selectmerchant.merId > 0 && (selectmerchant.status == 1 || selectmerchant.status == 5)) {
					
					return
				} else if (selectmerchant.merId >= 0 && (selectmerchant.status == 3 || selectmerchant.status == 4)) {
					uni.redirectTo({
						url: '/openmerchant/shopentry/process?mer_id=' + selectmerchant.merId //已开通商户未填写资料
					});
					return
				} else if (selectmerchant.merId > 0 && selectmerchant.status == 0) {
					uni.redirectTo({
						url: '/openmerchant/shopentry/processaudit?submitCode=' + 3 //已开通商户待审核
					});
					return
				} else if (selectmerchant.merId > 0 && selectmerchant.status == 2) {
					uni.redirectTo({
						url: '/openmerchant/shopentry/processaudit?submitCode=' + 2 //已开通商户审核拒绝
					});
					return
				}
			
			} 
			
			
		},
		methods: {
			// 退出登录
			logoutAction(){
				uni.removeStorageSync('userinfo');//清除用户信息
				uni.removeStorageSync('authorization');//清除authorization
				uni.removeStorageSync('selectmerchant');//清除商户数据
				uni.removeStorageSync('storeStaff');//部门id对应权限
				uni.removeStorageSync('jurisdiction');//管理员状态
				uni.removeStorageSync('mer_id');//环信和项目连接的id,登录环信需要
				//断开连接
				closeEaseIM();
				// this.$store.commit('SET_PIN_CONVERSATION_LIST', []);
				this.authorization = ''
				this.uid = ''
				
				
				
				uni.showToast({
					title: "退出成功",
					icon: "none"
				})
				// setTimeout(function() {
				// 	uni.redirectTo({
				// 		url: "/pages/user/login/index"
				// 	});
				// }, 700);
			},
			jinru(n,p){
				let name = p
				let page = n
				if(name=="分润设置") {
					let authorization = uni.getStorageSync('authorization')
					let userinfo = uni.getStorageSync('userinfo')
					let selectmerchant = uni.getStorageSync('selectmerchant')
					let uid = userinfo.uid
					if (authorization && uid) {
						if (selectmerchant.merId >= 0 && selectmerchant.status == -1) {
							uni.redirectTo({
								url: "/openmerchant/guide/index" //有或者没有商户 没有金额支付and激活码支付
							});
							return
						} else if (selectmerchant.merId > 0 && (selectmerchant.status == 1 || selectmerchant.status == 5)) {
							uni.redirectTo({
								url:page
							})
							return
						} else if (selectmerchant.merId >= 0 && (selectmerchant.status == 3 || selectmerchant.status == 4)) {
							uni.redirectTo({
								url: '/openmerchant/shopentry/process?mer_id=' + selectmerchant.merId //已开通商户未填写资料
							});
							return
						} else if (selectmerchant.merId > 0 && selectmerchant.status == 0) {
							uni.redirectTo({
								url: '/openmerchant/shopentry/processaudit?submitCode=' + 3 //已开通商户待审核
							});
							return
						} else if (selectmerchant.merId > 0 && selectmerchant.status == 2) {
							uni.redirectTo({
								url: '/openmerchant/shopentry/processaudit?submitCode=' + 2 //已开通商户审核拒绝
							});
							return
						}
					
					} else {
						uni.navigateTo({
							url: "/pages/user/login/index?type=1"
						});
						return
					}
					
				}else if(name=="锁定用户"){
					uni.redirectTo({
						url:page
					})
				}else{
					uni.redirectTo({
						url:page
					})
				}
			}
		}
	}
</script>
<style>
	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.storemanagement {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;

		.storemanagement-header {
			width: 100%;
			height: 328rpx;
			background: linear-gradient(180deg, rgba(31, 124, 255, 0.2200) 0%, rgba(255, 255, 255, 0.1500) 100%);
			position: relative;
			display: flex;
			justify-content: center;

			.storemanagement-header-text {
				position: absolute;
				font-size: 46rpx;
				font-weight: 500;
				color: #333333;
				top: 202rpx;
				left: 64rpx;
			}

			.storemanagement-list {
				width: 690rpx;
				height: 262rpx;
				position: absolute;
				top: 298rpx;
				display: flex;
				flex-flow: wrap;
				justify-content: space-between;

				.storemanagement-list-yi {
					margin-bottom: 26rpx;
					width: 330rpx;
					height: 118rpx;
					background: #FFFFFF;
					border-radius: 8rpx;
					display: flex;
					justify-content: space-around;
					align-items: center;

					.storemanagement-list-yi-text {
						font-size: 26rpx;
						font-weight: 500;
						color: #333333;
					}

					.storemanagement-list-yi-image {
						width: 92rpx;
						height: 92rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}
		.listadd-annkiu {
			width: 686rpx;
			height: 98rpx;
			background: #1F7CFF;
			border-radius: 8rpx;
			position: fixed;
			bottom: 26rpx;
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
			text-align: center;
			line-height: 98rpx;
		}
	}
</style>
