<template>
  <!-- 积分详情 -->
	<view>
		<view class='integral-details' :style="colorStyle">
			<view class='header'>
				<view class='currentScore'>总资金</view>
				<view class="scoreNum">{{userInfo.award_lack}}</view>
				<view class='line'></view>
				<view class='nav acea-row'>
					<view class='item'>
						<view class='num'>{{userInfo.action_integral}}</view>
						<view>贡献分</view>
					</view>
					<view class='item'>
						<view class='num'>{{userInfo.static_integral}}</view>
						<view>消费分</view>
					</view>
					<view class='item'>
						<view class='num'>{{userInfo.integral_price}}</view>
						<view>参考值</view>
					</view>
				</view>
			</view>
			<view class='wrapper'>
				<view class='nav acea-row'>
					<view class='item acea-row row-center-wrapper' :class='current==index?"on":""'
						v-for="(item,index) in navList" :key='index' @click='nav(index)'><text class='iconfont'
							:class="item.icon"></text>{{item.name}}</view>
				</view>
				<view class='list' >
					<view class='item acea-row row-between-wrapper' v-for="(item,index) in navList[current].integralList" :key="index">
						<view>
							<view class='state'>{{item.mark}}</view>
							<view>{{item.add_time}}</view>
						</view>
						<view class='num font-color' style="flex-shrink: 0;" >
							<view>+{{item.num}}</view>
							<view class='buttom' @click='out(item)' v-if="item.status==0">立即出局</view>
						</view>
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="navList[current].integralList.length>0">
						<text class='loading iconfont icon-jiazai' :hidden='navList[current].loading==false'></text>{{navList[current].loadTitle}}
					</view>
					<view v-if="navList[current].integralList.length == 0">
						<emptyPage title="暂无积分记录哦～"></emptyPage>
					</view>
				</view>
				<!-- <view class='list2' :hidden='current!=1'>
					<view class='item acea-row row-between-wrapper' v-for="(item,index) in navList[1].integralList" :key="index">
						<view>
							<view class='state'>{{item.mark}}</view>
							<view>{{item.add_time}}</view>
						</view>
						<view class='num font-color' v-if="item.pm">+{{item.number}}</view>
						<view class='num' v-else>-{{item.number}}</view>
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="navList[1].integralList.length>0">
						<text class='loading iconfont icon-jiazai' :hidden='navList[1].loading==false'></text>{{navList[1].loadTitle}}
					</view>
					<view v-if="navList[1].integralList.length == 0">
						<emptyPage title="暂无积分记录哦～"></emptyPage>
					</view>
				</view> -->
			</view>
		</view>
		<home v-if="navigation"></home>
		<!-- #ifdef MP -->
		<!-- <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize> -->
		<!-- #endif -->
	</view>
</template>

