<template>
	<view class="Order_body">
		<view class="navbar">
			<view class="nav-item" :class="{current: page.params.orderStatus == ''}" @click="tabClick('')">
				全部
			</view>
			<view class="nav-item" :class="{current: page.params.orderStatus == 1}" @click="tabClick(1)">
				待提货
			</view>
			<view class="nav-item" :class="{current: page.params.orderStatus == 2}" @click="tabClick(2)">
				已完成
			</view>
			<view class="nav-item" :class="{current: page.params.orderStatus == 99}" @click="tabClick(99)">
				退款/售后
			</view>
		</view>
		<view @click="goDetails(item)" v-for="item in list" class="order_item">
			<view class="order_item_title flex jw textov">
				<text class="siteName textov">自提油站：{{item.takeSiteName}}</text>
				<text class="type">{{item.statusMerge}}</text>
			</view>
			<view class="order_item_center flex  ac">
				<image mode="aspectFit" :src="item.oderDetailImg">
				</image>
				<view class="order_item_right">
					<view style=" font-size: 28rpx; color: #000000;">{{item.productName}}</view>
					<view style=" font-size: 24rpx; color: #999999;">规格：默认 <br /> {{item.integral}} X{{item.orderNum}}
					</view>
					<view style=" font-size: 26rpx;color: #333333;">共1件商品已支付积分：{{item.payIntegral}}</view>
				</view>
			</view>
			<view v-if="item.statusMerge=='待核销'" class="order_item_footer flex ac jc">
				提货码：{{item.takeCode}}
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import orderApi from '@/api/order.js'
	export default {
		data() {
			return {
				list: [],
				page: {
					"currentPage": 1,
					"pageSize": 10,
					"params": {
						"orderStatus": ""
					}
				},
				loadingType: 'more', //加载更多状态 
				pageData: null
			}
		},
		onLoad(e) {
			if(e.orderStatus){
				this.page.params.orderStatus = e.orderStatus;
			}
			this.getList()
		},
		onPullDownRefresh() {
			this.page.currentPage = 1;
			this.loadingType = 'more';
			this.getList();
		},
		//加载更多
		onReachBottom() {
			this.page.currentPage += 1
			this.getList();
		},
		filters: {
			orderStatus(e) {
				switch (Number(e)) {
					case 1:
						return '已支付'
					case 2:
						return '已核销'
					case 3:
						return '停止中'
					case 0:
						return '已下单'
					case -1:
						return '已取消'
					default:
						return '数据错误'
				}
			},
		},
		methods: {
			goDetails(e){
				uni.navigateTo({
					url:`/Order/pages/details/index?id=${e.orderId}`
				})
			},
			async getList() {
				if (this.loadingType === 'nomore') {
					return;
				};
				await orderApi.getByPageCustomer(this.page).then(res => {
					if (res.code == 20000) {
						this.list = this.page.currentPage != 1 ? this.list.concat(res.data.list) : res.data
							.list;
						this.loadingType = res.data.list.length < this.page.pageSize ? 'nomore' : 'more';
					}
				});
				uni.stopPullDownRefresh()
			},
			search() {
				this.page.currentPage = 1;
				this.loadingType = 'more';
				this.getList()
			},
			tabClick(index) {
				this.page.params.orderStatus = index;
				this.$nextTick(function(){
				    uni.pageScrollTo({
				        scrollTop: 0,
				        duration: 300
				    })
				})
				this.search()
			},
			getDetails(id) {

			}
		}
	}
</script>

<style lang="scss" scoped>
	@import 'index.scss';
</style>