<template>
	<view :data-theme="theme">
		<view class='my-account mb-40rpx pt-20 relative'>
      <!-- #ifdef MP -->
      <view class="relative">
        <nav-bar :isBackgroundColor="false" ref="navBarRef"  navTitle='我的账户' :isShowMenu="false" :backgroundColor="backgroundColor">
        </nav-bar>
      </view>
      <!-- #endif -->
			<view class='wrapper borderPad'>
				<!-- 新版头部 -->
				<view class="new-header">
					<!-- 底部：余额信息 -->
					<view class="rate-card-bottom">
						<view class="balance-main">
							<view class="balance-item">
								<view class="label">sLGNS余额</view>
								<view class="num">{{statistics.nowMoney || 0}}</view>
								<view style="display: flex"> 
									<view class="btn" style="margin-right: 50rpx;" v-if="statistics.rechargeSwitch" @click="openSubscribe('/pages/users/user_payment/index')">充值</view>
									<view class="btn btn-outline" :class="{disabled: !withdrawNumber.status}" @click="onWithdrawClick">提现</view>
 								</view>
							</view>
						</view>
						<view class="withdraw-tip">
							7天只能3次提现已用({{withdrawNumber.dailyCountAgo}})，今天只能2次提现已用({{withdrawNumber.dailyCount}})
						</view>
						<view class="balance-sub">
							<view class="sub-item">
								<text class="sub-label">余额充值(sL)</text>
								<text class="sub-value">{{statistics.recharge || '0.00'}}</text>
							</view>
							<view class="sub-item">
								<text class="sub-label">余额消费(sL)</text>
								<text class="sub-value">{{statistics.monetary || '0.00'}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class='nav acea-row row-between-wrapper mt20'>
          <navigator class='item acea-row row-between-wrapper' hover-class='none' url='/pages/users/user_bill/index?type=expenditure'>
            <view class="left">
              <view class="name">消费记录</view>
              <view>赚积分抵现金</view>
            </view>
            <view class="pictrue">
              <image src="../static/images/xiaofeijilu.png"></image>
            </view>
          </navigator>
          <navigator v-if="statistics.rechargeSwitch"  class='item acea-row row-between-wrapper' hover-class='none' url='/pages/users/user_bill/index?type=recharge'>
            <view class="left">
              <view class="name">充值记录</view>
              <view>满减享优惠</view>
            </view>
            <view class="pictrue">
              <image src="../static/images/chongzhijilu.png"></image>
            </view>
          </navigator>
				</view>
			</view>
		</view>
    <recommend ref="recommendIndex" @getRecommendLength="getRecommendLength"></recommend>
    <view class='noCommodity' v-if="isNoCommodity">
      <view class='pictrue'>
        <image :src="urlDomain+'crmebimage/presets/noShopper.png'"></image>
      </view>
      <text class="text-ccc">暂无商品</text>
    </view>
	</view>
</template>

<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	import {
		getMyAccountApi,
		getPaymentUserNumber
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import {
		alipayQueryPayResult
	} from '@/api/order.js';
	import recommend from "@/components/base/recommend.vue";
  import navBar from '@/components/navBar';
	let app = getApp();
	export default {
		components: {
			recommend,
      navBar
		},
		data() {
			return {
				urlDomain: this.$Cache.get("imgHost"),
				isClose: false,
				activity: {},
				hotScroll: false,
				statistics: {},
				hotPage: 1,
				hotLimit: 10,
				withdrawNumber: {},
				theme: app.globalData.theme,
				isNoCommodity: false,
        backgroundColor: '',
        rechargeSwitch: false, // 充值开关
			};
		},
		computed: mapGetters(['isLogin', 'userInfo', 'globalData']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.userDalance();
					}
				},
				deep: true
			}
		},
		onLoad() {
			if (this.isLogin) {
				// #ifdef H5
				var url = window.location.search;
				if (url) {
					var theRequest = new Object();
					if (url.indexOf("?") != -1) {
						var str = url.substr(1);
						var strs = str.split("&");
						for (var i = 0; i < strs.length; i++) {
							theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
						}
					}
					this.orderId = theRequest.out_trade_no; //返回的订单号
					this.alipayQueryPay();
				}
				// #endif
				this.userDalance();
			} else {
				toLogin();
			}
		},
		onReachBottom() {
			this.$refs.recommendIndex.get_host_product();
		},
		// 滚动监听
		onPageScroll(e) {
			// 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
			uni.$emit('scroll');
      // #ifdef MP
      if (e.scrollTop > 50) {
        this.backgroundColor = '#fff';
        this.iconColor = '#333333'
      } else if (e.scrollTop < 50) {
        this.backgroundColor = '';
        this.iconColor = '#fff'
      }
      // #endif
		},
		methods: {
			getRecommendLength(e) {
				this.isNoCommodity = e == 0 ? true : false;
			},
			/**
			 * 支付宝充值结果查询
			 */
			alipayQueryPay() {
				uni.showLoading({
					title: '查询中...'
				});
				alipayQueryPayResult(this.orderId).then(res => {
					this.userDalance();
					return this.$util.Tips({
						title: '充值成功'
					});
					uni.hideLoading();
				}).catch(err => {
					uni.hideLoading();
					return this.$util.Tips({
						title: err
					});
				})
			},
			userDalance() {
				getMyAccountApi().then(res => {
					this.statistics = res.data;
					console.log(this.statistics)
				})
				// 调用测试接口并打印
				getPaymentUserNumber().then(res => {
					this.withdrawNumber = res.data;
				});
			},
			openSubscribe(page) {
				uni.navigateTo({
					url: page,
				});
			},
			onWithdrawClick() {
				if (!this.withdrawNumber.status) return this.$util.Tips({title: '当前暂时无法提现'});
				this.openSubscribe('/pages/users/user_withd_slgns/index?lgns=' + this.statistics.nowMoney);
			}
		}
	}
