<template>
	<view class="content">

		<view class="banner">
			
			<view class="head-div flex">
				
				<view style="width: 118rpx;height: 118rpx;">
					<image style="width: 118rpx;height: 118rpx;border-radius: 50%;" :src="userInfo.headImage"></image>
				</view>
				
				<view style="padding: 10rpx 34rpx;">
					<view class="nickname">{{ userInfo.nickName }}</view>
					<view class="days">
						手机号：
						<view class="phone">{{ userInfo.phone }}</view>
					</view>
				</view>
				
			</view>
			
			<view style="position: absolute; top: 96rpx;right: 32rpx;" @click="toSetting">
				<image src="/static/icons/icon8.png" mode="aspectFit" style="width: 32rpx; height: 32rpx"></image>
			</view>
			
		</view>

		<view class="one-card">
			<view class="cart">
				<view class="collect" @click="clickCollect">
					<view class="tx">
						我的收藏
					</view>
					<view class="info">
						{{ collectNum }}位
					</view>
				</view>
				
				<view class="coupon" @click="clickCoupon">
					<view class="tx">
						我的优惠劵
					</view>
					<view class="info">
						{{ couponNum }}张
					</view>
				</view>
			</view>
		</view>

		<view class="two-card">
			<view class="flex" style="margin: 40rpx 0rpx;">
				<view style="width: 10rpx;height: 30rpx;background: #EF8C94;border-radius: 6rpx;" />
				<view class="head-title">常用功能</view>
			</view>
			
			<view class="flex flex-sb icons">
				<view class="icon-item" @click="toOrderManagement">
					<image class="icon" src="/static/icons/m1.png" />
					<view class="title">订单管理</view>
				</view>
				
				<view class="icon-item" @click="toMessage">
					<image class="icon" src="/static/icons/m2.png" />
					<view class="title">消息通知</view>
				</view>
				
				<view class="icon-item" @click="clickAddress">
					<image class="icon" src="/static/icons/m3.png" />
					<view class="title">地址管理</view>
				</view>
			</view>
			
			<view class="flex flex-sb icons">
				<view class="icon-item" @click="toComplain">
					<image class="icon" src="/static/icons/m4.png" />
					<view class="title">投诉建议</view>
				</view>
				
				<view class="icon-item" @click="clickService">
					<image class="icon" src="/static/icons/m5.png" />
					<view class="title">客服中心</view>
				</view>
				
				<view class="icon-item" @click="toEvaluate">
					<image class="icon" src="/static/icons/m6.png" />
					<view class="title">我的评价</view>
				</view>
			</view>
			
			<view class="flex flex-sb icons">
				<view class="icon-item" @click="clickSettled">
					<image class="icon" src="/static/icons/m7.png" />
					<view class="title">商家入驻</view>
				</view>
			</view>
			
		</view>

		<view style="text-align: center;color: #aaa;padding: 20px;line-height: 22px;">
			{{ copyright }}
			<br />
			{{ gs_name }}
			<br />
			{{ beian }}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {},
				couponNum: 0,
				collectNum: 0,
				copyright  : '',
				gs_name : '',
				beian : ''
			}
		},
		onShow() {
			this.getUserInfo()
			this.getCouponNum()
			this.getCollectNum()
			this.getConfig()
		},
		methods: {
			
			//获取用户信息
			getUserInfo() {
				this.$api('getUserInfo', {}, res => {
					if (res.code == 200) {
						this.userInfo = res.result;
						
						if(!res.result.phone){		//用户未绑定手机
							this.toPhoneDetail()
						}
					}
					if (res.code == 500 && res.message === '操作失败，用户不存在!') {
						localStorage.removeItem('token')
						localStorage.removeItem('userInfo')
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				})
			},
			
			//跳转设置页面
			toSetting() {
				uni.navigateTo({
					url: '/pages/mine/setting'
				})
			},
			
			//跳转收藏页面
			clickCollect() {
				uni.navigateTo({
					url: '/pages/mine/collect'
				})
			},
			
			//跳转优惠券页面
			clickCoupon() {
				uni.navigateTo({
					url: '/pages/mine/coupon'
				})
			},
			
			//跳转地址管理页面
			clickAddress() {
				uni.navigateTo({
					url: '/pages/mine/address'
				})
			},
			
			//跳转技师招募页面
			clickSettled() {
				uni.navigateTo({
					url: '/pages/mine/settled'
				})
			},
			
			//跳转我的钱包页面
			clickWallet() {
				uni.navigateTo({
					url: '/pages/mine/wallet'
				})
			},
			
			//跳转分销代理页面
			clickDistribute() {
				uni.navigateTo({
					url: '/pages/mine/distribution'
				})
			},
			
			//联系客服
			clickService() {
				uni.makePhoneCall({
					phoneNumber: this.phone,
					success: () => {},
					fail: () => {}
				});
			},
			
			//获取优惠券数量
			getCouponNum() {
				this.$api('getCouponList', {}, res => {
					if (res.code == 200) {
						this.couponNum = res.result.total;
					}
				})
			},
			
			//获取收藏技师数量
			getCollectNum() {
				this.$api('getCollectList', this.queryParams, res => {
					if (res.code == 200) {
						this.collectNum = res.result.total;
					}
				})
			},
			
			//获取配置信息
			getConfig() {
				this.$api('getConfig', {} ,res => {
					if(res.code == 200){
						res.result.forEach(item => {
							if(item.keyValue == 'phone'){
								this.phone = this.deleteTag(item.content);
							}
							if(item.keyValue == 'copyright'){
								this.copyright = item.content
							}
							if(item.keyValue == 'gs_name'){
								this.gs_name = item.content
							}
							if(item.keyValue == 'beian'){
								this.beian = item.content
							}
						})
					}
				})
			},
			
			//删除html标签
			deleteTag(html){		
				return html.replace(/<[^>]*>/g, '');
			},
			
			//跳转绑定手机页面
			toPhoneDetail(){
				uni.reLaunch({
					url : '/pages/mine/phoneDetail'
				})
			},
			
			//跳转消息通知
			toMessage(){
				uni.navigateTo({
					url: '/pages/message/message'
				})
			},
			
			//跳转投诉建议
			toComplain(){
				uni.navigateTo({
					url: '/pages/complain/complain'
				})
			},
			
			//跳转我的评价
			toEvaluate(){
				uni.navigateTo({
					url: '/pages/evaluate/evaluate'
				})
			},
			
			//跳转订单管理
			toOrderManagement(){
				uni.navigateTo({
					url: '/pages/orderManagement/orderManagement'
				})
			}
		}
	}
