<template>
	<view style="width:100vw;height:100vh;" class="column">
		<scroll-view :scroll-y="true"
		 @scroll="scroll" 
		 :scroll-top="scrollTop"
			class="col" style="width: 100%;height: 1px; flex: 1;overflow: hidden;background: #F3F1EF;">
				<view class="headStatus" v-if="scrollTop > 50" :style="[titleStyle,{
					zIndex: scrollTop < 10 ? 'unset' : 2,
					opacity: scrollTop < 10 ? '100' : scrollTop,
				}]">
					<view class="title" style="position: relative;">
						<u-icon name="arrow-left" size="38" color="#000"
						style="position: absolute;left: 32rpx;top:20rpx"></u-icon>
						{{ pageTitle }}
					</view>
				</view>
				<view class="userBox">
					<view class="userHeaderBox" :style="[titleStyle]">
						<view class="titlenav">
							<view class="carrHeader-left-icon" @click="goBack">
									<u-icon name="arrow-left" size="38" color="#000"></u-icon>
							</view>
							{{ pageTitle   }}
						</view>
						<view class="userHeadPic row">
							<view class="userHeadPicL">
								<u-avatar v-if="b2b_user_info.photo||CustomerIntegral.image" :src="b2b_user_info.photo?b2b_user_info.photo:CustomerIntegral.image" size="99" shape="circle"></u-avatar>
								<u-avatar v-else src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638748795455095258.png" size="99" shape="circle"></u-avatar>
								<!-- <image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638748795455095258.png" mode="widthFix"></image> -->
							</view>
							<view class="col column">
								<text v-if="b2b_user_info&&b2b_user_info.name" 
								class="userHeadPicR_title" @click="navigatorToProfile">
									{{ b2b_user_info.name }}
								</text>
								<text v-else-if="mall_UserInfo&&mall_UserInfo.Name" 
								class="userHeadPicR_title">
									{{mall_UserInfo.Name}}
								</text>
								<!-- v-if="CustomerIntegral&&CustomerIntegral.saleList&&CustomerIntegral.saleList.length>0" -->
								<text class="userHeadPicR_text" @click="goTisp">
									积分规则
									<!-- #ifdef MP-DI -->
									<!-- 销售:{{ b2b_user_info.salesBaseInfo.emName }} -->
									<!-- #endif -->
									<!-- #ifdef MP-AG -->
									<!-- 销售:{{ CustomerIntegral.saleList[0].saleName }}<template v-if="CustomerIntegral.saleList.length>0">等{{CustomerIntegral.saleList.length}}位</template> -->
									<!-- #endif -->
								</text>
							</view>
						</view>
						<view class="userHeadPasBox">
							<view class="userHeadPNumBox row-sb-n">
								<view class="userHeadPNum">
									<view class="userHeadPNumT">当前积分</view>
									<view class="userHeadPNumB">
										<text></text>
										{{ CustomerIntegral.integral>=0?CustomerIntegral.integral:0 }}
									</view>
								</view>
								<view class="userHeadPNum active">
									<view class="userHeadPNumT">待获取</view>
									<view class="userHeadPNumB">
										<text></text>
										{{ CustomerIntegral.waitIntegral>=0?CustomerIntegral.waitIntegral:0 }}
									</view>
								</view>
							</view>
							<view class="userHeadPNumS row-sb-n">
								<view class="userHeadPNumSL">已消耗</view>
								<view class="userHeadPNumSR">
									<text>{{ CustomerIntegral.useIntegral>=0?CustomerIntegral.useIntegral:0 }}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="listBox column"
						:class="[showTisp?'active':'']"
						style="padding: 0 32rpx;width: 100vw;">
						<view class="userMyOrderBox column">
							<view style="padding: 20rpx 0;">
								<view class="userMyOrderState row-sb-n">
									<view v-for="(item,index) in stateList" :key="index"
									:class="[msg.active==item.ID?'active':'']"
									@click="research(item.ID)">
										{{ item.Name }}
									</view>
								</view>
								<view class="row">
										<view class="row" @click="SelectDate" v-if="msg.active!=3">
											<text>{{year}}年</text>
											<text>{{month}}月</text>
											<u-icon name="arrow-down" size="28" color="#000"></u-icon>
										</view>
										
								</view>
							</view>
							<scroll-view :scroll-y="true" class="col"
							@scrolltolower="lower" 
							style="height: 1px;flex: 1; width: 100%;overflow: hidden;">
								<view class="userHeadPListBox" v-if="dataList&&dataList.length>0">
									<view class="userHeadPList row" 
									v-for="(item,index) in dataList" :key="index"
									@click="goDetails(item)">
										<view class="userHeadPListL">
											<image mode="scaleToFill" :src="item.imgCover"/>
											<text>共{{item.peopleNum}}人</text>
										</view>
										<view class="userHeadPListA col column">
											<view class="userHeadPListATitel">
												<!--积分{{ item.type==1?'收获':'消耗' }}-->
												{{ item.lineName }}
											</view>
											<view class="userHeadPListATime">
												{{ msg.active!=3?item.updateTime:item.orderId }}
											</view>
										</view>
										<view class="userHeadPListR">
											{{item.type==1?'+':''}}{{ item.integralNum }}
										</view>
									</view>
								</view>
								<u-empty v-if="dataList.length == 0 && !loading" text="暂无数据" mode="data" :padding-top="!showTisp?10:30"></u-empty>
								<u-loadmore v-else :status="status" :load-text="loadText" :font-size="24" :margin-top="20" :margin-bottom="20" bg-color="#fff" />
							</scroll-view>
						</view>
					</view>
					<u-alert-tips v-if="showTisp" :show="showTisp" :close-able="true" @close="showTisp=false"
						style="padding: 30rpx 30rpx;"
						type="warning"
						title="2025年2月1日（包含）起生效"
						description="积分：平台所有跟团游产品均可参加积分活动，积分获得比例：100:1（例：客人实付金额100元，获得1个积分)。团队出发后7个工作日内将会存入积分余额。"
						></u-alert-tips>
				</view>
			
		</scroll-view>
		<u-picker mode="time" v-model="showTime" :defaultTime="times" :params="params" @confirm = 'confirm'></u-picker>
	</view>
