<template>
	<view class="content">
		<view class="list" v-if="orderList.length > 0">
			<view class="label" v-for="(item, index) in orderList" :key="index">
				<view class="item">
					<image class="item-head" :src="item.avatar ? item.avatar : '/static/imgs/default_myHead.png'" mode="aspectFill"></image>
					<view class="item-cont">
						<view class="item-left">
							<view class="item-top">
								{{item.nickname}}
							</view>
							<view class="item-identity">
								{{item.username}}
							</view>
						</view>
						<view class="item-right" @click="clickCall(item.username)">
							联系
						</view>
					</view>
				</view>
				<view class="see">
					<view class="see-item">
						<view class="see-name">
							捐献金额
						</view>
						<view class="see-text see-color">
							<text>￥</text>{{item.orders_sum_amount}}
						</view>
					</view>
					<view class="see-item">
						<view class="see-name">
							捐献数量
						</view>
						<view class="see-text">
							{{item.orders_count}}
						</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 { dataUser } from '@/apis/interfaces/user'
	export default {
		data() {
			return {
               orderList   : [],
			   page        : {},     //分页信息
			   lodingStats : false   //加载状态
			};
		},
        onShow() {
			// 数据-订单列表
			this.censusInfo();
        },
        
		methods:{
			// 查看数据-订单列表
			censusInfo(page) {
			    dataUser({
                    page : page || 1
                }).then(res => {
					console.log(res.data)
					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;
	}
	.list {
		padding: 30rpx;
		box-sizing: border-box;
		.label {
			background-color: #ffffff;
			margin-bottom: 30rpx;
			border-radius: 10rpx;
			padding: $padding;
			box-sizing: border-box;
		}
		.item {
			position: relative;
			.item-head {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}
			.item-cont {
				position: absolute;
				left: 0;
				top: 0;
				padding-left: 130rpx;
				box-sizing: border-box;
				width: 100%;
				display: flex;
				.item-left {
					flex: 1;
					line-height: 54rpx;
					.item-top {
						font-weight: 600;
						margin-right: $margin - 10;
					}
					.item-identity {
						font-size: $title-size-m;
						color: #8282a7;
					}
				}
				.item-right {
					display: inline-block;
					font-size: $title-size-m;
					background-color: #edf4ff;
					color: #5370eb;
					height: 54rpx;
					line-height: 54rpx;
					padding: 0 $padding + 10;
					border-radius: $radius * 4;
					margin-top: $margin - 5;
				}
			}
		}
		
		.see {
			padding: 30rpx 0;
			display: flex;
			background-color: #f4f7fd;
			border-radius: 10rpx;
			margin-top: 30rpx;
			.see-item {
				flex: 2;
				text-align: center;
				.see-name {
					font-size: 24rpx;
					color: #383c4b;
					margin-top: 5rpx;
				}
				.see-text {
					font-size: 28rpx;
					font-weight: 600;
					margin-top: 10rpx;
					text {
						font-size: 22rpx;
					}
					&.see-color {
						color: red;
					}
				}
			}
		}
	}
</style>