<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 == showType?'item active':'item'"
						@click="orderStatusChange(item)"
					>
						<view class="text">
							{{ item.name }}
						</view>
					</view>
				</view>
			</view>
		</view>
		
			<mescroll-body top="88upx" ref="mescrollRef">
				<view class="phone-list" v-if="showType==1">
				<view v-for="(item,index) in dataList" :key="index" class="item" >
					<image src="/static/images/company/deenergize_icon.png" class="w32 h32"></image>
				    <view class="phone-name">
						 <view class="justify-between align-center" style="width: 100%;">
							 <view class="name">{{item.name}}</view>
							 <view class="type">去电</view>
						 </view>
						 <view class="time">{{item.time}}</view>
					 </view>
				</view>
				</view>
				<view class="sms-list" v-if="showType==2">
				<view v-for="(item,index) in dataList2" :key="index" class="item" >
					<view class="title">{{item.content}}</view>
				    <view class="box">
						 <view class="time">{{item.time}}</view>
						 <view class="state">{{item.state}}</view>
					 </view>
				</view>
				</view>
				<view class="h150"></view>
			</mescroll-body>
		<view class="btn-box2">
			<view v-if="showType==1" class="sub-btn" @click="navgetTo(orderStatusValue)">
				<image src="/static/images/company/make_phone_call_icon.png" class="w48 h48"></image>
				<text>拨打电话</text>
			</view>
			<view v-if="showType==2" class="sub-btn" @click="navgetTo(orderStatusValue)">
				<image src="/static/images/company/send_SMS_icon.png" class="w48 h48"></image>
				<text>发送短信</text>
			</view>
		</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 {
				orderStatus:[
					{name:"电话记录",val:1},
					{name:"短信记录",val:2},
				],
				showType:1,
				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: [
					{orderId:1, name:'今日 11:22',time:'4分16秒'},
					{orderId:2, name:'昨天 09:16',time:'4分16秒'},
					{orderId:3, name:'1月12 13:06',time:'4分16秒'}
				],
				dataList2: [
					{orderId:1,content:'服用胰岛素口服液 规格20mg*20 每次1片1日一次 用法口服',state:'已送达',time:'2025-2-20 10:29',},
					{orderId:2,content:'服用胰岛素口服液 规格20mg*20 每次1片1日一次 用法口服',state:'已送达',time:'2025-2-20 10:29',},
					{orderId:3,content:'服用胰岛素口服液 规格20mg*20 每次1片1日一次 用法口服',state:'已送达',time:'2025-2-20 10:29',}
				]
			}
		},
		onLoad() {
			// uni.$on('refreshDoctorOrder', () => {
			// 	this.mescroll.resetUpScroll()
			// })
		},
		methods: {
			pay(item){
				uni.navigateTo({
					url: '/pages_/doctor/paymentOrder?orderId='+item.orderId
				})
			},
			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.showType = item.val
				this.mescroll.resetUpScroll()
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					status:this.showType,
					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) {
				if(item.orderType==1){
					uni.navigateTo({
						url: '/pages_doctor/doctorOrderIM?orderId='+item.orderId
					})
				}
			}
		}
	}
</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 40upx;
			background-color: #FFFFFF;
			.tab-inner{
				height: 88upx;
				line-height: 88upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				overflow-x: auto;
			}
			.item{
				flex:1;
				font-size: 28upx;
				white-space: nowrap;
				line-height: 1;
				font-family: PingFang SC;
				font-weight: 500;
				color: #626468;
				// margin-right: 60upx;
				display: flex;
				align-items: center;
				justify-content: center;
				&:last-child{
					margin-right: 0;
				}
				&.active{
					font-weight: bold;
					color:#008FD3;
					&::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;
				}
			}
		}
		.btn-box2{
			z-index: 9999;
			width: 100%;
			padding: 30upx;
			position: fixed;
			bottom: 0;
			left: 0;
			box-sizing: border-box;
			// background: #FFFFFF;
			
			 
			.sub-btn{
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #008FD3;
				border-radius: 44upx;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					margin-right: 16rpx;
				}
			}
		}
	   .phone-list{
		   padding: 30rpx;
		   background: #FFFFFF;
		   border-radius: 16rpx 16rpx 16rpx 16rpx;
		   .item{
			   display: flex;
			   align-items: flex-start;
			   border-bottom: 1rpx solid #ECECEC;
			   padding-bottom: 30rpx;
			   margin-bottom: 30rpx;
			   &:last-child{
				   border-bottom: 0;
				    margin-bottom: 0;
					padding-bottom: 0;
			   }
			   .phone-name{
				   display: flex;
				   flex-direction: column;
				   align-items: flex-start;
				   justify-content: flex-start;
				   padding-left: 24rpx;
				       flex: 1;
				   .name{
				   				   font-family: PingFang SC;
				   				   font-weight: 500;
				   				   font-size: 32rpx;
				   				   color: #222426;
				   				   text-align: left;
				   }
				   .type{
					   font-family: PingFang SC;
					   font-weight: 400;
					   font-size: 28rpx;
					   color: #626468;
					   text-align: right;
				   }
				   .time{
					   font-family: PingFang SC;
					   font-weight: 400;
					   font-size: 28rpx;
					   color: #898E91;
					   text-align: left;
					   margin-top: 14rpx;
				   }
			   }
			   
		   }
	   }
	   .sms-list{
		   .item{
			   padding: 30rpx;
			   background: #FFFFFF;
			   border-radius: 16rpx 16rpx 16rpx 16rpx;
			   margin-bottom: 20rpx;
			   .title{
				   font-family: PingFang SC;
				   font-weight: 500;
				   font-size: 32rpx;
				   color: #222426;
				   text-align: left;
			   }
			   .box{
				   display: flex;
				   align-items: center;
				   justify-content: space-between;
				   padding-top: 22rpx;
				   .time{
					   font-family: PingFang SC;
					   font-weight: 400;
					   font-size: 24rpx;
					   color: #898E91;
					   text-align: left;
				   }
				   .state{
					   font-family: PingFang SC;
					   font-weight: 400;
					   font-size: 24rpx;
					   color: #2CAE5C;
					   text-align: right;
				   }
			   }
		   }
	   }
		
	}
</style>