</template>

<script>
	export default {
		components: {
			
		},
		data() {
			return {
				pageTitle: "积分",
				scrollTop: 0,
				showAuth: false,
				b2b_user_info: {},
				mall_UserInfo: {},
				stateList:[
					{Name:'全部',ID:0},
					{Name:'已获取',ID:1},
					{Name:'已消耗',ID:2},
					{Name:'待获取',ID:3},
				],
				msg:{
					pageIndex:1,//是	[string]
					pageSize:10,//是	[string]
					IntegralState:1, //状态 1已反积分记录 2待结算积分记录
					Type:0,//	类型 1存入 2扣除
					QStartDate:'',//	开始时间
					QEndDate:'',
					active:0,
				},
				dataList: [],
				status: "加载中",
				page_count: 0,
				loadText: {
					loadmore: "轻轻上拉，加载更多",
					loading: "努力加载中",
					nomore: "没有更多了",
				},
				loading: false,
				showTime: false,
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				year: '',
				month: '',
				times: '',
				CustomerIntegral:{},
				titleStyle:{},
				showTisp: false,
			};
		},
		onLoad() {
			this.b2b_user_info = uni.getStorageSync('b2b_user');
			this.mall_UserInfo = uni.getStorageSync("mall_UserInfo");
			this.showAuth = !this.mall_UserInfo || !this.b2b_user_info;
		},
		onShow() {
			const that = this
            uni.getSystemInfo({
                success(res) {
                    that.titleStyle = {
                    paddingTop: `${res.statusBarHeight}px`
                    };
                },
            });
			const now = new Date();
			this.year = now.getFullYear();
			this.month = String(now.getMonth() + 1).padStart(2, '0');
			this.msg.QStartDate = this.year + '-' + this.month + '-01'
			now.setMonth(now.getMonth() + 1, 0);
			this.msg.QEndDate = this.year + '-' + this.month + '-'+now.getDate()
			this.times = this.year + '-' + this.month
			this.msg.pageIndex = 1
			this.dataList = []
			this.getList();
			this.GetCustomerIntegral()
		},
		created() {
			
		},
		methods: {
			goTisp(){
				this.showTisp = true
				this.scrollTop = 500
			},
			confirm(e){
				if(this.year==e.year&&this.month==e.month) return
				this.year = e.year
				this.month = e.month 
				this.times = this.year + '-' + this.month
				const now = new Date(this.year, this.month, 1); // 设置为下个月第1天
				now.setDate(now.getDate() - 1); // 减1天即为上个月最后一天
				this.msg.QStartDate = this.year + '-' + this.month + '-01'
				this.msg.QEndDate = this.year + '-' + this.month + '-'+now.getDate()
				this.research()
			},
			SelectDate(){
				this.showTime = true
			},
			goDetails(item) {
				let obj = JSON.stringify(item);
				let path = `/pages/user-center/discountDetails?data=${encodeURIComponent(obj)}&discountType=6`
				uni.navigateTo({
					url: path,
				});
			},
			scroll(e) {
				this.scrollTop = e.detail.scrollTop;
			},
			goUrl(url) {
				uni.navigateTo({ url });
			},
			lower(e) {
				if (this.msg.pageIndex < this.page_count) {
					this.msg.pageIndex++;
					this.status = "loading";
					this.getList();
				} else {
					this.status = "nomore";
				}
			},
			research(ID) {
				if(ID>=0) {
					this.msg.active = ID
					if(ID!=3){
						if(this.msg.QStartDate==''){
							const now = new Date();
							this.year = now.getFullYear();
							this.month = String(now.getMonth() + 1).padStart(2, '0');
							this.msg.QStartDate = this.year + '-' + this.month + '-01'
							now.setMonth(now.getMonth() + 1, 0);
							this.msg.QEndDate = this.year + '-' + this.month + '-'+now.getDate()
							this.times = this.year + '-' + this.month
						}
						this.msg.Type = ID
						this.msg.IntegralState = 1
					}else{
						this.msg.QStartDate = ''
						this.msg.QEndDate = ''
						this.msg.IntegralState = 2
					}
				}
				this.msg.pageIndex = 1
				this.dataList = []
				this.getList()
			},
			getList() {
				this.loading = true
				uni.showLoading({
					title: '加载中',
					icon: 'none'
				})
				this.apipost('b2b_get_GetCustomerIntegralPageList',this.msg,
					(res) => {
						this.loading = false
						uni.hideLoading();
						if(res.data.pageData.length>0){
							this.dataList = this.dataList.concat(res.data.pageData)
						}
						this.page_count = res.data.pageCount;
					},(err)=>{
						this.loading = false
						uni.hideLoading();
					}
				);
			},
			GetCustomerIntegral() {
				this.apipost("b2b_get_GetCustomerIntegralDetail",{},
					(res) => {
						this.CustomerIntegral = res.data
					}
				);
			},
			goBack(){
                uni.navigateBack({delta:-1})
            }
		}
	};
