<template>
	<view>
		<image src="../../../static/img/user/1.png" class="width100 images"></image>
		<view class="width100 font16 fcorfff title fotct paddtop15">今日积分收入</view>
		<view class="width100 font48 fcorfff title fotct paddtop15">
			{{ !distribution.toDayIntegralNum ? 0 : distribution.toDayIntegralNum}}
		</view>
		<view class="title paddtop15 alijus fcorfff  fotct">
			<view class="width30w ">
				<view class="width100 font14">邀请人数</view>
				<view class="width100 font18 paddtop5">
					{{ !distribution.inviteeNum ? 0 : distribution.inviteeNum}}
				</view>
			</view>
			<view class="backcorfff" style="width: 1px;height: 50px;"></view>
			<view class="width30w">
				<view class="width100 font14">积分收入</view>
				<view class="width100 font18 paddtop5">
					{{ !distribution.integralIncome ? 0 : distribution.integralIncome}}
				</view>
			</view>
			<view class="backcorfff" style="width: 1px;height: 50px;"></view>
			<view class="width30w">
				<view class="width100 font14">积分笔数</view>
				<view class="width100 font18 paddtop5">{{ !distribution.orderCount ? 0 : distribution.orderCount}}
				</view>
			</view>
		</view>
		<view class="font14 width20w fcorfff title fotct mart10"
			style="padding: 3px 5px;border-radius: 15px;border: 1px solid;" @click="jumpmypro()">我的邀请码</view>

		<view class="width90 mart40 alijus ">
			<view class="font14 fcor666 paddtop5 paddbotm5  margle20  marRight20" v-for="(item,index) in cateTypeList"
				@click="switchid(item)" :class="[goodtyid == item.id ? 'fon62ac borbtom fontwig6 font16' : '']"
				:key="index">
				{{item.title}}
			</view>
		</view>

		<view class="alijus width90 fotct mart20 font14 fcor666" v-if="goodtyid == 1">
			<view class="width30w fotlt">
				名称
			</view>
			<view class="width30w">
				电话
			</view>
			<view class="width30w">
				邀请时间
			</view>
		</view>
		<view class="width100" v-if="goodtyid == 1">
			<view v-if="dataslist == '' " class="mart60 fotct font14 fcor666">
				<image mode="widthFix" style="width: 70vw;" :src="imagewxUrl+imgadres"></image>
			</view>
			<view class="alijus width90 fotct mart15 font14 fcor999" v-for="(item,index) in dataslist" :key="index">
				<view class="width30w fotlt">
					{{item.userName}}
				</view>
				<view class="width30w fotlt">
					{{item.phone}}
				</view>
				<view class="width30w">
					{{item.createTime | timeFormat('yyyy-mm-dd hh:mm:ss')}}
				</view>
			</view>
		</view>

		<view class="width100" v-if="goodtyid == 2">
			<view v-if="integralList == '' " class="mart60 fotct font14 fcor666">
				<image mode="widthFix" style="width: 70vw;" :src="imagewxUrl+imgadres"></image>
			</view>
			<view class="alijus width94 mart15 font14 fcor999" v-for="(item,index) in integralList" :key="index">
				<image :src="imageUrl+item.ext1" class="icon40" mode="widthFix"></image>
				<view class="width85 bor-botm1">
					<view class="width100 alijusstart">
						<view class="width70 fcor333 paddleft10">{{item.title}}</view>
						<view class="width30 fcor333 fontwig6 font20 fotrt">+{{item.integralNum}}</view>
					</view>
					<view class="width100 fcor999 font13 paddleft10 paddbotm5">
						{{item.ext3}} | {{item.userName}}
					</view>
				</view>
			</view>
		</view>

		<view class="width100" v-if="goodtyid == 3">
			<view v-if="distrOrderList == '' " class="mart60 fotct font14 fcor666">
				<image mode="widthFix" style="width: 70vw;" :src="imagewxUrl+imgadres"></image>
			</view>
			<view class="alijus width100 mart15 font14 fcor999" v-for="(item,index) in distrOrderList" :key="index">
				<view class="width100 bor-botm1 paddleft5 paddtright10">
					<view class="width100 alijusstart">
						<view class="width70 fcor333 paddleft10">{{item.goodsTypeName}}</view>
						<view class="width30 fcor333 fontwig6 font20 fotrt">¥{{item.totalPrice}}</view>
					</view>
					<view class="width100 fcor999 font13 paddleft10 paddbotm5">
						{{item.time}} ｜ {{item.memName}}
					</view>
				</view>
			</view>
		</view>

		<view class="height45"></view>
	</view>
