<style scoped>
@import url("@/asset/css/flex.css");
	.jz_Reserve {
		padding-bottom: 180rpx;
		background-color: #fff;
	}

	.jz_ReserTop {
		width: 100%;
		min-height: 300rpx;
		box-shadow: 0px 2px 15px 0px rgba(76, 76, 76, 0.13);
		background-color: #fff;
		border-bottom-left-radius: 60rpx;
		border-bottom-right-radius: 60rpx;
		padding: 40rpx;
	}

	.jz_ReserTitle {
		color: #111111;
		font-weight: 600;
		font-size: 36rpx;
	}

	.jz_ReserIn {
		color: #111;
		font-size: 24rpx;
		font-weight: 500;
	}

	.jz_ReseQue {
		color: #dfbe6e;
		font-size: 24rpx;
		padding-top: 30rpx;
		border-top: 1px solid #e7e7e7;
		margin-top: 20px;
	}

	.jz_ReseQue img {
		width: 16px;
		height: 14px;
		position: relative;
		top: 2px;
		margin-right: 5px;
	}

	.jz_ReseOrder {
		padding: 40rpx;
	}

	.jz_ReDix {
		display: flex;
		align-items: center;
		margin-bottom: 10px;
	}

	.jz_RedixTitle {
		width: 90px;
		flex-shrink: 0;
	}

	.jz_orderbox {
		height: 160rpx;
		position: fixed;
		background-color: #fff;
		bottom: 0;
		width: 100vw;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 99;
	}

	.jz_OrderDiv {
		width: 90%;
		height: 100rpx;
		background-color: #fff;
		margin: auto;
		padding: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-shadow: 0px 10rpx 30rpx 0px rgba(36, 36, 36, 0.2);
		border-radius: 16px;
		z-index: 999;
	}

	.jz_OrderReNow {
		/* #ifdef MP-ALIPAY */
		width: 150rpx;
		/* #endif */
		height: 80rpx;
		background-color: #111111;
		text-align: center;
		line-height: 80rpx;
		color: #fff;
		font-weight: 600;
		font-size: 28rpx;
		border-radius: 16rpx;
	}

	.jz_form {
		margin-top: 40rpx;
		padding: 0 45rpx;
	}

	.jz_form .form-items {
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
		padding-bottom: 20rpx;
		border-bottom: 1px solid #f5f5f5;
		font-size: 28px;
		font-weight: 500;
	}

	.jz_form .form-items:last-child {
		border-bottom: none;
	}

	.jz_form .form-items .label {
		font-size: 28rpx;
		font-weight: 600;
		margin-right: 60rpx;
		flex-shrink: 0;
		width: 115rpx;
		text-align: right;
	}

	.jz_form .form-items .val {
		flex: 1;
	}

	.jz_ReserTop .o-timer {
		height: 100rpx;
		background: #ecf1f4;
		border-radius: 20rpx;
		padding: 0 40rpx;
		margin-bottom: 30rpx;
	}

	.jz_ReserTop .o-timer .time-item {
		font-size: 32rpx;
		font-weight: 800;
	}

	.jz_ReserTop .o-timer .time-split {
		font-size: 24rpx;
		font-weight: 400;
		text-align: center;
		margin: 0 20rpx;
	}

	.jz_ReserTop .o-timer .update {
		font-size: 24rpx;
		font-weight: 400;
		text-align: right;
		color: #000;
		display: flex;
		align-items: center;
	}

	.jz_Reserve .flex {
		display: flex;
		align-items: center;
	}

	.jz_Reserve .big-title {
		position: relative;
	}

	.jz_Reserve .big-title::before {
		display: block;
		width: 71rpx;
		height: 12rpx;
		background: #dfbe6e;
		border-radius: 4rpx;
		content: " ";
		position: absolute;
		left: 0;
		bottom: 6rpx;
		z-index: 1;
	}

	.jz_Reserve .big-title text {
		font-size: 34rpx;
		font-weight: bold;
		color: #1f1f1f;
		position: relative;
		z-index: 2;
	}

	.jz_Reserve .empty-block {
		height: 20rpx;
		background: #ecf1f4;
	}

	.jz_form .form-items .val input {
		border: none;
		padding: 0;
		margin: 0;
		outline: none;
		height: 38rpx;
		line-height: 38rpx;
		font-size: 28rpx;
		font-weight: 500;
		width: 100%;
	}

	.jz_Reserve .grey {
		color: #6e6e6e !important;
	}

	.jz_Reserve .f12 {
		font-size: 24rpx !important;
	}

	.jz_Reserve .f11 {
		font-size: 22rpx !important;
	}

	.jz_Reserve .f14 {
		font-size: 28rpx !important;
	}

	.jz_Reserve .regular {
		font-weight: 500 !important;
	}

	.jz_Reserve .sheshi {
		margin-top: 50rpx;
	}

	.jz_Reserve .sheshi .she-title {
		font-size: 28rpx;
		font-weight: 800;
	}

	.jz_Reserve .sheshi .she-content {
		margin-top: 24rpx;
	}

	.jz_Reserve .sheshi .she-content text {
		font-size: 24rpx;
		font-weight: 500;
		color: #4a4a4a;
		line-height: 40rpx;
		margin-right: 24rpx;
	}

	.jz_GuestList {
		box-shadow: 0px 2px 15px 0px rgba(76, 76, 76, 0.13);
		padding: 20rpx;
		margin: 25rpx;
		border-radius: 25rpx;
	}

	.jz_GuestList .form-items:last-child {
		margin-bottom: 0;
		padding-bottom: 0;
	}

	.jz_TextArea {
		height: 50px;
		margin-bottom: 10px;
		width: auto;
		border: 1px solid #dfddd8;
		border-radius: 4px;
		margin: 25rpx;
		padding: 20rpx;
	}
	.visaProduct_rColor{
		color: #FF3166;
	}
	.visaProductTitle{
		font-weight: 800;
		font-size: 32rpx;
	}
	.visaProductTextR{
		font-size: 20rpx;
		margin-left: 24rpx;
	}
	.visaProductTextL{
		font-size: 35rpx;
		font-weight: bold;
	}
	