<script>
	import home from '@/components/home';
	import {
		getUserInfo,
		getIntegralListAction,
		getIntegralListActionOut
	} from '@/api/user.js';
	import dayjs from '@/plugin/dayjs/dayjs.min.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import emptyPage from '@/components/emptyPage.vue';
	import colors from '@/mixins/color'
	export default {
		components: {
			emptyPage,
			home
		},
		filters: {
			dateFormat: function(value) {
				return dayjs(value * 1000).format('YYYY-MM-DD');
			}
		},
		mixins:[colors],
		data() {
			return {
				navList: [{
						'name': '消费分',
						'icon': 'icon-mingxi',
						page: 1,
						limit: 10,
						integralList: [],
						loadend: false,
						loading: false,
						loadTitle: '加载更多',
					},
					{
						'name': '贡献分',
						'icon': 'icon-tishengfenzhi',
						page: 1,
						limit: 10,
						integralList: [],
						loadend: false,
						loading: false,
						loadTitle: '加载更多',
					}
				],
				current: 0,
				userInfo: {},
				
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				isTime: 0
			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getUserInfo();
						this.getIntegralList();
					}
				},
				deep: true
			}
		},
		onLoad() {
			if (this.isLogin) {
				this.getUserInfo();
				this.getIntegralList();
			} else {
				toLogin()
			}
		},
		onShow() {
			uni.removeStorageSync('form_type_cart');
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			this.getIntegralList();
		},
		methods: {
			/**
			 * 授权回调
			 */
			onLoadFun: function() {
				this.getUserInfo();
				this.getIntegralList();
				this.isShowAuth = false;
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			// 立即出局
			out(item){
				uni.showModal({
					title: '提示',
					content: '是否立即出局',
					success: res => {
						if(res.confirm){
							getIntegralListActionOut({
								id:item.id
							}).then((res)=>{
								uni.showToast({
									title:res.msg
								});
							}).catch((err)=>{
								uni.showToast({
									title: err,
									icon:'error'
								});
							})
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getUserInfo: function() {
				let that = this;
				getUserInfo({
				}).then(function(res) {
					console.log(res.data);
					res.data.integral_price = (+res.data.integral_price).toFixed(2);
					res.data.static_integral = (+res.data.static_integral).toFixed(2);
					res.data.action_integral = (+res.data.action_integral).toFixed(2);
					that.$set(that, 'userInfo', res.data);
				});
			},

			/**
			 * 获取积分明细
			 */
			getIntegralList: function() {
				let that = this.navList[this.current];
				const SplitArray = this.$util.SplitArray;
				const thatt = this;
				if (that.loading) return;
				if (that.loadend) return;
				that.loading = true;
				that.loadTitle = '';
				getIntegralListAction({
					page: that.page,
					limit: that.limit,
					type:this.current
				}).then(function(res) {
					let list = res.data.list,
						loadend = list.length < that.limit;
					that.integralList = SplitArray(list, that.integralList);
					that.page = that.page + 1;
					that.loading = false;
					that.loadend = loadend;
					that.loadTitle = loadend ? '没有更多内容啦~' : "加载更多";
				}, function(res) {
					that.loading = false;
					that.loadTitle = '加载更多';
				});
			},
			nav: function(current) {
				this.current = current;
				this.getIntegralList();
			}
		}
	}
</script>

<style scoped lang="scss">
	.integral-details{
		.header {
			// background-image: url('data:image/jpeg;base64, ');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			width: 100%;
			height: 460rpx;
			font-size: 72rpx;
			color: #fff;
			padding: 31rpx 0 45rpx 0;
			box-sizing: border-box;
			text-align: center;
			font-family: 'Guildford Pro';
			background-color: var(--view-theme);
			.currentScore {
				font-size: 26rpx;
				color: rgba(255, 255, 255, 0.8);
				text-align: center;
				margin-bottom: 11rpx;
			}
			.scoreNum {
				font-family: "Guildford Pro";
			}
			.line {
				width: 60rpx;
				height: 3rpx;
				background-color: #fff;
				margin: 20rpx auto 0 auto;
			}
			.nav {
				font-size: 22rpx;
				color: rgba(255, 255, 255, 0.8);
				flex: 1;
				margin-top: 35rpx;
				.item {
					width: 33.33%;
					text-align: center;
					.num {
						color: #fff;
						font-size: 40rpx;
						margin-bottom: 5rpx;
						font-family: 'Guildford Pro';
					}
				}
			}
		}
	} 

	.integral-details{
		.wrapper{
			.nav {
				flex: 1;
				width: 690rpx;
				border-radius: 20rpx 20rpx 0 0;
				margin: -96rpx auto 0 auto;
				background-color: #f7f7f7;
				height: 96rpx;
				font-size: 30rpx;
				color: #bbb;
				.item {
					text-align: center;
					width: 50%;
					&.on {
						background-color: #fff;
						color: var( --view-theme);
						font-weight: bold;
						border-radius: 20rpx 0 0 0;
					}
					.iconfont {
						font-size: 38rpx;
						margin-right: 10rpx;
					}
				}
				.item:nth-of-type(2).on {
					border-radius: 0 20rpx 0 0;
				}
			}
			.list {
				background-color: #fff;
				padding: 24rpx 30rpx;
				.tip {
					font-size: 25rpx;
					width: 690rpx;
					min-height: 60rpx;
					border-radius: 50rpx;
					background-color: #fff5e2;
					border: 1rpx solid #ffeac1;
					color: #c8a86b;
					padding: 0 20rpx;
					box-sizing: border-box;
					margin-bottom: 24rpx;
					.tipCon{
						width: 595rpx;
					}
					.iconfont {
						font-size: 35rpx;
						margin-right: 15rpx;
					}
				}
				.item {
					height: 124rpx;
					border-bottom: 1rpx solid #eee;
					font-size: 24rpx;
					color: #999;
					.state {
						font-size: 28rpx;
						color: #282828;
						margin-bottom: 8rpx;
					}
					.num {
						font-size: 36rpx;
						font-family: 'Guildford Pro';
						color: #16AC57;
						display: flex;
						flex-direction: column;
						align-items: flex-end;
						&.font-color{
							color: #E93323!important;
						}
						
						.buttom{
							font-size: 24rpx;
							border-radius: 20rpx;
							line-height: 1;
							padding: 10rpx 20rpx;
							background-color:var(--view-theme);
							color: #FFF;
						}
					}
				}
			}
		} 
	} 

	.integral-details .wrapper .list2 {
		background-color: #fff;
		padding: 24rpx 0;
	}

	.integral-details .wrapper .list2 .item {
		background-image: linear-gradient(to right, #fff7e7 0%, #fffdf9 100%);
		width: 690rpx;
		height: 180rpx;
		position: relative;
		border-radius: 10rpx;
		margin: 0 auto 20rpx auto;
		padding: 0 25rpx 0 180rpx;
		box-sizing: border-box;
	}

	.integral-details .wrapper .list2 .item .pictrue {
		width: 90rpx;
		height: 150rpx;
		position: absolute;
		bottom: 0;
		left: 45rpx;
	}

	.integral-details .wrapper .list2 .item .pictrue image {
		width: 100%;
		height: 100%;
	}

	.integral-details .wrapper .list2 .item .name {
		width: 285rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #c8a86b;
	}

	.integral-details .wrapper .list2 .item .earn {
		font-size: 26rpx;
		color: #c8a86b;
		border: 2rpx solid #c8a86b;
		text-align: center;
		line-height: 52rpx;
		height: 52rpx;
		width: 160rpx;
		border-radius: 50rpx;
	}
</style>
