<template>
	<view class="content">
		<view class="top-fixed">
			<!-- tab切换 -->
			<view class="pub-tab-box">
				<view class="tab-inner">
					<view 
						v-for="(item,index) in orderStatus" 
						:key="index"
						:class="item.val == orderStatusValue?'item active':'item'"
						@click="orderStatusChange(item)">
						<view class="text">
							{{ item.name }}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="consu-list">
			<view class="tab-time">
				<picker class="birth-picker" mode="date"  fields="month"  @change="bindDateChange">
					<view class="left-box">
						<view>{{day}}</view>
						<image class="w48 h48" src="../static/images/health/arrow_down.png"></image>
					</view>
				</picker>
			</view>
			<mescroll-body top="176upx" ref="mescrollRef">
				<view v-for="(item,index) in dataList" :key="index" class="item">
					<view class="item-top">
						{{item.date}}
					</view>
					<view class="bottom-box" v-for="(it,idx) in item.list" :key="idx" @click="showDetail(it)">
						<view class="amount-paid">
							<view :class="'title bg'+it.type">{{it.typeName}}</view>
							<view class="data">{{it.data}} mmol/L</view>
						</view>
						<view class="time">{{utils.formatDate(it.createTime)}}</view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import {getMyDoctorOrderList,cancelOrder} from '@/api/doctorOrder.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				day:this.utils.timeFormat(new Date(),'yyyy年mm月'),
				orderStatus:[
					{name:"全部",val:""},
					{name:"正常",val:"0"},
					{name:"轻微",val:"1"},
					{name:"严重",val:"2"},
				],
				orderStatusValue:'',
				mescroll:null,
				// 上拉加载的配置
				upOption: {
					onScroll:true,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon:'/static/images/no_data.png',
						tip: '暂无数据'
					}
				},
				// 列表数据
				dataList: [
					{
					 list:[
							{
								type:1,
								typeName:'正常',
								data:10.9,
								createTime:'2025-06-25 12:39:55'
							},
							{
								type:2,
								typeName:'轻微',
								data:10.9,
								createTime:'2025-06-25 22:39:55'
							},
							{
								type:3,
								typeName:'严重',
								data:10.9,
								createTime:'2025-06-25 17:39:55'
							}
						],
						date:'2025-06-25',
						id:1
					},
					{
					 list:[
							{
								type:1,
								typeName:'正常',
								data:10.9,
								createTime:'2025-02-25 12:39:55'
							},
							{
								type:2,
								typeName:'轻微',
								data:10.9,
								createTime:'2025-02-25 20:39:55'
							}
						],
						date:'2025-02-25',
						id:2
					}
				]
			}
		},
		onLoad() {
			// uni.$on('refreshDoctorOrder', () => {
			// 	this.mescroll.resetUpScroll()
			// })
		},
		methods: {
			// 时间选择
			bindDateChange: function(e) {
				this.day = this.utils.timeFormat(new Date(e.target.value),'yyyy年mm月')
			},
			navgetTo(index){
				uni.navigateTo({
					url: index==0?'/pages_health/addServe':'/pages_health/addCompetitors'
				})
			},
			cancel(item){
				var that=this;
				uni.showModal({
				    title: '提示',
				    content: '确定取消订单吗',
				    success: function (res) {
				        if (res.confirm) {
							var data = {
								orderId:item.orderId
							};
							cancelOrder(data).then(res => {
								if(res.code==200){
									uni.showToast({
										icon:'success',
										title: '订单已取消',
									});
									 that.mescroll.resetUpScroll()
								}else{
									uni.showToast({
										icon:'none',
										title: res.msg,
									});
								}
							});
				        } 
						else if (res.cancel) {
				        }
				    }
				});
			},
			// tab切换
			orderStatusChange(item) {
				this.orderStatusValue = item.val
				if(item.val==1){
					this.dataList=this.dataList2
				}
				this.mescroll.resetUpScroll()
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					status:this.orderStatusValue,
					page: page.num,
					pageSize: page.size
				};
				// getMyDoctorOrderList(data).then(res => {
				// 	if(res.code==200){
				// 		//设置列表数据
				// 		if (page.num == 1) {
				// 			that.dataList = res.data.list; 
							
				// 		} else {
				// 			that.dataList = that.dataList.concat(res.data.list);
							 
				// 		}
				// 		that.mescroll.endBySize(res.data.list.length, res.data.total);
						
				// 	}else{
				// 		uni.showToast({
				// 			icon:'none',
				// 			title: "请求失败",
				// 		});
				// 		that.dataList = null;
				// 		that.mescroll.endErr();
				// 	}
				// });
			},
			showDetail(item){
				console.log(item,'pp')
				uni.navigateTo({
					url: '/pages_echarts/bloodSugarDetail'
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 20upx;
		.top-fixed{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 10;
		}
		.pub-tab-box{
			box-sizing: border-box;
			width: 100%;
			padding: 0 60upx;
			background-color: #FFFFFF;
			.tab-inner{
				height: 88upx;
				line-height: 88upx;
				display: flex;
				align-items: center;
				justify-content:space-between;
				overflow-x: auto;
			}
			.item{
				font-size: 28upx;
				white-space: nowrap;
				line-height: 1;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
				// margin-right: 60upx;
				display: flex;
				align-items: center;
				justify-content: center;
				&:last-child{
					margin-right: 0;
				}
				&.active{
					font-weight: bold;
					color: #333333;
					&::after {
						content: "";
						width: 48rpx;
						height: 8rpx;
						background: linear-gradient(120deg, #31A1FE  0%, #008FD3 100%);
						position: absolute;
						bottom: 0;
						border-radius: 6upx 6upx 0upx 0;
					}
				}
				.text{
					position: relative;
					z-index: 1;
				}
				.tab-bg{
					width: 72upx;
					height: 28upx;
					position: absolute;
					top: 17upx;
					left: 50%;
					transform: translateX(-36upx);
					z-index: -1;
				}
			}
		}
		.tab-time{
			padding: 32rpx 24rpx;
			    font-size: 30rpx;
			    color: #222426;
			    text-align: left;
				position: fixed;
				top:88upx;
				z-index:10;
			.birth-picker {
				flex: 1;
				display: flex;
				align-items: center;
				
				.left-box{
					width: 100%;
					font-weight: 500;
					font-size: 30rpx;
					color: #222426;
					display: flex;
					align-items: center;
					.input-box{
						// width: 470upx;
					}
					.arrow{
						width: 13upx;
						height: 23upx;
						margin-left: 20upx;
					}
				}
			}
		}
		.consu-list{
			.item{
				background: #FFFFFF;
				border-radius: 16upx;
				padding: 24rpx;
				position: relative;
				margin-bottom: 20upx;
				.item-top{
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #626468;
					text-align: left;
					padding:16rpx 0;
					.item-title{
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-bottom: 12rpx;
						
					}
					.ask-text{
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 36rpx;
						color: #222426;
						text-align: left;
					}
					.ask-time{
						font-size: 24rpx;
						color: #898E91;
						text-align: left;
						line-height: 40rpx;
					}
				}
				.bottom-box{
					// height: 80upx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding:32rpx 0;
					border-bottom: 1px solid #ECECEC;
					&:last-child{
						border-bottom: 0;
					}
					.amount-paid{
						display: flex;
						align-items: center;
				        .title{
							width: 72rpx;
							height: 72rpx;
							line-height: 72rpx;
							font-family: PingFang SC;
							font-weight: 500;
							font-size: 24rpx;
							color: #FFFFFF;
							text-align: center;
							margin-right: 18rpx;
							border-radius:50%;
						}
						.bg1{
							background: #52D087;
						}
						.bg2{
							background: #FFB992;
						}
						.bg3{
							background: #FF5558;
						}
						.data{
							font-weight: 500;
							font-size: 30rpx;
							color: #222426;
							text-align: left;
						}
					}
				    .time{
						font-size: 24rpx;
						color: #898E91;
						text-align: right;
					}
				}
			}
		}
		
	}
</style>
