<template>
	<view class="conatiner" :style="{paddingTop: top + 'px'}">
		<view class="header" @click="toLogin">
			<view class="avatar-container">
				<image class="avatar"
					:src="userInfo.userPic || 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_309.png'"
					mode="" />
			</view>
			<view class="login-btn">{{userInfo.user_name ? userInfo.user_name : '登录/注册'}}</view>
		</view>

		<view class="section">
			<view class="item" @click="handlePointsClick">
				<view class="item-content">
					<text class="item-title">积分</text>
					<text class="item-subtitle">我的剩余积分</text>
				</view>
				<image class="item-icon" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/5bf7d7dca1ff7_1.png">
				</image>
			</view>
			<view class="item" @click="handleSignClick">
				<view class="item-content">
					<text class="item-title">每日签到</text>
					<text class="item-subtitle">签到获取积分</text>
				</view>
				<image class="item-icon1" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_311.png" />
			</view>
		</view>

		<!-- 我的社区、申请业主、我的设备 -->
		<view class="section">
			<view class="item1">
				<view class="item_device" @click="handleCommunityClick">
					<image class="icon-community icon-img"
						src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_16.png"></image>
					<text class="community-title title-item">我的社区</text>
				</view>
				<view class="item_device" @click="handleApplyOwnerClick">
					<image class="icon-owner icon-img" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Frame.png" />
					<text class="owner-title title-item">申请业主</text>
				</view>
				<view class="item_device" @click="handleFacilityClick">
					<image class="icon-device icon-img" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Frame_1.png"/>
					<text class="device-title title-item">我的设备</text>
				</view>
				<view class="item_device" @click="handleMeApplyClick">
					<image class="icon-device icon-img" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/Group_905.png"/>
					<text class="device-title title-item">我的申请</text>
				</view>
			</view>
		</view>


		<!-- 我的订单 -->
		<view class="navigation">我的订单</view>
		<view class="order">
			<u-grid col="4" :border="false" >
				<u-grid-item  @click="headerOrderClick(item)" v-for="(item, index) in order_List" :key="index">
					<image class="nav_icon" :src="item.image" mode=""></image>
					<text class="grid-text">{{item.name}}</text>
				</u-grid-item>
			</u-grid>
		</view>
		
		<!-- 功能服务 -->
		<view class="navigation">功能服务</view>
		<view class="order">
			<u-grid col="4" :border="false" >
				<u-grid-item  @click="headerGridItemClick(item)" v-for="(item, index) in functional_List" :key="index">
					<image class="nav_icon" :src="item.image" mode=""></image>
					<text class="grid-text">{{item.name}}</text>
				</u-grid-item>
			</u-grid>
		</view>
		
		
		<view v-if="!isShop">
			<view class="navigation">商家服务</view>
			<view class="order">
				<u-grid col="4" :border="false" >
					<u-grid-item  @click="headerGridItemClick(item)" v-for="(item, index) in shopServer" :key="index">
						<image class="nav_icon" :src="item.image" mode=""></image>
						<text class="grid-text">{{item.name}}</text>
					</u-grid-item>
				</u-grid>
			</view>
		</view>

		<nav-footer />
	</view>
</template>

