<template>
	<view class="xkl-com-bg">
		<view style="height: 20rpx;"></view>
		<view>
			<view
				style="background-color: #ffffff;color: #666666;padding: 30rpx;font-size: 28rpx; margin-bottom: 20rpx;border-radius: 16rpx;"
				v-for="(item,index) in orderItems" :key="index" :url="`/pages/goods/detail?id=${item.id}`">
				<view class="u-flex u-flex-between" style="font-size: 30rpx;">
					<view>订单号：{{item.order_no}}</view>
					<u-tag :text="config.pay_type[item.pay_type]" :name="config.pay_type[item.pay_type]" plain
						size="mini" type="warning"></u-tag>
				</view>
				<view style="height: 20rpx;"></view>
				<view class="u-flex">
					<u--image width="220rpx" height="220rpx" :src="item.goods.cover[0]" radius="16rpx"></u--image>
					<view style="padding: 0 20rpx;">
						<view>{{item.goods.name}}</view>
						<view style="height: 10rpx;"></view>
						<view>数量：{{item.num}}</view>
						<view style="height: 10rpx;"></view>
						<view>订单金额：<text style="color: #FF1A1A;">￥{{item.pay_money}}</text></view>
						<view style="height: 10rpx;"></view>
						<view>用户名：{{item.shop.username}}</view>
						<view style="height: 10rpx;"></view>
						<view>手机号：{{item.shop.mobile}}</view>
					</view>
				</view>
				<u-divider></u-divider>
				<view class="u-flex u-flex-between">
					<view>{{item.created_at}}</view>
					<view>
						<u-tag :text="config.status[item.status]" plain size="mini" type="success"></u-tag>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="loadStatus" />
		<view style="height: 100rpx;"></view>
	</view>
</template>

<script>
	let self;
	export default {
		data() {
			return {
				tabData: {
					list: [{
						name: '待付款',
						status: 0,
					}, {
						name: '已完成',
						status: '1',
					}, ],
					current: 1
				},
				orderItems: [],
				search: {
					status: 1,
					page: 1
				},
				page: {
					current: 0,
					last_page: 1
				},
				loadStatus: 'loadmore',
				config: null
			}
		},
		mounted() {

		},
		onLoad() {
			self = this;
			self.getOrderItems();
		},
		onShow() {

		},
		onReachBottom() {
			if (!self.pageStatus()) {
				return;
			}
			self.loadStatus = 'loading';
			self.search.page = ++self.search.page;
			self.orderItems = [];

			self.getOrderItems();
		},
		async onPullDownRefresh() {
			self.search.page = 1;
			self.orderItems = [];

			await self.getOrderItems();
			uni.stopPullDownRefresh();
		},
		methods: {
			sectionChange(index) {
				self.search.status = self.tabData.list[index].status;
				self.tabData.current = index;
				self.orderItems = [];
				self.getOrderItems();
			},
			pageStatus() {
				self.loadStatus = 'loadmore';
				if (self.search.page >= self.page.last_page) {
					self.loadStatus = 'nomore';
					return false;
				}
				return true;
			},
			getOrderItems() {
				self.$http.post('/shop/admin/order/items', self.search).then(({
					data,
					success
				}) => {
					if (success) {
						self.orderItems = self.orderItems.concat(data.items.data);
						self.config = data.config;
						self.page.last_page = data.items.last_page;

						self.pageStatus();
					}
				})
			},
		}
	}
</script>

<style lang="scss">

</style>