<template>
	<view class="integralRecord">
		<!-- 分段器 -->
		<view class="segmented">
				<view class="tab_nav">
					<view class="navTitle" v-for="(item,index) in items" :key="index">
						<view :class="{'active':isActive == index}" @click="checked(index)">
							{{item}}
						</view>
					</view>
				</view>
		</view>
		<view class="msg-null" v-if="incomeList.length == 0 && isActive == 0 ">
			<image src="https://t9.9026.com/imgs/dataNull.png" style="width: 394rpx;height: 396rpx;" mode=""></image>
			<view class="msg-null-text">
				<text>暂无数据</text>
			</view>
		</view>
		<!-- 收入 -->
		<view class="List" v-if="isActive == 0 && incomeList.length > 0 ">
			<view class="ListItem" v-for="(item,index) in incomeList" :key="index">
				<view style="display: flex; justify-content: space-between;">
					<view class="title"><text>{{item.change_integral}}积分</text> </view>
					<view class='data'><text>{{item.created_at}}</text></view>
				</view>
				<view class="content" v-if="item.type==1"><text>投票奖励获得</text></view>
				<view class="content" v-if="item.type==2"><text>抽奖奖励获得</text></view>
			</view>
		</view>
		
		<view class="msg-null" v-if="spendingList.length == 0 && isActive == 1 ">
			<image src="https://t9.9026.com/imgs/dataNull.png" style="width: 394rpx;height: 396rpx;" mode=""></image>
			<view class="msg-null-text">
				<text>暂无数据</text>
			</view>
		</view>
		<!-- 支出 -->
		<view class="List" :style="{'--height':ListHeight+'rpx'}" v-if="isActive == 1 && spendingList.length > 0" >
			<view class="ListItem" v-for="(item,index) in spendingList" :key="index" >
				<view style="display: flex; justify-content: space-between;">
					<view class="title"><text>{{item.change_integral}}积分</text> </view>
					<view class='data'><text>{{item.created_at}}</text></view>
				</view>
				<view class="content" v-if="item.type==3"><text>兑换商品消耗</text></view>
				<view class="content" v-if="item.type==4"><text>后台增加/减少</text></view>
			</view>
		</view>
		
		<!-- 已经到底啦 -->
		<view class="home-bottom" style="margin-top: 88rpx;padding-bottom: 60rpx;"   v-if="isActive == 0 && incomeList.length > 0 ">
			<uni-load-more :status="status" color="#CCCCCC" :content-text="contentText"/>
		</view>
		<view class="home-bottom" style="margin-top: 88rpx;padding-bottom: 60rpx;"   v-if="isActive == 1 && spendingList.length > 0 ">
			<uni-load-more :status="status" color="#CCCCCC" :content-text="contentText"/>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				// 分段器
				items: ['收入', '支出',],
				isActive: 0,
				// list高度
				ListHeight: 800,
				// 组件uni-load-more
				status: 'noMore',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '——  已经到底啦  ——'
				},
				// 收入列表
				incomeList:[],
				// 支出列表
				spendingList:[],
			}
		},
		onLoad() {
			// 收入
			this.getIntegralList(1)
			// 支出
			this.getIntegralList(2)
		},
		methods:{
			//菜单index切换
			checked(index) {
				this.isActive = index
			},
			// 获取积分日志
			getIntegralList(type){
				if(type==1){
					this.$api.integral.getIntegralLog({
						page:1,
						type:1
					}).then(res=>{
						console.log(res,'收入积分日志')
						if(res.code==0){
							this.incomeList=res.data.data
						}
					})
				} else if (type==2){
					this.$api.integral.getIntegralLog({
						page:1,
						type:2
					}).then(res=>{
						console.log(res,'支出积分日志')
						if(res.code==0){
							this.spendingList=res.data.data
						}
					})
				}else{
					uni.showToast({
						title:'请传入正确type值!',
						icon:'none'
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	$pageColor:#F9F9F9;
	$bgColor:#FFFFFF;
	// flex布局居中对齐
	@mixin flexlayout {
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.integralRecord{
		height: 100%;
		background: $pageColor;
	}
	
	.msg-null{
		padding-top: 60rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		.msg-null-text{
			margin-top: 40rpx;
			font-size: 28rpx;
			color: #333;
		}
	}
	
	
	.segmented{
		height: 112rpx;
		width: 750rpx;
		background: $bgColor;
		box-shadow: 0px 4rpx 8rpx 0px rgba(0,0,0,0.04);
		border-radius: 0px 0px 16rpx 16rpx;
		//菜单切换
		.tab_nav {
			width: 690rpx;
			margin-left: 30rpx;
			padding:0 80rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-family: PingFang-SC-Heavy, PingFang-SC;
		}
		.tab_nav .navTitle {
			@include flexlayout()
			margin-top: 20rpx;
			width: 128rpx;
			flex: none;
			height: 28rpx;
			font-size: 32rpx;
			color: #666;
			position: relative;
		}
		.active {
			color: #D9A94D;
			font-weight: bold;
		
			&::after {
				display: inline-block;
				content: '';
				width: 48rpx;
				height: 12rpx;
				background: linear-gradient(90deg, #F3D69F 0%, #D9A94D 100%);
				border-radius: 6px;
				position: absolute;
				bottom: -30rpx;
				left: 40rpx;
			}
		}
	}
	::v-deep .segmented-control__text {
		font-size: 32rpx !important;
		font-family: PingFang-SC-Heavy, PingFang-SC;
		font-weight: 500 !important;
		color: #666666 !important;
	}
	
	::v-deep .segmented-control__item--text {
		font-size: 32rpx;
		font-family: PingFang-SC-Heavy, PingFang-SC;
		font-weight: 800 !important;
		padding: 10rpx 0 !important;
		border-radius: 4rpx !important;
		color: #D9A94D !important;
	}
	.List {
		width: 750rpx;
		background: $bgColor;
		box-shadow: 0px 4rpx 24rpx -10rpx rgba(101, 95, 90, 0.3);
		border-radius: 12rpx;
		margin-top: 24rpx;
		padding: 0rpx 28rpx 0 32rpx;
		box-sizing: border-box;
	
		.ListItem {
			width: 690rpx;
			border-bottom: #F0F0F0 solid 0.5rpx;
			position: relative;
			padding-top: 40rpx;
			padding-bottom: 40rpx;
			box-sizing: border-box;
			&:first-child{
				padding-top: 48rpx;
			}
			&:last-child{
				border-bottom: none;
			}
			.title {
				margin-bottom: 10rpx;
				text {
					font-size: 32rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: #333333;
				}
			}
	
			.data {
				text {
					font-size: 26rpx;
					font-family: PingFang-SC-Medium, PingFang-SC;
					font-weight: 500;
					color: #999999;
				}
			}
			.content {
				text {
					font-size: 28rpx;
					font-family: PingFang-SC-Medium, PingFang-SC;
					font-weight: 500;
					color: #333333;
				}
			}
			
		}
		// 消除最后一个下划线
		.ListItem:last-child {
			width: 690rpx;
			height: 160rpx;
			border-bottom: #F0F0F0 solid 0rpx;
			position: relative;
			padding-top: 35rpx;
			box-sizing: border-box;
			
			.title {
				margin-bottom: 10rpx;
				text {
					font-size: 32rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: #333333;
				}
			}
			
			.data {
				text {
					font-size: 26rpx;
					font-family: PingFang-SC-Medium, PingFang-SC;
					font-weight: 500;
					color: #999999;
				}
			}
			.content {
				text {
					font-size: 28rpx;
					font-family: PingFang-SC-Medium, PingFang-SC;
					font-weight: 500;
					color: #333333;
				}
			}
			
		}
	}
	
</style>