<template>
	<view>
		<view class="user-header" v-if="userInfo">
			<view class="avatar-btn">
				<image :src="userInfo?userInfo.avatar:'https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png'"></image>
			</view>
			<view class="user-info">
				<view class="name">{{userInfo.nickname}}</view>
				<!-- <view class="desc">180*******22</view> -->
			</view>
		</view>
		<view class="user-header" v-else>
			<view class="avatar-btn">
				<image src="https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png"></image>
			</view>
			<view class="user-info">
				<view class="name" @click="toLogin">请先登录</view>
			</view>
		</view>
		<view class="user-menu">
			<!-- <view class="menu-item">
				<view class="icon"><image src="/static/image/yuyue.png"></image></view>
				<view class="name">我的预约</view>
				<view class="right"><image src="/static/image/right.png"></image></view>
			</view>
			<view class="menu-item">
				<view class="icon"><image src="/static/image/info.png"></image></view>
				<view class="name">个人信息</view>
				<view class="right"><image src="/static/image/right.png"></image></view>
			</view> -->
			<view class="menu-item" @click="$dialog.jumpUri('/pages/user/complaint/complaint')">
				<view class="icon"><image src="/static/image/rule-rule.png"></image></view>
				<view class="name">我的投诉</view>
				<view class="right"><image src="/static/image/right.png"></image></view>
			</view>
			<view class="menu-item" @click="showService(1)">
				<view class="icon"><image src="/static/image/service.png"></image></view>
				<view class="name">商家客服</view>
				<view class="right"><image src="/static/image/right.png"></image></view>
			</view>
			<navigator hover-class="none" class="menu-item" url="/pages/user/license">
				<view class="icon"><image src="/static/image/zizhi.png"></image></view>
				<view class="name">服务资质</view>
				<view class="right"><image src="/static/image/right.png"></image></view>
			</navigator>
			<view class="menu-item" @click="outLogin">
				<view class="icon"><image src="/static/image/out.png"></image></view>
				<view class="name">退出</view>
				<view class="right"><image src="/static/image/right.png"></image></view>
			</view>
		</view>
		<uni-popup ref="maskpopup" type="bottom" border-radius="10px 10px 0 0" background-color="#ffffff" :mask-click="false">
			<view class="service-popup">
				<view class="top">
					<view class="item">客服时间：{{storeData.start_at}}-{{storeData.end_at}}</view>
					<view class="item">
						<button class="btn" @click="$dialog.jumpUri('/pages/service/chat/chat?poi='+storeData.poi_id+'&source=user',1);showService(2)">在线咨询商家</button>
					</view>
					<view class="item" v-if="storeData.service_mobile" @click="callMobile(storeData.service_mobile)">商家客服电话</view>
				</view>
				<view class="foot" @click="showService(2)">取消</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
var app;
import * as Api from "@/static/api/user.js";
export default {
	data() {
		return {
			userInfo:null,
			storeData:{}
		}
	},
	onShow() {
		this.getUser()
	},
	onLoad() {
		app = this;
		app.storeData = uni.getStorageSync("contact");
	},
	methods: {
		getUser(){
			Api.data().then((res)=>{
				if (res.code == 0) {
					return ;
				}
				app.userInfo = res.data;
			})
		},
		outLogin(order){
			app.$dialog.showError("确定要退出登录吗",function(res){
				if (res.confirm) {
					app.userInfo = null;
					uni.clearStorageSync();
				}
			})
		},
		toLogin(){
			uni.navigateTo({
				url:"/pages/auth/login",
				animationType:"slide-in-bottom"
			})
		},
		callMobile(mobile){
			uni.makePhoneCall({
				phoneNumber:mobile,
				success(res) {
					console.log(res)
				},fail(res) {
					console.log(res)
				}
			})
		},
		showService(type){
			if (type == 1) {
				uni.hideTabBar()
				app.$refs.maskpopup.open()
			} else {
				this.$nextTick(() => {
					uni.showTabBar()
				})
				app.$refs.maskpopup.close()
			}
		}
	}
}
</script>

<style>
page{background-color: #f8f8f8;}
.user-header{padding: 40upx;display: flex;align-items: center;background-color: #007aff;}
.user-header image{width: 100upx;height: 100upx;border-radius: 100upx;}
.user-header .user-info{margin-left: 20upx;}
.user-header .name{font-size: 32upx;color: #fff;}
.user-header .desc{font-size: 24upx;color: #f8f8f8;margin-top: 20upx;}
.user-menu{width: 95%;margin: 40upx auto;border-radius: 10upx;background-color: #fff;}
.user-menu .menu-item{height: 100upx;line-height: 100upx;display: flex;align-items: center;font-size: 28upx;color: #333;padding: 0 20upx;border-bottom: 2upx solid #f8f8f8;}
.user-menu .menu-item .icon{margin-right: 20upx;display: flex;align-items: center;justify-content: center;}
.user-menu .menu-item .right{margin-right: 0;margin-left: auto;}
.user-menu .menu-item .icon image{width: 40upx;height: 40upx;}
.user-menu .menu-item .right image{width: 40upx;height: 40upx;}

.service-popup .item{height: 100upx;line-height: 100upx;text-align: center;font-size: 28upx;color: #333;border-bottom: 2upx solid #f8f8f8;}
.service-popup .item .btn{background-color: #fff;border: 0;height: 100upx;line-height: 100upx;text-align: center;font-size: 28upx;color: #333;}
.service-popup .item .btn::after{border: 0;}
.service-popup .foot{height: 100upx;line-height: 100upx;text-align: center;font-size: 28upx;color: #333;border-top: 20upx solid #f8f8f8;}
</style>