</style>
<template>
	<view class="jz_Reserve">
		<view class="jz_ReserTop">
			<view class="o-timer flex">
				<view class="time-item">{{ getDate(currentPriceInfo.startDate) }}
					{{ getWeek(currentPriceInfo.startDate) }}</view>
				<view class="time-split">
					<view>{{ currentPriceInfo.dayNum }}天</view>
				</view>
				<view class="time-item" style="font-size: 26rpx; font-weight: 500; flex: 1">
					<text v-if="orderMsg.ManNum > 0">{{ orderMsg.ManNum }}成人</text>
					<text v-if="orderMsg.ChirdNoBedNum + orderMsg.ChirdNeedBedNum > 0">{{ orderMsg.ChirdNoBedNum + orderMsg.ChirdNeedBedNum }}儿童</text>
					<text v-if="orderMsg.BabyNum > 0">{{ orderMsg.BabyNum }}婴儿</text>
				</view>
				<view class="update" @click="updateUser">
					<text style="margin-right: 8rpx">修改</text>
					<u-icon name="arrow" size="20" />
				</view>
			</view>
			<view class="jz_ReserTitle">
				{{ currentPriceInfo.title?currentPriceInfo.title:'' }}
			</view>
			<view class="jz_ReserIn" style="margin: 33rpx 0 18rpx 0">
				{{ ltName?ltName:''  }}
			</view>
			<view class="big-title">
				<text>{{ realCurrentPriceInfo.priceUnion && realCurrentPriceInfo.priceUnion.startCityName?realCurrentPriceInfo.priceUnion.startCityName:currentPriceInfo.startCityName }}出发</text>
			</view>
			<view class="jz_ReseQue">
				<img src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/CustomizedCar/zuanshi.png" />即时确认：本产品付款后可快速确认，放心期待您的旅行
			</view>
		</view>
		<!-- #ifdef MP-DI -->
			<view class="column jz_form">
				<view class="row" style="margin-bottom: 40rpx;">
					<view class="visaProduct_rColor visaProductTextL">*</view>
					<view class="visaProductTitle">联系信息</view>
				</view>
				<view class="form-items">
					<view class="label">姓</view>
					<view class="val">
						<input type="text" v-model="customer.SurName" placeholder="输入姓" />
					</view>
				</view>
				<view class="form-items">
					<view class="label">名</view>
					<view class="val">
						<input type="text" v-model="customer.name" placeholder="输入名" />
					</view>
				</view>
				<view class="form-items">
					<view class="label">联系电话</view>
					<view class="val">
						<input type="text" v-model="customer.contactNumber" placeholder="输入电话号码" />
					</view>
				</view>
				<view class="form-items">
					<view class="label">邮箱地址</view>
					<view class="val">
						<input type="text" v-model="customer.Mailbox" placeholder="输入邮箱地址" />
					</view>
				</view>
			</view>
		<!-- #endif -->
		<view>
			<textarea class="jz_TextArea" placeholder="请输入备注信息" v-model="Remarks"></textarea>
		</view>

		<view class="empty-block"></view>
		<view style="padding: 50rpx 40rpx">
			<view class="big-title">
				<text>优惠券</text>
			</view>
			<view style="margin-top: 30px;display: flex; align-items: center;">
				<view style="font-size: 12px;width:1px;flex:1">请选择优惠券</view>
				<view style="display: flex;align-items: center;">
					<text style="color:#F20707;font-size: 12px;" @click="showCouponHandler">
						<text style="flex: 1;" v-if="useCouponIds.length == 0 &&couponList.length>0">{{couponList.length}}张可用优惠券</text>
						<text class="content" style="color:grey" v-else-if="couponList.length==0">暂无优惠券</text>
						<text class="content" v-else :style="{ color: mainColor }">已优惠 {{currentCoupon.discountMoney}} 元</text>
						<!-- <u-icon name="ellipsis" size="36" v-if="couponList.length > 0"></u-icon> -->
					</text>
					<u-icon name="arrow" :size="32" color="#111" v-if="couponList.length>0"></u-icon>
				</view>
			</view>
		</view>
		<template v-if="happinessPassbook&&happinessPassbook.client_Balance>0">
			<view class="empty-block"></view>
			<view style="padding: 50rpx 40rpx">
				<view class="big-title">
					<text>幸福存折</text>
				</view>
				<view style="margin-top: 30px;display: flex; align-items: center;">
					<view style="font-size: 12px;width:1px;flex:1">
						<!-- :max="happinessPassbook.max" -->
						<u-number-box 
						size="28" :min="0"
						@change="ChangeUse" 
						@blur="ChangeUse"
						v-model="happinessPassbook.RedEnvelopeMoney"
						inputWidth="150"></u-number-box>
					</view>
					<view style="display: flex;align-items: center;">
						<text style="color:#F20707;font-size: 12px;">
							<text class="content" :style="{ color: mainColor }">余额 {{ happinessPassbook.client_Balance-happinessPassbook.RedEnvelopeMoney}} 元</text>
							
						</text>
					</view>
					
				</view>
				<!-- <text class="content" style="color:#F20707;font-size: 24rpx;" v-if="happinessPassbook.max >0">一次最多可减 {{ happinessPassbook.max>happinessPassbook.client_Balance?happinessPassbook.client_Balance:happinessPassbook.max }}元</text> -->
			</view>
		</template>
		<view class="empty-block"></view>
		<view style="padding: 50rpx 40rpx">
			<view class="big-title">
				<text>费用明细</text>
			</view>
			<view class="jz_form" style="margin: 40rpx 0; padding: 0">
				<view class="form-items">
					<view class="label"> 商品总价 </view>
					<view class="val f14 regular" style="text-align: right">
						<text style="margin-right: 30rpx">{{ total }}人</text>
						<text class="red">￥{{ price }}</text>
					</view>
				</view>
				<view class="form-items" style="border-bottom: none">
					<view class="label" style="text-align: left;"> 明细 </view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">成人</text>
					</view>
					<view style="text-align: right">{{ orderMsg.ManNum }}人 × ¥
						<!-- #ifdef MP-DI  -->
							{{ currentPriceInfo.b2CPrice }}
						<!-- #endif -->
						<!-- #ifdef MP-AG -->
							{{ currentPriceInfo.b2BPrice }}
						<!-- #endif -->
					</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="orderMsg.ChirdNeedBedNum > 0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">儿童(占床)</text>
					</view>
					<view style="text-align: right">{{ orderMsg.ChirdNeedBedNum }}人 × ¥
					<!-- #ifdef MP-DI -->
						{{ currentPriceInfo.b2CPrice+(currentPriceInfo.childNeedPrice? currentPriceInfo.childNeedPrice: 0) }}
					<!-- #endif -->
					<!-- #ifdef MP-AG -->
						{{ currentPriceInfo.b2BPrice+(currentPriceInfo.childNeedPrice? currentPriceInfo.childNeedPrice: 0) }}
					<!-- #endif -->
				</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="orderMsg.ChirdNoBedNum > 0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">儿童(不占床)</text>
					</view>
					<view style="text-align: right">{{ orderMsg.ChirdNoBedNum }}人 × ¥
						<!-- #ifdef MP-DI -->
						{{ currentPriceInfo.b2CPrice-(currentPriceInfo.childNoNeedPrice? currentPriceInfo.childNoNeedPrice: 0) }}
					<!-- #endif -->
					<!-- #ifdef MP-AG -->
						{{ currentPriceInfo.b2BPrice-(currentPriceInfo.childNoNeedPrice? currentPriceInfo.childNoNeedPrice: 0) }}
					<!-- #endif -->
				</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="orderMsg.BabyNum > 0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">婴儿</text>
					</view>
					<view style="text-align: right">
						{{ orderMsg.BabyNum }}人 × ¥{{
              currentPriceInfo.babyPrice ? currentPriceInfo.babyPrice : 0
            }}</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="
            orderMsg.ChirdNum > 0 &&
            currentPriceInfo.babyChargePrice &&
            currentPriceInfo.babyChargePrice > 0
          ">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">儿童(附加费)</text>
					</view>
					<view style="text-align: right">
						{{ orderMsg.ChirdNum }}人 × ¥{{
              currentPriceInfo.babyChargePrice
            }}</view>
				</view>
			</view>
			<view class="flex f12 grey" style="margin-bottom: 40rpx" v-if="currentPriceInfo.visaPrice > 0">
				<view style="flex: 1">
					<text style="margin-right: 30rpx">签证费</text>
				</view>
				<view style="text-align: right">{{ orderMsg.ManNum + orderMsg.ChirdNum, }}人 × ¥{{currentPriceInfo.visaPrice}}</view>
			</view>

			<view class="flex f12 grey" style="margin-bottom: 40rpx" :style="{'color':mainColor+' !important'}" v-if="useCouponIds.length>0">
				<view style="flex: 1">
					<text style="margin-right: 30rpx">优惠券</text>
				</view>
				<view style="text-align: right">
					-¥{{currentCoupon.discountMoney}}</view>
			</view>
			<view class="flex f12 grey" style="margin-bottom: 40rpx" :style="{'color':mainColor+' !important'}" v-if="happinessPassbook.RedEnvelopeMoney>0">
				<view style="flex: 1">
					<text style="margin-right: 30rpx">幸福存折</text>
				</view>
				<view style="text-align: right">
					-¥{{happinessPassbook.RedEnvelopeMoney}}</view>
			</view>
			<view v-if="userVipRights && vipDiscountMoney>0" class="flex f12 grey" style="margin-bottom: 40rpx" :style="{'color':mainColor+' !important'}">
				<view style="flex: 1">
					<text style="margin-right: 30rpx">印象会员福利优惠({{userVipRights.DiscountType==1?`${userVipRights.DiscountValue*10}折`:`减${userVipRights.DiscountValue}/人`}})</text>
				</view>
				<view style="text-align: right">
					-¥{{vipDiscountMoney}}</view>
			</view>
			<view class="flex f12 grey" style="margin-bottom: 40rpx">
				<view style="flex: 1">
					<text style="margin-right: 30rpx">小计</text>
				</view>
				<view style="text-align: right">
					¥{{parseFloat((price-currentCoupon.discountMoney-vipDiscountMoney-happinessPassbook.RedEnvelopeMoney)).toFixed(2)}}</view>
			</view>

			<view class="f12" style="color:#ff3166;margin-bottom: 40rpx" v-if="activity && activity.Id">
				注意：本单以满足活动 "{{activity.CouponsName}}" 活动，出团后系统将自动发放优惠券到你的账户
			</view>
		</view>
		<view class="empty-block"></view>

		<coupon v-if="couponList.length > 0 && showCoupon" :price="price" 
			:list="couponList" :current="useCouponIds" @close="closeCouponHandler" 
			:current-price="realCurrentPriceInfo" :order="orderMsg"
			:numberPeople="total"></coupon>

		<view style="padding: 50rpx 40rpx" v-if="tips != ''">
			<view class="big-title">
				<text>重要提示</text>
			</view>
			<view class="sheshi">
				<view class="she-content">
					<text>{{ tips }}</text>
				</view>
			</view>
		</view>
		<view class="jz_orderbox">
			<view class="jz_OrderDiv">
				<view style="color: #ff3166; font-weight: bold">
					<text style="font-size: 22rpx">¥</text>
					<text style="font-size: 40rpx; margin: 0 20rpx 0 5rpx;font-family: nav-font;">{{
            (price-currentCoupon.discountMoney-vipDiscountMoney-happinessPassbook.RedEnvelopeMoney).toFixed(2)
          }}</text>
					<text style="color: #6e6e6e; font-size: 24rpx;font-family: microsoft yahei ui light;">共计{{ total }}人</text>
				</view>
				<view style="display: flex; margin-top: -2px">
						<button class="jz_OrderReNow" @click="goPay()" :disabled="submit" :loading="submit">
							<!-- #ifdef MP-DI -->
								立即支付
							<!-- #endif -->
							<!-- #ifdef MP-AG -->
								{{customer.isGuideOrLeader==1?'立即支付':'立即预定'}}
							<!-- #endif -->
						</button>
						
				</view>
			</view>
		</view>
		<!-- #ifdef MP-ALIPAY -->
		<subscribe-msg />
		<!-- #endif -->
		<u-popup v-model="showPz" mode="center" :mask-close-able="false" custom-style="padding:0;background:none;">
			<view style="height: 802rpx;width: 570rpx;">
				<view style="position: relative; width:100%;height:517rpx;background-repeat: no-repeat; background-size: 100% auto; background-image: url(https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638731507896933295.png);">
					<view style="position: absolute;top:233rpx;left:244rpx;">
						<text style="font-size: 89rpx;color: #FFFFFF;text-shadow: 0rpx 2rpx 7rpx rgba(144,5,0,0.44);">{{pzCoupon.expansionModel.denomination}}</text>
						<text style="font-weight: bold;font-size: 28rpx;color: #FFFFFF;margin-left: 6rpx;">元</text>
					</view>
					<view style="position: absolute;top:318rpx;left:82rpx;">
						<text style="font-size: 54rpx;color: #FF0063;text-shadow: 0rpx 2rpx 7rpx rgba(144,5,0,0.44);">
							{{pzCoupon.realDenomination}}
						</text>
						<text style="font-weight: bold;font-size: 22rpx;color: #FF0063;margin-left: 6rpx;">元</text>
					</view>
					<view style="position: absolute;top:380rpx;left:250rpx; text-align: center; width: 240rpx;">
						<text style="font-weight: bold;font-size: 24rpx;color: #FDE4D5;text-shadow: 0rpx 2rpx 0rpx rgba(67,12,7,0.17);">
							{{pzCoupon.remark}}
						</text>
					</view>
				</view>
				<view style="text-align: center;">
					<image @click="usePzCouponHandler" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638731507894902113.png" mode="widthFix" style="width: 281rpx;height: 123rpx;"></image>
				</view>
				<view style="text-align: center;margin-top: 106rpx;">
					<image @click="()=>showPz=false" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638731507894526128.png" mode="widthFix" style="width: 52rpx;height: 52rpx;"></image>
				</view>
			</view>
		</u-popup>
		<u-modal :border-radius="16" 
		@confirm="nativageToOrderHandle" 
		title="订单提醒" 
		content="订单创建成功,请您在30分钟内完成付款,否则将会被取消." 
		@cancel="navigatorToHomeHandle" 
		v-model="successVisible" confirm-text='查看订单' cancel-text='返回首页' 
		confirm-color='#DEBF7B' cancel-color='#080A09' :show-cancel-button="true"></u-modal>
	</view>
