index.vue 7.66 KB
<template>
	<view class="carPage">
		<uni-collapse accordion v-model="nowOpen" @change="changeCollapse">
			<uni-collapse-item open="true" :name="item.id" v-for="(item,index) in list" :key="index"
				v-show="item.carVoList.length>0">
				<template v-slot:title>
					<view class="flexTop">
						<view>
							<view class="greenSmall">路线{{index+1}}</view>
							<view class="qq">{{item.checkIn}} </view>
						</view>
						<view>
							<image src="./img/wf.png" style="width:64rpx;height: 64rpx;"></image>
						</view>
						<view>
							<view class="qq" style="margin-top: 52rpx;">{{item.checkOut}} </view>
						</view>
					</view>
				</template>
				<view class="roomList">
					<view class="room" v-for="r in item.carVoList" :key="r.id">
						<view class="ff">
							<view>
								<image class="roomCover" mode="aspectFill" :src="r.photos?.split(',')[0]"></image>
							</view>
							<view style="width: calc(100% - 180rpx);">
								<view class="name"> {{r.carType}}
									<view class="price">
										¥<text>{{r.inPrice > r.checkOut?r.checkOut:r.inPrice}}</text>
									</view>
								</view>
								<view class="flexinline">
									<text>座位数:{{r.carSeat}}</text>
									<text style="color: #D8DDDE;">|</text>
									<text>运营时间:{{r.operStart}} - {{r.operEnd}}</text>
								</view>
								<view class="tagline">
									<text class="tag">{{r.carColor}}</text>
									<text class="tag" v-show="r.checkOut==1">可送车</text>
									<text class="tag" v-show="r.checkIn==1">可接车</text>
								</view>
								<view class="flexinline" style="justify-content: flex-end;">
									<button @click="goNext(r)">立即预定</button>
								</view>
							</view>
						</view>



						<!-- 						<view class="carFlex" v-if="r.checkIn==1">
							 <text class="price">¥{{r.inPrice}}</text>
							 <view>
								  接站车辆数
								<uni-number-box @change="changecarNum" :min="0" v-model="r.inNum">
								</uni-number-box>
							 </view>
						</view>
						<view class="carFlex" v-if="r.checkOut==1">
							 <text class="price">¥{{r.outPrice}}</text>
							 <view>
								  送站车辆数
								<uni-number-box @change="changecarNum" :min="0" v-model="r.outNum">
								</uni-number-box>
							 </view>
						</view> 
-->
					</view>
				</view>


			</uni-collapse-item>
		</uni-collapse>

	<view class="nodata" v-if="list.length==0">
		<image mode="aspectFit" src="/static/nodata.png"></image>
		<text> 暂无可订车辆 </text>
	</view>


		<!-- 		<view class="bbfix">
			<view class="subBtn" style="filter: grayscale(1);" v-if="nowOpen==''"> 去下单 </view>
			<view class="subBtn" @click="submit" v-else> 去下单 </view>
		</view> -->
	</view>
</template>

<script setup>
	import {
		reactive,
		toRefs,
		getCurrentInstance
	} from 'vue';
	import * as hotel from '@/common/hotel.js';
	import {
		onLoad,
		onShareAppMessage,
		onShareTimeline,
		onPullDownRefresh
	} from '@dcloudio/uni-app';
	import _ from 'lodash';
	const app = getApp();
	const {
		proxy
	} = getCurrentInstance();
	const data = reactive({
		nowOpen: '',
		money: 0,
		list: []
	});
	const {
		list,
		nowOpen,
		money
	} = toRefs(data);
	let activeId = null
	let ccitem = {}
	onLoad(option => {
		activeId = option.activeId
		getList()
		uni.showLoading({
			title: '加载中'
		});
	})

	function getList() {
		hotel.getActivityCarList({
			activityId: activeId
		}).then(res => {
			list.value = res.rows
			nowOpen.value = list.value[0]?.id
			ccitem = list.value[0]
			console.log(nowOpen.value)
			for (var item of list.value) {
				for (var car of item.carVoList) {
					car.inNum = 0
					car.outNum = 0
				}
			}
			uni.hideLoading();
		})
	}

	function changecarNum(e) {
		// 算钱
		for (var car of ccitem.carVoList) {
			money.value = car.inNum * car.inPrice + car.outNum * (car.outPrice || 0)
		}
	}

	function changeCollapse(e) {
		console.log(e)
		if (e !== nowOpen.value) {

		}
		for (var cc of list.value) {
			if (cc.id == e) {
				ccitem = cc
			}
		}
	}

	function checkCarNum() {
		return _.some(ccitem.carVoList, function(car) {
			return car.inNum || car.outNum
		})
	}

	function submit() {
		if (checkCarNum()) {
			const obj = encodeURIComponent(JSON.stringify(ccitem))
			let path = `/pages_hotel/car/order?carList=${obj}`;
			uni.navigateTo({
				url: path
			});
		} else {
			uni.showToast({
				title: '请选择车辆',
				icon: 'none',
				duration: 2000
			})
			return
		}
	}

	function goNext(car) {
		const obj = encodeURIComponent(JSON.stringify(ccitem))
		const detail = encodeURIComponent(JSON.stringify(car))
		let path = `/pages_hotel/car/order?detail=${detail}&carList=${obj}`;
		uni.navigateTo({
			url: path
		});
	}
