<template>
	<!-- 我的余额模块 -->
	<view :style="colorStyle">
		<view class='my-account'>
			<!-- #ifdef MP -->
			<view class="accountTitle">
				<view :style="{height:getHeight.barTop+'px'}"></view>
				<view class="sysTitle  colorfff" :style="{height:getHeight.barHeight+'px'}" @click="goarrow">
					<text class="iconfont icon-ic_leftarrow"></text>
					<view>我的积分</view>
				</view>
			</view>
			<view :style="{height:(getHeight.barTop+getHeight.barHeight)+'px'}"></view>
			<!-- #endif -->
			<view class='wrapper'>
				<view class='header'>
					<view class='headerCon'>
						<view class='account acea-row row-top row-between'>
							<view class='assets' style="width: 377rpx;">
								<view class="colorhei">我的积分</view>
								<view class='money'>{{userInfo.integral}}</view>
							</view>
							<!-- #ifdef APP-PLUS || H5 -->
							<navigator url="/pages/users/user_payment/index" hover-class="none" class='recharge'>充值
							</navigator>
							<!-- #endif -->
							<!-- #ifdef MP -->
							<view  @click="openpopup"
								class='recharge'>立即兑换</view>
							<!-- #endif -->
						</view>
						<view class='cumulative acea-row row-middle'>
							<view class='item'>
								<view>累计积分</view>
									<view class='money'>{{userInfo.sum_integral}}</view>
							</view>
							<view class='item'>
								<view>累计消费</view>
								<view class='money'>{{userInfo.deduction_integral}}</view>
							</view>
						</view>
					</view>
				</view>
				<view>
					<view class="jifenboxtitle">
						积分明细
					</view>
					<view class="jifenbox" v-for="(item,index) in integralList[0].list">
						<view class="jifenbox1">
							<view class="colorhui1 fs-30 text-30rpx">{{item.mark}}</view>
							<view class="colorhui1  fs-30 text-30rpx">{{ item.pm ? '+' : '-' }}{{ item.number }}</view>
						</view>
						<view class="colorhui">{{ item.add_time }}</view>
					</view>
				</view>
			</view>
			<!-- <recommend :hostProduct="hostProduct"></recommend> -->
		</view>
		<uni-popup ref="popup" type="bottom" border-radius="20rpx 20rpx 0 0">
			<view class="popupbox">
				<view class="toptitle">
					<view class="colorfff  fs-30 text-30rpx">积分兑换成现金</view>
					<text class="iconfont iconfont icon-ic_close fs-44 colorhui" @click="close"></text>
				</view>
				<view class="colorhui jifen">
					我的积分：{{userInfo.integral}}
				</view>
				<view class="jifenbl">
					<view class="jifenblleft">
						<image class="wh62" style="margin-top: 42rpx;margin-right: 24rpx;" src="@/static/img/qianxin.png" mode=""></image>
						<view class="colorhei">{{biliduihuan.integral}}</view>
					</view>
					<view class="colorhei">
						={{biliduihuan.integral_money}}元
					</view>
				</view>
				<view class="duihuanbox">
					<view :class="duihuanbox1==index?'duihuanxuanz':'duihuanwxz'" v-for="(item,index) in duihuanboxlist" @click="duihclick(index)">
					{{item}}
					</view>
				</view>
				<view class="ts">
					最低100积分，不足100的积分将原路返回
				</view>
				<view class="ljdh" @click="lijisub">立即兑换</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup1" type="center">
			<view class="popupbox1">
					<text style="float: right;" class="iconfont iconfont icon-ic_close fs-44 colorhui1" @click="close1"></text>
					<image src="https://bar.jiuhaosh.cn/static/sbgx.png" mode="" class="popupboximg"></image>
					<view class="neir">
						积分兑换要成为会员 
						<br />
						才可以兑换哦~
					</view>
					<view class="huiyuanbtn" @click="chuiyuan">我要充会员</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getProductHot
	} from '@/api/store.js';
	import {
		openRechargeSubscribe
	} from '@/utils/SubscribeMessage.js';
	import {
		getUserInfo,
		userActivity,
		postSignUser,
		getIntegralList,
		updatejifenduiyue,
		getMenuList
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import recommend from '@/components/recommend/index';
	import home from '@/components/home';
	import colors from "@/mixins/color";
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	export default {
		components: {
			recommend,
		},
		mixins: [colors],
		data() {
			return {
				duihuanbox1:0,
				duihuanboxlist: ['1000', '2000', '3000', '全部兑换'],
				imgHost: HTTP_REQUEST_URL,
				// #ifdef MP
				getHeight: this.$util.getWXStatusHeight(),
				// #endif
				userInfo: {},
				userInfo1: {},
				hostProduct: [],
				isClose: false,
				recharge_switch: 0,
				activity: {},
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				hotScroll: false,
				hotPage: 1,
				hotLimit: 10,
				page: 1,
				limit: 10,
				integralList: [],
				list: [],
				times: [],
				loadend: false,
				loading: false,
				loadTitle: '加载更多',
				biliduihuan:{}
			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						// this.getUserInfo();
						// this.get_activity();
					}
				},
				deep: true
			}
		},
		onLoad() {
			this.get_host_product();
			if (this.isLogin) {
				// this.getUserInfo();
				this.get_activity();
			} else {
				toLogin()
			}
		},
		onShow() {
			uni.removeStorageSync('form_type_cart');
			this.getSignUserInfo()
			this.getIntegralList();
			this.getbili()
			this.getUserInfo()
		},
		onReachBottom() {
			this.getIntegralList();
		},
		methods: {
			getbili(){
				getMenuList().then(res=>{
					this.biliduihuan=res.data
				})
			},
			lijisub(){
				var number=this.duihuanboxlist[this.duihuanbox1]
				if(this.duihuanboxlist[this.duihuanbox1]=='全部兑换'){
					number=this.userInfo.integral
				}
				updatejifenduiyue({number:number}).then(res=>{
					
					if(res.status==200){
						this.$util.Tips({
							title: res.msg
						});
						this.getSignUserInfo()
						this.getIntegralList();
						 this.$refs.popup.close('bottom')
					}else{}
					uni.showModal({
						title: '提示',
						content: res.msg,
						showCancel: false,
						confirmText: '我知道了'
					});
				})
			},
			getIntegralList() {
				let that = this;
				if (that.loading) return;
				if (that.loadend) return;
				that.loading = true;
				that.loadTitle = '';
				getIntegralList({
					page: that.page,
					limit: that.limit
				}).then(function(res) {
					let data = res.data;
					let list = data.list;
					let times = data.times;
					let integralList = [];
					for (let i = 0; i < times.length; i++) {
						if (!that.times.includes(times[i])) {
							that.times.push(times[i]);
							that.integralList.push({
								time: times[i],
								list: [],
							});
						}
					}
					for (let i = 0; i < that.integralList.length; i++) {
						for (let j = 0; j < list.length; j++) {
							if (times[i] == list[j].time_key) {
								that.integralList[i].list.push(list[j]);
							}
						}
					}
					let loadend = list.length < that.limit;
					that.page = that.page + 1;
					that.loading = false;
					that.loadend = loadend;
					that.loadTitle = loadend ? '没有更多内容啦~' : "加载更多";
				}, function(res) {
					this.loading = false;
					that.loadTitle = '加载更多';
				});
				console.log('integralList',that.integralList);
			},
			getSignUserInfo: function() {
				let that = this;
				postSignUser({
					sign: 1,
					integral: 1,
					all: 1
				}).then(function(res) {
					console.log(123,res);
					that.userInfo=res.data
					let clearTime = res.data.clear_time;
					let showTime = clearTime-(86400*14);
					let timestamp = Date.parse(new Date())/1000;
					if(showTime < timestamp){
						that.isTime = 1
					}else{
						that.isTime = 0
					}
				});
			},
			openpopup(){
				if(!this.userInfo1.pay_vip_status){
					this.$refs.popup1.open('center')
				}else{
				 this.$refs.popup.open('bottom')
				 }
			},
			close(){
				 this.$refs.popup.close('bottom')
			},
			duihclick(e){
				this.duihuanbox1=e
			},
			goarrow() {
				uni.navigateBack()
			},
			// #ifdef MP
			openSubscribe: function(page) {
				uni.showLoading({
					title: '正在加载',
				})
				openRechargeSubscribe().then(res => {
					uni.hideLoading();
					uni.navigateTo({
						url: page,
					});
				}).catch(() => {
					uni.hideLoading();
				});
			},
			// #endif
			chuiyuan(){
				uni.navigateTo({
					url:'/pages/annex/vip_paid/index'
				})
			},
			close1(){
				this.$refs.popup1.close('center')
			},
			/**
			 * 获取用户详情
			 */
			getUserInfo: function() {
				let that = this;
				getUserInfo().then(res => {
					that.userInfo1=res.data
				});
			},
			/**
			 * 获取活动可参与否
			 */
			get_activity: function() {
				let that = this;
				userActivity().then(res => {
					that.$set(that, "activity", res.data);
				})
			},
			/**
			 * 获取我的推荐
			 */
			get_host_product: function() {
				let that = this;
				if (that.hotScroll) return
				getProductHot(
					that.hotPage,
					that.hotLimit,
				).then(res => {
					that.hotPage++
					that.hotScroll = res.data.length < that.hotLimit
					that.hostProduct = that.hostProduct.concat(res.data)
				});
			}
		},
		onPageScroll(e) {
			uni.$emit('scroll');
		},
		onReachBottom() {
			this.get_host_product();
		}
	}
