<template>
	<view class="content">
		<view class="content-money">
			<view class="status_bar"><!-- 这里是状态栏 --></view>
			<view class="body-title">
				<view class="goback-box" @click="toBack">
					<image class="goback" src="../../static/icon/fanhui.png" mode=""></image>
				</view>
				<view class="header">我的奖金</view>
			</view>
			<view class="content-bg">
				<image src="../../static/img/myfans.png" mode=""></image>
			</view>
			<view class="money-box">
				<view class="money">{{ userInfo.brokerage_price || 0 }}</view>
				<view>当前余额</view>
			</view>
		</view>
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<!-- 空白页 -->
			<empty v-if="orderList.length === 0"></empty>

			<!-- 订单列表 -->
			<view v-else>
				<view v-for="(item, index) in orderList" :key="index" class="order-item">
					<view class="i-top b-b">
						<text class="time">{{ item.order_id }}</text>
						<text class="state" :style="{ color: item.stateTipColor }">{{ item.stateTip }}</text>
					</view>

					<view class="goods-box-single">
						<image class="goods-img" :src="item.image" mode="aspectFill"></image>
						<view class="right">
							<text class="title clamp">{{ item.name }}</text>
							<text class="attr-box">x1</text>
							<text class="price">{{ moneyNum(item.price) }}</text>
						</view>
					</view>
				</view>
				<uni-load-more :status="loadingType"></uni-load-more>
			</view>
		</scroll-view>
		<navigator url="./yjchange">
		<view class="action-btn">佣金转账</view>
		</navigator>
	</view>
</template>

<script>
	import {
		seller
	} from '@/api/order.js';
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import uniLoadMore from '@/uview-ui/components/u-loadmore/u-loadmore.vue';
	import empty from '@/uview-ui/components/u-empty/u-empty.vue';
	export default {
		filters: {
			getMoneyStyle
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
		},
		components: {
			empty,
			uniLoadMore
		},
		data() {
			return {
				loadingType: 'more',
				orderList: [],
				page: 1, //当前页数
				limit: 10 //每次信息条数
			};
		},
		filters: {
			moneyNum(value) {
				return +value;
			}
		},
		onShow() {
			this.loadData();
		},
		methods: {
			// 转换金额为数字
			moneyNum(value) {
				return +value;
			},
			// 页面跳转
			navto(e) {
				uni.navigateTo({
					url: e
				});
			},
			// 点击返回 我的页面
			toBack() {
				uni.reLaunch({
					url:'/pages/user/user'
				})
			},
			//获取收入支出信息
			async loadData(source) {
				let obj = this;
				seller({
						type: 3,
						page: obj.page,
						limit: obj.limit
					})
					.then(({
						data
					}) => {
						let arr = data.map(e => {
							e.stateTip = '已完成';
							e.stateTipColor = '#909399';
							return e;
						});
						obj.orderList = obj.orderList.concat(arr);

						// console.log(navItem.orderList);
						obj.page++;
						if (obj.limit == data.length) {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							obj.loadingType = 'more';
							return;
						} else {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							obj.loadingType = 'noMore';
						}
						uni.hideLoading();
					})
					.catch(e => {
						console.log(e);
					});
			},

			//swiper 切换
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				this.loadData('tabChange');
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #f1f1f1;
		height: 100%;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.content-money {
		position: relative;
		height: 400rpx;

		.content-bg {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			width: 750rpx;
			height: 400rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.body-title {
			height: 80rpx;
			text-align: center;
			font-size: 35rpx;
			position: relative;

			.header {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #fffeff;
				height: 80rpx;
				font-size: 36rpx;
				font-weight: 700;
				z-index: 9;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.goback-box {
				position: absolute;
				left: 18rpx;
				top: 0;
				height: 80rpx;
				display: flex;
				align-items: center;
			}

			.goback {
				z-index: 100;
				width: 34rpx;
				height: 34rpx;
			}
		}
	}


	.money-box {
		position: relative;
		z-index: 2;
		padding-top: 90rpx;
		color: #ffffff;
		text-align: center;

		.money {
			font-size: 72rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #ffffff;
		}

		.text {
			font-size: 30rpx;
		}
	}

	.list-scroll-content {
		height: calc(100% - 175px);
		padding-top: 30rpx;
	}

	.order-item {
		display: flex;
		flex-direction: column;
		border-radius: 20rpx;
		background: #fff;
		margin: 0rpx 30rpx 30rpx 30rpx;


		.i-top {
			display: flex;
			align-items: center;
			height: 80rpx;
			font-size: $font-base;
			color: $font-color-dark;
			position: relative;
			padding: 0 30rpx;

			.time {
				flex: 1;
			}

			.state {
				color: $base-color;
			}

		}

		/* 单条商品 */
		.goods-box-single {
			display: flex;
			padding: 20rpx 30rpx;

			// background: #f7f7f7;
			.goods-img {
				display: block;
				width: 120rpx;
				height: 120rpx;
			}

			.right {
				flex: 1;
				display: flex;
				flex-direction: column;
				padding: 0 0 0 24rpx;
				overflow: hidden;

				.row {
					margin-top: 10rpx;
				}


				.title {
					font-size: $font-base + 2rpx;
					color: $font-color-dark;
					line-height: 1;
					width: 80%;
				}

				.attr-box {
					display: flex;
					justify-content: flex-end;
					font-size: $font-sm + 2rpx;
					color: $font-color-light;
				}

				.price {
					display: inline;
					font-size: $font-base + 2rpx;
					color: $font-color-dark;

					&:before {
						content: '￥';
						font-size: $font-sm;
					}
				}
			}
		}
	}

	.action-btn {
		position: fixed;
		bottom: 0rpx;
		left: 0rpx;
		width: 750rpx;
		text-align: center;
		font-size: $font-lg;
		color:#E6C79D;
		background: #fff;
		border: 2rpx solid #E6C79D;
		padding: 20rpx;
	}
</style>