<!-- 佣金明细 -->
<template>
	<view>
		<!-- <z-paging ref="paging" refresher-complete-delay="200" v-model="rewardLog" @query="queryList"> -->
		<!-- #ifdef H5 -->
		<view style="color: #000000;">
			<tn-nav-bar backgroundColor="#ffffff" :bottomShadow="false">推广佣金明细</tn-nav-bar>
			<view :style="{height: tobheight+'px'}"></view>
		</view>
		<!-- #endif -->

		<!-- <view slot="top" class="z_tabs" :style="{marginTop: tobheight+'px'}"></view> -->
		<view class="commission-log-wrap">
			<!-- 钱包卡片 -->
			<view class="wallet-wrap">
				<view class="wallet-card">
					<view class="head-box u-flex">
						<view class="head-title">累计收入</view>
						<button class="u-reset-button look-btn" @tap="showMoney = !showMoney">
							<!-- <view class="u-iconfont" :class="showMoney ? 'uicon-eye-fill' : 'uicon-eye-off'" style="color: #fff;font-size: 50rpx;"></view> -->
							<u-icon :name="showMoney ? 'eye-fill':'eye-off'" color="#fff" size="22"></u-icon>
						</button>
					</view>
					<view class="card-num">{{ showMoney ?  Number(recommendSum.total_income).toFixed(2) : '***' }}
					</view>
					<view class="card-bottom u-flex u-row-left">
						<view class="card-item u-flex-1">
							<view class="item-title">待入账佣金</view>
							<view class="item-value">
								{{ showMoney ? Number(recommendSum.wait_income).toFixed(2) : '***' }}
							</view>
						</view>
						<view class="card-item u-flex-1">
							<view class="item-title">可提现佣金</view>
							<view class="item-value">
								{{ showMoney ?Number(recommendSum.cashing).toFixed(2) : '***' }}
							</view>
						</view>
						<!-- 	<view class="card-item u-flex-1">
										<view class="item-title">待入账佣金</view>
										<view class="item-value">{{ showMoney ? on_cashout_money || '0.00' : '***' }}</view>
									</view> -->
						<view class="card-item u-flex-1">
							<view class="item-title">已提现佣金</view>
							<view class="item-value">
								{{ showMoney ? Number(recommendSum.cashed).toFixed(2) : '***' }}
							</view>
						</view>
					</view>
					<button class="u-reset-button draw-btn"
						@tap="jump('/pages/user/commission/withdraw',{type:2})">提现</button>

					<view class="cashTips">
						注：可提现佣金/已提现佣金包含了任务佣金和推广佣金
					</view>
				</view>
			</view>

			<!-- 筛选 -->
			<view class="" v-if="commissionList.length==0">
				<empty style=""></empty>
			</view>

			<view class="item-box">
				<!-- 佣金明细列表 -->
				<view class="log-item u-flex u-row-between" v-for="item in commissionList" :key="item.id">
					<view class="item-left u-flex">
						<view class="">
							<view class="log-name">{{ item.title }}</view>
							<view class="log-notice">{{ item.created_at }}</view>

							<view class="nextUser" v-if="item.source_user">
								<image class="nextAvatar"
									:src="item.source_user.avatar!=''?item.source_user.avatar:'/static/images/head.jpg'"
									mode=""></image>
								<view class="nextUserName">
									{{item.source_user.nickname }}
								</view>
							</view>
						</view>
					</view>
					<view class="item-right">
						<view v-if="item.status==0" class="log-num"
							style="display: flex;flex-direction: column;align-items: center;">
							<view class="" style="color:orange;width: 100rpx;text-align: center;">
								待入账
							</view>
							<view class="" style="color:orange">
								{{item.amount}}
							</view>
						</view>
						<view v-if="item.status==1" class="log-num"
							style="display: flex;flex-direction: column;align-items: center;">
							<view class="" style="color:#05C3A1">
								+{{item.amount}}
							</view>
						</view>
						<view v-if="item.status==2" class="log-num"
							style="display: flex;flex-direction: column;align-items: center;">
							<view class="" style="color:red;width: 70rpx;margin-left: 10rpx;">
								审核失败
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 	</z-paging>
		<wike-loading-page :isLoading="isLoading"></wike-loading-page> -->
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';

	import {
		recommendList,
		recommendCount
	} from '@/api/my/index.js'

	import empty from '@/components/empty/empty.vue'
	export default {
		data() {
			return {
				// isLoading: true,
				isLoading: false,
				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: [{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00'
					},
					{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00'
					},
					{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00'
					},
					{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00'
					}
				], //佣金记录
				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',
				alreadyWithdral_money: '0.00',

				commissionList: [],
				recommendSum: {}
			};
		},
		computed: {
			...mapGetters(['appInfo', 'isLogin', 'userInfo'])
		},
		async onLoad() {

		},
		async onShow() {
			let ress = await recommendCount()
			console.log('推广佣金汇总返回值', ress);
			if (ress.code == 0) {
				this.recommendSum = ress.data
			}

			let res = await recommendList()
			if (res.code == 0) {
				res.data.data.forEach((item, index) => {
					item.description = JSON.parse(item.description)
				})

				this.commissionList = res.data.data
				console.log('推广佣金明细返回值', res, this.commissionList);
			}
		},

		methods: {
			queryList(pageNo, pageSize) {
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				this.$refs.paging.complete([{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00',
						type: 1
					},
					{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00',
						type: 1
					},
					{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00',
						type: 1
					},
					{
						mark: '任务佣金收入',
						create_time: '2023-06-02',
						money: '99.00',
						type: 1
					},
					{
						mark: '佣金提现',
						create_time: '2023-06-02',
						money: '99.00',
						type: 0
					},
					{
						mark: '佣金提现',
						create_time: '2023-06-02',
						money: '99.00',
						type: 0
					},
					{
						mark: 'gpt消耗',
						create_time: '2023-06-02',
						money: '99.00',
						type: 0
					},
					{
						mark: 'gpt消耗',
						create_time: '2023-06-02',
						money: '99.00',
						type: 0
					},
					{
						mark: 'gpt消耗',
						create_time: '2023-06-02',
						money: '99.00',
						type: 0
					},
				]);




				// 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">
	.nextUser {
		display: flex;
		align-items: center;
		margin-top: 10rpx;
		margin-bottom: 10rpx;

		.nextAvatar {
			width: 40rpx;
			height: 40rpx;
			border-radius: 50%;
			margin-right: 20rpx;
		}

		.nextUserName {
			font-size: 24rpx;
			color: #ccc;
			// font-weight: 600;
		}
	}


	.cashTips {
		margin-top: 20rpx;
		color: white;
		font-size: 12rpx;
	}

	// 分类
	.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: 200rpx;
		background-color: #fff;
		padding: 0 60rpx;
		border-bottom: 1rpx solid #eee;
		padding-top: 10rpx;

		.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>