<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/gssy.png" mode=""></image></view>
			<view class="money-box">
				<view class="money">{{ userInfo.profit }}</view>
				<view>总收益</view>
			</view>
		</view>
		<scroll-view :style="{ height: maxheight }" 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 class="price-box">
						共
						<text class="num">1</text>
						件商品 邮费
						<text class="price">0</text>
						实付款
						<text class="price">{{ moneyNum(item.price) }}</text>
					</view>
				</view>
				<uni-load-more :status="loadingType"></uni-load-more>
			</view>
		</scroll-view>
	</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 {
			maxheight:'',
			loadingType: 'more',
			orderList: [],
			page: 1, //当前页数
			limit: 10 //每次信息条数
		};
	},
	filters: {
		moneyNum(value) {
			return +value;
		}
	},
	onReady() {
		const that = this;
		uni.getSystemInfo({
			success: resu => {
				const query = uni.createSelectorQuery();
				query.select('.list-scroll-content').boundingClientRect();
				query.exec(function(res) {
					that.maxheight = resu.windowHeight - res[0].top + 'px';
				});
			},
			fail: res => {}
		});
	},
	onShow() {
		this.loadData();
	},
	methods: {
		// 转换金额为数字
		moneyNum(value) {
			return +value;
		},
		// 页面跳转
		navto(e) {
			uni.navigateTo({
				url: e
			});
		},
		// 点击返回 我的页面
		toBack() {
			uni.navigateBack({});
		},
		//获取收入支出信息
		async loadData(source) {
			let obj = this;
			if (obj.loadingType === 'loading'||obj.loadingType === 'nomore') {
				//防止重复加载
				return;
			}
			// 修改当前对象状态为加载中
			obj.loadingType = 'loading';
			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;
		}
	}
}
.info-box {
	width: 670rpx;
	height: 186rpx;
	background: #ffffff;
	box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
	border-radius: 20rpx;
	margin: -100rpx auto 0;
	position: relative;
	z-index: 2;
	.info-item {
		width: 50%;
		display: flex;
		flex-direction: column;
		align-items: center;
		line-height: 1;
		.info-font {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #999999;
		}
		.info-num {
			margin-top: 30rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #181818;
		}
	}
	.shu {
		width: 2rpx;
		height: 74rpx;
		background: #dcdfe6;
	}
}
.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);
}
.order-item {
	display: flex;
	flex-direction: column;
	background: #fff;
	margin-top: 16rpx;

	.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;
		}

		.del-btn {
			padding: 10rpx 0 10rpx 36rpx;
			font-size: $font-lg;
			color: $font-color-light;
			position: relative;

			&:after {
				content: '';
				width: 0;
				height: 30rpx;
				border-left: 1px solid $border-color-dark;
				position: absolute;
				left: 20rpx;
				top: 50%;
				transform: translateY(-50%);
			}
		}
	}

	/* 多条商品 */
	.goods-box {
		height: 160rpx;
		padding: 20rpx 0;
		white-space: nowrap;

		.goods-item {
			width: 120rpx;
			height: 120rpx;
			display: inline-block;
			margin-right: 24rpx;
		}

		.goods-img {
			display: block;
			width: 100%;
			height: 100%;
		}
	}

	/* 单条商品 */
	.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;
			}

			.row_title {
				padding: 5rpx 10rpx;
				background-color: #dddddd;
				border-radius: 10rpx;
				font-size: 22rpx;
				color: #ffffff;
			}

			.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;
				}
			}
		}
	}
	.buy-box {
		height: 84rpx;
		padding: 0 22rpx;
		background-color: #ffffff;
		.buy-info {
			height: 100%;
			display: flex;
			align-items: center;
			.font {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
			}
			.avter {
				margin-left: 10rpx;
				width: 46rpx;
				height: 46rpx;
				border-radius: 50%;
			}
			.buy-name {
				margin-left: 10rpx;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}
			.phone {
				margin-left: 12rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;
			}
		}
	}
	.upimg {
		padding-left: 20rpx;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		display: flex;

		.up-tit {
			display: inline-block;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #6d7c88;
		}

		.img-wrap {
			width: 153rpx;
			height: 152rpx;

			border-radius: 20rpx;

			image {
				border-radius: 20rpx;
				width: 153rpx;
				height: 152rpx;
				background-color: #ccc;
			}
		}
	}
	.price-box {
		display: flex;
		justify-content: flex-end;
		align-items: baseline;
		padding: 20rpx 30rpx;
		font-size: $font-sm + 2rpx;
		color: $font-color-light;

		.num {
			margin: 0 8rpx;
			color: $font-color-dark;
		}

		.price {
			font-size: $font-lg;
			color: $font-color-dark;

			&:before {
				content: '￥';
				font-size: $font-sm;
				margin: 0 2rpx 0 8rpx;
			}
		}
	}

	.action-box {
		padding: 0 30rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		height: 100rpx;
		position: relative;
	}

	.refuse {
		margin: 0;
		padding: 0;
		width: 160rpx;
		height: 60rpx;
		border: 2rpx solid #ebebeb;
		border-radius: 28rpx;
		text-align: center;
		line-height: 60rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		&:after {
			border-radius: 100px;
		}

		&.recom {
			color: #999999;

			&:after {
				border-color: #999999;
			}
		}
	}

	.action-btn {
		width: 160rpx;
		height: 60rpx;
		margin: 0;
		margin-left: 24rpx;
		padding: 0;
		text-align: center;
		line-height: 60rpx;
		font-size: $font-sm + 2rpx;
		color: $font-color-dark;
		background: #fff;
		border-radius: 100px;
		border: 2rpx solid #fd3b39;
		border-radius: 28px;
		&:after {
			border-radius: 100px;
		}

		&.recom {
			color: $base-color;

			&:after {
				border-color: $base-color;
			}
		}

		&.evaluate {
			color: $color-yellow;

			&:after {
				border-color: $color-yellow;
			}
		}
	}
}
</style>
