<template>
	<view class="container">
		<scroll-view class="order-list" scroll-y="true" @scrolltolower="handleLoadMore(6)">
			<view style="padding: 10px 0" v-if="!orderList.length">
				<u-divider color="#909399" border-color="#909399" bg-color="#f7f7f7">没有更多了</u-divider>
			</view>
			<orderItem v-for="(item, index) in orderList" :key="index" :orderData="item" :isPick="true"></orderItem>
		</scroll-view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	import orderItem from '@/pagesMain/orderItem.vue'
	export default {
		components: {
			orderItem
		},
		data() {
			return {
				pageIndex: 1,
				isOver: false,
				orderList: [],
				type: 6
			}
		},
		onLoad(options) {
			this.type = options.type
		},
		onShow(options) {
			this.pageIndex = 1
			this.isOver = false
			this.orderList = []
			this.getOrderList(this.type)
		},
		onPullDownRefresh() {
			this.pageIndex = 1
			this.isOver = false
			this.orderList = []
			this.getOrderList(this.type, 'refresh')
		},
		methods: {
			//  刷新数据
			reasetList() {
				this.pageIndex = 1
				this.isOver = false
				this.orderList = []
				this.getOrderList(this.type)
			},
			//  懒加载
			handleLoadMore(type) {
				if (!this.isOver) {
					this.pageIndex++
					this.getOrderList(type)
				}
			},
			//  获取全部订单
			getOrderList(type, refresh) {
				NET.request(API.getOrderList + this.pageIndex + '/10', {
					flag: type,
				}, 'GET').then(res => {
					if (refresh == 'refresh') {
						uni.stopPullDownRefresh();
					}
					this.isOver = res.data.list.length != 10
					this.orderList = this.orderList.concat(res.data.list)
					if (this.orderList.length) {
						this.orderList.forEach(v => {
							v.noPick = true
							if (v.products.some(vv => {return vv.productType == 3} )) {
							    v.noPick = false
							}
						})
					}
				}).catch(error => {
					this.$refs.uTips.show({
						title: error.data.msg,
						type: 'warning',
					})
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	page {
		width: 100%;
		height: 100%;
	}

	.container {
		width: 100%;
		height: 100%;
		float: left;
		background-color: #f7f7f7;

		.order-tab {
			width: 100%;
			height: 45px;
			float: left;
		}

		.order-list {
			width: calc(100% - 30px);
			height: calc(100% - 46px);
			float: left;
			margin: 0 15px;
			box-sizing: border-box;
			padding-top: 15px;
		}
	}
</style>
