<template>
	<view class="page">
		<u-tabs active-color="#26c570" :list="list" :current="current" @change="change"></u-tabs>
		<view v-if="alllist.length == 0" style="text-align: center;margin-top: 50rpx;" class="tit1">暂无数据</view>
		<view style="padding: 0 20rpx;">
			<view v-for="(item,index) in alllist" :key="index" @click="gopath('/pages/orderList/orderListdetails',item.orderId)"
				style="background: #fff;margin-top: 40rpx;padding: 30rpx;border-radius: 18rpx;">
				<view style="display: flex;align-items: center;justify-content: space-between;margin-bottom: 20rpx;">
					<view style="display: flex;align-items: center;">
						<view class="t1" style="margin-right: 15rpx;">订单号：{{item.orderId}}</view>
						<u-icon name="arrow-right" color="#979797" size="24"></u-icon>
					</view>
					<view class="t1">
						<span v-if="item.state === 1">待付款</span>
						<span v-if="item.state === 2">待发货</span>
						<span v-if="item.state === 3">待收货</span>
						<span v-if="item.state === 4">已完成</span>
						<span v-if="item.state === 5">已关闭</span>
					</view>
				</view>
				<view v-for="(item1,index1) in item.products" :key="index1"
					style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 20rpx;">
					<view style="display: flex;">
						<view>
							<image style="width: 200rpx;height: 200rpx;bitem-radius: 18rpx;overflow: hidden;" mode="aspectFill"
								:src="imgurl+item1.image"></image>
						</view>
						<view
							style="display: flex;flex-direction: column;justify-content: space-between;margin-left: 15rpx;">
							<view>{{item1.productName}}</view>
							<view v-if="item1.value">规格：{{ item1.value }}</view>
						</view>
					</view>
					<view style="display: flex;flex-direction: column;justify-content: space-between;height: 200rpx;text-align: right;">
						<view class="t1">￥ {{item1.productPrice*item1.number}}</view>
						<view class="t1">X{{ item1.number }}</view>
					</view>
				</view>
				<view
					style="display: flex;justify-content: space-between;padding-top: 30rpx;border-top: 2rpx solid #eee;align-items: center;">
					<view>
							共{{item.products.length}}件商品，合计
							<text style="color: red;">¥{{ item.price }}</text>
					</view>
					<!-- 下单时间： -->
					<view class="t1">{{item.createTime}}</view>
					<!-- 					<view
						style="background: #26c570;color: #fff;bitem-radius: 36rpx;font-size: 20rpx;padding: 14rpx 20rpx;">
						查看详情</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					{
						type:'',
						name: '全部'
					},
					{
						type:'1',
						name: '待付款'
					},
					{
						type:'2',
						name: '待发货',
					},
					{
						type:'3',
						name: '已发货',
					},
					{
						type:'4',
						name: '已完成',
					},
					{
						type:'5',
						name: '已关闭',
					},
				],
				current: 0,
				alllist: [],
				pageindex: {
					page: 1,
					pageSize: 10,
					state:''
				},
				imgurl: '',
				total:0
			};
		},
		onLoad(optiong) {
			this.imgurl = this.$img
			if(uni.getStorageSync('shopId')) {
				this.getALL()
			} else {
				
			}
			
			
		},
		onReachBottom (e){
			console.error(e)
			if (this.alllist.length < this.total) {
				this.pageindex.page++
				this.getALL()
			}
		},
		methods: {
			gopath(url,id){
				uni.navigateTo({
					url:url+'?id='+id
				})
			},
			getALL() {
				this.$http.sendRequest('/order/getAll', 'POST', this.pageindex, 1).then(res => {
					//成功回调	
					this.alllist = [...this.alllist,...res.data.data.list]
					this.total = res.data.data.total
					console.error(this.alllist)
				})
			},
			change(index) {
				this.current = index;
				if(this.current == 0) {
					this.pageindex.state = ''
				} else {
					this.pageindex.state = this.list[this.current].type
				}
				this.pageindex.page = 1
				this.alllist = []
				this.getALL()
			}

		}
	}
</script>

<style scoped lang="scss">
	.page {}

	.t1 {
		font-size: 26rpx;
		color: #979797;
	}
</style>