<template>
	<view>
		<view :class="'mine' + (skinNotColor ? ' not-color' : '')">
			<image src="/static/images/wdbg.png" class="wdbg"
				></image>
			<view class="minec">
				<image :src="userInfos.avatar ? userInfos.avatar : '/static/images/userimg.png'" mode="aspectFit"
					class="user" ></image>
				<view class="mines"  v-if="isLogin">
					<view class="ddflex">{{userInfos.nickName?userInfos.nickName:userInfos.username?userInfos.username:''}}
					</view>
					<text class="edu" v-if="userInfos.mobile">{{userInfos.mobile}}</text>
				</view>
				<view class="flex" v-else>
					<text class="login-btn" @click="jumpUrl('')">点击登录</text>
				</view>
				
			</view>
		</view>

		<view class="yichang-box ddflex">
			<view class="yichang-item fflex" @click="jumpUrl('warning/abnormalAlarm/abnormalAlarm')">
				<view class="yichang-title">异常告警</view>
				<view class="yichang-data">{{alarmCount}}<text class="symbol">条</text></view>
				<view class="yichang-btn">去查看</view>
				<image src="../../static/images/ycjg.png"></image>
			</view>
			<view class="yichang-item fflex" style="margin-left: 26rpx;" @click="jumpUrl('warning/orderAlarm/orderAlarm')">
				<view class="yichang-title">异常处理</view>
				<view class="yichang-data">{{exceptionOrderCount}}<text class="symbol">个</text></view>
				<view class="yichang-btn">去处理</view>
				<image src="../../static/images/yccl.png"></image>
			</view>
		</view>
		
		<view class="order">
			<view class="tits dflex">
				<view class="flex">我的服务</view>
			</view>
			<view class="list2 dflex">
				<navigator url="/pages/order/order" hover-class="none" class="li" open-type="switchTab">
					<image src="../../static/pages/images/user_service1.png"></image>
					<text>我的订单</text>
				</navigator>
				<navigator v-if="!userInfos.storeId" url="" hover-class="none" class="li" @click="jumpUrl('pages/myStore/myStore')">
					<image src="../../static/pages/images/user_service2.png"></image>
					<text>我的商家</text>
				</navigator>
				<navigator v-if="!userInfos.storeId" url="" hover-class="none" class="li" @click="jumpUrl('pages/myMerchant/myMerchant')">
					<image src="../../static/pages/images/user_service3.png"></image>
					<text>我的门店</text>
				</navigator>
				<navigator url="" hover-class="none" class="li" @click="jumpUrl('pages/operationData/operationData')">
					<image src="../../static/pages/images/user_service4.png"></image>
					<text>运营数据</text>
				</navigator>
				<view class="li">
					<contact-button img-url="../../static/pages/images/user_service5.png" img-style='width: 74rpx;height: 74rpx;margin: 0 auto 12rpx;' button-text="官方客服" styles="line-height:initial;"></contact-button>
				</view>
				<navigator url="/pages/about/about" hover-class="none" class="li">
					<image src="../../static/pages/images/user_service6.png"></image>
					<text>关于我们</text>
				</navigator>

				<navigator url="/mine/feedback/feedback" hover-class="none" class="li">
					<image src="../../static/pages/images/user_service7.png"></image>
					<text>建议反馈</text>
				</navigator>
				<navigator url="" hover-class="none" class="li" @click="logout">
					<image src="../../static/pages/images/user_service8.png"></image>
					<text>退出登录</text>
				</navigator>

			</view>
		</view>
		
		<footer-copyright></footer-copyright>
		<foot channel="user" :isUpdate="isUpdate"></foot>
	</view>
</template>

<script>
	// pages/user/user.js
	const app = getApp();
	const req = require("../../utils/request.js");
	const route = require("../../utils/route");
	import foot from "../../components/nav-bar/index";
	import footerCopyright from "../../components/footer-copyright/footer-copyright";

	export default {
		data() {
			return {
				skinNotColor: req.public.skinNotColor,
				picUrlss: req.public.picUrls,
				bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
				// merchantId: '',
				iconSrc: req.public.iconSrc,
				
				isLogin:false,
				
				userInfos: null,
				
				alarmCount:0,
				exceptionOrderCount:0
			};
		},

		components: {
			foot,
			footerCopyright
		},
		props: {},

		onLoad(options) {
			
			this.userInfos = req.getStorage('userInfo');
			if(this.userInfos){
				this.isLogin = true
			}else{
				this.isLogin = false
			}
			
		},

		onShow: function() {
			this.setData({
				isUpdate: !this.isUpdate
			});
			this.userInfos = req.getStorage('userInfo');
			if(this.userInfos){
				this.isLogin = true
				this.getUserInfo()
				this.getWarningData()
			}else{
				this.isLogin = false
			}
		},
		methods: {
			jumpUrl(url) {
				if (!req.isLogin()) return false;
				app.globalData.navigateTo(url);
			},
			getUserInfo(){
				req.getRequest('/admin/v2/userInfo',{},res=>{
					
				})
			},
			getWarningData(){
				req.getRequest('/admin/v2/alarm/alarmCount',{},res=>{
					this.alarmCount = res.alarmCount?res.alarmCount:0
					this.exceptionOrderCount = res.exceptionOrderCount?res.exceptionOrderCount:0
				})
			},
			logout(){
				uni.showModal({
					title:'提示',
					content:'确定退出登陆？',
					success: (res) => {
						if(res.confirm){
							req.removeStorage('userInfo')
							req.removeStorage('AUTH_TOKEN')
							this.userInfos =  null
							this.isLogin = false
							req.isLogins(true)
						}
					}
				})
			}
		}
	};
</script>
<style>
	@import "./user.css";
</style>
