<template>
	<view class='container'>
		<view class="sv-y">
			<scroll-view scroll-y>
				<view class="flex-column">
					<view class="flex-column mlr-24 mt-25 br-10 pad-20"
						style="color: #878787;background-color: #171717;">
						<view class="flex">
							<image class="wh-175 br-20" :src="$config.cdnUrl+data.image.split(',')[0]"></image>
							<view class="flex-column fs-28 plr-20 flex-between" style="flex: 1;">
								<view class="flex">
									<text class="fs-32 flex-1 common-line one-line-ellipsis"
										style="color: white;">{{data.name}}</text>
									<text @click="onYl" class="fs-24 plr-24 ptb-10 br-30"
										style="color: #FE42C2;border: 1px solid #FE42C2;">查看位置</text>
								</view>
								<view class="flex">
									<view class="flex-column" style="flex: 1;">
										<view class="flex-column fs-24" style="color: #868686;">
											<text>{{data.poster}}</text>
										</view>
										<view class="flex mt-10" style="color:#FFC100;justify-content: flex-end;">
											<text class="fs-46">￥{{data.dkPrice}}</text>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="flex fs-28 flex-between mt-30" style="color: #878787;">
							<text style="color: white;">预定日期</text>
							<text>{{$wskj.getTime(data.ydTime)}}</text>
						</view>
						<view class="flex fs-28 flex-between mt-30 mb-20" style="color: #878787;">
							<text style="color: white;">场次信息</text>
							<text>{{data.ccInfo}}</text>
						</view>
					</view>


					<view class="flex-column mlr-24 mt-25 br-10 pad-20 fs-32"
						style="color: #878787;background-color: #171717;">
						<text style="color: white;">预订须知</text>
						<text class="fs-24 mt-25">1.支付成功之后将获得入场电子券
							2.参与购票后电子券直接生效，有效期从预约时间到次日早上8点
							3.未成年人禁止购票，购票后无法进入，门店概不负责
							4.多次下单不支付系统将判定您恶意下单，当日无法再下单
							5.如果您执行的是定卡操作，请注意您支付的为定卡押金
							6.最终解释权由本司所有</text>
					</view>

					<view class="flex-column mlr-24 mt-25 br-10 pad-20 fs-32"
						style="color: #878787;background-color: #171717;">
						<text style="color: white;">预订信息</text>
						<view class="flex fs-28 flex-between mt-30 mb-20" style="color: #878787;">
							<text style="color: white;">姓名</text>
							<view>
								<input placeholder="请输入" v-model="name" style="text-align: right;" />
							</view>
							<!-- <text>{{userInfo.nickname}}</text> -->
						</view>
						<view class="flex fs-28 flex-between mt-30 mb-20" style="color: #878787;">
							<text style="color: white;">电话</text>
							<view>
								<input placeholder="请输入" v-model="mobile" style="text-align: right;" maxlength="11" />
							</view>
							<!-- <text>{{userInfo.mobile}}</text> -->
						</view>
						<view class="flex fs-28 flex-between mt-30 mb-20" style="color: #878787;">
							<text style="color: white;">人数</text>
							<view>
								<input placeholder="请输入" v-model="number" style="text-align: right;" />
							</view>

						</view>
						<view @click="onShowBirthday(true)" class="flex fs-28 flex-between mt-30 mb-20"
							style="color: #878787;">
							<text style="color: white;">预计到店时间</text>
							<text>{{time==''?'请选择':time}}</text>
						</view>
						<view class="flex fs-28 flex-between mt-30 mb-20" style="color: #878787;">
							<text style="color: white;">主题</text>
							<view>
								<input placeholder="请输入" v-model="theme" style="text-align: right;" />
							</view>
						</view>
						<view class="flex fs-28  mt-30 mb-20" style="color: #878787;">
							<text style="color: white;flex: 1;">备注</text>
							<view>
								<input placeholder="请输入" v-model="remarks" style="text-align: right;" />

							</view>
						</view>
					</view>
					<view class="flex mlr-24 mt-25 br-10 plr-20 ptb-20 fs-32 flex-between"
						style="color: #878787;background-color: #171717;align-items: center;">
						<text style="color: white;">应付定金</text>
						<text class="fs-42" style="color: #FD46B9;">￥{{data.dkPrice}}</text>
					</view>
				</view>

			</scroll-view>
			<!-- 生日选择 -->
			<u-datetime-picker :show="birthdayShow" v-model="value" mode="date" @confirm="onBirthday"
				@cancel="birthdayShow=false" @close="birthdayShow=false"></u-datetime-picker>
		</view>
		<view class="h-100 mtb-30 mlr-24">
			<view @click="onSubmit" class="fullscreen-btn" style="background-color: #FE42C2;">
				<text>立即支付</text>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				birthdayShow: false,
				value: Number(new Date()),
				name: '',
				mobile: '',
				time: '',
				number: '',
				theme: '',
				remarks: '',
				timeIndex: 0,
				id: 0,
				data: {},
				userInfo: '',
			};
		},
		onLoad(e) {
			this.id = e.id;
			const token = uni.getStorageSync('token')
			if (!token) {
				//沒有登录  先登录
				if (!e.share == false) {
					this.$wskj.to('/pages/login/wechatlogin?share=1')
				}
			}

		},
		onShow() {
			this.getTimestamp()
			this.getUserInfo()
			this.getData()
		},
		methods: {
			onShowBirthday(b) {
				this.birthdayShow = b;
			},
			onYl() {
				if (!this.data.localSeat) {
					this.$u.toast('管理者未设置图片')
					return
				}
				uni.previewImage({
					urls: [this.$config.cdnUrl + this.data.localSeat],
					current: 0
				});
			},
			getUserInfo() {
				const params = {
					url: '/system/member/getMemberInfo',
					method: "GET",
					data: {}
				}
				this.$request(params).then(res => {
					this.userInfo = res.data
					this.name = res.data.realname || ''
					this.mobile = res.data.mobile || ''
				})
			},
			getData() {
				const params = {
					url: '/system/party/getPartyById/' + this.id,
					method: "GET",
					data: {}
				}
				this.$request(params).then(res => {
					res.data.ydTime = res.data.startTime.substring(0, 10)
					res.data.ccInfo = res.data.startTime.substring(10, 16)
					this.data = res.data
				})
			},
			getTimestamp() {
				const currentDate = new Date(); // 创建一个表示当前时间的Date对象
				this.currentTimestamp = currentDate.getTime(); // 获取当前时间的时间戳并赋值给变量
				console.log(currentDate.getTime())
			},
			onBirthday(e) {
				this.birthdayShow = false;
				this.time = this.$wskj.timeFormat(e.value, 'yyyy-mm-dd hh:MM')
				this.$emit('onBirthday', this.time)

			},
			onSubmit() {
				if (!this.name) {
					this.$u.toast('请输入姓名')
					return
				}
				if (!this.mobile) {
					this.$u.toast('请输入手机号')
					return
				}
				const params = {
					url: '/system/party/buySeat',
					data: {
						name: this.name,
						mobile: this.mobile,
						peopleNumber: this.number,
						reachTime: this.time,
						subject: this.theme,
						note: this.remarks,
						shopId: this.data.shopId,
						partyId: this.data.id,
						price: this.data.dkPrice,
						type: 1,
					}
				}
				this.$request(params).then(res => {
					this.wechatpay(res.data)

				})
			},
			wechatpay(orderId) {
				const params = {
					url: '/system/party/wechatpay?orderId=' + orderId + '&openId=' + uni.getStorageSync('openId'),
					data: {}
				}
				this.$request(params).then(res => {
					uni.requestPayment({
						provider: 'wxpay',
						appid: res.data.result.appId, // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
						nonceStr: res.data.result.nonceStr, // 随机字符串
						package: res.data.result.package, // 固定值
						timeStamp: res.data.result.timeStamp, // 时间戳（单位：秒）
						paySign: res.data.result.paySign, // 签名，这里用的 MD5/RSA 签名
						signType: 'MD5',
						success: (res) => {
							this.$wskj.to('/pagesMain/pages/zfjg?orderId=' + orderId)
						},
						fail: (err) => {
							console.log(err);
						}
					});
				})
			},
			getDayOfWeek(dateString) {
				// 将日期字符串转换为Date对象
				const date = new Date(dateString);
				// 获取星期的方法返回0-6的值，0代表星期天
				const weekday = date.getDay();
				// 将数字转换为星期几的中文表示
				const weeks = ['周天', '周一', '周二', '周三', '周四', '周五', '周六'];
				return weeks[weekday];
			}

		},
	};
