<template>
	<view class="pagesCons">
		<view class="tab-body">
					<scroll-view scroll-y class="scroll-view" @scrolltolower="onreachBottom">
						<view class="check-order-list" v-for="(item,index) in list" :key="item.id"
						 >
							<view class="order-log">
								<view v-if="!item.expressNum">待发货</view>
								<view v-else>
									<view>
										快递公司：<text class="address-title">{{item.expressName}}</text>
										<u-button v-if="item.expressState=='WAIT_SIGN'" 
										:custom-style="btnStyle" 
										@click="handleGet(index)"
										 type="primary" shape="circle" size="mini" >确认收货</u-button>
									</view>
									<view>
										<text>运单编号：</text>
										<text>{{item.expressNum}}</text>
										<u-button @click="copyLogNum(item.expressNum)" style="margin-left: 20upx;" shape="square" size="mini">复制</u-button>
									</view>
								</view>
							</view>
							<u-gap height="10" bg-color="#f8f8f8"></u-gap>
							<view class="bundle-list" v-for="row in item.orderGoodsList" :key="row.id">
								<view class="img-cont">
									<image :src="row.goodsImages"></image>
								</view>
								<view >
									<view class="ellipsis-two">{{row.goodsName}}</view>
									<view class="bundle-num">
										<view ><text class="price-num">{{row.payGold}}</text> <text class="price-text">乐豆</text></view>
										<view >X {{row.buyQty}}</view>
									</view>
								</view>
							</view>
						</view>
						<u-empty style="padding-top: 10vh;height: auto;" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'"
						 mode="list"></u-empty>
						<view style="padding: 20upx;">
							<u-loadmore v-if="total>pageSize || status=='loading'" :status="status" />
						</view>
					</scroll-view>
		</view>
	</view>
</template>

<script>
	import { queryOrderExpress, finishOrder } from '@/api/order.js'
	export default {
		components: {
		},
		data() {
			return {
				btnStyle:{
					width: '180rpx',
					fontSize: '30rpx',
					float: 'right'
				},
				isShow: false, // 是否显示物流弹框
				status: 'loadmore',
				noDataText: '暂无数据',
				list: [],
				total: 0,
				orderSn: '' // 订单编号
			}
		},
		onLoad(option) {
			if(option.orderNo) {
				this.orderSn = option.orderNo
				this.getRow()
			}
		},
		methods: {
			// scroll-view到底部加载更多
			onreachBottom() {
				if (this.list.length < this.total) {
					this.pageNo += 1
					this.getRow()
				} else {
					uni.showToast({
						title: '已经到底了',
						icon: 'none'
					});
					this.status = "nomore"
				}
			},
			// 查询列表
			getRow() {
				this.status = "loading"
				queryOrderExpress({orderSn:this.orderSn}).then(res => {
					console.log(res,'rrrrrrrr')
					if (res.status == 200) {
						this.list = res.data || []
					} else {
						this.list = []
						this.total = 0
						this.noDataText = res.message
					}
					this.status = "loadmore"
				})
			},
			// 确认收货
			handleGet(index) {
				console.log(index,'iiiiiiiiii')
				let params = {
					  "expressNo": this.list[index].expressNo,
						"orderNo": this.list[index].orderNo,
				}
				finishOrder(params).then(res=>{
					if(res.status==200) {
						uni.showToast({
							title:res.message,
							icon: 'none'
						})
						this.getRow()
					} else {
						uni.showToast({
							title:res.message,
							icon: 'none'
						})
					}
				})
			},
			
			// 复制运单编号 
			copyLogNum (logNum) {
				// H5 不支持
				uni.setClipboardData({
					data: logNum,
					success: function(res) {
						uni.getClipboardData({
							success: function(res) {
								uni.showToast({
									title: '已复制到剪贴板',
									icon: 'none'
								});
							}
						});
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		width: 100%;
		background: #F8F8F8;
	}

	.pagesCons {
		height: 100%;
		width: 100%;
		background: #F8F8F8;
		display: flex;
		flex-direction: column;

		.text-right {
			text-align: right;
		}

		.tab-body {
			flex: 1;
			display: flex;
			flex-direction: column;

			.uTabs {
				border-bottom: 1px solid #EEEEEE;
				box-shadow: 1px 1px 3px #eeeeee;
			}

			.check-list {
				flex: 1;
				overflow-y: scroll;

				.swiper-item {
					width: 100%;
					height: 100%;
					overflow: hidden;

					.scroll-view {
						width: 100%;
						height: 100%;
						overflow: auto;
					}
				}
			}
			// 列表样式
			.check-order-list {
				background: #ffffff;
				padding: 10upx 20upx;
				margin: 25upx;
				border-radius: 6upx;
				box-shadow: 1px 1px 3px #EEEEEE;
				font-size: 28upx;
				.check-row {
					display: flex;
					align-items: center;
					padding: 20upx 10upx;

					.icon-xian {
						text-align: right;
						width: 40upx;
					}

					&:first-child {
						border-bottom: 1px dashed #F8F8F8;

						.createDate {
							color: #666;
							font-size: 26upx;
							margin-left: 10upx;
						}
					}

					&:last-child {
						border-top: 1px dashed #F8F8F8;
					}

					>view {
						&:first-child {
							flex: 1;
						}
					}
				}
				// 订单中商品列表
				.bundle-list {
					display: flex;
					padding: 20upx 10upx;
					font-size: 28upx;
					border-bottom: 1px solid #F8F8F8;
					&:last-child {
						border-bottom: none;
					}
					.img-cont {
						width: 160upx;
						height: 160upx;
						>image {
							width: 100%;
							height: 100%;
						}
					}
					>view {
						&:last-child {
							flex: 1;
							margin-left: 20upx;
							padding: 10upx 0upx;
							display: flex;
							flex-direction: column;
							justify-content: space-between;
						}
					}
					.bundle-num {
						display: flex;
						justify-content: space-between;
					}
				}
				.btn-cont {
					width: 180upx;
					height: 60upx;
					float: right;
					// background-color: #2979ff;
					// color: #fff;
					// text-align: center;
					// border-radius: 100upx;
					font-size: 30upx;
				}
				.price-text{
					font-size: 20upx;
					margin-left: 10upx;
				}
				.price-num{
					font-size: 32upx;
					color: red;
				}
				.total-text{
					margin-right: 50upx;
				}
				.money-total{
					margin-right: 10upx;
				}
			}
		}
		// 物流弹窗
		.order-log {
			padding: 20upx ;
			font-size: 28upx;
			>view{
				line-height: 60upx;
			}
		}
	}
</style>
