<!-- 佣金明细 -->
<template>
	<view>
		<view style="color: #000000;">
			<tn-nav-bar backgroundColor="#ffffff" :bottomShadow="false">邀请码</tn-nav-bar>
			<!-- <view :style="{height: tobheight+'px'}"></view> -->
		</view>
		<z-paging ref="paging" refresher-complete-delay="200" v-model="rewardLog" @query="queryList">
			<view slot="top" class="z_tabs" :style="{marginTop: tobheight+'px'}"></view>
			<view class="commission-log-wrap">
				邀请码<button>复制</button>
			</view>
		</z-paging>
		<wike-loading-page :isLoading="isLoading"></wike-loading-page>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				isLoading: true,
				tobheight: 45,
				platform: this.$platform.get(),
				stateCurrent: 'all', //默认
				stateMap: {
					all: '全部收入',
					waiting: '待入账',
					accounted: '已入账',
					back: '已退回',
					cancel: '已取消'
				},
				classType: {
					'-1': '#EB2B3D',
					'0': '#05C3A1',
					'1': '#7063D2',
					'-2': '#EEEEEE'
				},
				statusList: [{
						name: '全部',
						value: 'all'
					},
					{
						name: '待入账',
						value: 'waiting'
					},
					{
						name: '已入账',
						value: 'accounted'
					},
					// {
					// 	name: '已退回',
					// 	value: 'back'
					// },
					// {
					// 	name: '已取消',
					// 	value: 'cancel'
					// }
				],
				incomeLog: [],
				showMoney: true, //是否显示金额
				//日期选择
				showCalendar: false,
				selDateText: '',
				rewardLog: [{}], //佣金记录
				propsDate: '', //日期参数
				totalMoney: '', //收入
				loadStatus: 'loadmore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
				currentPage: 1,
				lastPage: 1,
				isEmpty: false,
				on_cashout_money: '0.00',
				money_total: '0.00',
				money: '0.00'
			};
		},
		computed: {
			...mapGetters(['appInfo', 'isLogin', 'userInfo'])
		},
		onLoad() {
			const that = this;
			if (this.platform == 'wxMiniProgram') {
				var menumtop = uni.getMenuButtonBoundingClientRect().top - uni.getSystemInfoSync().statusBarHeight
				var paddingtop = uni.getSystemInfoSync().statusBarHeight + menumtop
				this.tobheight = (menumtop + paddingtop + uni.getMenuButtonBoundingClientRect().height)
			}
			this.getToday();

			this.getCommissionLog();
		},
		onShow() {
			this.getCheck()
		},

		methods: {
			queryList(pageNo, pageSize) {
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				const params = {
					page: pageNo,
					limit: pageSize,
					// level: this.level,
				};
				this.$http('commission.incomeLog', params).then(res => {
					if (res.code == 0) {

						this.$refs.paging.complete(res.data.data);

					}
				});
			},
			getCheck() {
				var that = this;
				that.$http('commission.auth').then(res => {
					if (res.code == 0) {
						uni.setNavigationBarTitle({
							title: this.appInfo.site_name
						});
						that.on_cashout_money = res.data.on_cashout_money > 0 ? res.data.on_cashout_money : '0.00'
						that.money_total = res.data.money_total > 0 ? res.data.money_total : '0.00'
						that.money = res.data.money
						that.isLoading = false
					}
				})
			},
			jump(path, parmas) {
				this.$Router.push({
					path: path,
					query: parmas
				});
			},
			// 切换分类
			onTab(state) {
				if (this.stateCurrent !== state) {
					this.rewardLog = [];
					this.currentPage = 1;
					this.lastPage = 1;
					this.stateCurrent = state;
					this.getCommissionLog();
				}
			},

			//  今日
			getToday() {
				let now = new Date();
				this.selDateText = `${now.getFullYear()}.${now.getMonth() + 1}.${now.getDate()}`;
				let dateText = `${now.getFullYear()}/${now.getMonth() + 1}/${now.getDate()}`;
				this.propsDate = `${dateText}-${dateText}`;
			},

			// 选择日期
			selDate(e) {
				this.rewardLog = [];
				this.currentPage = 1;
				this.lastPage = 1;
				this.selDateText = `${e.startYear}.${e.startMonth}.${e.startDay}-${e.endYear}.${e.endMonth}.${e.endDay}`;
				let dateText = `${e.startYear}/${e.startMonth}/${e.startDay}-${e.endYear}/${e.endMonth}/${e.endDay}`;
				this.propsDate = dateText;
				this.getCommissionLog();
				this.$refs.uCalendar.init();
			},

			// 佣金明细
			getCommissionLog() {
				let that = this;
				that.loadStatus = 'loading';
				that.$http(
					'commission.incomeLog', {
						// date: that.propsDate,
						// type: that.stateCurrent,
						page: that.currentPage
					},
					'加载中...'
				).then(res => {
					uni.stopPullDownRefresh();
					if (res.code === 0) {
						// that.totalMoney = res.data.total_money;
						that.rewardLog = [...that.rewardLog, ...res.data.data];
						that.lastPage = res.data.last_page;
						that.isEmpty = !that.rewardLog.length;
						that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
					}
				});
			},

			// 加载更多
			loadMore() {
				if (this.currentPage < this.lastPage) {
					this.currentPage += 1;
					this.getCommissionLog();
				}
			}
		}
	};
