<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" style="width: 97%;font-size: 17px;">
					<span v-if="item.purchaserId === null || item.purchaserId === '' || item.purchaserId === undefined">车牌号 {{ item.veNo }}</span>
					<span v-else>采购商 {{ item.purchaserName }}</span>
					<span>
						<view class="state" v-if="item.purchaserId === null || item.purchaserId === '' || item.purchaserId === undefined"><text class="icon">&#xe830;</text>待下单</view>
						<view class="state" v-else><text class="icon" style="color: #13ce66">&#xe830;</text>已下单</view>
					</span>
				</view>
				<view class="con">
					<view class="productName omit">{{ item.goodsName }}</view>
					<view class="desc omit">
						<text>{{ item.tradeAreaName }}</text>
					</view>
					<view class="price">上架金额 ¥ {{ item.resalePrice }}</view>
				</view>
				<view class="clear"></view>
				<view class="op">
					<view class="date">{{ item.createTime }}</view>
					<!-- <view class="an" style="color: #4581fb" @click.stop="payTax(item)" v-if="item.isPay == 1 && item.payTax == 0">去缴费税</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: '全部'},
				{ name: '待下单'},
				{ name: '已下单'},
			],
			param: { pageNo: 1, pageSize: 10 },
			list: [],
			isOrderList: [],
			noOrderList: [],
			loadMore: true
		};
	},
	onLoad() {
		this.getData();
		uni.$on('goodsHandle', res => {
			this.refresh();
		});
	},
	methods: {
		getData(e) {
			this.http.request({
				url: '/level-two-server/app/TbOrders/getLeaderOrderList',
				loading: 'false',
				data: this.param,
				success: res => {
					this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
					this.list.push(...res.data.data);
					this.noOrderList = this.list.filter(item => item.purchaserId === null || item.purchaserId === '' || item.purchaserId === undefined);
					this.isOrderList = this.list.filter(item => !this.noOrderList.includes(item));

					if(e != undefined && e.name == '待下单') {
						this.list = this.noOrderList;
					}
					if(e != undefined && e.name == '已下单') {
						this.list = this.isOrderList;
					}
				}
			});
		},
		//点击tab切换
		click(e) {
			this.refresh(e);
		},
		payTax(item) {
			uni.navigateTo({ url: '/pages/market/two/leader/feeDetail?resalePrice=' + item.resalePrice +'&id=' + item.id});
		},
		detail(item) {
			uni.navigateTo({ url: '/pages/market/two/leader/detail?id=' + item.id });
		},
		//刷新数据
		refresh(e) {
			this.loadMore = true;
			this.param.pageNo = 1;
			this.list = [];
			this.noOrderList = [];
			this.isOrderList = [];
			this.getData(e);
		}
	},
	//下拉刷新
	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>