</script>

<style scoped lang="scss">
	.popupbox1{
		width: 600rpx;
		height: 500rpx;
		background: #1C1A1F;
		box-shadow: 0rpx 5rpx 16rpx 0rpx rgba(6,3,14,0.39);
		border-radius: 20rpx;
		padding: 20rpx;
		text-align: center;
		.popupboximg{
			width: 171rpx;
			height: 189rpx;
			margin: 0 auto;
		}
		.neir{
			font-family: Alibaba PuHuiTi;
			font-weight: 400;
			font-size: 36rpx;
			color: #FFFFFF;
			line-height: 56rpx;
			text-align: center;
		}
		.huiyuanbtn{
			width: 400rpx;
			height: 80rpx;
			background: #F8BF1F;
			border-radius: 40rpx;
			margin: 50rpx auto;
			font-family: Alibaba PuHuiTi;
			font-weight: 400;
			font-size: 30rpx;
			text-align: center;
			color: #080313;
			line-height: 80rpx;
		}
	}
	.jifenbox {
		width: 702rpx;
		height: 148rpx;
		background: #1B1A1D;
		border-radius: 10rpx;
		padding: 31rpx 39rpx;
		margin: 10rpx auto;

		.jifenbox1 {
			display: flex;
			justify-content: space-between;
		}
	}

	.popupbox {
		width: 750rpx;
		height: 750rpx;
		background: #28282A;
		padding: 30rpx;

		.toptitle {
			display: flex;
			justify-content: space-between;
		}

		.jifen {
			margin-top: 29rpx;
			margin-bottom: 49rpx;
		}

		.jifenbl {
			width: 600rpx;
			height: 150rpx;
			background: linear-gradient(-55deg, #EAA931, #FEE38F);
			border-radius: 20rpx;
			margin: 0 auto;
			line-height: 150rpx;
			padding: 0 50rpx;
			display: flex;
			justify-content: space-between;
			margin-bottom: 40rpx;

			.jifenblleft {
				display: flex;
			}
		}

		.duihuanbox {
			display: flex;
			justify-content: space-between;
			.duihuanxuanz{
				background: rgba(234,169,49,0);
				border-radius: 10rpx;
				border: 1px solid #EAA931;
				color: #FAAD35;
				padding: 23rpx 43rpx;
			}
			.duihuanwxz{
				background: rgba(234,169,49,0);
				border-radius: 10rpx;
				border: 1px solid #7B7A7F;
				color: #7B7A7F;
				padding: 23rpx 43rpx;
			}
		}
	}
.ts{
	margin-top: 80rpx;
	margin-bottom: 40rpx;
	text-align: center;
	color: #7B7A7F;
}
.ljdh{
	width: 690rpx;
	height: 100rpx;
	background: #FAAD35;
	border-radius: 50rpx;
	margin: 0 auto;
	margin-bottom: 59rpx;
	text-align: center;
	line-height: 100rpx;
	color: #080313;
}
	.jifenboxtitle {
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 36rpx;
		color: #FFFFFF;
		margin: 40rpx 25rpx;
	}

	/deep/.recommend {
		padding: 40rpx 20rpx 0 20rpx;
	}

	.my-account {
		.accountTitle {
			// background-color: var(--view-minorColorT);
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			z-index: 99;

			.sysTitle {
				width: 100%;
				position: relative;
				font-weight: 500;
				color: #FFFFFF;
				font-size: 30rpx;
				display: flex;
				margin-top: 20rpx;

				.iconfont {
					// position: absolute;
					margin-left: 12rpx;
					font-size: 36rpx;
					// left:11rpx;
					// width: 60rpx;
				}
			}
		}

		.advert {
			width: 710rpx;
			height: 332rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			margin: 20rpx auto 0 auto;
			padding: 0 32rpx;

			.title {
				font-size: 32rpx;
				font-weight: 500;
				color: #333333;
				height: 108rpx;
				line-height: 108rpx;
				border-bottom: 1px solid #eee;
			}

			.list {
				margin-top: 34rpx;

				.line {
					height: 126rpx;
					width: 1rpx;
					background-color: #EEEEEE;
				}

				.item {
					text-align: center;
					font-weight: 400;
					color: #999999;
					font-size: 22rpx;

					.pictrue {
						width: 66rpx;
						height: 66rpx;
						margin: 0 auto;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.name {
						font-weight: 500;
						color: #333333;
						font-size: 28rpx;
						margin: 20rpx 0 8rpx 0;
					}
				}
			}
		}
	}

	.my-account .wrapper {
		padding-top: 32rpx;
		// background: linear-gradient(180deg, var(--view-minorColorT) 0%, #f5f5f5 100%);
	}

	.my-account .wrapper .header {
		width: 710rpx;
		height: 362rpx;
		background: linear-gradient(to right, #EAA931, #FEE38F);
		border-radius: 32rpx;
		margin: 0 auto;
		box-sizing: border-box;
		color: rgba(255, 255, 255, 0.8);
		font-size: 24rpx;
		position: relative;
	}

	.my-account .wrapper .header .headerCon {
		padding-top: 36rpx;
	}

	.my-account .wrapper .header .headerCon .pictrue {
		height: 284rpx;
		width: 290rpx;
		position: absolute;
		right: 0;
		bottom: 0;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.my-account .wrapper .header .headerCon .account {
		padding: 0 32rpx;
	}

	.my-account .wrapper .header .headerCon .account .assets .money {
		font-size: 64rpx;
		color: #080313;
		font-family: 'SemiBold';
		margin-top: 12rpx;
	}

	.my-account .wrapper .header .headerCon .account .recharge {
		font-size: 24rpx;
		width: 160rpx;
		height: 56rpx;
		border-radius: 50rpx;
		background-color: #080313;
		text-align: center;
		line-height: 56rpx;
		color: #F2C158;
		font-weight: 500;
	}

	.my-account .wrapper .header .headerCon .cumulative {
		width: 100%;
		height: 142rpx;
		margin-top: 62rpx;
		padding-left: 32rpx;
		position: absolute;
		left: 0;
		bottom: 0;
	}

	.my-account .wrapper .header .headerCon .cumulative .item {
		// flex: 1;
		width: 225rpx;
		position: static;
		z-index: 9;
		color: #080313;
	}

	.my-account .wrapper .header .headerCon .cumulative .item .money {
		font-size: 40rpx;
		font-family: 'SemiBold';
		color: #080313;
		margin-top: 12rpx;
	}

	.my-account .wrapper .nav {
		margin: 20rpx;
		margin-top: 40rpx;
	}

	.my-account .wrapper .nav .item {
		font-size: 24rpx;
		color: #999;
		width: 348rpx;
		height: 152rpx;
		background: #1B1A1D;
		border-radius: 24rpx;
		// border: 4rpx solid #fff;
		padding: 0 31rpx;
		box-sizing: border-box;

		.name {
			font-size: 28rpx;
			color: #C6C4CA;
			font-weight: 500;
			margin-bottom: 8rpx;
		}
	}

	.my-account .wrapper .nav .item .pictrue {
		width: 96rpx;
		height: 96rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.my-account .wrapper .list {
		padding: 0 30rpx;
	}

	.my-account .wrapper .list .item {
		margin-top: 44rpx;
	}

	.my-account .wrapper .list .item .picTxt .iconfont {
		width: 82rpx;
		height: 82rpx;
		border-radius: 50%;
		background-image: linear-gradient(to right, #ff9389 0%, #f9776b 100%);
		text-align: center;
		line-height: 82rpx;
		color: #fff;
		font-size: 40rpx;
	}

	.my-account .wrapper .list .item .picTxt .iconfont.yellow {
		background-image: linear-gradient(to right, #ffccaa 0%, #fea060 100%);
	}

	.my-account .wrapper .list .item .picTxt .iconfont.green {
		background-image: linear-gradient(to right, #a1d67c 0%, #9dd074 100%);
	}

	.my-account .wrapper .list .item .picTxt {
		width: 428rpx;
		font-size: 30rpx;
		color: #282828;
	}

	.my-account .wrapper .list .item .picTxt .text {
		width: 317rpx;
	}

	.my-account .wrapper .list .item .picTxt .text .infor {
		font-size: 24rpx;
		color: #999;
		margin-top: 5rpx;
	}

	.my-account .wrapper .list .item .bnt {
		font-size: 26rpx;
		color: #282828;
		width: 156rpx;
		height: 52rpx;
		border: 1px solid #ddd;
		border-radius: 26rpx;
		text-align: center;
	}

	.my-account .wrapper .list .item .bnt.end {
		font-size: 26rpx;
		color: #aaa;
		background-color: #f2f2f2;
		border-color: #f2f2f2;
	}
</style>