</script>

<style scoped>
	.container {
		width: 100%;
		height: 100%;
		background: #0F0F0F;
		background-color: ;
		display: flex;
		flex-direction: column;
	}

	.good-hot {
		margin: 25rpx;
		height: 160rpx;
	}

	/* 注意点，测试下来，设置水平滑动也要给一个固定高度 */
	.scroll-view_H {
		margin-top: 30rpx;
		width: 100%;
		white-space: nowrap;
		height: 100rpx;
		flex-direction: row;
	}

	.scroll-view_H view {
		display: inline-block;
		width: 120rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}

	/* 去掉最后一个元素的 margin-right: 16rpx 设置为0 */
	/* .scroll-view_H view:last-child {
		margin-right: 0;
	} */

	.scroll-view_H .fl-item-sel {
		display: flex;
		height: 100%;
		width: 100rpx;
		flex-direction: column;
		background: #FE42C2;
		border-radius: 20rpx;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;
	}

	.scroll-view_H .fl-item {
		display: flex;
		height: 100%;
		width: 100rpx;
		flex-direction: column;
		border-radius: 20rpx;
		justify-content: center;
		align-items: center;
		color: #878787;
	}

	.sv-y {
		flex: 1;
		/* 自动占满剩余的空间 */
		overflow-y: auto;
		/* 允许纵向滚动 */
	}

	.btn-box {
		width: 90%;
		position: fixed;
		bottom: 100rpx;
		left: 50%;
		margin-left: -45%;
	}
</style>