<template>
	<view style="width:100vw;height:100vh;" class="column">
		<scroll-view :scroll-y="true" @scroll="scrollHandler" @scrolltoupper="scrollTopHandler" class="col" style="height: 1px;width: 100%;">
			<view class="userStyle">
				<view class="headStatus" v-if="scrollTop > 50" :style="{
					zIndex: scrollTop < 10 ? 'unset' : 2,
					opacity: scrollTop < 10 ? '100' : scrollTop,
				}">
					<view class="title">{{ pageTitle }}</view>
				</view>
				<view class="userBox" style="height:100vh">
					<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||statistics.image" :src="b2b_user_info.photo?b2b_user_info.photo:statistics.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">
                                Hello，{{ b2b_user_info.name }}
								</text>
								<text v-else-if="mall_UserInfo&&mall_UserInfo.Name" 
								class="userHeadPicR_title">
                                Hello，{{mall_UserInfo.Name}}
								</text>
								<text class="userHeadPicR_text">
                                    尊敬的VIP用户，<!-- #ifdef MP-DI -->国旅优选<!-- #endif --><!-- #ifdef MP-AG -->旅小友<!-- #endif -->已与您同行
                                    <text style="font-size: 28rpx;color: #9B571E;font-weight: bold;">318</text>天
                                </text>
							</view>
						</view>
						<view class="userHeadPasBox">
							<view class="userHeadCostBox">
								<view class="userHeadCostType row-sb-n items-center">
                                    <view class="userHeadCostTText row items-center justify-center" 
									v-for="(item,index) in typeList" :key="index"
									:class="[msg.Type==item.ID?'active':'']"
									@click="research(item.ID)">
                                        <image v-if="msg.Type==item.ID" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638778211798604496.png" />
                                        <text>{{ item.Name }}</text>
                                    </view>
                                </view>
								<view class="userHeadCostTime row justify-center">
									<view>2025.02-2025.08</view>
								</view>
								<view class="userHeadCostChart">
									// <mrsongCharts 
									// type='ring' 
									// align='center'
									// :config="config"
									// :options="options" />
								</view>
							</view>
						</view>
					</view>
					<view style="height: 21rpx;"></view>
					<view style="padding: 0 32rpx;width: 100vw;height: 1px;flex: 1;">
                        <view class="userMyOrderBox column">
                            <view class="userMyOrderTitle row-sb-n" style="padding: 20rpx 0;">
								<view class="userMyOrderTL">幸福存折明细</view>
								<view class="userMyOrderTR row items-center" @click="goUrl('/pages/user-center/happinessPassbook')">
									<text class="userMyOrderTRTj">合计</text>
									<view class="userMyOrderTRQ"> <text>¥</text><text>900</text></view>
									<u-icon class="userMyOrderTRR" name="arrow-down" size="28" color="#B2B3B3"></u-icon>
								</view>
                            </view>
                            <scroll-view :scroll-y="true" class="col"
							@scrolltolower="lower" 
							style="height: 1px;flex: 1; width: 100%;">
                                <view class="userHeadPListBox">
                                    <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>共4人</text>
                                        </view>
                                        <view class="userHeadPListA col column">
                                            <view class="userHeadPListATitel">{{ item.lineName }}</view>
                                            <view class="userHeadPListATime">
												{{ item.updateTime }}
											</view>
                                        </view>
                                        <view class="userHeadPListR">
                                            +¥{{ item.money }}
                                        </view>
                                    </view>
                                </view>
								<u-empty v-if="dataList.length == 0 && !loading" text="暂无数据" mode="data" padding-top="20"></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>
				</view>
			</view>
			
		</scroll-view>
		<u-picker mode="time" v-model="showTime" :defaultTime="times" :params="params" @confirm = 'confirm'></u-picker>
	</view>
</template>

