<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">{{item.enterpriseName}}</view>
				<view class="state" v-if="item.enterpriseConfirm == 0">
					<text class="icon">&#xe830;</text>
					<text>待确认</text>
				</view>
				<view class="state" v-if="item.enterpriseConfirm == 1">
					<text class="icon" style="color: #13ce66">&#xe830;</text>
					<text>已确认</text>
				</view>
				<view class="state" v-if="item.enterpriseConfirm == 2">
					<text class="icon" style="color: #f44336">&#xe622;</text>
					<text>已拒绝</text>
				</view>
				<view class="state" v-if="item.enterpriseConfirm == 3">
					<text class="icon" style="color: #00BFFF">&#xe622;</text>
					<text>等待司机确认</text>
				</view>
				<image src="../../../../../static/news.jpg" mode="aspectFill" class="pic"></image>
				<view class="con">
					<view class="productName omit">{{ item.goodsNames }}</view>
					<view class="desc omit">
						<text>{{ item.totalWeight }}{{ item.goodsUnit }}</text>
						<text>{{ item.tradeAreaName }}</text>
					</view>
					<view class="price">¥ {{ item.totalPrice }}</view>
				</view>
				<view class="clear"></view>
				<view class="op">
					<view class="date">2022-12-12:12:12</view>
					<template v-if="item.enterpriseConfirm == 0">
						<view class="an" style="color: #f44336"
							@click.stop="confirm(item.id, item.goodsId, 2, '确认拒绝？')">拒绝订单</view>
						<view class="an" style="color: #4581fb"
							@click.stop="confirm(item.id, item.goodsId, 1, '确认接单？')">确认订单</view>
					</template>
					<template v-if="item.enterpriseConfirm == 1">
						<view class="an" style="color: #13ce66" @click.stop="showPop(item)">物流车辆</view>
					</template>
					<template v-if="item.enterpriseConfirm == 4">
						<view class="an" style="color: #4581fb">物流信息</view>
					</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: '全部', enterpriseConfirm: '', isOrders: '' },
					  { name: '待确认', enterpriseConfirm: 0, isOrders: 1 },
					  { name: '已确认', enterpriseConfirm: 1, isOrders: 1 },
					  { name: '已拒绝', enterpriseConfirm: 2, isOrders: 0 }
				],
				param: {
					pageNo: 1,
					pageSize: 10
				},
				list: [],
				loadMore: true,
				show: false,
				value: 0
			};
		},
		onLoad() {
			this.getData();
			uni.$on("refreshPage", res => {
				console.log("zzzzz");
				this.refresh();
			})
		},
		methods: {
			getData() {
				this.http.request({
					url: '/level-one-server/app/TbOrder/getList',
					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);
						}
						this.list.map(item => {
							if(item.callCarStatus == 1){
								item.enterpriseConfirm = 3
							} else if(item.callCarStatus == 2){
								item.enterpriseConfirm = 4
							}
						})
					}
				});
			},
			// 商家确认
			confirm(id, goodsId, status, content) {
				//enterprise_confirm：'商铺确认情况[0=待确认,1=已确认,2=拒绝]'
				uni.showModal({
					title: '提示',
					content: content,
					success: res => {
						if (res.confirm) {
							this.http.request({
								url: '/level-one-server/app/TbOrder/updateEnterpriseConfirm',
								data: {
									id: id,
									goodsId: goodsId,
									enterpriseConfirm: status
								},
								method: 'POST',
								success: resp => {
									uni.showToast({
										title: '操作成功'
									});
									this.refresh();
								}
							});
						}
					}
				});
			},
			//点击tab切换
			click(e) {
				this.param.enterpriseConfirm = e.enterpriseConfirm;
				this.param.isOrders = e.isOrders;
				this.refresh();
			},
			detail(item) {
				uni.navigateTo({
					url: '/pages/market/one/merchant/order/detail?id=' + item.id
				});
			},
			//刷新数据
			refresh() {
				this.loadMore = true;
				this.param.pageNo = 1;
				this.list = [];
				this.getData();
			},
			// 弹窗显示司机信息
			showPop(item) {
				// this.show = !this.show
				uni.navigateTo({
					url: '/pages/market/one/merchant/order/vehice?item=' + JSON.stringify(item)
				})
			},
			close() {
				this.show = false
				this.refresh()
			},
		},
		//下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.refresh();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		//上拉加载
		onReachBottom() {
			if (this.loadMore) {
				this.param.pageNo++;
				this.getData();
			}
		}
	};
</script>

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