<template>
	<view class="container">
		<view class="dom-top">
			<view class="dom-item" v-for="(item, index) in domTopData" :key="index" @tap="statusClick(item.id)">
				<text :class="item.id === riderStatus ? 'active-dom-top' : ''">{{item.name}}</text>
			</view>
		</view>
		<scroll-view scroll-y style="overflow: hidden;">
			<view v-for="item in riderData" :key="item.id" style="margin: 10rpx 0;">
				<rider-order :orderInfo="item" @orderCilck="goOrderClick" :statusId="riderStatus"></rider-order>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getRiderList
	} from '@/api/rider.js';
	import riderOrder from "@/components/riderOrder/index.vue";
	let app = getApp();
	export default {
		name: 'riderShipping',
		components: {
			riderOrder,
		},
		data() {
			return {
				riderData: [], // 订单数组
				loading: false, //是否加载中
				loadend: false, //是否加载完毕
				loadTitle: '加载更多', //提示语
				page: 1,
				limit: 20,
				isReceiveId: null,
				riderStatus: 1,
				domTopData: [{
						id: 1,
						name: '待接单'
					},
					{
						id: 8,
						name: '待取货'
					},
					{
						id: 4,
						name: '配送中'
					},
					{
						id: 5,
						name: '已完成'
					}
				],
			}
		},
		methods: {
			/**
			 * 切换类型
			 */
			statusClick: function(status) {
				if (status == this.riderStatus) return;
				this.page = 1;
				this.riderStatus = status;
				this.loadend = false;
				this.getRiderDataList();
			},
			/**
			 * 获取订单列表
			 */
			getRiderDataList: function() {
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loading = true;
				that.loadTitle = "加载更多";
				getRiderList({
					status: that.riderStatus,
					page: that.page,
					limit: that.limit
				}).then(res => {
					let list = res.data.list || [];
					let loadend = list.length < that.limit;
					that.riderData = that.$util.SplitArray(list, that.riderData);
					that.$set(that, 'riderData', that.riderData);
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? "我也是有底线的" : '加载更多';
					that.page = that.page + 1;
				}).catch(err => {
					that.loading = false;
					that.loadTitle = "加载更多";
				})
			},
			goOrderClick(id) {
				this.isReceiveId = id
				console.log(id)
			}
		},
		onLoad(options) {
			this.getRiderDataList()
		},
		mounted() {

		},
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	.dom-top {
		width: 100%;
		height: 96rpx;
		font-weight: 400;
		font-size: 27rpx;
		color: #141414;
		background-color: #fff;
		// padding: 19rpx 115rpx 38rpx 115rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.dom-item {
			flex: 1;
			text-align: center;
			height: 96rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

	}



	.active-dom-top {
		color: $bg-color-primary;
		border-bottom: 9rpx solid $bg-color-primary;
		border-bottom-top-radius: 6rpx;
		border-bottom-bottom-radius: 6rpx;
		border-bottom-left-radius: 6rpx;
		border-bottom-right-radius: 6rpx;
	}
</style>