</script>

<style scoped>
	body {
		background-color: #f5f5f5;
	}

	.banner {
		width: 100%;
		height: calc(392rpx -160rpx);
		background: #F1B8BD;
	}

	.head-div {
		width: calc(100vw - 72rpx);
		height: 268rpx;
		padding: 72rpx 36rpx 0;
		margin: 0 auto;
	}

	.nickname {
		font-size: 36rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: 700;
		text-align: left;
		color: #fff;
		line-height: 42rpx;
	}

	.days {
		display: flex;
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		text-align: left;
		color: #fff;
		line-height: 28px;
		margin-top: 10rpx;
	}

	.bind{
		background: #e2e2e2;
		padding: 0rpx 10rpx;
		border-radius: 10rpx;
	}

	.one-card {
		width: calc(100% - 80px);
		border-radius: 16rpx;
		margin: -50rpx auto 0;
		background-color: #fff;
		padding: 20px;
	}

	.two-card {
		width: calc(100% - 60px);
		border-radius: 16rpx;
		margin: 20rpx auto;
		padding: 0rpx 10px;
		border-radius: 16px;
	}

	.title {
		height: 40rpx;
		line-height: 40rpx;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		text-align: center;
		color: #2f2e2e;
		margin-top: 15rpx;
	}

	.icon {
		margin: 0 auto;
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
	}
	
	.icon-item{
		display: flex;
		flex-direction: column;
		justify-content: center;
		width: calc(33.33% - 20rpx);
		background: #fff;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 40rpx 0rpx;
		margin-bottom: 20rpx;
	}

	.head-title {
		font-size: 30rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		color: #2f2e2e;
		line-height: 30rpx;
		margin-left: 10rpx;
		font-weight: 700;
	}


	.font-4 {
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		text-align: left;
		color: #ffffff;
		text-shadow: 0 4rpx 6rpx 0 rgba(40, 170, 133, 0.81);
		line-height: 44rpx;
		position: absolute;
		top: 32rpx;
		left: 72rpx;
		z-index: 1;
	}

	.font-5 {
		font-size: 30rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		text-align: left;
		color: #ffffff;
		line-height: 72rpx;
		text-shadow: 0 4rpx 6rpx 0 rgba(0, 0, 0, 0.16);
	}

	.button-cz {
		width: 200rpx;
		height: 58rpx;
		line-height: 58rpx;
		background: linear-gradient(182deg, #ffffff 2%, #a6fce3 88%);
		border-radius: 30rpx;
		box-shadow: 0 6rpx 12rpx 0 rgba(129, 209, 186, 0.66);

		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: 700;
		text-align: center;
		color: #3fc791;

		position: absolute;
		top: 72rpx;
		right: 52rpx;
		z-index: 1;
	}

	.cart {
		width: 100%;
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.cart>view {
		width: calc(50% - 10px);
		height: 140rpx;
		background-size: 100% 100%;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 26rpx;
		line-height: 46rpx;
	}

	.cart>view>view {}

	.cart>view>.info {
		color: #666;
		font-size: 20rpx;
	}

	.cart>view>view>text {
		font-size: 30rpx;
		font-weight: 600;
	}

	.collect {
		margin-top: 10px;
		background: url(/static/ms/merit.png);
		margin-right: 5px;
	}

	.coupon {
		margin-left: 5px;
		margin-top: 10px;
		background: url(/static/ms/meleft.png);
	}

	.cart-top {
		width: calc(100% - 20px);
		height: 30px;
		display: block;
		position: absolute;
		left: 14px;
		background-color: #666;
		top: 45px;
		border-radius: calc(30% + 10px);
	}
</style>