</script>

<style scoped lang="scss">
	.btn.disabled {
		opacity: 0.5;
		background: rgba(255, 255, 255, 0.1) !important;
		border-color: rgba(255, 255, 255, 0.3) !important;
		color: rgba(255, 255, 255, 0.6) !important;
		pointer-events: none; // 禁止点击
	}

.my-account{
  @include shallow-gradient(theme);
}

	/* 新版UI样式 */
	.new-header {
		width: 100%;
		margin: 0 auto;
		color: #fff;
		filter: drop-shadow(0 4rpx 10rpx rgba(255, 77, 140, 0.3));
	}
	
	.rate-card-top {
		// 上半部分渐变：根据图示调整为更亮的粉色渐变
		background: linear-gradient(90deg, #ff6b9f 0%, #FF4D8C 100%);
		border-radius: 24rpx 24rpx 24rpx 24rpx; // 上部卡片其实也可以全圆角，看起来是两张卡叠在一起
		padding: 25rpx 25rpx 25rpx 25rpx;
		position: relative;
		z-index: 2;
		margin-bottom: 20rpx; // 给中间螺旋效果留空隙，或者实际上是紧贴的但通过z-index处理
		margin-bottom: 14rpx; // 微调间距适应螺旋
	}
	
	.rate-title-row {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 24rpx;
		
		.title {
			font-size: 30rpx;
			font-weight: bold;
			padding-bottom: 4rpx;
			display: inline-block;
			letter-spacing: 1px;
		}
		
		.refresh-icon {
			width: 40rpx;
			height: 40rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.iconfont {
				font-size: 34rpx;
				font-weight: bold;
			}
		}
	}
	
	.rate-content {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		position: relative;
		
		.rate-info {
			flex: 1;
			z-index: 2;
		}
		
		.rate-row {
			display: flex;
			align-items: center;
			font-size: 26rpx;
			margin-bottom: 14rpx;
			line-height: 1.2;
			
			.label {
				width: 100rpx;
				font-size: 30rpx;
				opacity: 0.85;
				font-weight: 100;  
			}
			
			.value {
				margin: 0 6rpx 0 20rpx; // value紧跟label后，还是有固定间距，看图是靠左
				font-size: 30rpx;
				min-width: 100rpx;
				font-weight: 300;  
			}
			
			.percent {
				font-weight: 300; 
				font-size: 30rpx;
				margin-right: 4rpx;
				
				&.up { color: #fff; }
				&.down { color: #fff; }
			}
			
			.trend-icon {
				width: 24rpx;
				height: 24rpx;
				margin-top: 4rpx;
				margin-left: 6rpx;
			}
			
			.icon-up { display: inline-block; }
			.icon-down { display: inline-block; }
		}
		
		.coin-img {
			width: 160rpx;
			height: 140rpx;
			position: absolute;
			right: 0;
			top: -80rpx;
			z-index: 1;
			
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
	
	// 螺旋视觉效果容器
	.spiral-binding {
		position: absolute;
		bottom: -24rpx; // 调整位置以连接上下两部分
		left: 0;
		width: 100%;
		height: 48rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 10;
		
		image {
			width: 92%; // 根据实际图片宽度微调，留一点边距看起来更自然
			height: 100%;
		}
	}
	
	.rate-card-bottom {
		// 下半部分渐变：稍微红一点
		background: linear-gradient(135deg, #FF79A8 0%, #FF5993 100%);
		border-radius: 24rpx 24rpx 24rpx 24rpx;
	 
		position: relative;
		z-index: 1;
		
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		min-height: 340rpx; // 保证高度一致
	}
	
	.balance-main {
		display: flex;
		align-items: center;
		padding: 30rpx 0 20rpx 0;
		flex: 1;
		
		.balance-item {
			flex: 1;
			text-align: center;
			position: relative;
			display: flex;
			flex-direction: column;
			align-items: center;
			
			// 中间分割线
			&.border-right::after {
				content: '';
				position: absolute;
				right: 0;
				top: 50%;
				transform: translateY(-50%);
				height: 60rpx;
				width: 2rpx;
				background: rgba(255,255,255,0.2);
			}
			
			.label {
				font-size: 30rpx;
				opacity: 0.8;
				margin-bottom: 10rpx;
				font-weight: 100;
			}
			
			.num {
				font-size: 45rpx; // 金额大号字体
				font-weight: bold;
				// font-family: 'DIN', sans-serif; // 如果有数字字体
				margin-bottom: 24rpx;
				text-shadow: 0 2rpx 4rpx rgba(0,0,0,0.05);
			}
			
			.btn {
				width: 200rpx;
				height: 60rpx;
				line-height: 56rpx; // 扣除border
				border-radius: 34rpx;
				border: 2rpx solid #fff;
				font-size: 28rpx;
				text-align: center;
				background: rgba(255,255,255,0.15);
				backdrop-filter: blur(4rpx);
				box-sizing: border-box;
				
				&.btn-outline {
					background: rgba(255,255,255,0.15); // 统一样式
				}
				
				&:active {
					opacity: 0.8;
					transform: scale(0.98);
				}
			}
		}
	}
	
	.withdraw-tip {
		text-align: center;
		color: rgba(255, 255, 255, 0.8); // 颜色淡一点
		font-size: 24rpx;
		font-weight: 300; // 细体
		margin-bottom: 20rpx;
		letter-spacing: 1px;
	}
	
	.balance-sub {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: rgba(0, 0, 0, 0.05); // 底部深色条
		padding: 24rpx 40rpx;
		border-radius: 0 0 24rpx 24rpx; // 仅底部圆角
		
		.sub-item {
			font-size: 24rpx;
			display: flex;
			align-items: center;
			
			.sub-label {
				opacity: 0.9;
				margin-right: 20rpx;
				font-weight: 100;
				font-size: 28rpx;
			}
			
			.sub-value {
				font-weight: 500;
				font-size: 28rpx;
			}
		}
	}
	.my-account .wrapper .nav .item {
    font-size: 24rpx;
    color: #999;
    width: 342rpx;
    height: 152rpx;
    background: linear-gradient(180deg, #FFF7F0 0%, #FFFFFF 100%);
    border-radius: 24rpx;
    border: 4rpx solid #fff;
    padding: 0 31rpx;
    box-sizing: border-box;
    .name{
      font-size: 28rpx;
      color: #333;
      font-weight: 500;
      margin-bottom: 8rpx;
    }
	}

	.my-account .wrapper .nav .item .pictrue {
    width: 96rpx;
    height: 96rpx;
    image{
      width: 100%;
      height: 100%;
    }
	}
</style>