</script>

<style scoped lang="scss">
	:deep(.uni-collapse-item__title-arrow) {
		position: absolute;
		right: 0;
		top: 10rpx;
		padding: 10rpx 30rpx;
		background: #F7F8FA;
		border-radius: 20px;
	}

	:deep(.uni-collapse-item__title) {
		position: relative;
	}

	.carPage {
		:deep(.uni-collapse-item) {
			margin: 0;
			padding: 0;
		}
	}

	.flexTop {
		display: flex;
		padding: 20rpx 0;
		align-items: center;

		&>view {
			width: 30%;
			text-align: center;
			padding: 0 30rpx;
		}

		&>view:first-child {
			text-align: left;
		}

		&>view:last-child {
			text-align: right;
		}

		.tt {
			color: #1EC886;
			font-size: 28rpx;
			padding: 30rpx;
		}

		.qq {
			font-size: 30rpx;
			margin-top: 24rpx;
		}

		.greenSmall {
			font-size: 24rpx;
			color: #1EC886;
		}
	}

	.roomList {
		padding: 20rpx;
		box-sizing: border-box;
	}

	.room {
		.ff {
			display: flex;
		}

		position: relative;
		padding: 30rpx 0;
		border-bottom: 1px solid #DCDCDC;

		&:last-child {
			border-bottom: none;
		}

		.name {
			font-size: 34rpx;
			width: 100%;

			.price {
				float: right;
			}
		}

		.orange {
			font-size: 24rpx;
		}

		.po {
			position: absolute;
			right: 0;
			bottom: 15rpx;
			display: flex;
			align-items: flex-end;
		}

		.price {
			margin-right: 10rpx;
		}
	}

	.roomCover {
		width: 160rpx;
		margin-right: 20rpx;
		height: 170rpx;
		border-radius: 15rpx;
	}

	.price {
		display: flex;
		align-items: baseline;
		color: #1EC886;

		text {
			color: #1EC886;
			font-size: 55rpx;
		}
	}

	.flexinline {
		display: flex;
		font-size: 24rpx;
		color: #5E5E5E;
		width: 100%;

		text {
			margin-right: 15rpx;
		}

		.price {
			text {
				margin: 0;
			}
		}

		button {
			color: #fff;
			width: 180rpx;
			margin: 0;
			height: 50rpx;
			line-height: 50rpx;
			font-size: 26rpx;
			border-radius: 25rpx;
			background: linear-gradient(270deg, #54E1B9, #00CAA6);
		}
	}

	.carFlex {
		display: flex;
		font-size: 24rpx;
		color: #5E5E5E;
		width: 100%;
		justify-content: space-between;
		align-items: center;

		.price {
			display: block;
			width: 160rpx;
			text-align: center;
		}

		view {
			display: flex;
			align-items: center;
		}

		:deep(.uni-numbox) {
			margin-left: 20rpx;
		}
	}

	.bbfix {
		background: #fff;
		height: 150rpx;
		display: flex;
		position: fixed;
		z-index: 89;
		width: 100%;
		bottom: 0;
		align-items: baseline;
		justify-content: space-between;
		border-top: 1rpx solid #dcdcdc;

		.price {
			padding-left: 20rpx;

			text {
				font-weight: bold;
				font-size: 45rpx;
				color: #ff8124;
			}
		}

		.subBtn {
			font-size: 36rpx;
			color: #ffffff;
			background: #ff8124;
			height: 120rpx;
			line-height: 100rpx;
			padding: 0 30rpx;
		}
	}
</style>