train-apply-three.vue 10.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
<template>
	<view class="box">
		<view class="box-title">
			<view class="title-left">是否住宿</view>
			<view class="title-right ">
				<radio-group name="radio" @change="radio">
					<label>
						<radio value="1" :checked="flag" />
						<text></text>
					</label>
					<label>
						<radio value="0" :checked="!flag" />
						<text></text>
					</label>
				</radio-group>
			</view>
		</view>

		<!-- 酒店信息 -->
		<view class="box-conter" v-if="flag">
			<checkbox-group @change="change">
				<view class="conter-conter" v-for="item in range" :key="item.id">
					<view class="bgcColor">
						<view class="conter-top">
							<view class="text">{{ item.name }}</view>
							<checkbox :value="item.hotelFlag" @click="checkedFN(item)" :disabled="disabled" />
						</view>
						<view class="box-dress">
							<uni-icons custom-prefix="iconfont" type="icon-31dingwei" color="#95A1A6"></uni-icons>
							{{ item.address }}
						</view>
						<view class="conter-text">
							<view class="conter-liner">
								<view class="liner-left">房型:</view>
								<view class="liner-right">{{ item.houseType }}</view>
							</view>

							<view class="conter-liner">
								<view class="liner-left">价格:</view>
								<view class="liner-right">{{ item.spend }}</view>
							</view>

							<view class="conter-liner">
								<view class="liner-left">餐食:</view>
								<view class="liner-right">{{ item.haveDinner == 1 ? '含早' : '不含早参' }}</view>
							</view>

							<view class="conter-liner">
								<view class="liner-left">入住时间:</view>
								<view class="liner-right liner-move">
									<view class="liner-right-hotl" v-for="val in item.move" :key="val.id">
										<uni-datetime-picker
											:start="val.moveIntoTime"
											:end="val.leaveTime"
											type="daterange"
											v-model="val.move"
											return-type="yyyy/MM/dd"
											@change="maskClick(val)"
										/>
										<uni-icons
											class="liner-del"
											@click="delHot(item, val)"
											v-if="item.move.length > 1"
											custom-prefix="custom-icon"
											type="trash"
											size="20"
										/>
									</view>
									<uni-icons
										@click="addHot(item)"
										custom-prefix="custom-icon"
										type="plusempty"
										size="20"
									/>
								</view>
							</view>
						</view>
					</view>
				</view>
			</checkbox-group>
			<view class="remark" v-if="hotelList">
				<view class="liner-left">备注:</view>
				<input class="uni-input" v-model="remark" placeholder="请输入你的内容" />
			</view>
		</view>
		<view class="foot ">
			<view class="button1" @click="upFN">上一步</view>
			<view class="button" @click="nextFN">下一步</view>
		</view>
	</view>
</template>

<script setup>
import * as train from '@/common/train.js';
import {
	onLoad,
	onReady,
	onShareAppMessage,
	onShareTimeline,
	onPullDownRefresh,
	onReachBottom,
	onShow
} from '@dcloudio/uni-app';
import { ref, getCurrentInstance, reactive, watch, toRefs } from 'vue';

const emit = defineEmits(['nextFN']);
const props = defineProps({
	projectIdsArray: {},
	id: {},
	signId: {},
	examIdsArry: {}
});
const moveList = ref([
	{
		id: 1,
		move: null
	}
]);
const hotShow = ref(true);
const popup = ref();
const hotlList = ref();
const omve = ref();
const arr = ref([]);
const range = ref();
const id = ref(props.id);
const hotelIdsArray = ref();
const state = ref(); //是否住宿
const remark = ref();
const flag = ref(true);
const disabled = ref(false);
const costID = ref();
const code = ref();
const status = ref();
const signId = ref();
const data = reactive({
	addForm: {}
});
const { addForm } = toRefs(data);

