<template>
	<view class="page">
		<u-navbar :is-back="false" title="订单管理" :border-bottom="false" :background="bgc" title-color='#2E4975' title-size='36' height='45'></u-navbar>

		<view class="tap">
			<view class="tap_cont " :class="status==0?'act1':''" @click="changeidx(0)">
				全部
			</view>
			<view class="tap_cont" :class="status==1?'act1':''" @click="changeidx(1)">
				进行中
			</view>
			<view class="tap_cont" :class="status==2?'act1':''" @click="changeidx(2)">
				待支付
			</view>
			<view class="tap_cont" :class="status==3?'act1':''" @click="changeidx(3)">
				已完成
			</view>
			
		</view>

		<u-mask :show="show" :z-index='100' />
		<view class="card" v-for="(item,index) in list" :key="index" @click="todetail(item)">
			<view class="btn_box" v-if="item.status==4">
				<view class="btn1">续租</view>
				<view class="btn2">还车</view>
			</view>
			<view class="info_li">
				<view class="txt">取车时间：{{item.pickupTime}}</view>
				<view class="txt3" :style="{ color: typeReturn(item.status).color }">
				  {{ typeReturn(item.status).text }}
				</view>
			</view>
			<view class="info_li">
				<view class="txt"  v-if="item.returnMethod==1">取车方式：自行前往门店</view>
				<view class="txt"  v-if="item.returnMethod==2">取车方式：自行前往门店</view>
				<view class="txt"  v-if="item.returnMethod==3">取车方式：自行前往门店</view>
			</view>
			<view class="info_li">
				<view class="txt">还车时间：{{item.expiryTime}}</view>
				<!-- <view class="txt3" style="color: #4297F3;">待取车</view> -->
			</view>
			<view class="info_li"  v-if="item.returnMethod">
				<view class="txt" v-if="item.returnMethod==1">还车方式：自行前往门店</view>
				<view class="txt" v-if="item.returnMethod==2">还车方式：上门取车</view>
			</view>
			
			<view class="info_li">
				<view class="txt">用户地址：福鼎市太姥山镇秦屿大道2号</view>
				<view class="txt2">{{item.totalFee}}元</view>
			</view>
			<view class="line"></view>
			<view class="info_li">
				<view class="txt">门店：{{item.storeName}}</view>
			</view>
			<view class="info_li">
				<view class="txt">车型：{{item.model}}</view>
			</view>
		</view>
		<view class="warp_box" v-if="fasle">
			<swiper class="swiper" :style="{ height: swiperHeight + 'rpx' }" :current='curtitidx' @change="swiperchange" style="padding-bottom: 50rpx;" next-margin='0rpx'>
				<swiper-item>
					<view class="swiper-item">
						<view class="card">
							<view class="btn_box">
								<view class="btn1">续租</view>
								<view class="btn2">还车</view>
							</view>
							<view class="info_li">
								<view class="txt">还车时间：2024-09-11 13:56</view>
								<view class="txt3" style="color: #4297F3;"></view>
							</view>
							<view class="info_li">
								<view class="txt">还车方式：自行前往门店</view>
							</view>
							<view class="info_li">
								<view class="txt">用户地址：福鼎市太姥山镇秦屿大道2号</view>
								<view class="txt2">118.8元</view>
							</view>
							<view class="line"></view>
							<view class="info_li">
								<view class="txt">门店：云行租车（汇丰公寓）</view>
							</view>
							<view class="info_li">
								<view class="txt">车型：全新车网红泡泡</view>
							</view>
						</view>
					</view>
				</swiper-item>

				<swiper-item>
					<view class="swiper-item">
						<view class="card">
							<!-- Add content here -->
						</view>
					</view>
				</swiper-item>

				<swiper-item>
					<view class="swiper-item">
						<!-- Add content here -->
					</view>
				</swiper-item>

				<swiper-item>
					<view class="swiper-item">
						<view class="card">
							<!-- Add content here -->
						</view>
					</view>
				</swiper-item>

				<swiper-item>
					<view class="swiper-item">
						<!-- Add content here -->
					</view>
				</swiper-item>
			</swiper>
		</view>

		<!-- <u-select v-model="shows" :list="list" title='添加方式' @confirm="searchconfirm"></u-select> -->
		<TabBar :indexs='2' style=""></TabBar>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				bgc: {
					backgroundColor: "#fff",
				},


				searchKeyword: '',
				status: 0,
				swiperHeight: 400,
				list:[]


			}
		},
		onShow() {
			this.getList()
		},
		watch: {
			curtitidx(newValue, oldValue) {
				// 处理userId变化的逻辑
				console.log('userId 发生变化', newValue, oldValue);
				// if (newValue == 0) {
				// 	this.swiperHeight = (this.allList.length * 440)
				// } else if (newValue == 1) {
				// 	this.swiperHeight = this.ingList.length * 440
				// } else if (newValue == 2) {
				// 	this.swiperHeight = this.reprement.length * 440
				// } else if (newValue == 3) {
				// 	this.swiperHeight = this.alreadyList.length * 440
				// }
			}
		},
		computed: {
			userId() {
				return this.$store.getters.userId;
			},
		},
		computed: {

		},
		onReachBottom() {
			// 触底时增加 pageNum 并调用 getlist 获取更多数据
			this.pageNum++;
			if (this.curtitidx == 0) {
				this.orderList()

			} else if (this.curtitidx == 1) {
				this.orderList1()

			} else if (this.curtitidx == 2) {
				this.orderList2()

			} else if (this.curtitidx == 3) {
				this.orderList3()

			} else if (this.curtitidx == 4) {
				this.orderList4()

			}
		},
		methods: {
			todetail(item){
				if(item.status!=5&&item.status!=6){
					uni.navigateTo({
						url:'/page_user/user_order?orderNo='+item.orderNo
					})
				}
			
			},
			typeReturn(num) {
			  let result = {
			    text: '',
			    color: '#4297F3' // 默认颜色
			  };
			
			  if (num == 0) {
			    result.text = '待支付';
			    result.color = '#F14C4C'; // 待支付颜色
			  } else if (num == 1) {
			    result.text = '待取车';
			  } else if (num == 2) {
			    result.text = '待送车';
			  } else if (num == 3) {
			    result.text = '送车中';
			  } else if (num == 4) {
			    result.text = '进行中';
			  } else if (num == 5) {
			    result.text = '超时取消';
			    result.color = '#ccc'; // 超时取消颜色
			  } else if (num == 6) {
			    result.text = '已取消';
			    result.color = '#ccc'; // 已取消颜色
			  } else if (num == 7) {
			    result.text = '已完成';
			    result.color = '#3D3D3D'; // 已完成颜色
			  } else if (num == 8) {
			    result.text = '已结束';
			  }
			
			  return result;
			},
			getList(){
				let status=''
				if(this.status==0){
					status=''
				}else if(this.status==1){
					status='4'
				}else if(this.status==2){
					status='0'
				}else if(this.status==3){
					status='8'
				}
				this.$u.get(`/appVerify/myOrderList?status=`+status).then((res) => {
					if (res.code === 200) {
						this.list=res.data
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			async swiperchange(e) {
				// this.curtitidx = e.detail.current
				// console.log(	this.curtitidx,'eee');
				// // this.pageNum=1
				// // this.allList=[]
				// // this.ingList=[]
				// // this.reprement=[]
				// // this.alreadyList=[]
				// if ( e.detail.current == 0) {
				// 	this.orderList()
				// } else if ( e.detail.current == 1) {
				// 	this.orderList1()
				// } else if ( e.detail.current == 2) {
				// 	this.orderList2()
				// } else if ( e.detail.current == 3) {
				// 	this.orderList3()
				// }else if ( e.detail.current ==4 ) {
				// 	this.orderList4()
				// }
			},
			async changeidx(idx) {
				this.status=idx
				this.getList()
				// 	this.pageNum=1
				// 	this.allList=[]
				// 	this.ingList=[]
				// 	this.reprement=[]
				// 	this.alreadyList=[]
				// if (idx == 0) {

				// 	this.orderList()

				// } else if (idx == 1) {
				// 	this.orderList1()
				// } else if (idx == 2) {
				// 	this.orderList2()
				// } else if (idx == 3) {
				// 	this.orderList3()
				// } else if (idx == 4) {
				// 	this.orderList4()
				// }

			},
			formatDate(value) {
				if (!value) return '';
				let date = new Date(value);
				let month = date.getMonth() + 1; // 月份从0开始计数，所以加1
				let day = date.getDate();
				let hours = date.getHours();
				let minutes = date.getMinutes();

				// 确保月份、日期、小时和分钟都是两位数
				month = month < 10 ? '0' + month : month;
				day = day < 10 ? '0' + day : day;
				hours = hours < 10 ? '0' + hours : hours;
				minutes = minutes < 10 ? '0' + minutes : minutes;

				return `${month}-${day} ${hours}:${minutes}`;
			},
			searchconfirm(e) {
				// console.log(e,'eeeeeeeeee');
				this.typeidx = e[0].value
				this.tit = e[0].label

				// console.log(e);
				// this.mode = e[0].label
				// this.gettype()
			},


		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	.page {
		width: 750rpx;

		.card {
			position: relative;
			margin: 0 auto;
			margin-top: 20rpx;
			width: 714rpx;
			padding: 32rpx 24rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			.line{
				margin-top: 26rpx;
				width: 100%;
				height: 1rpx;
				background: #D8D8D8;
			}
			.txt {
				font-weight: 400;
				font-size: 26rpx;
				color: #3D3D3D;
			}
		
			.info_li:first-child {
				margin-top: 0;
			}
			.btn_box{
				display: flex;
				flex-wrap: nowrap;
				
				position: absolute;
				right: 26rpx;
				bottom: 54rpx;
				.btn1{
					display: flex;
					align-items: center;
					justify-content: center;
					width: 106rpx;
					height: 52rpx;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #4297F3;
					font-weight: 400;
					font-size: 26rpx;
					color: #4297F3;
				}
				.btn2{
					margin-left: 28rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					width: 106rpx;
					height: 52rpx;
					background: #4297F3;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #4297F3;
					
					font-weight: 400;
					font-size: 26rpx;
					color: #FFFFFF;
				}
			}
			.info_li {
				margin-top: 18rpx;
				width: 100%;
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				justify-content: space-between;
		
				.txt1 {
					font-weight: 400;
					font-size: 30rpx;
					color: #6F6F6F;
				}
		
				.txt2 {
					font-weight: 600;
					font-size: 32rpx;
					color: #3D3D3D;
				}
			}
		}
		.warp_box {
			.swiper {
				.swiper-item {
					.card {
						position: relative;
						margin: 0 auto;
						margin-top: 20rpx;
						width: 714rpx;
						padding: 32rpx 24rpx;
						background: #FFFFFF;
						border-radius: 20rpx 20rpx 20rpx 20rpx;
						.line{
							margin-top: 26rpx;
							width: 100%;
							height: 1rpx;
							background: #D8D8D8;
						}
						.txt {
							font-weight: 400;
							font-size: 26rpx;
							color: #3D3D3D;
						}

						.info_li:first-child {
							margin-top: 0;
						}
						.btn_box{
							display: flex;
							flex-wrap: nowrap;
							
							position: absolute;
							right: 26rpx;
							bottom: 54rpx;
							.btn1{
								display: flex;
								align-items: center;
								justify-content: center;
								width: 106rpx;
								height: 52rpx;
								border-radius: 8rpx 8rpx 8rpx 8rpx;
								border: 2rpx solid #4297F3;
								font-weight: 400;
								font-size: 26rpx;
								color: #4297F3;
							}
							.btn2{
								margin-left: 28rpx;
								display: flex;
								align-items: center;
								justify-content: center;
								width: 106rpx;
								height: 52rpx;
								background: #4297F3;
								border-radius: 8rpx 8rpx 8rpx 8rpx;
								border: 2rpx solid #4297F3;
								
								font-weight: 400;
								font-size: 26rpx;
								color: #FFFFFF;
							}
						}
						.info_li {
							margin-top: 18rpx;
							width: 100%;
							display: flex;
							flex-wrap: nowrap;
							align-items: center;
							justify-content: space-between;

							.txt1 {
								font-weight: 400;
								font-size: 30rpx;
								color: #6F6F6F;
							}

							.txt2 {
								font-weight: 600;
								font-size: 32rpx;
								color: #3D3D3D;
							}
						}
					}
				}
			}
		}

		.tap {
			padding-top: 24rpx;
			width: 750rpx;
			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			justify-content: space-around;
			background: #FFFFFF;

			.tap_cont {
				text-align: center;
				padding-bottom: 15rpx;
				width: 100rpx;
				font-weight: 500;
				font-size: 32rpx;
				color: #3D3D3D;
				border-bottom: 6rpx solid #fff;
			}

			.act1 {
				border-bottom: 6rpx solid #4C97E7;
				color: #4C97E7;
			}
		}

		.top_box {

			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			padding: 28rpx 30rpx;
			// padding: 20rpx 0;

			margin: 0 auto;
			width: 672rpx;
			height: 100rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 22rpx 0rpx rgba(0, 0, 0, 0.07);
			border-radius: 10rpx 10rpx 10rpx 10rpx;

			.left_text {
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				width: 25%;
				font-weight: 400;
				font-size: 32rpx;
				color: #3D3D3D;

				.icon-xiangxia1 {
					font-size: 26rpx;
				}
			}

			.timebox {
				width: 75%;
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				margin-left: 34rpx;

				.left_time {
					text-align: center;
					margin-right: 6rpx;
					height: 50rpx;
					width: 45%;
					border: 2rpx solid #ccc;
					border-radius: 12rpx;
					font-weight: 400;
					font-size: 32rpx;
					color: #979797;
				}

				.right_time {
					text-align: center;
					margin-left: 6rpx;
					height: 50rpx;
					width: 45%;
					border: 2rpx solid #ccc;
					border-radius: 12rpx;
					font-weight: 400;
					font-size: 32rpx;
					color: #979797;
				}
			}
		}


	}
</style>