<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" @click="click" :lineHeight="5"></u-tabs>
		</view>
		<view class="goodsList">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<view class="title">广西京东自营店南宁分店</view>
				<view class="state" v-if="item.goodsStatus == 1">
					<text class="icon" style="color: #13ce66">&#xe830;</text>
					<text>已完成</text>
				</view>
				<view class="state" v-else>
					<text class="icon" style="color: #f44336">&#xe622;</text>
					<text>下架</text>
				</view>
				<image src="../../../../static/news.jpg" mode="aspectFill" class="pic"></image>
				<view class="con">
					<view class="productName omit">八角茴香（未磨）（可食用）</view>
					<view class="desc omit">
						<text>50吨</text>
						<text>云南互市区云南互市区云南互市区云南互市区云南互市区</text>
					</view>
					<view class="price">¥ 5000</view>
				</view>
				<view class="clear"></view>
				<view class="op">
					<view class="date">2022-12-12:12:12</view>
					<view class="an" style="color: #f44336">取消订单</view>
					<view class="an" style="color: #4581fb">通知确认</view>
				</view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			tab: [
				{ name: '全部', goodsStatus: '' },
				{ name: '待确认', goodsStatus: 1 },
				{ name: '已确认', goodsStatus: 0 },
				{ name: '已完成', goodsStatus: 0 },
				{ name: '已取消', goodsStatus: 0 }
			],
			param: { pageNo: 1, pageSize: 10, isOrders: 0 },
			list: [],
			loadMore: true
		};
	},
	onLoad() {
		this.getData();
		uni.$on('goodsHandle', res => {
			this.refresh();
		});
	},
	methods: {
		getData() {
			this.http.request({
				url: '/level-one-server/app/TbGoodsTransit/getTransitList',
				loading: 'false',
				data: this.param,
				success: res => {
					this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
					this.list.push(...res.data.data);
				}
			});
		},
		//点击tab切换
		click(e) {
			this.param.goodsStatus = e.goodsStatus;
			this.refresh();
		},
		del(id) {
			uni.showModal({
				title: '提示',
				content: '确定删除?',
				success: res => {
					if (res.confirm) {
						this.http.request({
							url: '/level-one-server/app/TbGoodsTransit/deleteById?id=' + id,
							success: res => {
								uni.showToast({ title: '删除成功' });
								this.refresh();
							}
						});
					}
				}
			});
		},
		detail(id) {
			uni.navigateTo({ url: '/pages/market/two/leader/detail' });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNo = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNo++;
			this.getData();
		}
	},
	onNavigationBarButtonTap() {
		uni.navigateTo({ url: '/pages/goodsManage/oneMarket/editGoods' });
	}
};
</script>

<style lang="scss">
page {
	background-color: $pg;
}
</style>
