<template>
	<view style="background:#F3F1EF; height:100vh;display: flex;flex-direction: column;">
		<scroll-view scroll-y="true" style="height: 1px;flex: 1;box-sizing: border-box;">
			<view class="hotel-order">
				<view class="o-head">
					<view class="o-head-title">{{ dataList.Name }}</view>
					<view class="o-timer">
						<view class="row-sb-n">
							<view class="row items-center">
								<view class="time-item">
									{{formatDate(orderMsg.OrderDate)}}<text>{{ getWeek(orderMsg.OrderDate) }}</text>
								</view>
								<!-- <view class="time-itemZhi"><text>-</text></view>
								<view class="time-item"><text></text>
								</view>
								<view class="timeline"></view>
								<view class="time-split">
									<view>晚</view>
								</view> -->
							</view>
							<view class="o-detail" @click="goUrl">详情</view>
						</view>
						<view class="room-dateil row items-center">
							<view class="room-name">{{ orderMsg.CarName }}({{  orderMsg.PeopleNum }}人)</view>
							<!-- <view class="roomline"></view>
							<view class="room-remark">
								{{orderMsg.Num}}辆
							</view> -->
							<view class="roomline"></view>
							<view class="roomPrice">
								{{dataList.CurrencyCode}}
								{{getPrice(orderMsg.Unit_Price)}}
							</view>
						</view>
					</view>


				</view>
				<view class="form" v-if="orderMsg.OrderType<3">
					<view class="row-sb-n visaProductTextBox">
						<view class="row col" style="width:1px;flex: 1;">
							<view class="visaProduct_rColor visaProductTextL">*</view>
							<view class="visaProductTitle">航班信息</view>
						</view>
					</view>
					<view>
						<view class="form-items">
							<view class="label">航厦</view>
							<view class="val">
								<input type="text" v-model="orderMsg.AirportTerminal" placeholder="请输入航厦" />
							</view>
						</view>
						<view class="form-items">
							<view class="label">航空公司</view>
							<view class="val">
								<input type="text" v-model="orderMsg.AirLine" placeholder="请输入航空公司" />
							</view>
						</view>
						<view class="form-items">
							<view class="label">航班号</view>
							<view class="val">
								<input type="text" v-model="orderMsg.FlightNumber" placeholder="请输入航班号" />
							</view>
						</view>
						<view class="form-items">
							<view class="label">{{orderMsg.OrderType==1?'抵达':'起飞'}}时间</view>
							<view class="val flex form-itemsTime" @click="timeType=1,showtime=true">
								<view style="flex: 1;" class="f14"
								:style="{color:orderMsg.FlightTime?'#000':'#808080'}">{{orderMsg.FlightTime?orderMsg.FlightTime:`请选择${orderMsg.OrderType==1?'抵达':'起飞'}时间`}}</view>
								<u-icon name="arrow" color="#D9D9D9" size="20" />
							</view>
						</view>
					</view>
				</view>
				<view class="form">

					<view class="row-sb-n visaProductTextBox">
						<view class="row col" style="width:1px;flex: 1;">
							<view class="visaProduct_rColor visaProductTextL">*</view>
							<view class="visaProductTitle">{{orderMsg.OrderType==1?'接机':orderMsg.OrderType==2?'送机':'包车'}}信息</view>
						</view>
						<view class="row-sbas-n items-center">
							<!---->
							<view class="addPnum addPnumL" @click="orderMsg.Num>1?editNum(1):''">
								<image v-if="orderMsg.Num>1" style="width: 27rpx;height: 27rpx;display: block;"
									src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638751245939665786.png" />
								<image v-else style="width: 27rpx;height: 27rpx;display: block;"
									src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638755711218891689.png" />
							</view>
							<view class="col row items-center textCenter visaProductTetx">
								{{orderMsg.Num}}
								辆
							</view>
							<view class="addPnum addPnumR" @click="editNum()">
								<image style="width: 27rpx;height: 27rpx;display: block;"
									src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638751245974558349.png" />
							</view>
						</view>
					</view>
					<view>
						
						<view class="form-items" style="padding: 10rpx 10rpx 20rpx 15rpx;">
							<view class="label">
								联系姓名
							</view>
							<view class="val row">
								<input type="text" v-model="orderMsg.SurName" placeholder="请输入姓" />
								<input type="text" v-model="orderMsg.Name" placeholder="请输入名" />
							</view>
						</view>
						<view class="form-items" style="padding: 10rpx 10rpx 20rpx 15rpx;">
							<view class="label">
								性别
							</view>
							<view class="val row">
								<label class="bus-radio row items-center"
								v-for="(item, index) in radioList" :key="item.value"
								@click="radioChange(item.value)"
								>
									<view class="bus-radioLeft">{{item.name}}</view>
									<view class="bus-radioRight row items-center justify-center"
									:class="[orderMsg.Sex==item.value?'active':'']">
										<view v-if="orderMsg.Sex==item.value"></view>
									</view>
								</label>
							</view>
						</view>
						<view class="form-items">
							<view class="label">联系电话</view>
							<view class="form-itemsL row" @click="showCountry=true">
								<text>+{{ orderMsg.PhoneCode }}</text>
								<!--'arrow-up':'arrow-down'-->
								<u-icon name="arrow-down" color="#080A09" size="20" />
							</view>
							<view class="val">
								<input type="text" v-model="orderMsg.Mobile" placeholder="请输入电话号码" />
							</view>
						</view>
						<view class="form-items">
							<view class="label">联系方式</view>
							<view class="val">
								<input type="text" v-model="orderMsg.ContactWay" placeholder="用于接收信息" />
							</view>
						</view>
						<view class="form-items">
							<view class="label">{{orderMsg.OrderType==1?'接机':orderMsg.OrderType==2?'送机':'包车'}}时间</view>
							<view class="val flex form-itemsTime" @click="timeType=0,showtime=true">
								<view style="flex: 1;" class="f14"
								:style="{color:orderMsg.OrderDate?'#000':'#808080'}">{{orderMsg.OrderDate}}</view>
								<u-icon name="arrow" color="#D9D9D9" size="20" />
							</view>
						</view>
						<view class="form-items">
							<view class="label">上车地址</view>
							<view class="val">
								<input type="text" v-model="orderMsg.GetonAddress" placeholder="请输入上车地址" />
							</view>
						</view>
						<view class="form-items">
							<view class="label">下车地址</view>
							<view class="val">
								<input type="text" v-model="orderMsg.GetoffAddress" placeholder="请输入下车地址" />
							</view>
						</view>
						<view class="form-items row items-center">
							<view class="label active">
								成人
							</view>
							<view class="LastNameBox" style="width: 1px;flex: 1;">
								<u-number-box :min="1" v-model="orderMsg.ManNum" placeholder="成人数" 
								@change="(e)=>{orderMsg.ManNum=e.value,getPeoples()}" />
							</view>
						</view>
						<view class="row-sbas-n">
							<view class="form-items row col" >
								<view class="label active">
									儿童
								</view>
								<view class="LastNameBox" style="width: 1px;flex: 1;">
									<view class="row items-center">
										<u-number-box :min="0" v-model="orderMsg.ChildNum" placeholder="儿童数"  
										@change="(e)=>{orderMsg.ChildNum=e.value,getPeoples()}"/>
									</view>
								</view>
							</view>
							<view class="form-items row col" >
								<view class="label active">
									婴儿
								</view>
								<view class="LastNameBox" style="width: 1px;flex: 1;">
									<view class="row items-center">
										<u-number-box :min="0" v-model="orderMsg.BabyNum" placeholder="婴儿数"  
										@change="(e)=>{orderMsg.BabyNum=e.value,getPeoples()}"/>
									</view>
								</view>
							</view>
						</view>
						<view class="row-sbas-n">
							<view class="form-items row col" >
								<view class="label active">
									手提
								</view>
								<view class="LastNameBox" style="width: 1px;flex: 1;">
									<view class="row items-center">
										<u-number-box :min="0" v-model="orderMsg.HandLuggageNum" placeholder="手提数" />
									</view>
								</view>
							</view>
							<view class="form-items row col" >
								<view class="label active">
									托运
								</view>
								<view class="LastNameBox" style="width: 1px;flex: 1;">
									<view class="row items-center">
										<u-number-box :min="0" v-model="orderMsg.RegisteredLuggageNum" placeholder="托运数" />
									</view>
								</view>
							</view>
						</view>
						
					</view>
					<view>
						<textarea class="jz_TextArea" placeholder="请输入备注信息" v-model="orderMsg.Remark"></textarea>
					</view>
				</view>
				<view class="CouponBox">
					<view class="big-title">
						<text>优惠券</text>
					</view>
					<view style="margin-top: 20px;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 == 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>
				<view class="PriceBox">
					<view class="big-title">
						<text>订单金额</text>
					</view>
					<view class="form" style="margin:20rpx 0 15rpx 0;padding: 0;">
						<view class="form-items PriceZaiXian">
							<view class="label">
								商品总价
							</view>
							<view class="val f14 regular" style="text-align: right;">
								<text style="margin-right: 5rpx;">{{orderMsg.peoples}}人</text>
								<text style="margin-right: 10rpx;">{{orderMsg.Num}}辆</text>
								<text class="red">
									{{dataList.CurrencyCode}}{{getPrice(orderMsg.Unit_Price*orderMsg.Num)}}
								</text>
							</view>
						</view>
						<view class="form-items PriceMinXi" style="border-bottom: none;">
							<view class="label">
								明细
							</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">
								{{orderMsg.Num}}辆×{{dataList.CurrencyCode}}{{getPrice(orderMsg.Unit_Price)}}
							</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">
							<view style="flex: 1">小计</view>
							<view>
								{{dataList.CurrencyCode}}{{ getPrice((orderMsg.Unit_Price*orderMsg.Num)-currentCoupon.discountMoney) }}
							</view>
						</view>
					</view>

				</view>
				<view class="buyTispBox" v-if="dataList.BuyNotes">
					<view class="big-title">
						<text class="">购买说明</text>
					</view>
					<view class="rule">
						<text class="king"></text>
						{{ dataList.BuyNotes  }}
					</view>
				</view>
				<view style="height: 27rpx"></view>
			</view>
		</scroll-view>
		<view class="opera-box">
			<view class="box flex">
				<view class="price">
					<text class="f11">{{dataList.CurrencyCode}}</text>
					<text>
						{{ getPrice((orderMsg.Unit_Price*orderMsg.Num)-currentCoupon.discountMoney) }}
					</text>
				</view>
				<view class="sum-detail">共计 {{orderMsg.Num}}辆</view>
				<u-button :ripple="true" :hair-line="false"
					:disabled="(this.orderMsg&&this.orderMsg.Money==0)||submit"
					:custom-style="(this.orderMsg&&this.orderMsg.Money==0)||submit?btnStyle2:btnStyle"
					@click="goPay" :loading="submit">立即购买</u-button>
			</view>
		</view>
		<u-picker 
		:startYear="$utils.GetDateFewFaysLater(0).year"
		:startMonth="$utils.GetDateFewFaysLater(0).month" 
		:startDay="$utils.GetDateFewFaysLater(0).dd"
		:startHours="$utils.GetDateFewFaysLater(0).hour"
		:startMinutes="$utils.GetDateFewFaysLater(0).minute"
		v-model="showtime" 
		mode="time" 
		@cancel="confirm"
		@confirm='confirm' 
		:params="paramsTime"
		confirmColor="#B99846"
		:defaultTime="timeType&&orderMsg.FlightTime==''?orderMsg.OrderDate:orderMsg.OrderDate"></u-picker>
		<u-toast ref="uToast" />
		<u-picker mode="selector" v-model="showCountry" :default-selector="[0]" :range="countrys"
			@confirm='(e)=>{changeDown(e,CountryType)}' range-key="label" @input="showCountry=false"></u-picker>
		<coupon v-if="couponList.length > 0 && showCoupon" :price="orderMsg.Money" :list="couponList"
			:current="useCouponIds" @close="closeCouponHandler" :order="orderMsg" :numberPeople="orderMsg.peoples">
		</coupon>
	</view>
