<template>
	<view>
		<view class="tab" style="height: 180px;">
			<u-tabs :list="tab" @click="click" :lineHeight="5"></u-tabs>
			<view style="display: flex;margin-top: 10px;">
				<u--input placeholder="输入名字" border="surround" v-model="param.buyUserName"
					@clear="param.buyUserName='';getData()" clearable>
				</u--input>
				<view class="reset_btn" @click="getData">搜索</view>
			</view>
			<view style="border-radius: 10px;padding: 10px 20px;">
				<view style="margin-top: 10px;">
					<u-row customStyle="margin-bottom: 10px">
						<u-col span="6">
							<view>商品 {{settle.goodsName}}</view>
						</u-col>
						<u-col span="6">
							<view class="demo-layout bg-purple">车牌号 {{settle.veNo}}</view>
						</u-col>
					</u-row>
					<u-row customStyle="margin-bottom: 10px">
						<u-col span="4">
							<view>重量 {{settle.sumGrossWt}}</view>
						</u-col>
						<u-col span="8">
							<view class="demo-layout bg-purple">申报时间 {{settle.declTime.substr(0,16)}}</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</view>

		<view class="goodsList" >
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<view class="title">{{ item.buyUserName }}
					<view class="state" v-if="item.peopleConfirmStatus == 0&&item.upStatus==1&&item.resaleStatus==0">
						<text class="icon">&#xe830;</text>
						<text>未确认</text>
					</view>
					<view class="state" v-if="item.peopleConfirmStatus == 1&&item.upStatus==1&&item.resaleStatus==0">
						<text class="icon" style="color: #13ce66">&#xe830;</text>
						<text>已确认未上架</text>
					</view>
					<view class="state" v-if="item.peopleConfirmStatus == 1&&item.upStatus==2&&item.resaleStatus==0">
						<text class="icon" style="color: #13ce66">&#xe830;</text>
						<text>已上架未转售</text>
					</view>
					<view class="state" v-if="item.resaleStatus == 1">
						<text class="icon" style="color: #13ce66">&#xe830;</text>
						<text>已转售</text>
					</view>
				</view>
				<view class="con">
					<view class="desc omit">
						<text>重量 {{ item.totalWeight }} | 数量 {{item.buyQty}} </text>
					</view>
					<view class="desc omit">
						<text>申报额度 ¥{{ item.buyAmount }}</text>
					</view>
					<view class="price" v-if="item.upPrice">上架 ¥{{ item.upPrice }}</view>
				</view>
				<view class="op">
					<template>
						<a :href="'tel:'+item.phone" class="an down_btn">拨打电话</a>
					</template>
				</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: '全部',
						peopleConfirmStatus: '', //边民确认状态
						upStatus: '', //订单完成状态
						resaleStatus: '' //订单转售状态
					},
					{
						name: '未确认',
						peopleConfirmStatus: 0,
						upStatus: 1,
						resaleStatus: 0
					},
					{
						name: '未上架',
						peopleConfirmStatus: 1,
						upStatus: 1,
						resaleStatus: 0
					},
					{
						name: '已上架',
						peopleConfirmStatus: 1,
						upStatus: 2,
						resaleStatus: 0
					},
					{
						name: '已转售',
						peopleConfirmStatus: 1,
						upStatus: 2,
						resaleStatus: 1
					}
				],
				param: {
					pageNo: 1,
					pageSize: 10,
					buyUserName: '',
					saleMainId: ''
				},
				settle: {},
				user: this.getUser(),
				list: [],
				loadMore: false,
			};
		},
		onLoad(e) {
			if (e.mainId) {
				this.param.saleMainId = e.mainId;
				this.settle = e;
				this.getData();
			}

		},
		methods: {
			makePhoneCall(item) {
				uni.makePhoneCall({
					phoneNumber: item.phone
				});
			},
			getData() {
				this.http.request({
					url: '/level-one-server/app/TbOrder/getListBySaleMainId',
					loading: 'false',
					data: this.param,
					success: res => {
						this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
						if (res.data.data) {
							this.list.push(...res.data.data);
						}
						if (this.param.pageNo == 1 &&res.data.data&& res.data.data.length==0) {
							this.list = []
						}
					}
				});
			},
			// 点击tab切换
			click(e) {
				this.param.peopleConfirmStatus = e.peopleConfirmStatus;
				this.param.upStatus = e.upStatus;
				this.param.resaleStatus = e.resaleStatus;
				this.refresh();
			},
			detail(item) {
				uni.navigateTo({
					url: '/pages/market/one/leader/detail?id=' + item.id
				});
			},
			// 刷新数据
			refresh() {
				this.loadMore = true;
				this.param.pageNo = 1;
				this.list = [];
				this.getData();
			},

		},
		//下拉刷新
		onPullDownRefresh() {
			this.param.pageNo = 1;
			this.param.buyUserName = '';
			setTimeout(() => {
				this.getData();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		//上拉加载
		onReachBottom() {
			if (this.loadMore) {
				this.param.pageNo++;
				this.getData();
			}
		}
	};
</script>

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

	.state {
		margin-right: -70px;
	}

	.tab {
		.reset_btn {
			line-height: 35px;
			padding: 0 15px;
			border: 1px solid #e2e2e2;
			border-radius: 8px;
			margin-left: 10px;
			background: #e2e2e2
		}
	}

	.goodsList {
		.item {
			.con {
				width: 60%;

				.desc {
					uni-text {
						padding-right: 5px;
					}
				}
			}
		}
	}
	.down_btn {
		color: #f0f4f7;
		width: 66px;
		background-color: #3c9cff;
		text-align: center;
		border-radius: 10px;
		font-size: 13px;
		padding: 2px 4px;
		text-decoration: none;
	}
	.call_phone {
		position: relative;
		right: 20px;
		top: 5px;
		display: flex;
	}
</style>