</template>

<script>
	import coupon from '@/components/coupon/index';
	export default {
		components: {
			coupon
		},
		data() {
			return {
				submit: false,
				pageTitle: "订单填写",
				lineId: 0,
				orderMsg: {
					ManNum: 0, //成人
					ChirdNoBedNum: 0, //儿童不占床
					ChirdNeedBedNum: 0, //儿童占床
					BabyNum: 0, //婴儿
					ChirdNum: 0, //儿童数量
					VisaNum: 0,
				},
				activity: {},
				price: 0,
				currentPriceInfo: {},
				total: 0,
				YSeatNum: 0,
				ESeatNum: 0,
				FSeatNum: 0,
				sumSeat: 0,
				userInfo: {},
				ltName: "",
				tips: "",
				contactMobile: "",
				contactName: "",
				orderInfo: {},
				orderData: "",
				Remarks: "", //备注
				GuestList: [],
				couponList: [],
				showCoupon: false,
				useCouponIds: [],
				currentCoupon: {
					discountMoney: 0
				},
				mainColor: '',
				realCurrentPriceInfo: {},
				customer: {},
				CreateBy: 0,
				showPz:false,
				pzCoupon:null,
				userInfo: {},
				userVipRights:null,
				vipDiscountMoney:0,
				successVisible: false,
				happinessPassbook: {
					RedEnvelopeMoney: 0,
				}
			};
		},
		created() {
			uni.setNavigationBarTitle({
				title: "订单支付预览",
			});
			this.mainColor = this.$uiConfig.mainColor;
			this.activeStyle = `background:${this.mainColor};`;
		},
		onLoad(option) {
			this.customer = {
				SurName: '',
				Mailbox: '',
				...uni.getStorageSync("b2b_user")
			};
			if (option.currentPriceInfo) {
				this.currentPriceInfo = JSON.parse(
					decodeURIComponent(option.currentPriceInfo)
				);
			}
			if (option.seat) {
				let t = JSON.parse(decodeURIComponent(option.seat));
				this.orderMsg.ManNum = Number(t.crCount);
				this.orderMsg.ChirdNeedBedNum = Number(t.etCount);
				this.orderMsg.ChirdNoBedNum = Number(t.etbCount);
				this.orderMsg.BabyNum = Number(t.yeCount);
				this.orderMsg.VisaNum = this.orderMsg.ManNum + this.orderMsg.ChirdNeedBedNum + this.orderMsg.ChirdNoBedNum + this.orderMsg.BabyNum;
				this.calcMoney();
			}
			if (option.tcid) {
				this.getDetails(option.tcid, option.cityId);
			}
			if (option.lineId) {
				this.lineId = option.lineId
			}
			if (option.CreateBy) {
				this.CreateBy = option.CreateBy
			}
			// #ifdef MP-AG
				this.GetCustoemrBalance()
			// #endif
			
		},
		methods: {
			GetCustoemrBalance(){
				this.apipost("b2b_get_GetCustoemrBalance", {}, (res) => {
						if (res.resultCode == 1) {
							this.happinessPassbook = {
								...res.data,
								RedEnvelopeMoney:0
							}
						}
					},
					(err) => {
						uni.hideLoading()
					}
				);
			},
			ChangeUse(e) {
				if((e.value>this.happinessPassbook.max&&this.happinessPassbook.max>this.happinessPassbook.client_Balance)||
				(e.value>this.happinessPassbook.client_Balance)){
					uni.showToast({
						title: `本单最多可减${this.happinessPassbook.client_Balance}元`,
						icon:'none'
					})
					this.happinessPassbook.RedEnvelopeMoney = this.happinessPassbook.client_Balance
					return
				}else if(e.value>this.happinessPassbook.max&&this.happinessPassbook.max<=this.happinessPassbook.client_Balance){
					uni.showToast({
						title: `本单最多可减${this.happinessPassbook.max}元`,
						icon:'none'
					})
					this.happinessPassbook.RedEnvelopeMoney = this.happinessPassbook.max
					return
				}else if(e.value>0&&e.value<=this.happinessPassbook.max&&e.value<=this.happinessPassbook.client_Balance) this.happinessPassbook.RedEnvelopeMoney = e.value;
				else this.happinessPassbook.RedEnvelopeMoney = 0;
			},
			navigatorToHomeHandle() {
				uni.redirectTo({
					url: '/pages/index/index'
				})
			},
			nativageToOrderHandle(){
				let OrderTypeStr = ''
				// #ifdef MP-DI
					OrderTypeStr = '1,2,3'
				// #endif
				// #ifdef MP-AG
					OrderTypeStr = '2'
				// #endif
				uni.redirectTo({
					url: `/pages/AggregateOrders/AggregateOrdersList?OrderTypeStr=${OrderTypeStr}`,
				});
			},
			submitB2COrderHandler(OrderId) {
				const pts = [2,1,3]
				const productType = pts[this.currentPriceInfo.teamType]
				
				let guestInfo = `成人x${this.orderMsg.ManNum}; `;
				if (this.orderMsg.ChirdNeedBedNum > 0) {
					guestInfo += `占床儿童${this.orderMsg.ChirdNeedBedNum}; `;
				}
				if (this.orderMsg.ChirdNoBedNum > 0) {
					guestInfo += `不占床儿童x${this.orderMsg.ChirdNoBedNum}; `;
				}
				if (this.orderMsg.BabyNum > 0) {
					guestInfo += `婴儿x${this.orderMsg.BabyNum}; `;
				}
				let startCityName =  this.realCurrentPriceInfo.priceUnion && this.realCurrentPriceInfo.priceUnion.startCityName?this.realCurrentPriceInfo.priceUnion.startCityName:this.currentPriceInfo.startCityName
				let msg = {
					SurName: this.customer.SurName,
					Name: this.customer.name,
					ContactNumber: this.customer.contactNumber,
					Mailbox: this.customer.Mailbox,
					GoodsId: this.currentPriceInfo.tcid,
					GoodsName: this.currentPriceInfo.title,
					GoodsPic: this.currentPriceInfo.CoverImg? this.currentPriceInfo.CoverImg : '',
					GoodsType: productType,
					OrderMake: `${this.currentPriceInfo.startDate}从${startCityName}出发 ${guestInfo}`,
					TotalPrice: this.price,
					PreferentialPrice: this.currentCoupon.discountMoney+this.vipDiscountMoney,
					ErpOrderId: OrderId,
					Country: 0,
					PlatformTax: 0,
					Income: 0,
					Refund: 0,
					MallBaseId: this.userInfo.MallBaseId,
					CreateBy:0,
					// #ifdef MP-DI
					DOrderType:1,
					// #endif
					// #ifdef MP-AG
					DOrderType:2,
					// #endif
					CustomerId: this.customer.customerInfoChildrenId,
					OpenId: uni.getStorageSync("mall_UserInfo").OpenId,
					CreateBy: this.CreateBy,
				};
				// #ifdef MP-DI
				if(this.customer.salesBaseInfo&&this.customer.salesBaseInfo.employeeId){
					msg.CreateBy = this.customer.salesBaseInfo.employeeId
				}
				// #endif
				
				this.apipost("AddOrderInfo_post", msg, (res) => {
					if (res.resultCode == 1) {
						this.orderInfo =JSON.parse(res.data.sPayInfo)
						uni.showToast({
							icon: 'none',
							title: '订单创建成功'
						})
						this.goPayHandler(res.data.OrderNo);
					} else {
						uni.showToast({
							title:res.message,
							icon:'none',
							duration:3000
						})
						this.submit = false;
					}
				});
			},
			goPayHandler(OrderNo) {
				let that = this;
				uni.requestPayment({
					provider: "wxpay",
					timeStamp: this.orderInfo.timeStamp,
					nonceStr: this.orderInfo.nonceStr,
					package: this.orderInfo.package,
					signType: this.orderInfo.signType,
					paySign: this.orderInfo.sign,
					success: function(res) {
						console.log("success", res);
						that.submit = false;
						uni.showToast({
							title: "支付成功",
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages/jiuzhai/paysuccess?PreferPrice=" +
								(that.price-that.currentCoupon.discountMoney-that.vipDiscountMoney).toFixed(2) +
									"&isFrom=1",
							});
						}, 100);
					},
					fail: function(err) {
						console.log("fail:", err);
						that.submit = false;
						that.successVisible = true
						// uni.showToast({
						// 	title: "支付失败",
						// 	icon: "none",
						// });
						// setTimeout(() => {
						// 	uni.redirectTo({
						// 		url: "/pages/jiuzhai/jz_SureOrder?OrderNo=" + OrderNo,
						// 	});
						// }, 100);
					},
				});
			},
			showCouponHandler() {
				this.showCoupon = this.couponList.length > 0;
			},
			closeCouponHandler(e) {
				if (e != -1) {
					this.useCouponIds = e;
					//叠加使用优惠券
						let TotalDiscountAmount = 0
						this.couponList.forEach(x=>{
							let findIndex = this.useCouponIds.findIndex(y=>x.id==y)
							if(findIndex!=-1){
								let discountMoney = 0
								if(x.couponsType==1){
									discountMoney = x.denomination	
								}else{
									discountMoney = (parseFloat(this.price) * (1 - parseFloat(x.denomination / 10)))
									.toFixed(2)
								}
								TotalDiscountAmount += discountMoney
							}
						})
						if(TotalDiscountAmount)this.currentCoupon.discountMoney = TotalDiscountAmount
						else this.currentCoupon.discountMoney = 0
				}else{
					this.currentCoupon.discountMoney = 0
					this.useCouponIds = []
				}
				this.showCoupon = false;
				this.calcVipDisscountHandle()
			},
			getUserCouponList() {
				let couponParams = {
					"lineId": this.lineId, //线路ID
					"lineteamId": 0, //系列ID
					"userId": 0, //AccountId
					"CouponsUseScope": 2, //特定使用平台(当地游=8   跟团游=2 小包团=10)
					"isExpansion": 0, //是否启动膨胀金1-是
					// #ifdef MP-DI
					"CustomerType": 1, //客户类型 0-同行，1-直客
					// #endif
					// #ifdef MP-AG
					"CustomerType": 0, //客户类型 0-同行，1-直客
					// #endif
					"TCID": this.currentPriceInfo.tcid,
				}
				if (this.currentPriceInfo.teamType == "0") {
					//跟团游
					couponParams.CouponsUseScope = 2;
				} else if (this.currentPriceInfo.teamType == "1") {
					//小包团
					couponParams.CouponsUseScope = 10;
				} else if (this.currentPriceInfo.teamType == "2") {
					//当地游
					couponParams.CouponsUseScope = 8;
				}
				if (this.currentPriceInfo.lineteamId) {
					couponParams.lineteamId = this.currentPriceInfo.lineteamId;
				}
				couponParams.userId = this.customer.accountId;
				this.apipost(
					"coupon_post_GetUserCanUseCouponList", couponParams,
					(res) => {
						if (res.resultCode == 1) {
							let arrList = function(list){
								list.forEach(x=>{
									x.checkId=0
									x.check=false
								})
							}
							arrList(res.data)
							this.couponList = res.data
							this.calcPzCouponHandler()
							this.calcMaxCouponHandle()
							this.getUserVipInfo(this.realCurrentPriceInfo.lineId)
						}
					},
					(err) => {}
				);
			},
			calcMaxCouponHandle(){
				const shengyu = this.realCurrentPriceInfo.totalSeat-this.realCurrentPriceInfo.leaderNum
				const remainNum = this.realCurrentPriceInfo.remainNum
				const orderNum = this.orderMsg.ManNum+this.orderMsg.ChirdNeedBedNum+this.orderMsg.ChirdNoBedNum
				let errorMsg = null
				if (this.realCurrentPriceInfo && this.realCurrentPriceInfo.teamType==1) {
					if(shengyu!=remainNum) errorMsg = '当前定制团存在其他订单，无法使用专享优惠券'
					else if(orderNum<shengyu) errorMsg = '报名人数小于团队机位人数，无法使用专享优惠券'
				}
				if(this.couponList && this.couponList.length>0){
					let maxCouponId = 0
					let discount = 0
					const money = this.price
					this.couponList.forEach(x=>{
						if(x.couponsUseScope==10&&errorMsg) {
							
						}else{
							if(x.couponsType==1 && x.denomination>discount&&(this.total>=x.orderGuestNum||!x.orderGuestNum)&&this.price>=x.useCondition) {
								discount=x.denomination
								maxCouponId = x.id
							}
							if(x.couponsType==2){
								let disMoney = money*(1-x.denomination)
								if(discount<disMoney&&(this.total>=x.orderGuestNum||!x.orderGuestNum)&&this.price>=x.useCondition){
									discount=disMoney
									maxCouponId = x.id
								}
							}
						}
					})
					if(maxCouponId>0) this.closeCouponHandler([maxCouponId])
				}
			},
			calcVipDisscountHandle(){
				const money = this.price-this.currentCoupon.discountMoney
				let vipMoney = 0
				if(this.userVipRights){
					const v = this.userVipRights
					if(v.DiscountType==1) vipMoney += money*(1-v.DiscountValue)
					else vipMoney += v.DiscountValue*(parseInt(this.orderMsg.ManNum) + parseInt(this.orderMsg.ChirdNum))
					
					this.vipDiscountMoney = Number(vipMoney.toFixed(2))
				}
			},
			usePzCouponHandler(){
				this.showPz = false
				this.closeCouponHandler([this.pzCoupon.id])
				this.pzCoupon = null
			},
			calcPzCouponHandler(){
				this.couponList.forEach((x)=>{
					if(x.expansionModel.denomination>0){
						if(this.pzCoupon && this.pzCoupon.expansionModel.denomination<x.expansionModel.denomination&&(this.total>=x.orderGuestNum||!x.orderGuestNum))
							this.pzCoupon=x
						else if(!this.pzCoupon&&(this.total>=x.orderGuestNum||!x.orderGuestNum))
							this.pzCoupon=x
						
						x.realDenomination = x.denomination
						x.denomination =x.expansionModel.denomination
					}
				})
				this.showPz = this.pzCoupon?true:false
			},
			changecheckbox(e, index, item) {
				if (item.IsHightSchool) {
					let newObj = JSON.parse(JSON.stringify(item));
					newObj.IsHightSchool = false;
					this.$set(this.GuestList, index, newObj);
				} else {
					let newObj = JSON.parse(JSON.stringify(item));
					newObj.IsHightSchool = true;
					this.$set(this.GuestList, index, newObj);
				}
			},
			//获取详情
			getDetails(id, cityId) {
				uni.showLoading({
					title: '加载中'
				});
				this.apipost(
					"b2b_get_GetB2BTravelInfoNoDesV1", {
						tcid: id,
						cityId
					},
					(res) => {
						uni.hideLoading();
						if (res.resultCode == 1) {
							this.realCurrentPriceInfo = res.data.currentPriceInfo
							this.tips = res.data.feature.importantTipText;
							this.ltName = res.data.ltName;
							this.realCurrentPriceInfo.lineId = res.data.lineId
							this.currentPriceInfo.visaPrice = res.data.currentPriceInfo.visaPrice
							this.calcMoney()
							this.getCouponActivityHandler(res.data)
							this.getUserCouponList();
						}
					},
					(err) => {
						uni.hideLoading()
					}
				);
			},
			getUserVipInfo(lineId){
				const parameter = {
					VipCusType:1,
					CustomerId:this.customer.customerId
				}
				// #ifdef MP-DI
				parameter.VipCusType = 2
				// #endif
				
				this.apipost( "vip_post_CheckCustomerIsVip", parameter,(r) => {
					const v = r.data
					if(v.FinishOrderCount >= v.OrderCount){
						let rule = v.RuleList.find(x=>x.LineId==lineId)
						if(!rule) rule = v.RuleList.find(x=>x.LineId==0)
						if(rule) {
							this.userVipRights = rule
						}
						this.calcVipDisscountHandle()
					}
				})
			},
			getCouponActivityHandler(d) {
				uni.hideLoading();
				let msg = {
					TCID: d.currentPriceInfo.tcid,
					CustomerId: this.customer.customerId,
					OrderId: 0,
					StratDate: d.currentPriceInfo.startDate,
					OrderGuest: this.total,
					lineId: d.lineId
				}
				this.apipost("coupon_post_GetAutoCouponOrder", msg, (res) => {
						if (res.resultCode == 1) {
							this.activity = res.data
						}
					},
					(err) => {
						uni.hideLoading()
					}
				);
			},
			updateUser() {
				uni.navigateBack({
					delta: 1,
				});
			},
			getWeek(date) {
				if(!date) return
				date.split("-").forEach((x, i) => {
				 	 if (i == 0) {
				 	 	 date = x;
				 	 } else {
				 	 	 date = date + "/" + x;
				 	 }
				 });
				var weekArray = new Array("日", "一", "二", "三", "四", "五", "六");
				var week = weekArray[new Date(date).getDay()]; //注意此处必须是先new一个Date
				return "周" + week;
			},
			getDate(date) {
				if (date) {
					let arr = date.split("-");
					return arr[1] + "月" + arr[2] + "日";
				}
			},
			//改变成人
			changeMan(e) {
				this.orderMsg.ManNum = e.value;
				this.calcMoney();
			},
			//改变儿童不占床
			changeChirdNoBedNum(e) {
				this.orderMsg.ChirdNoBedNum = e.value;
				this.calcMoney();
			},
			//改变儿童占床
			changeChirdNeedBedNum(e) {
				this.orderMsg.ChirdNeedBedNum = e.value;
				this.calcMoney();
			},
			//改变婴儿
			changeBabyNum(e) {
				this.orderMsg.BabyNum = e.value;
				this.calcMoney();
			},
			//计算价格
			calcMoney() {
				var price = 0;
				//	#ifdef MP-DI
					price = this.currentPriceInfo.b2CPrice;
				//	#endif
				//	#ifdef MP-AG
					price = this.currentPriceInfo.b2BPrice;
				//	#endif
				this.orderMsg.ChirdNum = parseInt(this.orderMsg.ChirdNoBedNum) + parseInt(this.orderMsg.ChirdNeedBedNum);
				//计算总人数
				this.total = parseInt(this.orderMsg.ManNum) + parseInt(this.orderMsg.ChirdNum) + parseInt(this.orderMsg.BabyNum);
				this.orderMsg.VisaNum = this.total;
				this.sumSeat = this.total;

				let money = price * this.orderMsg.ManNum;
				money += price * this.orderMsg.ChirdNum;
				money +=
					(this.currentPriceInfo.babyChargePrice ?
						this.currentPriceInfo.babyChargePrice :
						0) * this.orderMsg.ChirdNum;
				money +=
					(this.currentPriceInfo.babyPrice ?
						this.currentPriceInfo.babyPrice :
						0) * this.orderMsg.BabyNum;
				money +=
					(this.currentPriceInfo.childNeedPrice ?
						this.currentPriceInfo.childNeedPrice :
						0) * this.orderMsg.ChirdNeedBedNum;
				if (this.orderMsg.ChirdNoBedNum > 0) {
					money -=
						(this.currentPriceInfo.childNoNeedPrice ?
							this.currentPriceInfo.childNoNeedPrice :
							0) * this.orderMsg.ChirdNoBedNum;
				}
				if (this.currentPriceInfo.visaPrice) {
					money += (this.orderMsg.ManNum + this.orderMsg.ChirdNum) * this.currentPriceInfo.visaPrice
				}

				this.price = Number(money.toFixed(2));

				//根据总人数 生成旅客信息
				for (var i = 0; i < this.total; i++) {
					let obj = {
						Id: 0,
						SurName: "", //姓
						Name: "", //名
						IdCard: "", //身份证
						MobilePhone: "", //联系电话
						IsHightSchool: false, //是否高校学生1 是  2否
					};
					this.GuestList.push(obj);
				}
			},
			validate(){
				let  email = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
				let msg = ''
				if(this.customer.SurName==''||!this.customer.SurName){
					msg = '请输入姓'
				} else if(this.customer.name==''||!this.customer.name){
					msg = '请输入名'
				} else if(this.customer.contactNumber==''||!this.customer.name){
					msg = '请输入联系电话'
				} else if(this.customer.contactNumber&&this.customer.contactNumber.length!=11){
					msg = '请输入正确的电话号码'
				}else if(this.customer.Mailbox==''||!this.customer.Mailbox){
					msg = '请输入邮箱地址'
				}else if (!email.test(this.customer.Mailbox)) {
					msg = '请输入正确的邮箱地址'
				}
				return msg
			},
			//去支付
			goPay() {
				if(this.submit) return
				// #ifdef MP-DI
				const error = this.validate()
				if(error!=''){
					uni.showToast({
						icon:'none',
						title:error
					})
					return
				}
				// #endif
				this.submit = true;
				this.userInfo = uni.getStorageSync("mall_UserInfo");
				this.basedataObj = uni.getStorageSync("basedata").mall;
				
				let newobj = JSON.parse(JSON.stringify(this.GuestList));
				newobj.forEach((x) => {
					if (x.IsHightSchool) {
						x.IsHightSchool = 1;
					} else {
						x.IsHightSchool = 2;
					}
				});
				var MiniAppUserId = 0;
				if (this.userInfo && this.userInfo.UserId) {
					MiniAppUserId = this.userInfo.UserId;
				}

				var ContactName = this.customer.SurName+this.customer.name; //联系人
				var ContactMobile = this.customer.contactNumber; //联系电话  
				var CustomerType = 0;
				var CustomerId = 0
				var CustomerCreateBy = this.customer.createBy;
				var price = 0;
				var CreateBy = 0
				var DirectCustomerId = 0
				// #ifdef MP-DI
					CustomerType = 4;
					price = this.currentPriceInfo.b2CPrice;
					DirectCustomerId = this.customer.customerId
				// #endif
				// #ifdef MP-AG
					CustomerType = this.customer.isMember
					price = this.currentPriceInfo.b2BPrice;
					CreateBy = this.CreateBy
					CustomerId = this.customer.customerId
				// #endif
				let CouponAllotIds = ''
				if(this.useCouponIds.length>0){
					CouponAllotIds = this.useCouponIds.join(',')
				}
				const guestCount = parseInt(this.orderMsg.ManNum) +
						parseInt(this.orderMsg.ChirdNum) +
						parseInt(this.orderMsg.BabyNum)
				let msg = {
					OrderId: 0,
					TCID: this.currentPriceInfo.tcid,
					CustomerType: CustomerType,
					GroupType: 1,
					ContactName: ContactName,
					ContactMobile: ContactMobile,
					CustomerId: CustomerId,
					DepartureCityId: 0,
					IsIntermodal: 2,
					Unit_Price: price,
					TC_Price: price,
					CouponAllotIds: CouponAllotIds,
					ManNum: this.orderMsg.ManNum,
					ChirdNum: this.orderMsg.ChirdNum,
					ChirdNeedBedNum: this.orderMsg.ChirdNeedBedNum,
					BabyNum: this.orderMsg.BabyNum,
					OldPeopleNum: 0,
					SingleRoomNum: 0,
					PreferPrice: this.price,
					YSeatNum: this.orderMsg.ManNum + this.orderMsg.ChirdNum,
					ESeatNum: 0,
					FSeatNum: 0,
					Commission: 0, //todo 提成
					ClientSource: 2,
					BrandId: 0,
					TradeWay: 0,
					PlatformOrder: "",
					GuestNum: guestCount,
					IsChildrenTour: this.currentPriceInfo.isSupportChildren,
					IsBirdDiscount: this.zaoniao > 0 ? 1 : 2,
					PredictRoomNum: 1,
					BigRoomNum: 0,
					TripleRoomNum: 0,
					TradeDate: this.currentPriceInfo.startDate,
					CostType: 0,
					MinOrderPrice: 0,
					VisaNum: guestCount,
					SafeNum: guestCount,
					AirticketNum: 0,
					ReturnArriveCityId: 0,
					IsReturnIntermodal: 2,
					GoCityTime: "",
					BackCityTime: "",
					ScenicRefundArr: [],
					CommissionSharePeople: 0,
					CommissionShareMoney: 0,
					MiniAppUserId: MiniAppUserId,
					CreateBy: CreateBy, //同行联系人创建人  CustomerCreateBy
					DirectCustomerId: DirectCustomerId, //直客Id
					DisValue: this.vipDiscountMoney,
					// #ifdef MP-DI
					OrderSource: 7,
					// #endif
					// #ifdef MP-AG
					OrderSource: 5,
					RedEnvelopeMoney: this.happinessPassbook.RedEnvelopeMoney,
					// #endif
					// // #ifdef MP-WEIXIN
					// OrderSource: 5,
					// // #endif
					// #ifdef MP-ALIPAY
					OrderSource: 6,
					// #endif
					//MiniAppUserId: this.userInfo.UserId,
					Remarks: this.Remarks, //备注
					//GuestList: newobj,
					// #ifdef MP-DI
					ClientType: 2,
					// #endif
					// #ifdef MP-AG
					ClientType: 1,
					// #endif
					orderForm: 4,// 订单来源 4-小程序
				};
				// #ifdef MP-DI
				if(this.customer.salesBaseInfo&&this.customer.salesBaseInfo.employeeId){
					msg.CreateBy = this.customer.salesBaseInfo.employeeId
				}
				// #endif
				if (this.realCurrentPriceInfo.priceUnion) {
					msg.DepartureCityId = this.realCurrentPriceInfo.priceUnion.unionCityId
					msg.IsIntermodal = 1
					msg.ReturnArriveCityId = this.realCurrentPriceInfo.priceUnion.unionCityId
					msg.IsReturnIntermodal = 1
				}
				this.apipost(
					"sellorder_post_SetOrderInfoForB2B",
					msg,
					(res) => {
						if (res.resultCode == 1) {
							const tempData = res.data
							if(tempData.CounponList && tempData.CounponList.length>0){
								uni.setStorageSync('coupons',tempData.CounponList)
							}
							// #ifdef MP-DI
								this.submitB2COrderHandler(tempData.OrderId)
							// #endif
							// #ifdef MP-AG
							if(this.customer.isGuideOrLeader==1){
								this.submitB2COrderHandler(tempData.OrderId)
							}else{
								uni.showToast({
									title: '订单创建成功.',
									icon: 'none'
								})
								uni.redirectTo({
									url: `/pages/AggregateOrders/AggregateOrdersList?OrderTypeStr=2`,
								});
							}
								
							// #endif
							
						} else {
							uni.showToast({
								title:res.message,
								icon:'none',
								duration:3000
							})
						}
						// #ifdef MP-AG
							this.submit = false;
						// #endif
					},
					(e) => {
						this.submit = false;
						uni.showToast({
							title:e.message,
							icon:'none',
							duration:3000
						})
					}
				);
			},
			// #ifdef MP-WEIXIN
			//微信支付
			queren(OrderId) {
				let url = "/api/WeChatPay/GetTravlePayInfo";
				let GoodsName = this.currentPriceInfo.title;
				GoodsName = GoodsName.slice(0, 10);
				this.request2({
						url: url,
						data: {
							OrderId: OrderId,
							GoodsName: GoodsName,
							OrderPayType: 1,
							OpenId: uni.getStorageSync("mall_UserInfo").OpenId,
						},
					},
					(res) => {
						try {
							this.orderInfo = JSON.parse(res.data);
							// this.Pay(OrderId);
							this.subscribeMsg(OrderId);
						} catch (e) {
							uni.showToast({
								title: '无法正常拉取微信支付，你可以稍后重试或联系销售人员线下转款',
								icon: 'none'
							})
							setTimeout(() => {
								uni.redirectTo({
									url: "/pages/jiuzhai/jz_SureOrder?orderId=" + OrderId
								});
							}, 1000);
						}
					},
					(err) => {
						console.log(err)
					}
				);
			},
			subscribeMsg(OrderId) {
				const that = this;
				let tempObj = [];
				var basedataObj = uni.getStorageSync("basedata");
				if (basedataObj && basedataObj.mall && basedataObj.mall.wechatmessage && basedataObj.mall.wechatmessage.length > 0) {
					tempObj = basedataObj.mall.wechatmessage;
				}
				let tmplIds = [];
				if (tempObj && tempObj.length > 0) {
					tempObj.forEach((x) => {
						if (x.Name == "下单成功提醒" || x.Name == "订单取消提醒") {
							tmplIds.push(x.MessageId);
						}
					});
				}
				uni.requestSubscribeMessage({
					tmplIds: tmplIds,
					complete(res) {
						that.Pay(OrderId);
					},
				});
			},
			Pay(OrderId) {
				let that = this;
				uni.requestPayment({
					provider: "wxpay",
					timeStamp: this.orderInfo.timeStamp,
					nonceStr: this.orderInfo.nonceStr,
					package: this.orderInfo.package,
					signType: this.orderInfo.signType,
					paySign: this.orderInfo.sign,
					success: function(res) {
						console.log("success", res);
						uni.showToast({
							title: "支付成功",
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages/jiuzhai/paysuccess?PreferPrice=" +
									this.price +
									"&isFrom=1",
							});
						}, 100);
					},
					fail: function(err) {
						console.log("fail:", err);
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages/jiuzhai/jz_SureOrder?orderId=" + OrderId,
							});
						}, 100);
					},
				});
			},
			// #endif
			// #ifdef MP-ALIPAY
			//支付宝支付
			querenAli(data) {
				let that = this;
				uni.showLoading({
					title: "支付中",
				});
				let url = "/api/WeChatPay/GetTravlePayInfo";
				let GoodsName = this.currentPriceInfo.title;
				this.request2({
						url: url,
						data: {
							OrderId: data.OrderId,
							GoodsName: GoodsName,
							OrderPayType: 2,
							OpenId: uni.getStorageSync("mall_UserInfo").OpenId,
						},
					},
					(res) => {
						this.orderInfo = JSON.parse(res.data);
						if (res.data) {
							that.$utils.SubscribeMsgAli(() => {
								that.PayAli(res.data, data);
							});
						} else {
							uni.hideLoading();
							uni.showToast({
								title: "获取交易号失败",
								duration: 2000,
							});
						}
					}
				);
			},
			PayAli(tradeNO, data) {
				let that = this;
				my.tradePay({
					tradeNO: tradeNO,
					success: function(res) {
						console.log("success", res);
						const list = ["9000"];
						if (list.includes(res.resultCode)) {
							let cbObj = {
								TradeNo: tradeNO,
								OrderNo: data.OrderNo,
								OrderId: data.OrderId,
								preferPrice: data.PreferPrice,
							};
							that.payAliCallback(cbObj);
						} else {
							uni.hideLoading();
							uni.showToast({
								title: "支付失败",
								icon: "none",
							});
							setTimeout(() => {
								uni.redirectTo({
									url: "/pages/jiuzhai/jz_MyOrder",
								});
							}, 1000);
						}
					},
					fail: function(err) {
						console.log("fail:", err);
						uni.hideLoading();
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages/jiuzhai/jz_MyOrder",
							});
						}, 1000);
					},
				});
			},
			payAliCallback(obj) {
				this.request2({
						url: "/api/AliPay/ALiPayCallBackDmcNotify",
						data: {
							OrderNo: obj.OrderNo,
							OrderId: obj.OrderId,
							UserId: uni.getStorageSync("mall_UserInfo").UserId,
							TradeNo: obj.TradeNo,
							ProjectType: 2,
							PreferPrice: obj.preferPrice,
						},
					},
					(res) => {
						console.log("cb", res);
						this.submit = false;
						uni.redirectTo({
							url: "/pages/jiuzhai/paysuccess?PreferPrice=" +
								obj.preferPrice +
								"&isFrom=1",
						});
						uni.hideLoading();
					},
					(err) => {
						this.submit = false;
						console.log("cb2", err);
						uni.hideLoading();
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages/jiuzhai/jz_MyOrder",
							});
						}, 1000);
					}
				);
			},
			// #endif
		},
	};
</script>