</script>

<style scoped>
	@import url('../../asset/css/flex.css');
	.listBox{
		height: 1px;
		flex: 1;
		overflow: hidden;
	}
	.listBox.active{
		min-height: 936rpx;
	}
	.row-sbas-n {
		justify-content: space-between;
	}
	.relative {
		position: relative;
	}

	.userBox {
		display: flex;
		flex-direction: column;
		align-items: center;
		background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638778933736114322.png')no-repeat ;
        background-size: 100% auto;
		background-color: #F3F2EF;
		height: 100vh;
		// padding-bottom: env(safe-area-inset-bottom);
	}

	.order_bar_list {
		padding: 22rpx 55rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.order_bar_item {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 20rpx;
		position: relative;
	}

	.badge {
		position: absolute;
		right: -10rpx;
		top: -10rpx;
		padding: 0 8rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 20rpx;
		background: #FF3166;
		color: #fff;
		min-width: 28rpx;
		height: 28rpx;
		border-radius: 14rpx;
	}

	.headStatus {
		position: fixed;
		width: 140vw;
		padding-right: 40vw;
		padding-bottom: 10px;
		left: 0;
		right: 0;
		top: 0;
		display: flex;
		background: #CFE2A0;
	}

	.headStatus .title {
		font-size: 32rpx;
		color: #000;
		flex: 1;
		width: 1px;
		line-height: 34px;
		text-align: center;
	}
	.userMyOrder {
		background: #FFF;
		border-radius: 20rpx;
		padding: 33rpx 0 22rpx 0;
	}
	.userMyOrderTitle {
		padding: 23rpx 31rpx 0 31rpx;
	}
	.userMyOrderTitL {
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 32rpx;
		color: #080A09;
	}
	.userMyOrderTitR {
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #B2B3B3;
		align-items: center;
	}
	.userMyOrderTitRIght {
		margin-left: 11rpx;
		transform: rotate(90deg);
	}

	.orderProductBox {
		padding: 0 20rpx;
	}
	.orderProduct {
		width: 648rpx;
		height: 132rpx;
		background: #F7F7F7;
		border-radius: 18rpx;
		padding: 21rpx 20rpx;
	}
	.orderProductL {
		width: 91rpx;
		height: 88rpx;
		border-radius: 14rpx;
		overflow: hidden;
		margin-right: 18rpx;
	}
	.orderProductR_state {
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #080A09;
		padding-top: 5rpx;
	}
	.orderProductR_text {
		width: 100%;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #8C8C8C;
		padding-top: 4rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
    .userMyOrderBox{
        background: #FFFFFF;
        overflow: hidden;
        border-radius: 20rpx;
        padding: 25rpx 34rpx 45rpx 34rpx;
		height: 1px;
		flex: 1;
		overflow: hidden;
    }
    .userHeadPList{
        padding: 20rpx 0;
    }
    .userHeadPListL{
        width: 91rpx;
        height: 88rpx;
        border-radius: 14rpx;
        overflow: hidden;
        position: relative;
    }
    .userHeadPListL image{
        width: 91rpx;
        height: 88rpx;
        display: block;
    }
    .userHeadPListL text{
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1;
        background: rgb(178, 179, 179,.8);
        border-radius: 0rpx 0rpx 14rpx 14rpx;
        color: #fff;
        font-size: 20rpx;
        padding: 5rpx 0;
        text-align: center;
    }
    .userHeadPListA{
        margin-left: 29rpx;
        margin-right: 20rpx;
    }
    .userHeadPListATitel{
        font-weight: bold;
        font-size: 28rpx;
        color: #080A09;
        margin-top: 5rpx;
		width: 348rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
    }
    .userHeadPListATime{
        font-weight: 500;
        font-size: 24rpx;
        color: #8C8C8C;
        margin-top: 18rpx;
    }
    .userHeadPListR{
        font-weight: bold;
        font-size: 28rpx;
        color: #B99846;
    }
	.userMyOrderState{
		margin-bottom: 40rpx;
	}
	.userMyOrderState view{
		flex: 1;
		margin-left: 20rpx;
		background: #F3F2EF;
		color: #757776;
		font-size: 29rpx;
		text-align: center;
		line-height: 80rpx;
		border-radius: 14rpx;
	}
	.userMyOrderState view:first-child{
		margin-left: 0;
	}
	.userMyOrderState view.active{
		background: #000;
		color: #fff;
	}
	.userHeaderBox{
        width: 750rpx;
    }
    .titlenav {
		width: 100%;
		text-align: center;
		font-size: 16px;
		color: #000;
        position: relative;
		padding: 15rpx 0;
	}
    .carrHeader-left-icon{
        position: absolute;
        left: 32rpx;
        top: 20rpx;
        z-index: 2;
    }
    .userHeadPic{
        padding: 29rpx 20rpx 25rpx 62rpx;
    }
    .userHeadPicL{
        width: 97rpx;
        height: 97rpx;
        overflow: hidden;
        border-radius: 50%;
        margin-right: 27rpx;
    }
    .userHeadPicL image{
        width: 97rpx;
        height: 97rpx;
        display: block;
    }
    .userHeadPicR_title{
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 36rpx;
        color: #080A09;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .userHeadPicR_text{
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 24rpx;
        color: #61462E;
        margin-top: 16rpx;
        letter-spacing: 1rpx;
    }
    .jz_LineDetaVipPr{
		margin-top: 28rpx;
		position: relative;
		left: -20rpx;
	}
	.jz_LineDetaVip{
		width: 100%;
		height: 120rpx;
		background: linear-gradient(90deg, #3F423F, #313131);
		border-radius: 18rpx;
		display: flex;
		flex-direction: column;
		padding: 15rpx 0 6rpx 0;
		margin-top: 18rpx;
		margin-bottom: 18rpx;
	}
	.jz_LineDetaVipTop{
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #E2C27A;
		letter-spacing: .1rpx;
		display: flex;
		align-content: center;
		padding: 0 34rpx;
	}
	.jz_LineDetaVipTop img{
		width: 21rpx;
		height: 21rpx;
		display: inline-block;
		margin-left: 5rpx;
	}
	.jz_LineDetaVPB{
		display: flex;
		
	}
	.jz_LineDetaVPBBox{
		display: flex;
		align-items: center;
		width: 1px;
		flex: 1;
	}
	.jz_LineDetaVPBN{
		width: 30rpx;
		height: 30rpx;
		background: #2E2E2E;
		border-radius: 50%;
		text-align: center;
		line-height: 28rpx;
		font-family: DIN Black;
		font-weight: bold;
		font-size: 24rpx;
		color:  #494949;;
	}
	.jz_LineDetaVPBLine{
		flex: 1;
		height: 10rpx;
		background: #000;
	}
	.jz_LineDetaVPBBoxI{
		position: relative;
		flex: 1;
	}
	.jz_LineDetaVPBBoxI img{
		width: 87rpx;
		height: 99rpx;
		position: absolute;
		bottom: -35rpx;
		right: 8rpx;
		z-index: 2;
	}
	.jz_LineDetaVPBBox.active .jz_LineDetaVPBN{
		background: linear-gradient(270deg, #C99E59, #FFFFB3);
	}
	.jz_LineDetaVPBBox.active .jz_LineDetaVPBLine{
		background: #C99E59;
		color: #583F2C;
	}
    .VPBLRadiusL{
		border-radius: 20rpx 0 0 20rpx ;
	}
	.VPBLRadiusR{
		border-radius: 0 20rpx 20rpx 0;
	}
	.jz_LineDetaVPBY{
		position: absolute;
		left: -29rpx;
		right: 0;
		top: 0;
	}
    .userHeadPasBox{
        padding: 0 30rpx;
    }
    .userHeadPNum{
        width: 330rpx;
        border-radius: 18rpx;
        background: rgba(255, 255, 255,.2);
        padding: 30rpx 20rpx 40rpx 50rpx;
    }
    .userHeadPNumT{
        font-weight: 500;
        font-size: 28rpx;
        color: #4F360D;
        margin-bottom: 21rpx;
    }
    .userHeadPNumB{
        color: #FF3166 ;
        font-size: 48rpx;
        font-weight: bold;
    }
    .userHeadPNumB text{
        font-size: 29rpx;
    }
    .userHeadPNum.active .userHeadPNumB{
        color: #4F360D;
    }
    .userHeadPNumS{
        border-radius: 18rpx;
        background: rgba(255, 255, 255,.2);
        padding: 30rpx 40rpx 40rpx 50rpx;
        margin-top: 30rpx;
        margin-bottom: 40rpx;
    }
    .userHeadPNumSL{
        font-size: 29rpx;
        color: #4F360D;
    }
    .userHeadPNumSR{
        color: #4F360D ;
        font-size: 29rpx;
        font-weight: bold;
    }
    .userHeadPNumSR text{
        font-size: 48rpx;
    }
</style>