<template>
	<view class="main">
		<view class="tips">
			<text class="icon">&#xe694;</text>
			<text>账户余额保障中</text>
		</view>
		<view class="mcard">
			<view class="money">{{ money }}</view>
			<view class="desc">账户余额（元）</view>
			<view class="flex">
				<view class="f">
					<button class="btn" style="background-color: #607d8b" @click="go('/pages/user/money/cash_out')">
						<text class="icon">&#xe612;</text>
						<text>提现</text>
					</button>
				</view>
				<view class="f">
					<button class="btn" @click="go('/pages/user/money/add')">
						<text class="icon">&#xe7c4;</text>
						<text>充值</text>
					</button>
				</view>
			</view>
		</view>
		<view class="tab">
			<u-tabs :list="type" @click="click($event, 'type')"></u-tabs>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="popup(item)">
				<view class="title">{{ item.title }}</view>
				<view class="desc">
					<text v-if="item.state == 0 && item.type == 0 && item.payWay == 0" style="color: #f44336">未支付</text>
					<text v-if="item.state == 0 && item.type == 0 && item.payWay == 1" style="color: #f44336">待审核</text>
					<text v-if="item.state == 1 && item.type == 0" style="color: #4caf50">充值成功</text>
					<text v-if="item.state == 1 && item.type == 1" style="color: #4caf50">兼职支出</text>
					<text v-if="item.state == 0 && item.type == 2" style="color: #f44336">提现审核中...</text>
					<text v-if="item.state == 1 && item.type == 2" style="color: #4caf50">提现成功</text>
					<text v-if="item.state == 1 && item.type == 3" style="color: #4caf50">兼职收入</text>
					<text v-if="item.state == 2 && item.type == 2" style="color: #f44336">
						<text class="icon" style="padding-right: 5px">&#xe610;</text>
						<text>提现失败，退回余额</text>
					</text>
					<text v-if="item.state == 2 && item.payWay == 1" style="color: #f44336">
						<text class="icon" style="padding-right: 5px">&#xe610;</text>
						<text>审核失败</text>
					</text>
					<text v-if="item.state == 1 && item.type == 4" style="color: #4caf50">退款成功</text>
					<text>{{ item.createTime }}</text>
				</view>
				<view class="price">
					<text v-if="item.type == 0 || item.type == 3 || item.type == 4" style="color: orangered">+{{ item.money }}元</text>
					<text v-if="item.type == 1" style="color: darkgray">-{{ item.money }}元</text>
					<text v-if="item.type == 2 && item.state == 0" style="color: darkgray">-{{ item.money }}元</text>
					<text v-if="item.type == 2 && item.state == 1" style="color: darkgray">-{{ item.money }}元</text>
					<text v-if="item.type == 2 && item.state == 2" style="color: #f44336">+{{ item.money }}元</text>
				</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>
		<u-popup :show="show" round="15" mode="center" :closeable="true" :customStyle="{ width: '95%' }" @close="show = false">
			<view class="popup">
				<view class="mtt" v-if="item.type == 0 && item.payWay == 0">微信充值</view>
				<view class="mtt" v-if="item.type == 0 && item.payWay == 1">转账充值</view>
				<view class="mtt" v-if="item.type == 1">兼职支出</view>
				<view class="mtt" v-if="item.type == 2">余额提现</view>
				<view class="mtt" v-if="item.type == 3">兼职收入</view>
				<view class="mtt" v-if="item.type == 4">余额退款</view>
				<view>
					<view class="item">
						<text class="tt">操作内容</text>
						<text class="la">{{ item.title }}</text>
					</view>
					<view class="item" v-if="item.type == 0">
						<text class="tt">充值金额</text>
						<text class="la">¥{{ item.money }}</text>
					</view>
					<view class="item" v-if="item.type == 1">
						<text class="tt">兼职金额</text>
						<text class="la">¥{{ (item.money - item.serviceMoney).toFixed(2) }}</text>
					</view>
					<view class="item" v-if="item.type == 2">
						<text class="tt">提现金额</text>
						<text class="la">¥{{ item.money }}</text>
					</view>
					<view class="item" v-if="item.type == 3">
						<text class="tt">收入金额</text>
						<text class="la">¥{{ item.money }}</text>
					</view>
					<view class="item" v-if="item.type == 4">
						<text class="tt">兼职金额</text>
						<text class="la">¥{{ item.money }}</text>
					</view>
					<view class="item" v-if="item.serviceMoney">
						<text class="tt">服务费</text>
						<text class="la">¥{{ item.serviceMoney }}</text>
					</view>
					<view class="item" v-if="item.rate">
						<text class="tt">{{ item.type == 1 ? '兼职费率' : '提现费率' }}</text>
						<text class="la">{{ item.rate }}%</text>
					</view>
					<view class="item" v-if="item.type == 1">
						<text class="tt">实际扣除</text>
						<text class="la">¥{{ item.money }}</text>
					</view>
					<view class="item" v-if="item.type == 2">
						<text class="tt">实际到账</text>
						<text class="la">¥{{ (item.money - item.serviceMoney).toFixed(2) }}</text>
					</view>
					<view class="item">
						<text class="tt">操作状态</text>
						<text class="la" v-if="item.state == 0 && item.type == 0 && item.payWay == 0" style="color: #f44336">未支付</text>
						<text class="la" v-if="item.state == 0 && item.type == 0 && item.payWay == 1" style="color: #f44336">待审核</text>
						<text class="la" v-if="item.state == 2 && item.type == 0 && item.payWay == 1" style="color: #f44336">审核不通过</text>
						<text class="la" v-if="item.state == 1 && item.type == 0" style="color: #4caf50">充值成功</text>
						<text class="la" v-if="item.state == 1 && item.type == 1" style="color: #4caf50">支出成功</text>
						<text class="la" v-if="item.state == 0 && item.type == 2" style="color: #f44336">提现审核中...</text>
						<text class="la" v-if="item.state == 1 && item.type == 2" style="color: #4caf50">提现成功</text>
						<text class="la" v-if="item.state == 1 && item.type == 3" style="color: #4caf50">入账成功</text>
						<text class="la" v-if="item.state == 2 && item.type == 2" style="color: #f44336">提现失败，退回余额</text>
						<text class="la" v-if="item.state == 1 && item.type == 4" style="color: #4caf50">退款成功</text>
					</view>
					<view class="item" v-if="item.type == 0 && item.payWay == 1">
						<text class="tt">转账凭证</text>
						<view class="la">
							<image :src="ip + item.certificate" mode="aspectFill" @click="preview(item.certificate)"></image>
						</view>
					</view>
					<view class="item" v-if="item.state == 2 && item.msg">
						<text class="tt">失败原因</text>
						<text class="la" style="color: #f44336">{{ item.msg }}</text>
					</view>
					<view class="item">
						<text class="tt">创建时间</text>
						<text class="la">{{ item.createTime }}</text>
					</view>
					<view class="item" v-if="item.completeTime">
						<text class="tt">审核时间</text>
						<text class="la">{{ item.completeTime }}</text>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	data() {
		return {
			ip: this.http.ip,
			money: 0,
			current: 0,
			type: [
				{ name: '全部', value: '' },
				{ name: '充值', value: 0 },
				{ name: '支出', value: 1 },
				{ name: '提现', value: 2 },
				{ name: '收入', value: 3 },
				{ name: '退款', value: 4 }
			],
			list: [],
			param: { pageNum: 1, pageSize: 10 },
			loadMore: true,
			show: false,
			item: {}
		};
	},
	onLoad(e) {
		this.getInfo();
		this.getData();
		uni.$on('payMoney', (res) => {
			this.getInfo();
			this.refresh();
		});
	},
	methods: {
		getInfo() {
			this.http.request({
				url: '/app/user/info',
				success: (res) => {
					this.money = res.data.data.money;
					uni.setStorageSync('money', res.data.data.money || 0);
				}
			});
		},
		getData() {
			this.http.request({
				url: '/app/pay/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					this.list.push(...res.data.rows);
				}
			});
		},
		click(e) {
			this.param.type = e.value;
			this.refresh();
		},
		popup(item) {
			this.item = item;
			this.show = true;
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		preview(certificate) {
			uni.previewImage({
				urls: [this.ip + certificate],
				current: this.ip + certificate,
				success: (res) => {}
			});
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			this.getInfo();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.main {
	padding-top: 5px;
}
.tips {
	border-radius: 5px;
	margin-bottom: 8px;
}
.list {
	background-color: white;
	border-radius: 8px;
	padding: 15px 15px 15px 15px;
	.item {
		padding: 15px 0px 15px 0px;
		border-bottom: 1px solid $line;
		padding-bottom: 10px;
		&:first-child {
			padding-top: 0px;
		}
		&:last-child {
			border: 0px;
			padding-bottom: 5px;
		}
		.title {
			width: 70%;
		}
		.desc {
			font-size: 14px;
			padding-top: 5px;
			color: $font-c;
			text {
				padding-right: 15px;
			}
		}
		.price {
			float: right;
			margin-top: -48px;
		}
	}
}
</style>
