<template>
	<view class="dikou">
		<view class="dikou-header u-flex u-row-between u-col-top">
			<image src="static/images/yjbg.png" class="header-img" mode=""></image>
			<text class="top-font" @click="tobank">银行卡</text>
			<view class="header-item u-flex-1 u-flex-col">
				<view class="item-top u-flex">
					<text>佣金余额</text>
					<image style="margin-left: 10rpx;" src="static/images/dikou-tips.png" mode=""></image>
				</view>
				<view class="item-price u-flex u-row-between"
					style="border-bottom: 2rpx solid rgba(255,255,255,0.2);padding-bottom: 32rpx;">
					<view class="u-flex">
						{{Number(sum).toFixed(2) || '0.00'}}元
						<text style="margin-left: 20rpx;margin-right: 8rpx;" @click.stop="mingxi"
							class="fontm">佣金明细</text>
						<u-icon name="arrow-right" size="9" color="#fff"></u-icon>
					</view>
					<!-- <image style="margin-left: 20rpx;" @click="totixian" src="static/images/dikou-tixian.png"
						class="item-tixian" mode=""></image> -->
					<view class="tixian" @click="totixian">
						提现
					</view>
				</view>
				<!-- 				<view class="u-flex">
					<view class="left">
						<text class="top">订单佣金</text>
						<view class="bottom">
							{{order || '0.00'}}
						</view>
					</view>
					<view class="right">
						<text class="top">邀请佣金</text>
						<view class="bottom">
							{{invite || '0.00'}}
						</view>
					</view>
				</view> -->
				<view class="u-flex" style="margin-top: 30rpx;">
					<view class="" style="border-right: 1rpx solid rgba(255,255,255, 0.2);min-width: 170rpx;">
						<view class="fontm">订单佣金</view>
						<view class="bottom">{{Number(order).toFixed(2) || '0.00'}}</view>
					</view>
					<view class="" style="margin-left: 70rpx;">
						<view class="fontm">待结算订单佣金</view>
						<view class="bottom">{{Number(order_un_confirm).toFixed(2) || '0.00'}}</view>
					</view>
					<view class="" style="margin-left: 60rpx;">
						<view class="fontm">已结算订单佣金</view>
						<view class="bottom">{{Number(order_confirm).toFixed(2) || '0.00'}}</view>
					</view>
				</view>
				<view class="u-flex" style="margin-top: 30rpx;">
					<view class="" style="border-right: 1rpx solid rgba(255,255,255, 0.2);min-width: 170rpx;">
						<view class="fontm">邀请佣金</view>
						<view class="bottom">{{Number(invite).toFixed(2) || '0.00'}}</view>
					</view>
					<view class="" style="margin-left: 70rpx;">
						<view class="fontm">待结算邀请佣金</view>
						<view class="bottom">{{Number(invite_un_confirm).toFixed(2) || '0.00'}}</view>
					</view>
					<view class="" style="margin-left: 60rpx;">
						<view class="fontm">已结算邀请佣金</view>
						<view class="bottom">{{Number(invite_confirm).toFixed(2) || '0.00'}}</view>
					</view>
				</view>
			</view>
			<!-- 			<view class="header-item u-flex-1 u-flex-col " style="justify-content: center;">
				<view class="box">
					<view class="u-flex top1" style="">
						<text class="fontm" style="margin-right: 8rpx;min-width: 100rpx;"
							@click.stop="mingxi">佣金明细</text>
						<u-icon name="play-right-fill" style="transform: rotate(90deg);" color="#fff"
							size="12"></u-icon>
					</view>
					<view class="u-flex bottom1" style="">
						<text class="fontm" style="margin-right: 8rpx;min-width: 100rpx;" @click="tobank">银行卡</text>
						<u-icon name="play-right-fill" color="#fff" size="12"></u-icon>
					</view>
				</view>
			</view> -->
		</view>
		<view class="" style="height: 120rpx;"></view>
		<view class="dikou-list">
			<view class="list-header u-flex u-row-between">
				<view class="header-title u-flex-col">
					<text>收支明细</text>
					<text></text>
				</view>
				<view class="list-time u-flex" @click="workBtn()">
					<text class="text1">{{date || '选择时间'}}</text>
					<u-icon name="arrow-down-fill" size="9"></u-icon>
				</view>
			</view>
			<view class="list-item u-flex u-row-between" v-for="(item,index) in list" :key="index"
				v-if="list.length > 0">
				<view class="u-flex-col">
					<!-- 					<text v-if="item.souce_type=='invite'||item.souce_type=='order'"
						class="text1">{{item.source_type_name}}入账</text>
					<text v-else class="text1">佣金提现</text>
					<text class="text2">{{item.createtime}}</text> -->
					<text class="text1">{{item.source_type_name}}</text>
					<text class="text2">{{item.createtime}}</text>
				</view>
				<text class="text3" v-if="item.type=='income'" style="color: #35AA1F;">{{item.amount}}</text>
				<text class="text3" v-else style="color: #E02020;">{{item.amount}}</text>
			</view>
			<view style="height: 61vh;justify-content: center;" class="u-flex" v-if="list.length == 0">
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>
		</view>
		<u-datetime-picker ref="pickers" :show="showtime" mode="year-month" @confirm="changetime"
			@cancel="close()"></u-datetime-picker>
	</view>