</script>

<style lang="scss">
	// 分类
	.state-item {
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #fff;
		border-bottom: 1rpx solid rgba(#999, 0.5);

		.state-title {
			color: #666;
			font-weight: 500;
			font-size: 28rpx;
			line-height: 90rpx;
		}

		.title-active {
			color: #333;
		}

		.underline {
			display: block;
			width: 68rpx;
			height: 4rpx;
			background: #fff;
			border-radius: 2rpx;
		}

		.underline-active {
			background: #5e49c3;
			display: block;
			width: 68rpx;
			height: 4rpx;
			border-radius: 2rpx;
		}
	}

	// 钱包卡片
	.wallet-wrap {
		background-color: #fff;
		padding: 30rpx;
	}

	.wallet-card {
		width: 690rpx;
		height: 301rpx;
		background: url('http://file.shopro.top/imgs/commission/commission_card_bg.png') no-repeat;
		background-size: 100% 100%;
		border-radius: 20rpx;
		padding: 30rpx;
		position: relative;
		box-shadow: 1rpx 5rpx 16rpx 0px rgba(94, 73, 195, 0.81);

		.head-box {
			margin-bottom: 20rpx;

			.head-title {
				font-size: 24rpx;
				font-weight: 400;
				color: #ffffff;
			}

			.look-btn {
				color: #fff;
				font-size: 30rpx;
				background: none;
				padding: 0;
				margin-left: 20rpx;
			}
		}

		.card-num {
			font-size: 40rpx;
			font-weight: 500;
			color: #fefefe;
			margin-bottom: 30rpx;
		}

		.card-bottom {
			.card-item {
				.item-title {
					font-size: 24rpx;
					font-weight: 400;
					color: #ffffff;
					margin-bottom: 10rpx;
				}

				.item-value {
					font-size: 30rpx;
					font-weight: 500;
					color: #fefefe;
				}
			}
		}

		.draw-btn {
			position: absolute;
			top: 35rpx;
			right: 35rpx;
			width: 121rpx;
			line-height: 58rpx;
			background: #ffffff;
			border-radius: 29rpx;
			padding: 0;
			font-size: 24rpx;
			font-weight: 500;
			color: #5848c4;
		}
	}

	// 表头
	.head_box {
		height: 120rpx;
		padding: 0 30rpx;
		background-color: #f6f6f6;

		.date-btn {
			background-color: #fff;
			line-height: 54rpx;
			border-radius: 27rpx;
			padding: 0 20rpx;
			font-size: 24rpx;
			font-weight: 500;
			color: #666666;
		}

		.total-box {
			font-size: 24rpx;
			font-weight: 500;
			color: #666666;
		}
	}

	// 佣金明细列表
	.item-box {
		margin: 20rpx 0;
	}

	.log-item {
		height: 142rpx;
		background-color: #fff;
		padding: 0 60rpx;
		border-bottom: 1rpx solid #eee;

		.item-left {
			.log-img {
				width: 50rpx;
				height: 50rpx;
				border-radius: 50%;
				margin-right: 24rpx;
			}

			.log-name {
				font-size: 28rpx;
				font-weight: 500;
				color: #333333;
				margin-bottom: 12rpx;
			}

			.log-notice {
				font-size: 22rpx;
				font-weight: 500;
				color: #c0c0c0;
			}
		}

		.item-right {
			.log-num {
				font-size: 28rpx;
				font-weight: 500;
				color: #05c3a1;
			}

			.log-date {
				font-size: 24rpx;
				font-weight: 400;
				color: #c0c0c0;
			}
		}
	}
</style>