</template>

<script>
	import {
		userDistributionStatistics,
		distributionInviteList,
		distributionOrderList,
		promoteOrderList
	} from '../../../Utils/Api.js'
	let app = getApp();
	export default {
		data() {
			return {
				imagewxUrl: app.globalData.imageWxImg,
				imageUrl:app.globalData.imgUrl,
				imgadres: 'noorder.png',
				cateTypeList: [{
						id: 1,
						title: '邀请列表'
					},
					{
						id: 2,
						title: '积分记录'
					}, {
						id: 3,
						title: '推广记录'
					},
				],
				goodtyid: 1, //区分类型
				dataslist: [], //邀请列表
				distrOrderList: [], //订单列表
				distribution: '', //统计
				integralList: [], //积分数据
				pageNum: 1,
				pageSize: 10,
				isNoMoreData: false,
			}
		},
		onLoad() {
			this.userDistributionStatistics();
			this.distributionInviteList();
		},
		methods: {
			//跳转到生成海报
			jumpmypro() {
				uni.navigateTo({
					url: '/pages/user/generatePoster/generatePoster'
				})
			},
			//切换id
			switchid(item) {
				this.goodtyid = item.id;
				if (item.id == 1) {
					this.pageNum = 1;
					this.dataslist = [];
					this.isNoMoreData = false;
					this.distributionInviteList();
				} else if (item.id == 2) {
					this.pageNum = 1;
					this.integralList = [];
					this.isNoMoreData = false;
					this.distributionOrderList();
				} else if (item.id == 3) {
					this.pageNum = 1;
					this.distrOrderList = [];
					this.isNoMoreData = false;
					this.promoteOrderList();
				}
			},
			//分销统计
			userDistributionStatistics() {
				uni.showLoading({
					title: '加载中...'
				})
				userDistributionStatistics().then(res => {
					if (res.return_code == '000000') {
						this.distribution = res.return_data;
						uni.hideLoading();
					}
				})
			},
			//邀请列表
			distributionInviteList() {
				uni.showLoading({
					title: '加载中...'
				})
				if (this.isNoMoreData) {
					uni.hideLoading();
					return false;
				}
				let pagenum = this.pageNum;
				let params = {
					pageNum: pagenum,
					pageSize: this.pageSize,
				}
				distributionInviteList(params).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000') {
						this.isNoMoreData = res.return_data.list.length == this.pageSize ? false : true;
						this.dataslist = this.dataslist.concat(res.return_data.list);
						if (res.return_data.total == (this.pageNum * this.pageSize)) {
							this.isNoMoreData = true;
						}
						this.pageNum = res.return_data.list.length == this.pageSize ? ++pagenum : pagenum;
					} else {
						this.dataslist = [];
					}
				})
			},
			// 分销用户积分
			distributionOrderList() {
				uni.showLoading({
					title: '加载中...'
				})
				if (this.isNoMoreData) {
					uni.hideLoading()
					return false;
				}
				let pagenum = this.pageNum;
				let params = {
					pageNum: pagenum,
					pageSize: this.pageSize,
				}
				distributionOrderList(params).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000') {
						this.isNoMoreData = res.return_data.list.length == this.pageSize ? false : true;
						this.integralList = this.integralList.concat(res.return_data.list);
						if (res.return_data.total == (this.pageNum * this.pageSize)) {
							this.isNoMoreData = true;
						}
						this.pageNum = res.return_data.list.length == this.pageSize ? ++pagenum : pagenum;
					} else {
						this.integralList = [];
					}
				})
			},
			//分销用户订单列表
			promoteOrderList() {
				uni.showLoading({
					title: '加载中...'
				})
				if (this.isNoMoreData) {
					uni.hideLoading()
					return false;
				}
				let pagenum = this.pageNum;
				let params = {
					pageNum: pagenum,
					pageSize: this.pageSize,
				}
				promoteOrderList(params).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000') {
						this.isNoMoreData = res.return_data.list.length == this.pageSize ? false : true;
						this.distrOrderList = this.distrOrderList.concat(res.return_data.list);
						if (res.return_data.total == (this.pageNum * this.pageSize)) {
							this.isNoMoreData = true;
						}
						this.pageNum = res.return_data.list.length == this.pageSize ? ++pagenum : pagenum;
					} else {
						this.distrOrderList = [];
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.images {
		position: absolute;
		height: 235px;
	}

	.title {
		position: relative;
	}

	.borbtom {
		border-bottom: 3px solid #62ac4e;
	}

	.fon62ac {
		color: #62ac4e;
	}
</style>
