<template>
	<view class="good-list">
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<!-- 空白页 -->
			<!-- #ifdef H5 -->
			<empty src="../../static/error/emptyMyCart.png"
				v-if="navList[tabCurrentIndex].loaded === true && navList[tabCurrentIndex].orderList.length === 0">
			</empty>
			<!-- #endif -->
			<!-- #ifndef H5 -->
			<empty src="../static/error/emptyMyCart.png"
				v-if="navList[tabCurrentIndex].loaded === true && navList[tabCurrentIndex].orderList.length === 0">
			</empty>
			<!-- #endif -->
			<view @click="navTo( '/pages/order/orderDetail?id=' + item.order_id )"
				v-for="(item, index) in navList[tabCurrentIndex].orderList" :key="index" class="order-item position-relative">
				<view class="i-top b-b flex">
					<view class="order-code flex">
						<view class="no">
							订单编号:
						</view>
						<view>
							{{ item.order_id }}
						</view>
					</view>
					<text class="font-size-sm font-color-gray" >已完成</text>
				</view>
				<scroll-view class="goods-box" scroll-x>
					<view class="goods-item">
						<image class="goods-img" :src="item.cart_info.productInfo.image" mode="aspectFill">
						</image>
						<view class="good-name clamp">
							{{item.cart_info.productInfo.attrInfo.suk}}*{{item.cart_info.cart_num}}
						</view>
					</view>
				</scroll-view>
				<view class="info-info">
					<view class="js">
						<!-- 共{{item.cartInfo.length}}件 -->
					</view>
					<view class="hj">
						合计:{{+item.number}}/张
					</view>
				</view>
				<!-- 底部操作栏 -->
				<view class="btm-btn-wrap flex">
					<view class="btm-left">
						下单时间：{{item.day}}
					</view>
					<view class="btm-right flex">
					</view>
				</view>
			</view>
			<uni-load-more :status="navList[tabCurrentIndex].loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import {
		use_certificate
	} from '@/api/water.js';
	export default {
		data() {
			return {
				tabCurrentIndex: 0,
				navList: [{
					state: 0,
					text: '全部',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				}]
			};
		},
		computed: {
			allNumber() {
				const item = this.navList[0].orderList;
				let num = 0;
				for (let i = 0; i < item.length; i++) {
					num += item[i].certificate_num
				}
				return num
			}
		},
		onReachBottom() {
			this.getGoodList();
		},
		onLoad: function(option) {
			this.getGoodList();
		},
		methods: {
			// 返回退回
			back() {
				uni.reLaunch({
					url: '/pages/home/user'
				})
			},
			// 加载数据
			getGoodList(source) {
				//这里是将订单挂载到tab列表下
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				let state = navItem.state;
				console.log(navItem, '数据');
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				if (navItem.loadingType === 'loading') {
					//防止重复加载
					return;
				}
				if (navItem.loadingType === 'noMore') {
					//防止重复加载
					return;
				}
				// 修改当前对象状态为加载中
				navItem.loadingType = 'loading';

				use_certificate({
							page: navItem.page,
							limit: navItem.limit
						})
					.then(({
						data
					}) => {
						let arr = data.data
						console.log(arr,'arr');
						navItem.orderList = navItem.orderList.concat(arr);
						navItem.page++;
						if (navItem.limit == arr.length) {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'more';
							return;
						} else {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'noMore';
						}
						uni.hideLoading();
						this.$set(navItem, 'loaded', true);
					})
					.catch(e => {
						console.log(e);
					});
			},
		}
	};
</script>


<style lang="scss">
	.good-list {
		width: 750rpx;
		height: 100%;

		.good {
			background: #FFFFFF;
			box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
			width: 100%;
			border-radius: 14rpx;
			margin-bottom: 20rpx;
			position: relative;
			padding: 20rpx;

			.good-image {
				width: 180rpx;
				height: 180rpx;
				background-color: #eee;
				border-radius: 10rpx;
				flex-shrink: 0;

			}

			.right {
				height: 180rpx;
				position: relative;

				.good-name {
					font-size: 28rpx;
					font-weight: bold;
					color: #333333;
					padding-left: 20rpx;
				}

				.good-key {
					font-size: 22rpx;
					font-weight: 500;
					color: #999999;
					padding-left: 20rpx
				}

				.good-price {
					font-size: 28rpx;
					font-weight: bold;
					position: absolute;
					bottom: 0rpx;
					padding: 0 20rpx;
					left: 0;
					right: 0rpx;
					.num{
						color:$color-red;
					}
				}
			}
		}
	}

	.list-scroll-content {
		height: calc(100% - 200px - var(--status-bar-height));
		padding: 20rpx;
	}
	.order-item {
		padding-left: 30rpx;
		padding-right: 30rpx;
		margin: 0 30rpx;
		margin-bottom: 30rpx;
		border-radius: 30rpx;
		background: #fff;
		color: #A8ADBF;
	
		.i-top {
			height: 80rpx;
			.order-code{
				font-size: $font-sm;
				.no{
					padding: 10rpx 10rpx;
					background-color: #FFEAE5;
					color: #FD5B23;
					line-height: 1;
					border-top-right-radius: 10rpx;
					border-bottom-left-radius: 10rpx;
					margin-right: 10rpx;
					
				}
			}
			
			.del-btn {
				padding: 10rpx 0 10rpx 36rpx;
				font-size: $font-lg;
				position: relative;
	
				&:after {
					content: '';
					width: 0;
					height: 30rpx;
					border-left: 1px solid $border-color-dark;
					position: absolute;
					left: 20rpx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
	
		.info-info {
			width: 215rpx;
			height: 200rpx;
			position: absolute;
			top: 80rpx;
			right: 35rpx;
			display: flex;
			flex-direction: column;
			justify-content: flex-end;
			align-items: flex-end;
			font-size: 30rpx;
			font-weight: 500;
	
			.hj {
				padding-top: 40rpx;
				color: $font-color-dark;
				padding-bottom: 20rpx;
			}
		}
	
		/* 多条商品 */
		.goods-box {
			height: 200rpx;
			padding: 20rpx 0;
			white-space: nowrap;
			padding-right: 250rpx;
	
			.goods-item {
				width: 120rpx;
				height: 180rpx;
				display: inline-block;
				margin-right: 24rpx;
			}
	
			.goods-img {
				display: block;
				width: 120rpx;
				height: 120rpx;
			}
	
			.good-name {
				font-size: 24rpx;
				text-align: center;
				width: 120rpx;
				padding-top: 10rpx;
				margin-right: 0;
				color: $font-color-dark;
			}
		}
	
		.btm-btn-wrap {
			height: 90rpx;
			width: 100%;
			font-size: 24rpx;
			font-weight: 500;
			color: #A3A8BB;
			line-height: 1;
	
			.btm-right {
				justify-content: flex-end;
			}
	
			.btm-btn {
				width: 144rpx;
				padding: 10rpx 0;
				border: 2px solid #ededed;
				border-radius: 28rpx;
				font-size: 26rpx;
				font-weight: 500;
				text-align: center;
				margin-left: 10rpx;
				color: #999999;
			}
	
			.ksps {
				border-color: #4589ec;
				color: #4589ec;
			}
		}
	}

</style>
