<template>
	<view class="content">
		<view class="list" v-if="orderList.length > 0">
			<view class="item" v-for="(item, index) in orderList" :key="index">
				<view class="item-name">
					{{item.order_no}}
				</view>
				<view class="grey">
					<view class="label" v-if="item.state != null">
						<view class="label-name">
							订单状态
						</view>
						<view class="label-text label-color">
							{{item.state}}
						</view>
					</view>
					<view class="label" v-if="item.express.name != null">
						<view class="label-name">
							收件人
						</view>
						<view class="label-text">
							{{item.express.name}}
						</view>
					</view>
					<view class="label" v-if="item.express.mobile != null">
						<view class="label-name">
							手机号
						</view>
						<view class="label-text label-tel">
							<view class="label-tel-number">{{item.express.mobile}}</view>
							<view class="label-tel-dial" @click="clickCall(item.express.mobile)">拨打</view>
						</view>
					</view>
					<view class="label" v-if="item.qty != null">
						<view class="label-name">
							捐献数量
						</view>
						<view class="label-text">
							{{item.qty}}
						</view>
					</view>
					<view class="label" v-if="item.total != null">
						<view class="label-name">
							捐献金额
						</view>
						<view class="label-text label-price">
							<text>￥</text>{{item.total}}
						</view>
					</view>
					<view class="label" v-if="item.express.receive_at != null">
						<view class="label-name">
							签收时间
						</view>
						<view class="label-text">
							{{item.express.receive_at}}
						</view>
					</view>
					<view class="label" v-if="item.express.deliver_at != null">
						<view class="label-name">
							发货时间
						</view>
						<view class="label-text">
							{{item.express.deliver_at}}
						</view>
					</view>
					<view class="label" v-if="item.express.deliver_at != null">
						<view class="label-name">
							物流名称
						</view>
						<view class="label-text">
							{{item.express.express_name}}
						</view>
					</view>
					<view class="label" v-if="item.express.express_no != null">
						<view class="label-name">
							物流编号
						</view>
						<view class="label-text">
							{{item.express.express_no}}
						</view>
					</view>
					<view class="label" v-if="item.express.full_address != null">
						<view class="label-name">
							收货地址
						</view>
						<view class="label-text">
							{{item.express.full_address}}
						</view>
					</view>
				</view>
			</view>
			<view class="pagesLoding" v-if="lodingStats">
			    <block v-if="page.has_more">
			        <image class="pagesLodingIcon" src="/static/icons/refresh_loding.gif" mode="widthFix"></image>加载中...
			    </block>
			    <block v-else>
			        没有更多了~
			    </block>
			</view>
		</view>
		
		<view class="pack-center pages-hint" v-else>
		    <image src="/static/imgs/coupon_null.png"></image>
		    <view>暂无数据</view>
		</view>
	</view>
</template>

<script>
    import { dataOrder } from '@/apis/interfaces/user'
	export default {
		data() {
			return {
               orderList   : [],
			   page        : {},     //分页信息
			   lodingStats : false   //加载状态
			};
		},
		
        onShow() {
			// 数据-订单列表
			this.censusInfo();
			
			uni.setNavigationBarTitle({
			　　title: this.$Route.query.newTitle
			})
        },
        
		methods:{
			// 查看数据-订单列表
			censusInfo(page) {
			    dataOrder({
                    status: this.$Route.query.state,
                    page : page || 1
                }).then(res => {
					let listArr = this.orderList,
					    newData = []
					    if(page == 1 || page == undefined) listArr = []
					    newData = listArr.concat(res.data)
					this.orderList  = newData
					this.page       = res.page
					this.lodingStats= false
					uni.stopPullDownRefresh()
			    }).catch(err => {
					uni.showToast({
						title: err.message,
						icon: "none"
					})
				})
			},
			
			// 拨打电话
			clickCall (tel) {
				uni.makePhoneCall({
					phoneNumber: tel,//电话号码
					success: res => {
						console.log(res);
					},
					fail: err =>{
						console.log(err);
					}
				})
			},
			
			// 页面相关事件处理函数--监听用户下拉动作
			onPullDownRefresh() {
			    // 数据-订单列表
			    this.censusInfo();
			},
			        
			// 上拉加载
			onReachBottom(){
			    this.lodingStats = true
			    let pageNumber = this.page.current
			    if(this.page.has_more){
			        pageNumber++
					// 数据-订单列表
					this.censusInfo(pageNumber);
			    }
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		overflow: hidden;
		background-color: #f5f5f5;
		height: 100vh;
		overflow-y: scroll;
	}
	.pack-center {
		z-index: 9;
	}
	.list {
		padding: 30rpx;
		box-sizing: border-box;
		.item {
			background-color: #ffffff;
			margin-bottom: 30rpx;
			border-radius: 10rpx;
			padding: 30rpx;
			box-sizing: border-box;
			.item-name {
				font-weight: 600;
				margin-bottom: 30rpx;
			}
			.grey {
				background-color: #fcfcfc;
				border-radius: 10rpx;
				padding: 30rpx;
				box-sizing: border-box;
				.label {
					display: flex;
					padding-bottom: 30rpx;
					font-size: 28rpx;
					line-height: 48rpx;
					&:last-child {
						padding-bottom: 0;
					}
					.label-name {
						width: 170rpx;
						color: #a9a9a9;
					}
					.label-text {
						width: calc(100% - 170rpx);
						text-align: justify;
						&.label-color {
							color: #6884fc;
						}
						&.label-price {
							color: red;
							font-weight: 600;
						}
					}
					.label-tel {
						display: flex;
						.label-tel-number {
							flex: 1;
						}
						.label-tel-dial {
							background-color: #edf4ff;
							color: #5370eb;
							height: 44rpx;
							line-height: 44rpx;
							padding: 0 15rpx;
							font-size: 26rpx;
							border-radius: 4rpx;
						}
					}
				}
			}
		}
	}
</style>