</template>

<script>
	import coupon from '@/components/coupon/index';
	export default {
		components: {
			coupon
		},
		data() {
			return {
				btnStyle: {
					height: "80rpx",
					lineHeight: "80rpx",
					borderRadius: "16rpx",
					background: "#111",
					color: "#FFF",
					fontSize: "28rpx",
					fontWeight: "600",
					width: '193rpx',
				},
				btnStyle2: {
					height: "80rpx",
					lineHeight: "80rpx",
					borderRadius: "16rpx",
					background: "#eee",
					color: "#000",
					fontSize: "28rpx",
					fontWeight: "600",
					width: '193rpx',
				},
				orderMsg: {
					DiscountMoney: 0, //优惠
					CouponAllotIds: '', //优惠券Id
					// #ifdef MP-DI
					OrderSource: 2,
					// #endif
					// #ifdef MP-AG
					OrderSource: 0,//0同业，1-直客网页，2-直客小程序
					// #endif
					OrderForm: 0, //订单来源
					//备注
					CustomerId: 0, //同行Id
					DirectCustomerId: 0, //直客Id

					OrderId: 0,//	订单ID 修改时传递
					OrderType: 1,//	订单类型 1接机 2送机 3包车
					OrderDate: '',//	预定日期 （送机、包车精确到分钟）
					Unit_Price: 0,//	单价
					Num: 1,//	数量
					Money: 0,//	总金额
					Sex: 1,//	性别 1男 2女
					SurName: '',//	姓
					Name: '',//	名
					Remark: '',//	下单备注
					AirportId: '',//机场ID （包车机场相关的不用传，包括下方机场航班相关）
					AirportTerminal: '',//	航厦
					AirLine: '',//	航空公司名称
					FlightNumber: '',//	航班号
					FlightTime: '',//	航班时间
					GetonAddress: '',//	上车地点
					GetoffAddress: '',//	下车地点
					ManNum: 1,//	成人人数
					ChildNum: '',//	儿童人数
					BabyNum: '',//	婴儿人数
					HandLuggageNum: '',//	手提行李数量
					RegisteredLuggageNum: '',//	托运行李数量
					ContactWay: '',//	联络方式 前端自定义 json格式存储 最后序列化成 string 传给我
					Mobile: '',//	联络电话
					ProductId: '',//	产品ID
					CarId: '',//
					PhoneCode: '86',//	国家区号
					peoples: 1,
					PeopleNum: 0,
					TotalPeopl: 0,
				},
				showtime: false,
				timeType: 0,
				paramsTime: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				showCountry: false,
				countrys: [],
				couponList: [],
				showCoupon: false,
				useCouponIds: [],
				currentCoupon: {
					discountMoney: 0
				},
				showPz: false,
				pzCoupon: null,
				searchObj: null,
				mainColor: '',
				activeStyle: '',
				dataList: {},
				customer: {},
				CreateBy: 0,
				submit: false,
				orderInfo: null,
				price: 0,
				busInfor: null,
				userInfo: null,
				radioList:[
                    {name: '男',value: 1},
                    {name: '女',value: 2},
                ],
				ErpOrderId: '',
			}
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: "订单支付预览",
			});
			this.userInfo = uni.getStorageSync("mall_UserInfo");
			this.customer = uni.getStorageSync("b2b_user")
			if (options.msg) {
				let msg = JSON.parse(options.msg)
				this.orderMsg = {
					...this.orderMsg,
					...msg,
				}
				this.orderMsg.TotalPeopl = this.orderMsg.PeopleNum*this.orderMsg.Num
			}
			
			if (options.CreateBy) {
				this.CreateBy = options.CreateBy
			}
			
			this.CalTotalPrice();
			this.GetCountryInfo()
			this.getPeoples()
		},
		created() {
			this.mainColor = this.$uiConfig.mainColor;
			this.activeStyle = `background:${this.mainColor};`;
		},
		mounted() {
			uni.getStorage({
				key: "busInfor",
				success: (res) => {
					this.busInfor = JSON.parse(res.data);
					if (this.busInfor.CarType<3) {
						this.orderMsg.FlightTime = this.busInfor.time;
					}
					this.initData()
				},
			});
		},
		methods: {
			radioChange(e){
                this.orderMsg.Sex = e
            },
			getPeoples(){
				this.orderMsg.peoples = Number(this.orderMsg.ManNum) + Number(this.orderMsg.ChildNum) +Number(this.orderMsg.BabyNum);
				if(this.useCouponIds&&this.useCouponIds.length>0){
					this.calcMaxCouponHandle()
				}
			},
			getWeek(date) {
				var weekArray = new Array("日", "一", "二", "三", "四", "五", "六");
				var week = weekArray[new Date(date).getDay()]; //注意此处必须是先new一个Date
				return "周" + week;
			},
			submitB2COrderHandler(OrderId) {
				let guestInfo = `成人x${this.orderMsg.ManNum}; `;
				if (this.orderMsg.ChildNum > 0) {
					guestInfo += `儿童${this.orderMsg.ChildNum}; `;
				}if (this.orderMsg.BabyNum > 0) {
					guestInfo += `婴儿${this.orderMsg.BabyNum}; `;
				}
				let text = '接机'
				let GoodsType = 13
				if (this.orderMsg.OrderType == 2) {
					text = '送机'	
					GoodsType = 14
				}else if(this.orderMsg.OrderType == 3){
					text = '包车'
					GoodsType = 12	
				}
				this.ErpOrderId = OrderId
				let msg = {
					SurName: this.orderMsg.SurName,
					Name: this.orderMsg.Name,
					ContactNumber: this.orderMsg.Mobile,
					Mailbox: this.orderMsg.ContactWay,
					GoodsId: this.orderMsg.ProductId,
					GoodsName: this.dataList.Name,
					GoodsPic: this.dataList.ImageList[0]? this.dataList.ImageList[0] : '',
					GoodsType: GoodsType,
					OrderMake: `${this.orderMsg.OrderDate}${text}；${guestInfo}`,
					TotalPrice: this.orderMsg.Money,
					PreferentialPrice: this.currentCoupon.discountMoney,
					ErpOrderId: OrderId,
					Country: 0,
					PlatformTax: 0,
					Income: 0,
					Refund: 0,
					MallBaseId: this.userInfo.MallBaseId,
					DOrderType:1
				};
				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);
					}
				},err=>{
					uni.showToast({
						title:err.message,
						icon:'none',
						duration:3000
					})
					this.submit = false;
				});
			},
			goPayHandler(item) {
				let OrderNo = item.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) {
						that.submit = false;
						uni.showToast({
							title: "支付成功",
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages/jiuzhai/paysuccess?PreferPrice=" +
								(that.orderMsg.Money-that.currentCoupon.discountMoney).toFixed(2) +
									"&isFrom=6",
							});
						}, 100);
					},
					fail: function(err) {
						that.submit = true;
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/pages/bus/orderdetails?orderId=" + that.ErpOrderId,
							});
						}, 100);
					},
				});
			},
			//日期格式化
			getformatDateStr(value) {
				var dt = new Date(value);
				let year = dt.getFullYear();
				let month = (dt.getMonth() + 1).toString().padStart(2, "0");
				let date = (dt.getDate()).toString().padStart(2, "0");
				return year + "-" + month + "-" + date;
			},
			// 获取价格
			getPrices() {
				uni.showLoading();
				this.loading = true
				this.apipost('CarSingle_post_GetTYCarSingleProductMonthPrice', {
					ProductId: this.orderMsg.ProductId,
					AirportId: this.orderMsg.AirportId,
					CarTypeId: this.orderMsg.CarId,
					Month: this.orderMsg.OrderDate,
				}, res => {
					if (res.resultCode == 1) { 
						uni.hideLoading()
						this.PricesList = res.data;
						this.getCurrentPrice();
					}
				})
			},
			getCurrentPrice(){
				let OrderDate = this.orderMsg.OrderDate.slice(0,10)
				this.PricesList.forEach(item=>{
					if(item.Date==OrderDate){
						this.orderMsg.Unit_Price = item.Price;
						this.CalTotalPrice();
					}
				})
			},
			//计算总价
			CalTotalPrice() {
				this.orderMsg.Money = this.getPrice(this.orderMsg.Unit_Price * this.orderMsg.Num)
				this.price = this.orderMsg.Money;
			},
			initData() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				this.submit = true
				this.apipost(
					"CarSingle_post_GetTYCarSingleProductInfo", {
						ProductId: this.orderMsg.ProductId,
					},
					res => {
						if (res.resultCode == 1) {
							this.submit = false
							uni.hideLoading();
							this.dataList = res.data;
							this.getPrices()
							// 人民币才能用优惠券
							if (this.dataList.CurrencyCode=='CNY') {
								this.getUserCouponList()
							}
						}
					}, err => {
						uni.hideLoading();
						uni.showToast({
							title: err.message,
							icon: 'none',
						})
					});
			},
			getPrice(price) {
				return Math.ceil(price);
			},
			goUrl() {
				uni.navigateTo({
					url: `/pages/bus/orderInfor?id=${this.orderMsg.ProductId}&orderInfor=${JSON.stringify(this.orderMsg)}`,
				})
			},
			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.CalTotalPrice();	
			},
			calcMaxCouponHandle() {
				if (this.couponList && this.couponList.length > 0) {
					let maxCouponId = 0
					let discount = 0
					const money = this.price

					this.couponList.forEach(x => {
						if (x.couponsType == 1 && x.denomination > discount && (this.orderMsg.peoples >= 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.orderMsg.peoples >= x.orderGuestNum || !x
									.orderGuestNum)&&this.price>=x.useCondition) {
								discount = disMoney
								maxCouponId = x.id
							}
						}
					})
					if (maxCouponId > 0) this.closeCouponHandler([maxCouponId])
					else this.closeCouponHandler(-1)
				}
			},
			getUserCouponList() {
				let couponParams = {
					"lineId": '', //线路ID
					"lineteamId": 0, //系列ID
					"userId": this.customer.accountId,
					"CouponsUseScope": 6, //包车
					"isExpansion": 0, //是否启动膨胀金1-是
					// #ifdef MP-DI
					"CustomerType": 1, //客户类型 0-同行，1-直客
					// #endif
					// #ifdef MP-AG
					"CustomerType": 0, //客户类型 0-同行，1-直客
					// #endif
					"TCID": '',
				}
				this.apipost(
					"coupon_post_GetUserCanUseCouponList", couponParams,
					(res) => {
						if (res.resultCode == 1) {
							this.couponList = res.data
							this.calcMaxCouponHandle()
						}
					},
					(err) => {
						console.log("coupon_post_GetUserCanUseCouponList_err", err);
					}
				);
			},
			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.pzCoupon = x
						else
							this.pzCoupon = x
						x.realDenomination = x.denomination
						x.denomination = x.expansionModel.denomination
					}
				})
				this.showPz = this.pzCoupon ? true : false
			},
			GetCountryInfo() {
				this.apipost("GetCountryInfo_post", {}, (r) => {
					for (let i = 0; i < r.data.phoneCountList.length; i++) {
						let Count = r.data.phoneCountList[i]
						let obj = {
							...Count,
							value: Count.ID,
							label: Count.Name,
						}
						this.countrys.push(obj)
					}
				})
			},
			changeDown(e) {
				uni.hideLoading()
				let i = [e]
				this.orderMsg.PhoneCode = this.countrys[i].PhoneCode
			},
			editNum(type) {
				if (type == 1) {
					if (this.orderMsg.Num > 1) {
						this.orderMsg.Num--;
					}
				} else {
					this.orderMsg.Num++;
				}
				this.orderMsg.TotalPeopl = this.orderMsg.Num * this.orderMsg.PeopleNum;
				this.CalTotalPrice();
				setTimeout(() => {
					this.calcMaxCouponHandle()	
				},200)
			},
			formatDate(str) {
				let temp = str.split("-");
				let day = day = str.slice(8,10)
				return `${temp[0]}年${temp[1]}月${day}日`;
			},
			//选择时间
			confirm(val) {
				uni.hideLoading()
				if(!this.timeType){
					this.busInfor.time = `${val.year}-${val.month}-${val.day} ${val.hour}:${val.minute}`
					this.orderMsg.OrderDate = this.busInfor.time
					this.getPrices()
					this.showtime = false
					uni.setStorage({
						key: "busInfor",
						data: JSON.stringify(this.busInfor)
					})
				}else{
					this.orderMsg.FlightTime = `${val.year}-${val.month}-${val.day} ${val.hour}:${val.minute}`
				}
			},
			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.orderMsg.OrderType<3){
					if(this.orderMsg.AirportTerminal==''){
						msg = '请输入航厦'
					}else if(this.orderMsg.AirLine==''){
						msg = '请输入航空公司'	
					}else if(this.orderMsg.FlightNumber==''){
						msg = '请输入航班号'
					}else if(this.orderMsg.FlightTime==''){
						msg = `请选择航班${this.orderMsg.OrderType==1?'抵达':'起飞'}时间`	
					}
				}
				if (this.orderMsg.SurName == '') {
					msg = '请输入姓'
				} else if (this.orderMsg.Name == '') {
					msg = '请输入名'
				} else if (this.orderMsg.Mobile == '') {
					msg = '请输入联系电话'
				} else if (this.orderMsg.Mobile && this.orderMsg.Mobile.length != 11) {
					msg = '请输入正确的电话号码'
				} else if (this.orderMsg.ContactWay == '' || !this.orderMsg.ContactWay) {
					msg = '请输入联系方式'
				} else if (this.orderMsg.ManNum == '' 
				|| !this.orderMsg.ManNum 
				|| this.orderMsg.ManNum <= 0) {
					msg = '请输入至少 1 个成人人数'
				}else if (this.orderMsg.peoples>this.orderMsg.TotalPeopl) {
					msg = `总人数不能大于${this.orderMsg.TotalPeopl}`
				}
				return msg
			},
			//去支付
			goPay() {
				const error = this.validate()
				if(error!=''){
					uni.showToast({
						icon:'none',
						title:error
					})
					return
				}
				// #ifdef MP-AG
					if(!this.CreateBy){
						uni.showToast({
						title: `服务人员为空，请联系服务人员！`,
						icon: "none",
						});
						return
					}
				// #endif
				this.submit = true;

				let CouponAllotIds = ''
				if(this.useCouponIds.length>0){
					CouponAllotIds = this.useCouponIds.join(',')
				}
				let Money = this.getPrice((this.orderMsg.Unit_Price * this.orderMsg.Num)-this.currentCoupon.discountMoney)
				let msg = {
					OrderId: this.orderMsg.OrderId,//	订单ID 修改时传递
					OrderType: this.orderMsg.OrderType,//	订单类型 1接机 2送机 3包车
					OrderDate: this.orderMsg.OrderDate,//	预定日期 （送机、包车精确到分钟）
					Unit_Price: this.orderMsg.Unit_Price,//	单价
					Num: this.orderMsg.Num,//	数量
					Money: Money,//	总金额
					Sex: this.orderMsg.Sex,//	性别 1男 2女
					SurName: this.orderMsg.SurName,//	姓
					Name: this.orderMsg.Name,//	名
					Remark: this.orderMsg.Remark,//	下单备注
					AirportId: this.orderMsg.AirportId,//机场ID （包车机场相关的不用传，包括下方机场航班相关）
					AirportTerminal: this.orderMsg.AirportTerminal,//	航厦
					AirLine: this.orderMsg.AirLine,//	航空公司名称
					FlightNumber: this.orderMsg.FlightNumber,//	航班号
					FlightTime: this.orderMsg.FlightTime,//	航班时间
					GetonAddress: this.orderMsg.GetonAddress,//	上车地点
					GetoffAddress: this.orderMsg.GetoffAddress,//	下车地点
					ManNum: this.orderMsg.ManNum,//	成人人数
					ChildNum: this.orderMsg.ChildNum,//	儿童人数
					BabyNum: this.orderMsg.BabyNum,//	婴儿人数
					HandLuggageNum: this.orderMsg.HandLuggageNum,//	手提行李数量
					RegisteredLuggageNum: this.orderMsg.RegisteredLuggageNum,//	托运行李数量
					ContactWay: this.orderMsg.ContactWay,//	联络方式 前端自定义 json格式存储 最后序列化成 string 传给我
					Mobile: this.orderMsg.Mobile,//	联络电话
					ProductId: this.orderMsg.ProductId,//	产品ID
					CarId: this.orderMsg.CarId,
					CustomerId: this.customer.customerId,//客户id
					CreateBy: this.CreateBy,//销售
					// #ifdef MP-DI
					OrderSource: 2,
					// #endif
					// #ifdef MP-AG
					OrderSource: 0,//0同业，1-直客网页，2-直客小程序
					// #endif
					OrderForm: 0,//1电脑端
					// #ifdef MP-DI
					ClientType: 2,//客户类型 1同业 2直客
					// #endif
					// #ifdef MP-AG
					ClientType: 1,
					// #endif
					DiscountsIds: CouponAllotIds,
					DiscountsMoney:  this.currentCoupon.discountMoney,
				};
				// #ifdef MP-DI
					if(this.customer.salesBaseInfo&&this.customer.salesBaseInfo.employeeId){
						msg.CreateBy = this.customer.salesBaseInfo.employeeId
					}
				// #endif
				console.log(msg,'------')
				this.apipost(
					"CarSingle_post_SetTYCarOrder",
					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.Id)
							// #endif
							// #ifdef MP-AG
								uni.showToast({
									title: '订单创建成功.',
									icon: 'none'
								})
								uni.redirectTo({
									url: `/pages/AggregateOrders/AggregateOrdersList?OrderTypeStr=5`,
								});
							// #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
						})
					}
				);
			},
		}
	}
