<template>
	<view>
		<view class="search">
			<u-search placeholder="搜索商品名称" v-model="param.customerName" bgColor="white" @search="refresh()" :animation="true" actionText="取消" @clear="refresh()"></u-search>
			<view class="clear"></view>
		</view>
		<view class="goodsList">
			<view class="sort-list">
				<view class="sort-item" :class="{ active: item.check }" v-for="(item, index) in sort" :key="index" @click="select(item, index)">
					<text>{{ item.name }}</text>
					<text v-if="index > 0 && item.isAsc == 'desc'" class="icon">&#xeb0a;</text>
					<text v-if="index > 0 && item.isAsc == 'asc'" class="icon">&#xeb0b;</text>
				</view>
				<view class="type" @click="show = true">
					<text>分类</text>
					<text class="icon">&#xe8f2;</text>
				</view>
				<view class="clear"></view>
			</view>
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="title" @click="detail(item)">{{ item.createName }}</view>
				<image @click="detail(item)" src="../../../static/news.jpg" mode="aspectFill" class="pic"></image>
				<view class="con">
					<view class="productName omit" @click="detail(item)">{{ item.goodsName }}</view>
					<view class="desc" @click="detail(item)">{{ item.goodsQuantity }}吨</view>
					<view class="btn" v-if="user.userType == 2" @click="confirm(item)">立即接单</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>
		<productType v-model="show"></productType>
	</view>
</template>

<script>
export default {
	data() {
		return {
			user: this.getUser(),
			show: false,
			sort: [{ name: '综合' }, { name: '日期' }, { name: '价格' }],
			list: [],
			param: { pageNo: 1, pageSize: 10 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/level-two-server/app/TbGoodsDemand/getList',
				data: this.param,
				loading: 'false',
				success: res => {
					this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
					this.list.push(...res.data.data);
				}
			});
		},
		detail(item) {
			uni.navigateTo({ url: '/pages/market/two/detail?id=' + item.id });
		},
		confirm(item) {
			uni.navigateTo({ url: '/pages/market/two/leader/confirm?id=' + item.id });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: $pg;
}
.btn {
	width: 120rpx;
	height: 40rpx;
	background-color: #fff;
	color: #000;
	border: #b5b5b5 1px solid;
	position: relative;
	left: 350rpx;
	font-size: 14px;
}
</style>