<script>
	import { apiArr } from '../../api/login';
  import { menuButtonInfo, NavgateTo, picUrl, request } from '../../utils/index';
	export default {
		data() {
			return {
				top: 0,
				order_List: [{
						image: "https://zhsq.hshuishang.com/Public/img/common/order12.png",
						name: "物业账单",
						type: "h5",
						url: "",
					},
					{
						image: "https://zhsq.hshuishang.com/Public/img/common/order04.png",
						name: "社区服务",
						type: "h5",
						url: "/packages/communityService/index/index",
					},
					{
						image: "https://zhsq.hshuishang.com/Public/img/common/order11.png",
						name: "商家优惠",
						type: "h5",
						url: "",
					},
					{
						image: "https://zhsq.hshuishang.com/Public/img/common/order08.png",
						name: "积分商城",
						type: "h5",
						url: "",
					},
					{
						image: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/orderIcon_1.png",
						name: "社区健康",
						type: "h5",
						url: "",
					},
					{
						image: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/orderIcon_2.png",
						name: "生活缴费",
						type: "h5",
						url: "",
					},
					{
						image: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/orderIcon_3.png",
						name: "社区商城",
						type: "h5",
						url: "",
					},
					{
						image: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/orderIcon_4.png",
						name: "周边商超",
						type: "h5",
						url: "",
					},

				],
				functional_List: [{
						"image": "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_25.png",
						"name": "生活缴费",
						"url": "",
						"type": "h5"
					},
					{
						"image": "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_26.png",
						"name": "优惠卡券",
						// "url": "/packages/user/coupon/index",
						"type": "h5"
					},
					{
						"image": "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_35.png",
						"name": "我的卡券",
						"url": "",
						"type": "h5"
					},
					{
						"image": "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_30.png",
						"name": "营销推广",
						"url": "/packages/user/marketing/index",
						"type": "h5"
					},
					{
						"image": "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_27.png",
						"name": "个人设置",
						"url": "/packages/user/index/index",
						"type": "h5"
					},
					{
						"image": "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_29.png",
						"name": "平台客服",
						"url": "/packages/WaterPurifier/pages/Addfriend/Addfriend",
						"type": "h5"
					},

					{
						"image": "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/repairList.png",
						"name": "报修列表",
						"url": "/packages/OneRepair/pages/OwnerRepairList/OwnerRepairList",
						"type": "h5"
					},

				],
				shopServer: [{
						image: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/Group_774.png",
						name: "订单核销",
						type: "",
						url: "/shopWrite/index/index",
					},
					{
						image: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/Group_774.png",
						name: "核销列表",
						type: "",
						url: "/shopWrite/list/index",
					},
				],
				userInfo: {},
				isShop: false,
			}
		},

		methods: {	
			// 头像点击
			toLogin() {
				NavgateTo('/packages/user/index/index');
			},
			
			// 积分跳转
			handlePointsClick() {
				NavgateTo('/packages/user/points/index');
			},
			
			// 每日签到跳转
			handleSignClick() {
				NavgateTo('/packages/user/pointsSign/index');
			},
			
			// 我的社区跳转
			handleCommunityClick(){
				NavgateTo('/packages/community/index/index')
			},
			
			// 申请业主跳转
			handleApplyOwnerClick(){
				NavgateTo(`/packages/community/index/index?types=2`)
			},
			
			// 我的设备跳转
			handleFacilityClick() {
				this.NotOpen();
			},
			
			// 我的申请跳转
			handleMeApplyClick() {
				NavgateTo(`/packages/community/ownerList/index`)
			},
			
			// 我的订单跳转
			headerOrderClick(event) {
				if(!event.url) {
					this.NotOpen();
					return
				} else {
					if (!uni.getStorageSync('city')) {
						wx.showModal({
						  title: '提示',
						  content: '请先选择您的城市',
						  confirmText:"去选择",
						  complete: (res) => {
						    if (res.cancel) {}
						    if (res.confirm) {
									NavgateTo( '/pages/index/shopcity')
						    }
						  }
						})
						return
					}
					console.log('选择城市');
					NavgateTo( `${event.url}`)
				}
			},
			
			// 功能服务跳转
			headerGridItemClick(event) {
				if (!event.url) {
					this.NotOpen();
					return
				}
				// 如果点击为平台客服则允许跳转
				if (event.url === '/packages/WaterPurifier/pages/Addfriend/Addfriend') {
					NavgateTo( event.url, { isLogin: false})
					return;
				}
				if (event.url) {
					NavgateTo( event.url)
				}
			},
			
			// 暂未开通服务弹窗
			NotOpen() {
				uni.showModal({
					title: '提示',
					content: '此功能暂未开通！',
					showCancel: false,
					complete: (res) => {
						if (res.cancel) {
		
						}
					}
				})
				return
			},
			
			
			async getUserInfo() {
				const isCtoken = uni.getStorageSync('ctoken');
				console.log('12313131313', isCtoken)
				if (!isCtoken) return;
				const res = await request(apiArr.loginInfo, 'POST', {});
				const newUserInfo = {
					...res,
					userPic: res.img ? `${picUrl}${res.img}` : 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/person/Group_309.png'
				};
				this.userInfo = newUserInfo;
			},
			
		},
		onLoad() {
			const meun = menuButtonInfo();
			this.top = meun.height + meun.top;
		},
		
		onShow() {
			console.log('111');
			this.getUserInfo();
		},
	}
</script>

<style>
	@import url("./index.css");
</style>