|  | @@ -135,7 +135,7 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  <script lang="ts" setup>
 | 
	
		
			
				|  |  |  import { ref, onMounted } from 'vue';
 | 
	
		
			
				|  |  | -import { RouterUtils, TipsUtils, idCardHide,debounce } from '@/utils/util';
 | 
	
		
			
				|  |  | +import { RouterUtils, TipsUtils, idCardHide, debounce } from '@/utils/util';
 | 
	
		
			
				|  |  |  import { onLoad, onShareAppMessage } from '@dcloudio/uni-app';
 | 
	
		
			
				|  |  |  import { http } from '@/utils/http'
 | 
	
		
			
				|  |  |  import { useCacheStore } from '@/stores/cache'
 | 
	
	
		
			
				|  | @@ -177,11 +177,12 @@ const open_calendar = (e, i) => {
 | 
	
		
			
				|  |  |  // 日历回调确认
 | 
	
		
			
				|  |  |  const confirm = (e) => {
 | 
	
		
			
				|  |  |  	get_previewOrderPlaceSchool(e.fulldate)
 | 
	
		
			
				|  |  | -	 selIndex.value = -1
 | 
	
		
			
				|  |  | +	selIndex.value = -1
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 置灰处理
 | 
	
		
			
				|  |  |  const shouldGrayOut = (endTime: string) => {
 | 
	
		
			
				|  |  | +	if (!endTime) return true; // 如果没有结束时间,默认为不可用
 | 
	
		
			
				|  |  |  	// 只有当选中的日期是今天时才检查时间是否过期
 | 
	
		
			
				|  |  |  	if (dateList.value && dateList.value[selIndex.value] && dateList.value[selIndex.value].namedDay === '今天') {
 | 
	
		
			
				|  |  |  		return isTimeExpired(endTime);
 | 
	
	
		
			
				|  | @@ -199,6 +200,9 @@ const isTimeExpired = (endTime: string) => {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const rulesId = ref()
 | 
	
		
			
				|  |  |  const check_item = (e, i) => {
 | 
	
		
			
				|  |  | +	if (e.inventory < 1) return TipsUtils.tips_toast('余量不足,请选择其他时段')
 | 
	
		
			
				|  |  | +	if (shouldGrayOut(e.endTime)) return TipsUtils.tips_toast('该时段已过期,请选择其他时段')
 | 
	
		
			
				|  |  | +	console.log(e);
 | 
	
		
			
				|  |  |  	check_index.value = i
 | 
	
		
			
				|  |  |  	rulesId.value = e.id
 | 
	
		
			
				|  |  |  	orderFormData.value.productIds = e.id
 | 
	
	
		
			
				|  | @@ -218,22 +222,36 @@ const placeId = ref()
 | 
	
		
			
				|  |  |  const timeList = ref()
 | 
	
		
			
				|  |  |  const insureIdList = ref([])  // 保险列表
 | 
	
		
			
				|  |  |  const insurePrice = ref() // 保险价格
 | 
	
		
			
				|  |  | -const get_previewOrderPlaceSchool = (startTime) => {
 | 
	
		
			
				|  |  | +const inventory = ref() // 余量
 | 
	
		
			
				|  |  | +const get_previewOrderPlaceSchool = (startTime: string) => {
 | 
	
		
			
				|  |  |  	http.get('/order/previewOrderPlaceSchool', { data: { placeId: placeId.value, startTime: startTime }, loading: true }).then((res) => {
 | 
	
		
			
				|  |  |  		timeList.value = res.result
 | 
	
		
			
				|  |  | -		let defaultIndex = 0
 | 
	
		
			
				|  |  | +		// 重置选中索引
 | 
	
		
			
				|  |  | +		check_index.value = -1
 | 
	
		
			
				|  |  |  		if (res.result.timeSlot && res.result.timeSlot.length > 0) {
 | 
	
		
			
				|  |  | +			// 找到第一个可用的时段(有库存且未过期)
 | 
	
		
			
				|  |  | +			let defaultIndex = -1
 | 
	
		
			
				|  |  |  			for (let i = 0; i < res.result.timeSlot.length; i++) {
 | 
	
		
			
				|  |  | -				if (!isTimeExpired(res.result.timeSlot[i].endTime)) {
 | 
	
		
			
				|  |  | +				// 检查时段是否可用(有库存且未过期)
 | 
	
		
			
				|  |  | +				if (res.result.timeSlot[i].inventory > 0 && !shouldGrayOut(res.result.timeSlot[i].endTime)) {
 | 
	
		
			
				|  |  |  					defaultIndex = i
 | 
	
		
			
				|  |  |  					break
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -			check_index.value = defaultIndex
 | 
	
		
			
				|  |  | -			rulesId.value = res.result.timeSlot[defaultIndex].id
 | 
	
		
			
				|  |  | -			orderFormData.value.productIds = res.result.timeSlot[defaultIndex].id
 | 
	
		
			
				|  |  | +			// 只有找到可用时段才设置选中状态
 | 
	
		
			
				|  |  | +			if (defaultIndex !== -1) {
 | 
	
		
			
				|  |  | +				check_index.value = defaultIndex
 | 
	
		
			
				|  |  | +				rulesId.value = res.result.timeSlot[defaultIndex].id
 | 
	
		
			
				|  |  | +				inventory.value = res.result.timeSlot[defaultIndex].inventory
 | 
	
		
			
				|  |  | +				orderFormData.value.productIds = res.result.timeSlot[defaultIndex].id
 | 
	
		
			
				|  |  | +			} else {
 | 
	
		
			
				|  |  | +				// 如果没有可用时段,清空选中状态
 | 
	
		
			
				|  |  | +				rulesId.value = null
 | 
	
		
			
				|  |  | +				inventory.value = 0
 | 
	
		
			
				|  |  | +				orderFormData.value.productIds = null
 | 
	
		
			
				|  |  | +				TipsUtils.tips_toast('暂无可选时段')
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  		// 处理保险相关数据
 | 
	
		
			
				|  |  |  		res.result.insureIdList.map((item: any) => {
 | 
	
		
			
				|  |  |  			item.insuranceObvious = JSON.parse(item.insuranceObvious)
 | 
	
	
		
			
				|  | @@ -341,6 +359,14 @@ let orderFormData = ref({
 | 
	
		
			
				|  |  |  })
 | 
	
		
			
				|  |  |  const submitOrderImpl = () => {
 | 
	
		
			
				|  |  |  	if (userData.value.length === 0) return TipsUtils.tips_toast('请添加成员')
 | 
	
		
			
				|  |  | +	if (!rulesId.value) {
 | 
	
		
			
				|  |  | +		return TipsUtils.tips_toast('请选择可用时段')
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	if (inventory.value === 0) return TipsUtils.tips_toast('余量不足,请选择其他时段')
 | 
	
		
			
				|  |  | +	const selectedTimeSlot = timeList.value.timeSlot.find(item => item.id === rulesId.value)
 | 
	
		
			
				|  |  | +	if (selectedTimeSlot && shouldGrayOut(selectedTimeSlot.endTime)) {
 | 
	
		
			
				|  |  | +		return TipsUtils.tips_toast('所选时段已过期,请重新选择')
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  	let data = { ...orderFormData.value };
 | 
	
		
			
				|  |  |  	if (!insureData.value || insureData.value.length === 0) {
 | 
	
		
			
				|  |  |  		delete data.insureOrderInfoForm;
 | 
	
	
		
			
				|  | @@ -350,10 +376,10 @@ const submitOrderImpl = () => {
 | 
	
		
			
				|  |  |  			tmplIds: ['WSJjc9I24ijtr3EyNVXjEvTQm0gIECW9ABYVFcegOwM'],
 | 
	
		
			
				|  |  |  			success(su) {
 | 
	
		
			
				|  |  |  				TipsUtils.tips_toast('订阅成功')
 | 
	
		
			
				|  |  | -				getOrderQuery(res.result.orderCode,res.result.orderId)
 | 
	
		
			
				|  |  | +				getOrderQuery(res.result.orderCode, res.result.orderId)
 | 
	
		
			
				|  |  |  			},
 | 
	
		
			
				|  |  |  			fail(err) {
 | 
	
		
			
				|  |  | -				getOrderQuery(res.result.orderCode,res.result.orderId)
 | 
	
		
			
				|  |  | +				getOrderQuery(res.result.orderCode, res.result.orderId)
 | 
	
		
			
				|  |  |  				console.log(err, '订阅消息失败')
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		})
 | 
	
	
		
			
				|  | @@ -363,13 +389,13 @@ const submitOrderImpl = () => {
 | 
	
		
			
				|  |  |  const submitBooking = debounce(submitOrderImpl, 500)  //防抖
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // code编码 "100001支付成功";"100002查询失败"; "100003查询中 "; "100004支付失败"
 | 
	
		
			
				|  |  | -const getOrderQuery = (orderCode: string,orderId: string, retryCount = 0) => {
 | 
	
		
			
				|  |  | +const getOrderQuery = (orderCode: string, orderId: string, retryCount = 0) => {
 | 
	
		
			
				|  |  |  	http.get('/order/orderQuery', { data: { orderCode: orderCode }, loading: true }).then((res) => {
 | 
	
		
			
				|  |  |  		if (res.result == '100001') {
 | 
	
		
			
				|  |  |  			RouterUtils.to_page(`/pages/index/toBeUsed/index?orderId=${orderId}&orderType=${orderFormData.value.orderType}`)
 | 
	
		
			
				|  |  |  		} else if (retryCount <= 3) {
 | 
	
		
			
				|  |  |  			setTimeout(() => {
 | 
	
		
			
				|  |  | -				getOrderQuery(orderCode,orderId, retryCount + 1)
 | 
	
		
			
				|  |  | +				getOrderQuery(orderCode, orderId, retryCount + 1)
 | 
	
		
			
				|  |  |  			}, 1000)
 | 
	
		
			
				|  |  |  		} else {
 | 
	
		
			
				|  |  |  			if (res.result == '100003') {
 | 
	
	
		
			
				|  | @@ -385,7 +411,7 @@ const getOrderQuery = (orderCode: string,orderId: string, retryCount = 0) => {
 | 
	
		
			
				|  |  |  		console.error('查询订单失败:', error)
 | 
	
		
			
				|  |  |  		if (retryCount < 2) {
 | 
	
		
			
				|  |  |  			setTimeout(() => {
 | 
	
		
			
				|  |  | -				getOrderQuery(orderCode,orderId, retryCount + 1)
 | 
	
		
			
				|  |  | +				getOrderQuery(orderCode, orderId, retryCount + 1)
 | 
	
		
			
				|  |  |  			}, 1000)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	})
 |