onShow(() => {
	status.value = 3;
});
getList();
async function getList() {
	addForm.value.id = id.value;
	let res = await train.trainParticulars(addForm.value);
	status.value = res.data.signStatus;
	range.value = res.data.hotelList;
	range.value.forEach(item => {
		let tId = uuid();
		item.move = [
			{
				moveIntoTime: item.moveIntoTime.replace(/-/g, '/'),
				leaveTime: item.leaveTime.replace(/-/g, '/'),
				id: tId,
				hotlId: item.id,
				move: [item.moveIntoTime.replace(/-/g, '/'), item.leaveTime.replace(/-/g, '/')]
			}
		];
	});
	// 数据加工

	if (res.data.signId) signId.value = res.data.signId;
	console.log(range.value);
}

function uuid() {
	var s = [];
	var hexDigits = '0123456789abcdef';
	for (var i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23] = '-';
	var uuid = s.join('');
	return uuid;
}

// 是否住宿
function changeRadio(e) {
	console.log(e);
	if (e.target.value == 0) {
		hotShow.value = false;
	} else {
		hotShow.value = true;
	}
}

// 获取用酒店信息
function change(e) {
	hotelIdsArray.value = e.target;
}

// 封装数据处理
function changeKey(arr) {
	let newArr = [];
	arr.forEach(item => {
		newArr.push({
			text: item.moveIntoTimeStr,
			value: item.id
		});
	});
	return newArr;
}

// 下一步
async function nextFN() {
	await initData();
}

// 上一步
function upFN() {
	console.log(111);
	emit('nextFN', 1);
}

// 是否住宿
function radio(e) {
	console.log(e);
	e.target.value == 1 ? (flag.value = true) : (flag.value = false);
	console.log(flag.value);
}

// 页面跳转
async function goRenew() {
	let path = `/pages/train/costBreakdown/costBreakdown?id=` + id.value;
	await wx.navigateTo({
		url: path
	});
}

function checkedFN(item) {
	item.hotelFlag = !item.hotelFlag;
}

// 日期确定时处发
// function maskClick(item) {
// 	item.move.forEach(val => {
// 		val = val.replace(/-/g, '/');
// 	});
// 	console.log(item.move);
// 	console.log(item);
// }

// 添加住宿
function addHot(item) {
	let tId = uuid;
	item.move.push({
		moveIntoTime: item.moveIntoTime.replace(/-/g, '/'),
		leaveTime: item.leaveTime.replace(/-/g, '/'),
		id: tId,
		move: [item.moveIntoTime.replace(/-/g, '/'), item.leaveTime.replace(/-/g, '/')],
		hotlId: item.id
	});
}

function delHot(item, val) {
	item.move = item.move.filter(obj => {
		return obj.id != val.id;
	});
}

// 提交
async function initData() {
	let list = null;
	list = JSON.parse(JSON.stringify(range.value));
	// 1.过滤没有选中的酒店
	list = list.filter(item => {
		return item.hotelFlag == true;
	});
	// 2.过滤没有选择日期的
	let arr = [];
	list.forEach((item, index) => {
		arr[index] = item;
		arr[index].move = item.move.filter(val => {
			return val.move.length != 0;
		});
	});

	// 3.过滤酒店日期相同
	let arr1 = [];
	arr.forEach((item, index) => {
		item.move.forEach(val => {
			arr1.push(val);
		});
	});
	let arr2 = [];
	arr1.forEach(item => {
		item.move = item.move.join();
		arr2.push({
			hotlId: item.hotlId,
			move: item.move
		});
	});
	// // 去重
	// for (var i = 0; i < arr2.length - 1; i++) {
	// 	for (var j = i + 1; j < arr2.length; j++) {
	// 		if (arr2[i].move == arr2[j].move) {
	// 			arr2.splice(j, 1);
	// 			j--;
	// 		}
	// 	}
	// }

	if (flag.value) {
		if (arr2.length == 0) {
			uni.showToast({
				title: '请选择入住酒店!',
				duration: 2000,
				icon: 'error'
			});
			return false;
		}
		addForm.value.hotelIdsArray = arr2;
	} else {
		addForm.value.hotelIdsArray = [];
	}
	addForm.value.projectIdsArray = props.projectIdsArray;
	addForm.value.examIdsArray = props.examIdsArry;
	addForm.value.trainId = id.value;
	addForm.value.remark = remark.value;
	let res = null;
	// if (status.value == null || status.value == 4) {
	// 添加
	// addForm.value.id = null
	addForm.value.id = signId.value;
	res = await train.trainNext(addForm.value);
	signId.value = res.data;
	// } else {
	// 	// 修改
	// 	addForm.value.id = signId.value
	// 	res = await train.trainUpdata(addForm.value);
	// }
	costID.value = res.data;
	// 报名成功才跳转
	if (res.code == 200) {
		// 酒店是否已住满

		goRenew();
	}
}
</script>