<script>
	// import mrsongCharts from '@/uni_modules/mrsong-charts/components/mrsong-charts/mrsong-charts.vue';
	export default {
		components: {
			// mrsongCharts
		},
		data() {
			return {
				pageTitle: "省钱统计",
				scrollTop: 0,
				showAuth: false,
				b2b_user_info: {},
				mall_UserInfo: {},
				typeList:[
					{Name:'累计省钱',ID:0},
					{Name:'月度省钱',ID:1},
					{Name:'年度省钱',ID:2},
				],
				msg:{
					pageIndex:1,//是	[string]
					pageSize:10,//是	[string]
					BalanceState:0,//	状态 1查询已反记录 2查询待结算记录
					Type:0,//	类型 1存入 2扣除
					StartTime:'',//	开始时间
					EndTime:'',
				},
				statistics:{},
				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: '',
				CustomerBalance:{},
				titleStyle:{},
				config:{
					itemCount: 3, // x轴单屏显示数据的数量，默认为5个
					scrollShow: false, // 新增是否显示滚动条，默认false
					scrollAlign: 'left', // 滚动条初始位置
					rotateLabel: true, // X轴label旋转
					min: 0, // Y轴最小值
					// "max": 150, //Y轴大值
					unit: '', // Y轴单位
					enableScroll: false, // 开启滚动模式
					color: [
						// 颜色设置
						'#9A60B4',
						'#ea7ccc'
					]
				},
				options:{
					background: "#000000",
					color: ['#080A09', '#91CB74', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
					xAxis: {
						itemCount: 4, // x轴单屏显示数据的数量，默认为5个
						scrollShow: false, // 新增是否显示滚动条，默认false
						scrollAlign: 'left', // 滚动条初始位置
						rotateLabel: true // X轴label旋转
					},
					yAxis: {
						data: [
							{
								min: 0, // Y轴最小值
								// "max": 150, //Y轴大值
								unit: '' // Y轴单位
							}
						]
					},
					enableScroll: false, // 开启滚动模式
					fontColor: "#4F360D",
					padding:[
						20,20,20,20
					]
				}
			};
		},
		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.StartTime = this.year + '-' + this.month + '-01'
			now.setMonth(now.getMonth() + 1, 0);
			this.msg.EndTime = this.year + '-' + this.month + '-'+now.getDate()
			this.times = this.year + '-' + this.month
			this.getList();
			this.GetCustomerCenter()
			this.GetCustomerBalance()
		},
		methods: {
			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.StartTime = this.year + '-' + this.month + '-01'
				this.msg.EndTime = this.year + '-' + this.month + '-'+now.getDate()
				this.research()
			},
			SelectDate(){
				this.showTime = true
			},
			goDetails(item) {
				if(url) {
					let path = `/pages/user-center/happinessPasDetails?data=`+encodeURIComponent(item)
					uni.navigateTo({
						url: path,
					});
				}
			},
			scrollHandler(e) {
				this.scrollTop = e.detail.scrollTop;
			},
			scrollTopHandler() {
				this.scrollTop = 0;
			},
			goUrl(url) {
				uni.navigateTo({ url });
			},
			GetCustomerCenter(){
				this.apipost('b2b_get_GetCustomerCenter_New',
					{},
					(res) => {
						uni.hideLoading()
						this.statistics = res.data
					},err=>{
						uni.showToast({
							title: err.message,
							icon: "none",
						});
					}
				);
			},
			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==this.msg.Type) return
				if(ID>=0) this.msg.Type = ID
				this.msg.pageIndex = 1
				this.dataList = []
				this.getList()
			},
			getList() {
				this.loading = true
				uni.showLoading({
					title: '加载中',
					icon: 'none'
				})
				this.apipost('b2b_get_GetCustomerBalancePageList',this.msg,
					(res) => {
						this.loading = false
						uni.hideLoading();
						this.dataList = this.dataList.concat(res.data.pageData)
						this.page_count = res.data.pageCount;
					},(err)=>{
						this.loading = false
						uni.hideLoading();
					}
				);
			},
			GetCustomerBalance() {
				this.apipost("b2b_get_GetCustomerBalanceDetail",{},
					(res) => {
						this.CustomerBalance = res.data
					}
				);
			},
            goBack(){
                uni.navigateBack({delta:-1})
            }
		}
	};
</script>

<style scoped>
	@import url('../../asset/css/flex.css');
	.row-sbas-n {
		justify-content: space-between;
	}
	.relative {
		position: relative;
	}

	.userStyle .userBox {
		display: flex;
		flex-direction: column;
		align-items: center;
		background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638774847991690497.png')no-repeat #E8D1A2;
        background-size: 100% auto;
	    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-image: linear-gradient(to right, #e6b865, #ebb45e);
	}

	.headStatus .title {
		font-size: 18px;
		color: #fff;
		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;
        height: 100%;
        overflow: hidden;
        border-radius: 20rpx;
        padding: 25rpx 34rpx 45rpx 34rpx;
    }
    .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;
    }
    .userHeadPListATime{
        font-weight: 500;
        font-size: 24rpx;
        color: #8C8C8C;
        margin-top: 18rpx;
    }
    .userHeadPListR{
        font-weight: bold;
        font-size: 28rpx;
        color: #B99846;
    }
	.userHeaderBox{
        width: 750rpx;
    }
    .titlenav {
		width: 100%;
		text-align: center;
		font-size: 16px;
		color: #000;
        position: relative;
	}
    .carrHeader-left-icon{
        position: absolute;
        left: 32rpx;
        top: 7rpx;
        z-index: 2;
    }
    .userHeadPic{
        padding: 49rpx 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;
    }
    .userHeadCostBox{
        border-radius: 16rpx;
        background: -webkit-gradient(linear, 0 0, 0 100%, from(#FBF3E1), to(#F3E1BA));
        padding: 25rpx 22rpx 51rpx 22rpx;
    }
    .userHeadCostType{
        width: 641rpx;
        height: 93rpx;
        background: url("https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638778209274571586.png")no-repeat;
        background-size: 641rpx auto;
		padding: 13rpx 16rpx;
    }
	.userHeadCostType image{
		width: 34rpx;
		height: 34rpx;
	}
	.userHeadCostTText{
		flex: 1;
		line-height: 64rpx;
		font-weight: bold;
		font-size: 26rpx;
		color: #4F360D;
		text-align: center;
	}
	.userHeadCostTText.active{
		box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(247,236,211,0.38);
		border-radius: 14rpx;
		background: -webkit-gradient(linear, 0 0, 0 100%, from(#313131), to(#3F423F ));
		color: #F3F1EF;
	}
	.userHeadCostTime{
		padding: 32rpx 0 0 0;
	}
	.userHeadCostTime view{
		font-weight: 500;
		font-size: 24rpx;
		color: #4F360D;
		background: #EDDDBA;
		box-shadow: 0rpx 0rpx 4rpx 0rpx rgba(211,181,119,0.5);
		border-radius: 19rpx;
		padding: 0 23rpx;
	}
	.userHeadCostChart{
		height: 440rpx;
		// overflow: hidden;
	}
	.userMyOrderTL{
		font-weight: 800;
		font-size: 32rpx;
		color: #080A09;
	}
	.userMyOrderTRTj{
		font-weight: 500;
		font-size: 24rpx;
		color: #B2B3B3;
	}
	.userMyOrderTRQ{
		font-weight: bold;
		font-size: 36rpx;
		color: #000;
		padding: 0 7rpx 0 10rpx;
	}
	.userMyOrderTRQ:first-child{
		font-size: 26rpx;
	}
	.userMyOrderTRR{
		transform: rotate(-90deg);
	}
</style>