<template>
	<view class="cashOut_wrapper">
		<z-paging ref="paging" v-model="dataList" @query="queryList" :auto="true" :auto-show-back-to-top="true">
			<view class="" slot="top">
				<view class="title_box">
					<view class="title_icon"></view>
					<view class="title">
						<u-icon labelPos="left" space="5px" label="我的收益" size="18" name="info-circle-fill"
							@click="showIncome"></u-icon>
					</view>
				</view>

				<view class="priceBox">
					<view class="price">
						<text class="priceNum">{{moneyData.video_money}}</text>
						<text>元</text>
					</view>
					<view class="Btn" @click="cashOut()" :current='currentIndex'>
						去提现
					</view>
				</view>
				<view class="">
					<u-tabs :list="tabsList" @click="changeTabs"></u-tabs>
				</view>
			</view>

			<view class="dataList">
				<view class="item" v-for="(item,index) in dataList" :key="index">
					<view class="left">
						<view class="title">
							{{item.remark}}
						</view>
						<view class="time">
							{{ $util.timeStampTurnTime(item.create_time, 'date') }}
						</view>
					</view>
					<view class="right">
						{{item.money}} 元
					</view>
				</view>
			</view>

		</z-paging>



		<u-modal title="现金提现" :show="cashOutShow" closeOnClickOverlay showCancelButton>
			<view class="slot-content">
				<u--input prefixIcon="rmb" prefixIconStyle="font-size: 22px;color: #909399" placeholder="请输入提现金额"
					type="number" border="surround" v-model="cashOutPrice"></u--input>
			</view>
			<view class="cashOutBtn balance" slot="confirmButton" @click="cashOutToBanlance">
				提现到余额
			</view>
			<view class="cashOutBtn weixin" slot="confirmButton" @click="cashOutShow = false">
				提现到微信
			</view>
			<view class="cashOutBtn cancel" slot="confirmButton" @click="cashOutShow = false">
				取消
			</view>
		</u-modal>

		<u-modal :show="isShowIncome" title="收益说明" @confirm="isShowIncome=false">
			<view class="slot-content">
				<rich-text :nodes="incomeContent"></rich-text>
			</view>
		</u-modal>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabsList: [{
						name: '收益记录'
					},
					{
						name: '提现记录'
					}
				],
				currentIndex: 0,
				dataList: [],
				moneyData: {},
				//提现弹出框
				cashOutShow: false,
				cashOutPrice: '',
				isShowIncome: false,
				incomeContent: '',

			};
		},
		methods: {
			queryList(page, page_size) {
				console.log(this.currentIndex);
				let url = ''
				switch (this.currentIndex) {
					case 0:
						url = '/api/video/getLogList'
						break;
					case 1:
						url = '/api/video/getCashLogList'
						break;
					default:

						break;
				}
				let obj = {
					page,
					page_size
				}
				this.$api.sendRequest({
					url,
					data: obj,
					success: res => {
						this.$refs.paging.complete(res.data.list);
						if (this.currentIndex == 0) {
							this.moneyData = res.data.extend //video_total_money视频观看总收益  video_money 视频观看收益余额
						}
					}
				})
			},
			changeTabs(item) {
				this.currentIndex = item.index

				this.$refs.paging.reload()
			},
			cashOut() {
				this.cashOutShow = true
			},
			cashOutToBanlance() {

				if (this.cashOutPrice == '') {
					uni.showToast({
						title: '请输入提现金额',
						icon: 'none',
					})
					return
				}
				if (Number(this.cashOutPrice) > Number(this.moneyData.video_money)) {
					uni.showToast({
						title: '提现金额不可超过收益余额',
						icon: 'none',
					})
					return
				}
				if (Number(this.cashOutPrice) < 1) {
					uni.showToast({
						title: '提现金额不可低于1元',
						icon: 'none',
					})
					return
				}
				this.$api.sendRequest({
					url: '/api/video/getBanlance',
					data: {
						money: Number(this.cashOutPrice)
					},
					success: res => {
						uni.showToast({
							title: res.message,
							icon: 'none',
						})
						this.cashOutShow = false
						this.cashOutPrice = ''
						this.getMoneyData()
						this.$refs.paging.reload()
					}
				})


			},
			getMoneyData() {
				this.$api.sendRequest({
					url: '/api/video/getLogList',
					success: res => {
						this.moneyData = res.data
							.extend //video_total_money视频观看总收益  video_money 视频观看收益余额
					}
				})
			},
			showIncome() {
				this.$api.sendRequest({
					url: '/api/video/getConfig',
					data: {},
					success: res => {
						this.incomeContent = res.data.rule_content // 收益说明
						this.isShowIncome = true
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cashOut_wrapper {
		.title_box {
			display: flex;
			height: 40rpx;
			margin: 20rpx;

			.title_icon {
				width: 4rpx;
				height: 30rpx;
				background: #89D961;
				line-height: 40rpx;
				margin: 5rpx 10rpx;
			}


		}

		.priceBox {
			width: calc(100% - 60rpx);
			margin: 0 auto;
			display: flex;

			.price {
				margin-right: 30rpx;

				.priceNum {
					color: #f33b50;
					font-size: 34rpx;
				}

			}

			.Btn {
				margin: auto 0;
				width: 150rpx;
				height: 50rpx;
				line-height: 50rpx;
				text-align: center;
				background: #89D961;
				color: #fff;
				border-radius: 40rpx;
			}
		}

		.dataList {
			padding: 20rpx 0;

			.item {

				display: flex;
				justify-content: space-between;
				width: calc(100% - 60rpx);
				margin: 0rpx 30rpx;
				padding: 20rpx 0 5rpx;
				border-bottom: 1rpx solid #ccc;

				.left {
					.title {
						font-size: 30rpx;
					}

					.time {
						color: #999;
					}
				}

				.right {
					margin: auto 0;
					color: #f33b50;
				}
			}
		}


	}

	.cashOutBtn {
		width: calc(100% - 60rpx);
		height: 60rpx;
		line-height: 60rpx;
		margin: 0 auto 20rpx;
		border-radius: 30rpx;
		text-align: center;
	}


	.balance {
		background: #faa218;
		color: #fff;
	}

	.weixin {
		background: #89D961;
		color: #fff;
	}

	.cancel {
		border: 1rpx solid #999;
		color: #aaa;
	}


	/deep/ .u-tabs__wrapper__nav__item {
		flex: 1 1 0% !important;
	}
</style>