</template>

<script>
	import {
		getBank,
		commission_list,
		index,
		commission_data,
		commission_log_list
	} from "@/units/inquire.js"
	export default {
		data() {
			return {
				order_un_confirm: "", //rm //订单待结算佣金
				order_confirm: "", ////订单已经结算佣金
				invite_un_confirm: "", //irm //订单待结算佣金
				invite_confirm: "", // //订单待结算佣金
				order: '0.00',
				sum: '0.00',
				invite: '0.00',
				page: 1,
				list: [],
				total: 0,
				date: '',
				showtime: false,
				bankdata: {},
			}
		},
		onShow() {
			this.getuser()
			this.page = 1
			this.total = 0
			this.list = []
			this.getlist()
			this.getdata()
			this.getBank()
		},
		onReachBottom() {
			if (this.total != this.list.length) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			workBtn() {
				this.showtime = true
				this.$refs.pickers.innerValue = new Date(1672502400000).getTime()
			},
			mingxi() {
				uni.navigateTo({
					url: "/pagesD/mingxi"
				})
			},
			close() {
				this.showtime = false
			},
			getBank() {
				getBank().then(res => {
					this.bankdata = res.data || {}
				})
			},
			async changetime(e) {
				const timeFormat = uni.$u.timeFormat;
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.date = timeValue;
				this.page = 1
				this.total = 0
				this.list = []
				this.getlist()
				this.showtime = false
			},
			getdata() {
				commission_data().then(res => {
					if (res.code == 1) {
						this.invite = res.data.invite //邀请
						this.order = res.data.order //订单
						this.sum = res.data.sum //余额
						this.order_un_confirm = res.data.order_un_confirm //订单待结算佣金
						this.order_confirm = res.data.order_confirm //订单已经结算佣金
						this.invite_un_confirm = res.data.invite_un_confirm //订单待结算佣金
						this.invite_confirm = res.data.invite_confirm //订单待结算佣金
					} else {
						this.$u.toast(res.msg)
					}
				})
			},
			getlist() {
				commission_log_list({
					date: this.date,
					page: this.page
				}).then(res => {
					this.list = this.list.concat(res.data.data)
					this.total = res.data.total
				})
			},
			getuser() {
				index().then(res => {
					this.money = res.data.money
				})
			},
			tobank() {
				uni.navigateTo({
					url: "/pagesD/bank-card"
				})
			},
			totixian() {
				console.log(this.bankdata);
				if (this.bankdata.bank_name && this.bankdata.bank_no) {
					uni.navigateTo({
						url: "/pagesD/tixian1"
					})
				} else {
					uni.navigateTo({
						url: "/pagesD/bank-card"
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.top-font {
		font-size: 20rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		position: absolute;
		top: 8rpx;
		left: 610rpx;
	}

	.box {
		width: 172rpx;
		height: 188rpx;
		background: rgba(161, 208, 255, 0.2);
		border-radius: 16rpx;
		backdrop-filter: blur(3px);
		padding: 42rpx 28rpx;
		text-align: center;
		box-sizing: border-box;
		margin-left: 66rpx;
		margin-top: 30rpx;
	}

	.fontm {
		font-size: 20rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}

	.top1 {
		margin-bottom: 20rpx;
	}

	.bottom1 {
		border-top: 1rpx solid #FFFFFF;
		padding-top: 20rpx;
	}

	.dikou {
		padding: 0 20rpx;
		box-sizing: border-box;

		.dikou-list {
			// width: 686rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin-top: 20rpx;
			padding: 0 28rpx;


			.list-item {
				padding: 30rpx 0;
				border-bottom: 2rpx solid #F0F0F0;
				min-height: 61rpx;

				.text3 {
					font-size: 32rpx;
					font-family: JDZhengHT-Regular, JDZhengHT;
					font-weight: 400;
				}

				.text1 {
					font-size: 30rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-bottom: 12rpx;
				}

				.text2 {
					font-size: 24rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #222222;
				}
			}

			.list-header {
				padding: 28rpx 0 20rpx 0;

				.list-time {
					.text1 {
						font-size: 32rpx;
						font-family: SFPro-Regular, SFPro;
						font-weight: 400;
						color: #222222;
						margin-right: 8rpx;
					}
				}

				.header-title {
					text:first-child {
						font-size: 32rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						position: relative;
						z-index: 1;
					}

					text:last-child {
						width: 120rpx;
						height: 8rpx;
						background: linear-gradient(270deg, #0C66C2 0%, #FFFFFF 100%);
						border-radius: 6rpx;
						margin-top: -14rpx;
						margin-right: -20rpx;
					}
				}
			}
		}

		.bottom {
			font-size: 28rpx;
			font-family: JDZhengHT-Regular, JDZhengHT;
			font-weight: 400;
			color: #FFFFFF;
		}

		.dikou-header {
			margin: 20rpx auto;
			width: 686rpx;
			height: 264rpx;
			position: relative;
			z-index: 1;
			padding: 32rpx 0 0 0;

			.header-item {
				padding: 0 32rpx 0 32rpx;

				.left {
					.top {
						font-size: 20rpx;
						font-family: PingFangSC-Light, PingFang SC;
						font-weight: 300;
						color: #FFFFFF;
					}

					.bottom {
						font-size: 28rpx;
						font-family: JDZhengHT-Regular, JDZhengHT;
						font-weight: 400;
						color: #FFFFFF;
					}
				}

				.right {
					margin-left: 72rpx;

					.top {
						font-size: 20rpx;
						font-family: PingFangSC-Light, PingFang SC;
						font-weight: 300;
						color: #FFFFFF;
					}

					.bottom {
						font-size: 28rpx;
						font-family: JDZhengHT-Regular, JDZhengHT;
						font-weight: 400;
						color: #FFFFFF;
					}
				}

				.item-tixian {
					width: 108rpx;
					height: 48rpx;
				}

				.item-price {
					font-size: 52rpx;
					font-family: JDZhengHT-Regular, JDZhengHT;
					font-weight: 400;
					color: #FFFFFF;
					margin-bottom: 20rpx;
				}

				.item-top {
					margin-bottom: 20rpx;

					text {
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						margin-right: 8rpx;
					}

					image {
						width: 28rpx;
						height: 28rpx;
					}
				}
			}

			.header-img {
				width: 686rpx;
				height: 416rpx;
				position: absolute;
				top: 0;
				left: 0;
				z-index: -1;
			}
		}
	}

	.tixian {
		width: 148rpx;
		height: 56rpx;
		background: #FFFFFF;
		border-radius: 28rpx;
		font-size: 26rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #0C66C2;
		line-height: 56rpx;
		text-align: center;
	}

	page {
		background-color: #F3F3F3;
	}
</style>