<template>
	<view>
		<view class="my_top">
			<image src="../../static/images/top-bg.png" class="bg"></image>
		</view>
		<view class="list animated fadeInDown">
			<view class="uni-flex uni-row center">
				<view class="wallet">
					<text>我的服务点数</text>
					<text class="num">{{ user.wallet }}</text>					
				</view>
			</view>
		</view>
		<view class="uni-flex uni-row" style="padding:1rem; ">
			<button type="primary" style="-webkit-flex: 1;flex: 1;" @click="goto('/pages/wallet/topup/edit')">充值</button>
			<view class="text" style="width: 15rpx;"></view>
			<button type="default" style="-webkit-flex: 1;flex: 1;" @click="goto('/pages/wallet/topdown/edit')">兑现</button>
		</view>
		<view class="tab">
			<u-tabs :list="tab" @click="click" :lineHeight="5"></u-tabs>
		</view>
		<view class="goodsList">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">	
				<view class="title">{{ item.tagTypeName }}
					<view class="state" v-if="item.tagType == 1 ">
						<text class="icon" style="color:#13ce66">&#xe830;</text>
						<text>+{{ item.amount }}</text>
					</view>
					<view class="state" v-if="item.tagType == 2 ">
						<text class="icon" style="color:#FF2222">&#xe830;</text>
						<text>-{{ item.amount }}</text>
					</view>
					<view class="state" v-if="item.tagType == 3 ">
						<text class="icon" style="color:#CC8855">&#xe830;</text>
						<text>-{{ item.amount }}</text>
					</view>
				</view>
				<view class="op">					
					<view class="date">{{ item.recordTime }}</view>
				</view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				tab: [{
						name: '全部',
						tagType: ''
					},
					{
						name: '充值',
						tagType: '1'
					},
					{
						name: '兑现',
						tagType: '2'
					},
					{
						name: '扣除',
						tagType: '3'
					}
				],
				param: {
					pageNo: 1,
					pageSize: 10,
					tagType:''
				},
				list: [],
				loadMore: true,
			};
		},
		onLoad() {
			this.user = this.getUser()
		},
		onShow() {
			this.user = this.getUser();
			this.getData();
		},
		methods: {
			getData() {
				this.param.peopleId = this.user.fkId;
				this.http.request({
					url: '/level-one-server/app/WalletManage/getList',
					loading: 'false',
					data: this.param,
					success: res => {
						this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
						if (res.data.data) {
							this.list = res.data.data;
						}
					}
				});
			},
			// 点击tab切换
			click(e) {
				this.param.tagType = e.tagType;
				this.refresh()
			},
			detail(item) {
				let urlStr=''
				if(item.tagType==1){
					urlStr='/pages/wallet/topup/detail?id='
				}
				if(item.tagType==2){
					urlStr='/pages/wallet/topdown/detail?id='
				}
				if(item.tagType==3){
					urlStr='/pages/wallet/detail?id='
				}
				uni.navigateTo({
					url: urlStr + item.id
				});
			},
			goto(url) {
				uni.navigateTo({ url: url });
			},
			// 刷新数据
			refresh() {
				this.loadMore = true;
				this.param.pageNo = 1;
				this.list = [];
				this.getData();
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.refresh();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		//上拉加载
		onReachBottom() {
			if (this.loadMore) {
				this.param.pageNo++;
				this.getData();
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #f5f5f5;
	}
	.my_top {
		position: relative;
		overflow: hidden;
		image {
			width: 100%;
		}
	}
	.uni-flex {
		display: flex;
		flex-direction: row;
	}
	.uni-flex-item {
		flex: 1;
	}
	.uni-row {
		flex-direction: row;
	}
	.list {
		position: relative;
		padding: 0px 20px 10px 20px;
		margin-top: -226px;
		.center{
			-webkit-justify-content: center;
			justify-content: center;
			text-align: center;
			.wallet {
				display: flex;
				flex-direction: column;
				background-color: white;
				width: 15rem;
				height: 7rem;
				border-radius: 50%;
				.num {
					color: #0000CC;
					font-size: 43px;					
				}
			}
			.rbtn {			
				padding-left: 15px;
				width: 60%;
			}
		}
	}
	.state {
		margin-right: -70px;
	}

	.down_btn {
		color: #f0f4f7;
		width: 100px;
		background: #f9ae3d;
		text-align: center;
		border-radius: 10px;
		font-size: 12px;
		padding: 2px 5px;
	}
</style>