<template>
	<view class="main">
		<view class="backTop"></view>
		<!-- 头部开始 -->
		<view class="header box">
			<view class="header-zuo">
				<u-avatar
					:src="photo?photo:'https://qufang.oss-cn-beijing.aliyuncs.com/upload/icon/xcx/zkgj/headPicture.png'"
					size="148"></u-avatar>
			</view>
			<view class="header-you">
				<view class="userName">{{name}}</view>
				<view class="mobile">{{mobile}}</view>
			</view>
		</view>
		<view class="settingGroup box">
			<navigator class="line" url="/pages/mine/messageList">
				<view class="title" style="width: 21%;">
					<image src="/static/images/studyhot.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					消息
				</view>
				<view class="right" style="display: flex;align-items: center;">
					<view class="count" v-if="count!=0">{{count}}</view>
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</navigator>
			<template v-if="isPuqiang">
				<navigator class="line" url="/pages/mine/subscribe">
					<view class="title">
						<image src="/static/images/studyhot.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
						订阅消息
					</view>
					<view class="right">
						<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
					</view>
				</navigator>
			</template>
			<navigator class="line" url="/pages/mine/Myprofile">
				<view class="title">
					<image src="/static/images/setting.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					编辑资料
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</navigator>
			<view class="line" @click="phone">
				<view class="title">
					<image src="/static/images/Customer.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					客服电话
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</view>
			<view class="line" @click="scan">
				<view class="title" style="width: 220rpx;">
					<image src="/static/images/reg.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					访客登记码
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</view>
			<view class="line" @click="Changehepassword">
				<view class="title">
					<image src="/static/images/password.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					修改密码
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</view>
			<view class="line" @click="logout" style="border: none;">
				<view class="title">
					<image src="/static/images/exit.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					退出登录
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</view>

		</view>
		<u-tabbar activeColor="#1296db" inactiveColor="#999999" v-model="current" :list="tabbarList"></u-tabbar>
	</view>
</template>

<script>
	var app = getApp();
	var util = require("../../utils/util.js");
	var config = require("../../config");
	import tabbarList from '@/utils/tabbar.js'
	export default {
		data() {
			return {
				tabbarList: tabbarList,
				current: 0,
				tabList: [{
						name: '系统消息'
					},
					{
						name: '升级公告'
					},
				],
				name: "",
				photo: "",
				mobile: "",
				count: 0,
			};
		},
		computed: {
			isPuqiang() {
				return config.service.host.indexOf('xitong.pachira.cn') == -1
			}
		},

		onShow: function() {
			var userInfos = uni.getStorageSync('weapp_session_userInfo_data');
			this.name = userInfos.name,
				this.photo = userInfos.picUrl,
				this.mobile = userInfos.loginName
			this.updateInit()
			console.log(config.service.host.indexOf('xitong.pachira.cn') != -1)
		},
		methods: {
			updateInit() {
				uni.request({
					url: config.service.notReadNum,
					method: "GET",
					data: {
						id: uni.getStorageSync('weapp_session_userInfo_data').accountId,
						projectId: uni.getStorageSync('buildingID').id,
					},
					header: {
						'content-type': 'application/json',
						'Access-Token': uni.getStorageSync('weapp_session_login_data').token
					},
					success: (res) => {
						this.count = res.data.data
						this.tabbarList[3].count = res.data.data || 0
					}
				})
			},

			scan() {
				uni.navigateTo({
					url: "../mine/registerCode"
				})
			},
			//拨打电话
			phone() {
				wx.makePhoneCall({
					phoneNumber: '4008191707,8888' //仅为示例，并非真实的电话号码
				})
			},
			//修改密码
			Changehepassword() {
				uni.navigateTo({
					url: '/pages/mine/Changehepassword'
				});
			},
			//退出
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出？',
					cancelColor: "#999999",
					showCancel: true,
					success(res) {
						if (res.confirm) {
							app.Closewebsocke()
							uni.clearStorageSync(); //清除缓存
							uni.showToast({
								icon: "none",
								title: "退出成功"
							})
							uni.reLaunch({
								url: '/pages/login/index'
							});
						}
					}
				});
			},
			// tosubscr(){
			// 	let that=this;
			// 	wx.login({
			// 	  success (res) {
			// 	    if (res.code) {
			// 			let appid ='wxd9748307889cbe0d';
			// 			let secret = 'cfc40d2b86b650e216e900a2c430cd2b'
			// 			let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' +res.code + '&grant_type=authorization_code';
			// 			uni.request({
			// 				url: url, // 请求路径
			// 				success: result => {
			// 					that.$u.get("/user/bindMessage",{
			// 						openId:result.data.openid,
			// 						loginName:that.mobile
			// 					}).then(data => {
			// 						console.log(data)
			// 					})	
			// 				}	
			// 			})

			// 	    } else {
			// 	      console.log('登录失败！' + res.errMsg)
			// 	    }
			// 	  }
			// 	})
			// 	// /pages/mine/subscribe



			// },

		}
	};
</script>
<style lang="scss" scoped>
	.count {
		background: red;
		width: 50rpx;
		height: 50rpx;
		border-radius: 40rpx;
		color: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 24rpx;
		margin-right: 20rpx;
	}

	.main {
		padding: 0 30rpx;
		background: #F8F8F8;
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		padding-bottom: 40rpx;

		.backTop {
			background: #2671E2;
			position: absolute;
			left: 0;
			top: 0;
			width: 750rpx;
			height: 171rpx;
		}

		.box {
			background: #ffffff;
		}
	}

	.header {
		z-index: 2;
		width: 100%;
		height: 212rpx;
		border-radius: 12rpx;
		margin-top: 42rpx;
		display: flex;

		.header-zuo {
			width: 148rpx;
			height: 148rpx;
			margin-top: 32rpx;
			margin-left: 30rpx;
		}

		.header-you {
			margin-left: 20rpx;

			.userName {
				font-size: 36rpx;
				font-weight: 500;
				color: #303030;
				margin-top: 56rpx;
			}

			.mobile {
				font-size: 30rpx;
				color: #BDBDBD;
				margin-top: 20rpx;
			}
		}
	}

	.settingGroup {
		box-shadow: 0px 0px 12px 0px rgba(224, 224, 224, 0.3);
		border-radius: 12rpx;
		margin-top: 30rpx;
		color: #333333;
		font-size: 30rpx;
		display: flex;
		flex-direction: column;

		.line {
			height: 118rpx;
			border-bottom: 1rpx solid #EEEEEE;
			margin: 0 38rpx 0 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.title {
				display: flex;
				align-items: center;
				width: 190rpx;
				justify-content: space-between;
			}
		}
	}
</style>