<template>
	<view class="content">
		<view class="top hflex acenter jbetween">
			<view class="hflex acenter" @click="toLogin">
				<u-avatar :src="user.headimg"></u-avatar>
				<view class="user_name">{{user.nickname?user.nickname:'请先登录'}}</view>
			</view>
			<view class="message hflex acenter jcenter">
				<image src="/static/images/mine/message.png" style="width: 48rpx;height: 48rpx;"></image>
				<u-badge max="99" :absolute="true" :offset="[1,1]" :value="user.message_num" v-if="user.message_num>0"></u-badge>
			</view>
		</view>
		<view class="box">
			<view class="amount hflex acenter jbetween" @click="toMoney">
				<view class="amount_left">我的余额</view>
				<view class="amount_right">￥{{user.money}}</view>
			</view>
			<view class="order">
				<view class="order_top hflex acenter jbetween">
					<view class="order_title">商城订单</view>
					<view class="order_right">查看全部</view>
				</view>
				<view class="order_list hflex acenter jcenter">
					<block v-for="(item,index) in orderList" :key="index">
						<view class="order_item vflex acenter jcenter">
							<image :src="item.img" style="width: 52rpx;height: 52rpx;"></image>
							<u-badge :absolute="true" :offset="[1,20]" max="99" :value="item.number" v-if="item.number>0"></u-badge>
							<view class="order_text">{{item.name}}</view>
						</view>
					</block>
				</view>
			</view>
			<view class="cell">
				<view class="cell_item hflex acenter jbetween" @click="toService(1)">
					<view class="hflex acenter">
						<image src="/static/images/mine/cell1.png" style="width: 40rpx;height: 40rpx;"></image>
						<view class="cell_text">采购订单</view>
					</view>
					<u-icon name="arrow-right" color="#888888" size="12"></u-icon>
				</view>
				<view class="cell_item hflex acenter jbetween" @click="toService(2)">
					<view class="hflex acenter">
						<image src="/static/images/mine/cell2.png" style="width: 40rpx;height: 40rpx;"></image>
						<view class="cell_text">商家详情</view>
					</view>
					<u-icon name="arrow-right" color="#888888" size="12"></u-icon>
				</view>
				<view class="cell_item hflex acenter jbetween" @click="toService(3)">
					<view class="hflex acenter">
						<image src="/static/images/mine/cell3.png" style="width: 40rpx;height: 40rpx;"></image>
						<view class="cell_text">意见反馈</view>
					</view>
					<u-icon name="arrow-right" color="#888888" size="12"></u-icon>
				</view>
				<view class="cell_item hflex acenter jbetween" @click="toService(4)">
					<view class="hflex acenter">
						<image src="/static/images/mine/cell4.png" style="width: 40rpx;height: 40rpx;"></image>
						<view class="cell_text">平台规则</view>
					</view>
					<u-icon name="arrow-right" color="#888888" size="12"></u-icon>
				</view>
				<view class="cell_item hflex acenter jbetween" @click="toService(5)">
					<view class="hflex acenter">
						<image src="/static/images/mine/cell5.png" style="width: 40rpx;height: 40rpx;"></image>
						<view class="cell_text">设置</view>
					</view>
					<u-icon name="arrow-right" color="#888888" size="12"></u-icon>
				</view>
			</view>
		</view>
		<custom-tab-bar :current="3" />
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				user: {
					message_num: 12
				},
				login: true,
				orderList: [
					{
						img: '/static/images/mine/order1.png',
						name: '待付款',
						number: 12
					},
					{
						img: '/static/images/mine/order2.png',
						name: '待发货',
						number: 4
					},
					{
						img: '/static/images/mine/order3.png',
						name: '待收货',
						number: 0
					},
					{
						img: '/static/images/mine/order4.png',
						name: '退款/售后',
						number: 0
					}
				]
			}
		},
		onLoad() {
			that = this
		},
		onShow() {
			that.isLogin()
			that.getUser()
		},
		methods: {
			getUser() {
				$api.req({
					url: '/data/api.business.User/user_info'
				}, function(res) {
					if(res.code == 1) {
						that.user = res.data
					} else if(res.code == 0) {
						uni.removeStorageSync('token')
						that.login = false
						that.user = {}
					}
				})
			},
			isLogin() {
				var token = uni.getStorageSync('token')
				if(token) {
					that.login = true
				} else {
					that.login = false
				}
			},
			toLogin() {
				if(!that.login) {
					$api.jump('/pages/login/login/login')
				}
			},
			toMoney() {
				if(that.login) {
					$api.jump('/pages/mine/wallet/wallet')
				} else {
					$api.info('请先登录')
				}
			},
			toService(index) {
				var url = ''
				switch(index) {
					case 1 : 
						url = '/pages/mine/service/feed/feed';
						break;
					case 2 :
						url = '/pages/mine/service/feed/feed';
						break;
					case 3 :
						url = '/pages/mine/service/feed/feed';
						break;
					case 4 :
						url = '/pages/mine/service/feed/feed';
						break;
					case 5 :
						url = '/pages/mine/service/setting/setting';
						break;
				}
				if(that.login) {
					$api.jump(url)
				} else {
					$api.info('请先登录')
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		background: url('/static/images/mine/bg.png') no-repeat;
		background-size: 100%;
		// padding: 0 30rpx;
		.top {
			width: 100%;
			padding: 188rpx 0 0 30rpx;
			.user_name {
				font-size: 36rpx;
				font-weight: 500;
				color: #222222;
				line-height: 50rpx;
				padding-left: 16rpx;
			}
			.message {
				width: 104rpx;
				height: 68rpx;
				background: rgba(255,255,255,0.6);
				border-radius: 28rpx 0px 0px 28rpx;
				position: relative;
			}
		}
		.box {
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			.amount {
				width: 100%;
				height: 144rpx;
				box-sizing: border-box;
				padding: 0 24rpx;
				margin: 36rpx 0 20rpx;
				background: url('/static/images/mine/amount_bg.png') no-repeat;
				background-size: 100%;
				.amount_left {
					font-size: 30rpx;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 42rpx;
				}
				.amount_right {
					font-size: 48rpx;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 58rpx;
				}
			}
			.order {
				width: 100%;
				height: 240rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				.order_top {
					padding: 24rpx 30rpx 0;
					.order_title {
						font-size: 28rpx;
						font-weight: 500;
						color: #0A0A0A;
						line-height: 40rpx;
					}
					.order_right {
						font-size: 22rpx;
						font-weight: 400;
						color: #B4B4B4;
						line-height: 32rpx;
					}
				}
				.order_list {
					padding: 32rpx 0;
					.order_item {
						width: 25%;
						position: relative;
						.order_text {
							font-size: 24rpx;
							font-weight: 400;
							color: #0A0A0A;
							line-height: 34rpx;
							padding-top: 26rpx;
						}
					}
				}
			}
			.cell {
				margin: 20rpx 0 110rpx;
				width: 100%;
				height: 588rpx;
				background: #FFFFFF;
				border-radius: 20px;
				box-sizing: border-box;
				padding: 0 30rpx;
				.cell_item {
					height: 116rpx;
					padding: 34rpx 0;
					border-bottom: 1rpx solid #F4F4F4;
					.cell_text {
						padding-left: 20rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #222222;
						line-height: 36rpx;
					}
				}
				.cell_item:nth-last-child(1) {
					border-bottom: none;
				}
			}
		}
	}
</style>