<style scoped lang="scss">
.box {
	margin-top: 5rpx;
	padding: 25rpx;

	.bgcColor {
		background-color: #fff;
		border-radius: 15rpx;
		padding: 25rpx;
	}

	.box-title {
		padding: 25rpx;
		display: flex;
		justify-content: space-between;
		margin-bottom: 30rpx;
		background-color: #fff;
		border-radius: 15rpx;
	}

	.title-left {
		text {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #000000;
		}
	}

	.box-conter {
		padding: 25rpx 0;
		display: block;

		.conter-conter {
			margin-bottom: 20rpx;

			.conter-top {
				display: flex;
				justify-content: space-between;
				margin-bottom: 10rpx;

				.text {
					font-size: 33rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #2b3133;
				}

				.checkbox {
				}
			}

			.box-dress {
				font-family: PingFang SC;
				font-weight: 400;
				color: #2b3133;
				font-size: 24rpx;
				border-bottom: 1px solid #e6e6e6;
				padding-bottom: 32rpx;
			}

			.conter-text {
				.conter-liner {
					display: flex;
					justify-content: space-between;
					margin-top: 20rpx;
					padding: 0 10rpx;

					.liner-left {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #7b7f83;
						padding-top: 10rpx;
					}

					.liner-right {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #2b3133;
						width: 80%;
						text-align: right;
					}
				}
			}
		}
	}

	.remark {
		margin-top: 35rpx;
		display: flex;
		justify-content: space-between;
		margin-bottom: 120rpx;
		background-color: #fff;
		border-radius: 15rpx;
		padding: 10rpx 25rpx;

		.liner-left {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #7b7f83;
			padding-top: 18rpx;
		}
	}

	.foot {
		background-color: #ffffff;
		padding: 20rpx 0;
		position: absolute;
		left: 0;
		bottom: 0;
		width: 100%;
		display: flex;

		.button {
			margin: 0 auto;
			height: 80rpx;
			width: 300rpx;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			line-height: 80rpx;
			background: linear-gradient(270deg, #54e1b9, #00caa6);
			border-radius: 40rpx;
		}

		.button1 {
			margin: 0 auto;
			height: 80rpx;
			width: 300rpx;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			line-height: 80rpx;
			background: #fff;
			border-radius: 40rpx;
			border: 1px solid #2ed981;
			color: #2ed981;
		}
	}

	.select {
		width: 300rpx;
	}
}

.uni-date {
	flex: 0;
	width: 65%;
}

.popup-center {
	display: flex;
	justify-content: space-between;
}

.popup-title {
	display: flex;
	justify-content: space-between;
	border-bottom: 1px solid #e6e6e6;
	padding: 30rpx 50rpx;
}

.popup-title-left {
	font-size: 30rpx;
	font-weight: 400;
	color: 000;
	font-family: PingFangSC-Medium;
}

.popup-body {
	border-bottom: 1px solid #e6e6e6;
	padding: 15rpx 50rpx;
	color: #4c5359;
	font-size: 30rpx;
}

.popup-box {
	height: 500rpx;
	overflow-y: scroll;
}

.liner-right-hotl {
	display: flex;
}

.liner-del {
	margin-top: 19rpx;
}
</style>