</script>

<style>
	@import url("@/asset/css/flex.css");

	.hotel-order {
		color: #111111;
	}

	.opera-box {
		background-color: #FFF;
		padding: 20rpx 45rpx 40rpx 45rpx;
		/* 	position: fixed;
		bottom: 0;
		left: 0;
		right: 0; */
		z-index: 5;
	}

	.opera-box .box {
		height: 100rpx;
		background: #FFFFFF;
		box-shadow: 0px 10rpx 30rpx 0px rgba(36, 36, 36, 0.2);
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		padding: 0 10rpx 0 36rpx;
	}

	.opera-box .box .price {
		font-size: 40rpx;
		font-weight: 500;
		color: #D91818;
		margin-right: 20rpx;
	}

	.opera-box .box .sum-detail {
		font-size: 24rpx;
		flex: 1;
		font-weight: 500;
		color: #6E6E6E;
	}

	.hotel-order .red {
		color: #D91818 !important
	}

	.hotel-order .grey {
		color: #6E6E6E !important
	}

	.hotel-order .form {
		margin-top: 60rpx;
		padding: 0 19rpx 44rpx 19rpx;
		background: #fff;
		border-radius: 18rpx;
		margin: 28rpx 31rpx;
	}

	.hotel-order .form .form-items {
		display: flex;
		align-items: center;
		padding: 22rpx 15rpx;
		font-size: 28px;
		font-weight: 500;
		color: #303133;
	}
	.hotel-order .form .form-items .label {
		width: 130rpx;
		font-size: 28rpx;
		font-weight: 500;
		margin-right: 57rpx;
		flex-shrink: 0;
	}
	.hotel-order .form .form-items .label.active {
		width: 80rpx;
		margin-right: 10rpx;
	}

	.hotel-order .form .form-items .val {
		flex: 1;
	}

	.hotel-order .sheshi {
		margin-top: 50rpx;
	}

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

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

	.hotel-order .sheshi .she-content text {

		font-size: 24rpx;
		font-weight: 500;
		color: #4A4A4A;
		line-height: 40rpx;
		margin-right: 24rpx;
	}

	.hotel-order .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%;
	}

	.hotel-order .king {
		color: #DFBE6E !important;
	}

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

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

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

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

	.hotel-order .flex {
		display: flex;
		align-items: center;
	}

	.hotel-order .empty-block {
		height: 20rpx;
		background: #ECF1F4;
	}

	.hotel-order .flex-wrap {
		flex-wrap: wrap;
	}

	.hotel-order .o-head {
		padding: 20rpx 31rpx 46rpx 31rpx;
		background: #FFFFFF;
		box-shadow: 0px 2rpx 15rpx 0px rgba(76, 76, 76, 0.13);
		border-radius: 0px 0px 40rpx 40rpx;
	}

	.hotel-order .o-head .o-timer {
		background: #ECF1F4;
		border-radius: 18rpx;
		padding: 30rpx 30rpx;
	}

	.hotel-order .o-head .o-timer .time-item {
		font-weight: 800;
		font-size: 32rpx;
		color: #080A09;
	}

	.hotel-order .o-head .o-timer .time-item text {
		margin-left: 5rpx;
	}

	.hotel-order .o-head .o-timer .time-itemZhi {
		font-size: 32rpx;
		color: #080A09;
		padding: 0 10rpx;
	}

	.hotel-order .o-head .o-timer .timeline {
		width: 1rpx;
		height: 24rpx;
		background: #BCBCBC;
		background: #BCBCBC;
		margin-left: 18rpx;
		margin-right: 18rpx;
	}

	.hotel-order .o-head .o-timer .time-split {
		font-weight: 800;
		font-size: 32rpx;
		text-align: center;

	}

	.hotel-order .o-head .room-name {
		font-weight: 500;
		font-size: 28rpx;
		color: #1D1D20;
	}

	.hotel-order .o-head .room-remark {
		font-weight: 500;
		font-size: 28rpx;
		color: #1D1D20;
		flex-shrink: 0;
	}

	.hotel-order .o-head .rule {
		font-size: 22rpx;
		font-weight: 500;
		color: #6E6E6E;
		margin-top: 18rpx;
	}

	.hotel-order .big-title {
		position: relative;
	}

	.hotel-order .big-title::before {
		// display: block;
		// width: 71rpx;
		// height: 12rpx;
		// background: #DFBE6E;
		// border-radius: 4rpx;
		// content: ' ';

		// position: absolute;
		// left: 0;
		// bottom: 6rpx;
		// z-index: 1;
	}

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

	.o-head-title {
		font-weight: bold;
		font-size: 32rpx;
		color: #080A09;
		margin-bottom: 20rpx;
	}

	.o-detail {
		font-weight: 800;
		font-size: 32rpx;
		color: #B99846;
	}

	.room-dateil {
		margin-top: 3rpx;
	}

	.roomline {
		width: 1rpx;
		height: 24rpx;
		background: #BCBCBC;
		margin-left: 14rpx;
		margin-right: 14rpx;
	}

	.roomPrice {
		font-weight: 500;
		font-size: 28rpx;
		color: #1D1D20;
		flex-shrink: 0;
	}

	.visaProductTextBox {
		padding: 29rpx 0 21rpx 0;
		font-family: PingFang SC;
	}

	.visaProductTitle {
		font-weight: 800;
		font-size: 32rpx;
	}

	.visaProductTextL {
		font-size: 35rpx;
		font-weight: bold;
	}

	.visaProductTextR {
		font-size: 20rpx;
		margin-left: 24rpx;
	}

	.visaProduct_rColor {
		color: #FF3166;
	}

	.addPnum {
		padding: 9rpx 10rpx;
	}

	.addPnumL {
		margin-right: 17rpx;
	}

	.addPnumR {
		margin-left: 17rpx;
	}

	.visaProductTetx {
		font-weight: bold;
		font-size: 28rpx;
		color: #080A09;
	}

	.form-itemsTime {
		// font-weight: bold;
		// font-size: 28rpx;
		// color: #080A09;
	}

	.form-itemsL text {
		font-weight: bold;
		font-size: 28rpx;
		color: #B99846;
		margin-right: 26rpx;
	}

	.CouponBox {
		margin: 0 31rpx 32rpx 31rpx;
		padding: 18rpx 34rpx 35rpx 34rpx;
		background: #fff;
		border-radius: 18rpx;
	}

	.PriceBox {
		margin: 0 31rpx 32rpx 31rpx;
		padding: 18rpx 34rpx 35rpx 34rpx;
		background: #fff;
		border-radius: 18rpx;
	}

	.PriceZaiXian {
		border-bottom: 1rpx solid #F0F0F0;
	}

	.PriceZaiXian .label {
		font-weight: bold;
	}

	.hotel-order .form .form-items.PriceZaiXian {
		padding: 0;
		padding-top: 15rpx;
		padding-bottom: 20rpx;
	}

	.hotel-order .form .form-items.PriceMinXi {
		padding: 0;
		padding-top: 20rpx;
		padding-bottom: 30rpx;
	}

	.PriceTole {
		color: #BFB9B9;
	}

	.buyTispBox {
		border-radius: 18rpx;
		background: #fff;
		margin: 0 31rpx 27rpx 31rpx;
		padding: 37rpx 34rpx 47rpx 34rpx;
	}

	.buyTispBox .big-title {
		font-weight: 800;
		font-size: 32rpx;
		color: #080A09;
		margin-bottom: 37rpx;
	}

	.buyTispBox .rule {
		font-weight: 500;
		font-size: 24rpx;
		color: #1D1D20;
		line-height: 42rpx;
	}

	.LastNameBox view {
		/*margin-bottom: 20rpx;*/
	}

	.LastNameBox view:last-child {
		margin-bottom: 0;
	}

	.jz_TextArea {
		height: 50px;
		margin-bottom: 10px;
		width: auto;
		border: 1px solid #dfddd8;
		border-radius: 4px;
		margin: 0 10rpx;
		padding: 20rpx;
	}
	.bus-radio:last-child{
        margin-left: 137rpx;
    }
    .bus-radioLeft{
        margin-right: 23rpx;
        // font-weight: bold;
        font-size:28rpx;
        // color: #080A09;
    }
    .bus-radioRight{
        width: 29rpx;
        height: 28rpx;
        border-radius: 50%;
        border: 2rpx solid #BCBCBC;
    }
    .bus-radioRight view{
        width: 18rpx;
        height: 17rpx;
        background: #B99846;
        border-radius: 50%;
    }
    .bus-radioRight.active{
        border-color: #B99846;
    }
</style>