<template>
	<view class="app">
		<view class="user" v-if="appPersonallist">
			<image v-if="appPersonallist.headPictureUrl" class="img" :src="baseurl+appPersonallist.headPictureUrl"
				mode=""></image>
			<image class="img" v-else src="../../static/user.png" mode=""></image>
			<image class="bjimg" src="../../static/userbeijing.png" mode=""></image>
			<view class="phone" v-if="appPersonallist.patientName">
				{{appPersonallist.patientName}}
			</view>
			<view class="nickname">
				{{appPersonallist.phone}}
			</view>
			<view class="modify" @tap='updatainfo()'>
				修改信息
				<image src="../../static/xg.png" mode=""></image>
			</view>
		</view>
		<view class="user" v-else>
			<image class="img" src="../../static/user.png" mode=""></image>
			<image class="bjimg" src="../../static/userbeijing.png" mode=""></image>
			<view class="login" @tap='gologin'>
				登录
			</view>
		</view>
		<view class="userinfo">
			<view class="item">
				<image src="../../static/jkda.png" mode=""></image>
				<view class="text">
					健康档案
				</view>
			</view>
			<view class="item" @tap='gointegral'>
				<image src="../../static/jifen.png" mode=""></image>
				<view class="text">
					积分
				</view>
			</view>
			<view class="item" @tap="gocoupon">
				<image src="../../static/yhj.png" mode=""></image>
				<view class="text">
					优惠卷
				</view>
			</view>
		</view>
		<view class="content">
			<view class="CommodityOrder" @tap="goorder">
				<view class="title">
					商品订单
				</view>
				<view class="text">
					查看全部
					<image src="../../static/huijiantou.png" mode=""></image>
				</view>
			</view>
			<view class="center">
				<view class="OrderStatus" @tap="gopaid('WAIT_PAY')">
					<image src="/static/Tobepaid.png" mode=""></image>
					<view class="title">待付款</view>
					<view class="orderCount" v-if="list.waitPayCount>0&&list.waitPayCount<100">
						{{list.waitPayCount}}
					</view>
					<view class="orderCount" style="width: 57rpx;border-radius: 17rpx;right:25rpx"
						v-if="list.waitPayCount>=100">
						99+
					</view>
				</view>
				<view class="OrderStatus" @tap="goreceive('WAIT_RECEIVED_GOODS')">
					<image src="/static/received.png" mode=""></image>
					<view class="title">待收货</view>
					<view class="orderCount" v-if="list.waitReceivedGoodsCount>0&&list.waitReceivedGoodsCount<100">
						{{list.waitReceivedGoodsCount}}
					</view>
					<view class="orderCount" style="width: 57rpx;border-radius: 17rpx;right:25rpx"
						v-if="list.waitReceivedGoodsCount>=100">
						99+
					</view>
				</view>
				<view class="OrderStatus" @tap="gocompleted('RECEIVED_GOODS')">
					<image src="/static/evaluated.png" mode=""></image>
					<view class="title">待评价</view>
					<view class="orderCount" v-if="list.receivedGoodsCount>0&&list.receivedGoodsCount<100">
						{{list.receivedGoodsCount}}
					</view>
					<view class="orderCount" style="width: 57rpx;border-radius: 17rpx;right:25rpx"
						v-if="list.receivedGoodsCount>=100">
						99+
					</view>
				</view>
				<view class="OrderStatus" @tap="goEVALUATED('EVALUATED')">
					<image src="/static/finished.png" mode=""></image>
					<view class="title">已完成</view>
					<!-- <view class="orderCount" v-if="list.evaluatedCount>0&&list.evaluatedCount<100">
						{{list.evaluatedCount}}
					</view>
					<view class="orderCount" v-if="list.evaluatedCount>=100">
						99+
					</view> -->
				</view>
			</view>
		</view>
		<view class="service" @tap="gonursestation">
			<view class="serviceorder">护理站服务订单</view>
			<image src="../../static/huijiantou.png" mode=""></image>
		</view>
		<view class="service" style="top:1100rpx" @tap='remove'>
			<view class="serviceorder">退出账号</view>
			<image src="../../static/huijiantou.png" mode=""></image>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
	import {
		appPersonal,
		orderCount
	} from '@/api/Personal/Personal.js';
	import {
		existPatientInfo
	} from '@/api/startup/index.js'
	import baseurl from '@/api/baseurl.js'
	export default {
		data() {
			return {
				baseurl: '',
				appPersonallist: null, //获取个人信息
				timer: null,
				list: {},
			}
		},
		onShow() {
			let that = this
			this.baseurl = baseurl
			this.myInfo()
			const value = uni.getStorageSync('patientId');
			if (value) {
				orderCount(value).then(res => {
					that.list = res.data
				})
			} else {
				that.appPersonallist = null
				that.$refs.uToast.show({
					title: '请先登录',
					type: 'error',
					duration: '1000',
				})
			}
		},
		onLoad(options) {},
		methods: {
			remove() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认要退出此账号吗',
					success: function(res) {
						if (res.confirm) {
							uni.removeStorageSync('patientId');
							uni.removeStorageSync('openid');
							uni.removeStorageSync('phone');
							that.$refs.uToast.show({
								title: '退出账号成功',
								type: 'success',
								duration: '1000'
							})
							if (that.timer) {
								clearTimeout(that.timer)
							}
							that.timer = setTimeout(e => {
								uni.switchTab({
									url: '/pages/homepage/homepage'
								})
							}, 1000)
						}
					}
				});
			},
			removes() {
				uni.removeStorageSync('patientId');
				uni.removeStorageSync('openid');
				uni.removeStorageSync('phone');
				uni.removeStorageSync('Refresh');
				uni.navigateBack({
					delta: 1
				})
			},
			//获取个人信息
			myInfo() {
				var that = this
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					existPatientInfo(value).then(res => {
						if (res.code == 200 && res.msg == 'LOGIN') {
							appPersonal(value2).then(Response => {
								if (Response.code == 200) {
									that.appPersonallist = Response.data
									that.appPersonallist.homeLatitude = Number(that.appPersonallist
										.homeLatitude)
									that.appPersonallist.homeLongitude = Number(that.appPersonallist
										.homeLongitude)
								} else if (Response.code == 9999) {} else {
									that.removes();
								}
							})
						} else {
							that.removes();
						}
					})
				} else {
					that.removes();
				}
			},
			updatainfo() {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: `/pages/modify/modify`
					})
				} else {
					this.gologin();
				}
			},
			//护理站服务订单
			gonursestation() {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: '/pages/Nursingstationserviceorder/Nursingstationserviceorder'
					})
				} else {
					this.gologin();
				}
			},
			//待收货
			goreceive(item) {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: `/pages/CommodityOrder/CommodityOrder?orderStatus=${item}`
					})
				} else {
					this.gologin();
				}
			},
			//全部订单
			goorder() {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: '/pages/CommodityOrder/CommodityOrder'
					})
				} else {
					this.gologin();
				}
			},
			//去登陆
			gologin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			//优惠卷
			gocoupon() {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: '/pages/coupon/coupon'
					})
				} else {
					this.gologin();
				}
			},
			//积分页面
			gointegral() {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: '/pages/integral/integral'
					})
				} else {
					this.gologin();
				}
			},
			//已完成
			goEVALUATED(item) {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: `/pages/CommodityOrder/CommodityOrder?orderStatus=${item}`
					})
				} else {
					this.gologin();
				}
			},
			//待评价
			gocompleted(item) {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: `/pages/CommodityOrder/CommodityOrder?orderStatus=${item}`
					})
				} else {
					this.gologin();
				}
			},
			//待付款
			gopaid(item) {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: `/pages/CommodityOrder/CommodityOrder?orderStatus=${item}`
					})
				} else {
					this.gologin();
				}
			},
		},
	}
</script>
<style lang="scss">
	@import "./Personal.scss";
</style>
