<template>
	<block>
<!-- 		<view class="select">
			<view class="selectItem" @tap="changeStatus" data-status="id">
				<view>入团时间排序</view>
				<image :src="
                        order == 'id'
                            ? sort == 'asc'
                                ? 'https://ymyun-oss.oss-cn-hangzhou.aliyuncs.com/yidu_tc/public/upload/12/8/a970f9087def9ba466276f8a9ee59b1b.png'
                                : 'https://ymyun-oss.oss-cn-hangzhou.aliyuncs.com/yidu_tc/public/upload/12/8/5f1df0376dd2a026fdd14ca4d1d39974.png'
                            : 'https://ymyun-oss.oss-cn-hangzhou.aliyuncs.com/yidu_tc/public/upload/12/8/996fff6601b828ee6fcc46b1217b2d1a.png'
                    " mode="widthFix"></image>
			</view>

			<view class="selectItem" @tap="changeStatus" data-status="order">
				<view>订单数量</view>
				<image :src="
                        order == 'order_num'
                            ? sort == 'asc'
                                ? 'https://ymyun-oss.oss-cn-hangzhou.aliyuncs.com/yidu_tc/public/upload/12/8/a970f9087def9ba466276f8a9ee59b1b.png'
                                : 'https://ymyun-oss.oss-cn-hangzhou.aliyuncs.com/yidu_tc/public/upload/12/8/5f1df0376dd2a026fdd14ca4d1d39974.png'
                            : 'https://ymyun-oss.oss-cn-hangzhou.aliyuncs.com/yidu_tc/public/upload/12/8/996fff6601b828ee6fcc46b1217b2d1a.png'
                    " mode="widthFix"></image>
			</view>
		</view> -->

		<view class="mItem" v-for="(item, index) in list" :key="index">
			<image
				:src="item.avatar || 'https://ymyun-oss.oss-cn-hangzhou.aliyuncs.com/yidu_tc/public/upload/12/8/a035c7dae49cc9904c7b0977895ffb1e.png'">
			</image>

			<view class="mInfo">
				<view class="info1">
					<view>
						{{ item.username }}
						<text class="fz28">{{ item.mobile	 }}</text>
					</view>
					<view>{{ item.orderNum }}</view>
				</view>
				<view class="info2">
					<view>入团:{{ parse.filterTime(item.createtime) }}</view>
					<view>推广订单</view>
				</view>
			</view>
		</view>

		<view v-if="!list.length" style="color: #999; text-align: center; margin: 100rpx 0">暂无数据</view>


	</block>
</template>
<script module="parse" lang="wxs">
	module.exports = {
		filterTime: function(value) {

			var nowDate = getDate(value * 1000); //过期时间

			var year = nowDate.getFullYear(); //当前年份
			var month = nowDate.getMonth() + 1; //当前月份
			var date = nowDate.getDate(); //当前几号
			var hours = nowDate.getHours(); //当前几小时


			return year + '-' + month + '-' + date
		}

	}
</script>
<script>
	// pages/tabbar/index/index.js
	var app = getApp();
	export default {
		data() {
			return {
				list: [],
				loaded: false,
				page: 1,
				order: 'id',

				//id是入团时间 order_num是订单数
				//asc升序，desc降序
				sort: 'asc',

				type: 0,
				pageSize:10
			};
		},
		onLoad: function(options) {

			uni.setNavigationBarTitle({
				title: '我的团队'
			});


			this.getlist();
		},
		onPullDownRefresh: function() {},
		onReachBottom: function() {
			this.loaded || this.getlist();
		},
		onShareAppMessage: function() {},
		methods: {
			changeStatus(e) {
				var that = this;
				var status = e.currentTarget.dataset.status;
				var order = this.order;
				var sort = this.sort;

				if (status == 'id') {
					//点的是入团时间排序
					if (order == 'id') {
						// 之前也是筛选的入团时间
						if (sort == 'asc') {

							that.sort = 'desc'

						} else {

							that.sort = 'asc'

						}
					} else {
						//之前筛选的订单数量 那就要变成入团时间排序 并且默认升序

						that.order = 'id'
						that.sort = 'asc'

					}
				} else {
					//点的是订单数量
					if (order == 'order_num') {
						// 之前也是筛选的入团时间
						if (sort == 'asc') {

							that.sort = 'desc'

						} else {

							that.sort = 'asc'

						}
					} else {
						//之前筛选的订单数量 那就要变成入团时间排序 并且默认升序

						that.order = 'order_num'
						that.sort = 'asc'

					}
				}

				that.init();
				that.getlist();
			},

			toPage(e) {
				app.globalData.toPage(e);
			},

			init() {

				this.page = 1
				this.loaded = false
				this.list = []

			},

			async getlist() {
				var that = this;

				let res = await this.$api.request('/team/index', 'GET', {
					page: that.page,
					pagesize: that.pageSize,
					order: that.order,
					sort: that.sort
				});
				console.log(res)
				if (res) {
					
					if (res.length > 0) {

						this.list = this.list.concat(res);
						this.page++;

						// uni.setNavigationBarTitle({
						//     title: '我的团队(' + res.total + ')'
						// });

					} else {
						this.loaded = true
						this.$api.msg('没有更多数据');
					}
				}


			}
		}
	};
</script>
<style>
	page {
		background: #f4f5f9;
	}

	.select {
		padding: 30rpx 0 20rpx 0;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.selectItem {
		display: flex;
		align-items: center;
	}

	.selectItem>view {
		font-size: 28rpx;
	}

	.selectItem>image {
		width: 26rpx;
		margin-left: 12rpx;
	}

	.mItem {
		margin: 25rpx 30rpx 0;
		background: #fff;
		padding: 28rpx 20rpx;
		display: flex;
		align-items: center;
	}

	.mItem>image {
		width: 110rpx;
		height: 110rpx;
		border-radius: 50%;
		margin-right: 25rpx;
	}

	.mInfo {
		flex: 1;
		height: 110rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.info1 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-right: 36rpx;
	}

	.info1>view:nth-child(1) {
		font-size: 34rpx;
	}

	.fz28 {
		font-size: 28rpx;
	}

	.info1>view:nth-child(2) {
		color: #1479ff;
		font-size: 34rpx;
	}

	.info2 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 26rpx;
	}

	.info2>view:nth-child(1) {
		color: #9194a6;
	}

	.info2>view:nth-child(2) {
		color: #7B9D3E;
	}

	.fb {
		height: 112rpx;
		width: 100%;
		position: fixed;
		bottom: 0;
		background: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.addAddress {
		width: 670rpx;
		height: 80rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		background: #1479ff;
		border-radius: 50rpx;
	}

	.addAddress>view {
		color: #fff;
		font-size: 30rpx;
	}

	.addAddress>image {
		width: 30rpx;
		margin-right: 14rpx;
	}

	view {
		font-size: 24rpx;
	}
</style>
