<template>
	<view>
		<view class="bg-img flex justify-center align-center" style="background-image: url('https://upload-file-data.obs.cn-south-1.myhuaweicloud.com/97d63ec49f544a33a6a8cc3c0b64b17a-songRankBgImg.png');height: 302upx;">
			<view class="text-white" >
				<text class="text-lg">提现金额：</text>
				<text style="font-size: 60rpx;">￥{{total}}</text>
			</view>
		</view>
		<block v-for="(item,index) in list" :key="index">
			<view v-if="list" class="container">
				<view class="card">
					<view class="left">
						<view>
							活动名称：
							<text class="text-red">{{item.activityName}}</text>
						</view>
						<view>
							可用热力：
							<text class="text-red">{{item.usableHotValue}}</text>
						</view>
						<view>
							可提余额：
							<text class="text-red">￥{{item.usableCash}}</text>
						</view>
					</view>
					<view class="right">
						<u-number-box  v-model="withdrawList[index].totalCash" :positive-integer="false"  :index="index" :min="0" :max="max(item.usableCash)"  :input-width="100" :input-height="60"></u-number-box>
						<text  class="padding-left-sm text-red">元</text>
					</view>
				</view>
				<view class="flex align-center padding-right-sm">
					<view>提现密码：</view>
					<u-input v-model="password" type="password" :password-icon="true" placeholder="请输入提现密码" :clearable="false" />
				</view>
			</view>
		</block>
		<view class="" style="height: 140rpx;"></view>
		<view 
			class="footer-fixed flex align-center justify-end padding bg-white"
			style="padding: 30rpx;;border-top: 1rpx solid #e5e5e5;z-index: 9;">
			<button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;"
				@click="withdraw">确认提现</button>
		</view>
	</view>
</template>

<script>
	import md5Libs from "uview-ui/libs/function/md5";
	export default {
		computed:{
			max(){
				return data=>{
					if (this.$u.test.isEmpty(data)) {
						return 0
					}
					return parseInt(data)
				}
			},
			total:{
				get(){
					let total=0
					this.withdrawList.forEach(item=>{
						total+=item.totalCash
					})
					return total
				}
			}
		},
		data() {
			return {
				password: '',
				userId:'',
				list:[],
				withdrawList:[]
			}
		},
		onLoad(options) {
			this.userId=options.userId
			if (!this.userId) {
				this.$u.toast('用户未登录')
				return
			}
			this.fetchList()
		},
		methods: {
			fetchList(){
				let params={
					userId:this.userId,
					size:500
				}
				this.$u.api.user.statisticalList(params).then(res=>{
					this.list=res.records
					this.withdrawList=[]
					this.list.forEach(item=>{
						let obj={
							id:item.id,
							userId:item.userId,
							activityId:item.activityId,
							totalCash:0,
						}
						this.withdrawList.push(obj)
					})
				})
			},
			withdraw(){
				if (this.total<=0) {
					this.$u.toast("请输入正确的兑换金额")
					return
				}
				this.$u.api.user.withdraw(this.withdrawList).then(res=>{
					if (res) {
						this.$dialog.showModal(res+",请耐心等待",false).then(res=>{
							uni.navigateBack({
								delta:1
							})
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		margin: 15rpx;
		padding: 15rpx;
		border-radius: 12rpx;
		background-color: #FFFFFF;
		.card{
			display: flex;
			justify-content: space-between;
			.left{
				display: flex;
				flex-direction: column;
				
				view{
					padding: 7rpx 0;
				}
			}
			
			.right{
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
	
</style>
