<style scoped>
	@import url("@/asset/css/flex.css");
	.jz_SureOrder {
  position: relative;
}
.jz_SureTop {
  width: 100%;
  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_SureDfk {
  color: #111111;
  font-size: 40rpx;
  font-weight: bold;
  margin-left: 26rpx;
}
.jz_SureContent {
  width: 90%;
  margin: auto;
  min-height: 100px;
}
.jz_SureCommodity {
  padding: 30rpx 0;
  display: flex;
  border-bottom: 1px solid #e6e6e6;
}
.jzSureMoney {
  color: #333333;
  font-weight: bold;
  font-size: 20rpx;
}
.jz_SuOrder_img {
  width: 100rpx;
  height: 100rpx;
  border-radius: 20rpx;
  overflow: hidden;
  flex-shrink: 0;
}
.jz_SuOrder_img img {
  width: 100%;
  height: 100%;
}
.jz_OrderNum {
  color: #8f8f90;
  font-size: 24rpx;
  margin-right: 50rpx;
}
.jz_GoodName {
  color: #333333;
  font-size: 28rpx;
  width: 70%;
  margin-left: 15px;
  font-weight: bold;
}
.jz_OrderBold {
  color: #08090e;
  font-weight: bold;
}
.jz_PayDiv {
  position: absolute;
  width: 90%;
  margin: auto;
  bottom: 30rpx;
  display: flex;
  justify-content: space-between;
}
.jz_CancleBtn {
  width: 310rpx;
  height: 80rpx;
  border: 1px solid #111111;
  border-radius: 16rpx;
  color: #111111;
  font-weight: bold;
  text-align: center;
  line-height: 80rpx;
  font-size: 28rpx;
}

.jz_Reserve {
  padding-bottom: 120rpx;
}
.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_OrderDiv {
			position: fixed;
			width: 90%;
			height: 100rpx;
			background-color: #fff;
			margin: auto;
			bottom: 20px;
			padding: 20rpx;
			left: 40rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-shadow: 0px 10px 30px 0px rgba(36, 36, 36, 0.2);
			border-radius: 16px;
			z-index: 999;
		} */
.jz_orderbox {
  position: fixed;
  background-color: #fff;
  bottom: 0;
  width: 100vw;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0px 0rpx 50rpx 0px rgba(76, 76, 76, 0.13);
  z-index: 99;
  justify-content: flex-end;
  padding: 20rpx 30rpx;
}
.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 {
  min-width: 170rpx;
  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: 60rpx;
  padding: 0 45rpx;
}
.jz_form .form-items {
  margin-bottom: 30rpx;
  display: flex;
  align-items: center;
  padding-bottom: 30rpx;
  border-bottom: 1px solid #f5f5f5;
  font-size: 28px;
  font-weight: 500;
}
.jz_form .form-items .label {
  font-size: 28rpx;
  font-weight: 600;
  margin-right: 60rpx;
  flex-shrink: 0;
  width: 115rpx;
}
.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-item:last-child{
			text-align: right;
		} */
.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 text {
  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_Reserve .jz_SureVal {
  flex: 1;
  font-size: 28rpx;
  font-weight: 500;
  width: 100%;
}
.jz_MyGuestList .label {
  width: 115rpx;
}
.jz_MyGuestList {
  margin-top: 40rpx;
}
/deep/.showModalInfo .u-drawer-bottom{
	background-color: rgba(23,23,23,0) !important;
}
</style>
<template>
	<view class="jz_Reserve" v-if="orderData&&orderData.model">
		<view class="jz_ReserTop">
			<view class="orderStatusBox column" style="margin-bottom: 30rpx;justify-content: space-between">
				<view class="row-sbas-n">
					<view class="row items-center">
						<u-icon customPrefix="iconfont" name="icondaizhifu-" size="52" color="#DFBE6E" v-if="orderStatus.code == 0"></u-icon>
						<u-icon customPrefix="iconfont" name="iconquxiao" size="52" color="#f26c6c" v-if="orderStatus.code == -1"></u-icon>
						<u-icon customPrefix="iconfont" name="iconshenhezhong" size="52" color="#86d9a5" v-if="orderStatus.code == -2"></u-icon>
						<u-icon customPrefix="iconfont" name="iconzhengchang" size="52" color="#111" v-if="orderStatus.code == 1"></u-icon>
						<text style="
							margin-left: 26rpx;
							font-size: 40rpx;
							font-weight: 600;
							color: #111;
						">
						{{ orderStatus.text }}
						</text>
					</view>
					<!-- #ifdef MP-AG-->
					<u-count-down :showDays="false" :showHours="false" :timestamp="remainingSeconds" 
							@change="changeSeconds"
							v-if="orderData.model.OrderState==2&&b2b_user.isGuideOrLeader==1&&remainingSeconds>0" 
							color="#000" separator-color="#000" :show-days="false" bg-color="transparent"></u-count-down>
					<!-- #endif -->
					<!-- #ifdef MP-DI -->
					<u-count-down :showDays="false" :showHours="false" :timestamp="remainingSeconds" 
							@change="changeSeconds"
							v-if="orderData.OrderStatus==1&&remainingSeconds>0" 
							color="#000" separator-color="#000" :show-days="false" bg-color="transparent"></u-count-down>
					<!-- #endif -->
				</view>
				<!-- #ifdef MP-AG -->
				<view class="timecontent q-mt-sm" v-if="b2b_user.isGuideOrLeader==1&&(orderData.model.OrderState==2||orderData.model.OrderState==1||orderData.model.OrderState==4)">
						<view v-if="orderData.model.OrderState==2&&b2b_user.isGuideOrLeader==1&&remainingSeconds>0">
							<view class="row">
								<text>请您于{{dielineTime}}前支付：¥</text>
								<text class="bold">{{(orderData.model.PreferPrice-orderData.model.DiscountMoney-orderData.model.RedEnvelopeMoney).toFixed(2)}}</text>
							</view>
							<view class="small">
								完成支付才能锁定线路</view>
						</view>
						<view class="small" v-else-if="orderData.model.OrderState==4">
							取消原因：用户超时未付款，自动取消
						</view>
						<view class="small" v-else>
							感谢您的预定，服务专员将会持续为您提供服务
						</view>
					</view>
				</view>
				<!-- #endif -->
				<!-- #ifdef MP-DI -->
					<view v-if="(orderData.model.OrderState==2||orderData.model.OrderState==3)&&remainingSeconds>0">
						<view class="row">
							<text>请您于{{dielineTime}}前支付：¥</text>
							<text class="bold">{{(orderData.model.PreferPrice-orderData.model.DiscountMoney-orderData.model.RedEnvelopeMoney).toFixed(2)}}</text>
						</view>
						<view class="small">
							完成支付才能{{orderData.model.OrderState==2?'锁定':'候补'}}线路</view>
					</view>
					<view class="small" v-else-if="orderData.model.OrderState==4">
						取消原因：用户超时未付款，自动取消
					</view>
					<view class="small" v-else>
						感谢您的预定，服务专员将会持续为您提供服务
					</view>
				</view>
				<!-- #endif -->
				
			<view style="margin-bottom: 30rpx" v-if="
          orderData.model.RejectRemark && orderData.model.RejectRemark != ''
        ">
				<u-alert-tips type="error" title="订单取消失败" :description="orderData.model.RejectRemark"></u-alert-tips>
			</view>
			<view class="o-timer flex">
				<view class="time-item">{{ getDate(orderData.model.StartDate) }}
					{{ getWeek(orderData.model.StartDate) }}</view>
				<view class="time-split">
					<view>{{ orderData.model.DayNum }}天</view>
				</view>
				<view class="time-item" style="font-size: 26rpx; font-weight: 500; flex: 1">
					<text v-if="orderData.model.ManNum > 0">{{ orderData.model.ManNum }}成人</text>
					<text v-if="orderData.model.ChirdNum > 0">{{ orderData.model.ChirdNum }}儿童</text>
					<text v-if="orderData.model.BabyNum > 0">{{ orderData.model.BabyNum }}婴儿</text>
				</view>
				<view class="update">
					<!-- <text style="margin-right: 8rpx;">修改</text>
					<u-icon name="arrow" size="20" /> -->
				</view>
			</view>
			<view class="jz_ReserTitle" @click="goJzDetail">
				{{ orderData.model.Title }}
			</view>
			<view class="jz_ReserIn" style="margin: 33rpx 0 18rpx 0">
				<!-- {{currentPriceInfo.startCityName}}出发 {{currentPriceInfo.startDate}} -->
				{{ orderData.model.LtName }}
			</view>
			<view class="big-title" v-if="orderData.model.StartCityName">
				<text>{{ orderData.model.StartCityName }}出发</text>
			</view>
			<view class="jz_ReseQue">
				<img src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/CustomizedCar/zuanshi.png" />即时确认：本产品付款后可快速确认，放心期待您的旅行
			</view>
		</view>

		<view class="jz_form">
			<view class="form-items">
				<view class="label">订单编号</view>
				<view class="jz_SureVal">
					{{ orderData.model.OrderId }}
				</view>
			</view>
			<view class="form-items">
				<view class="label">下单日期</view>
				<view class="jz_SureVal">
					{{ orderData.model.CreateDate.replace("T", " ") }}
				</view>
			</view>
			<!-- #ifdef MP-DI -->
				<view class="form-items">
					<view class="label">联系人</view>
					<view class="jz_SureVal">
						{{ orderData.model.ContactName+'/'+orderData.model.ContactMobile }}
					</view>
				</view>
			<!-- #endif -->
			<!-- <view class="form-items">
				<view class="label">下单日期</view>
				<view class="jz_SureVal">
					{{ orderData.model.CreateDate.replace("T", " ") }}
				</view>
			</view> -->
		</view>
		<view class="empty-block"></view>
		<template v-if="orderData.model&&orderData.model.GuestList.length>0">
			<view class="jz_form jz_MyGuestList" v-for="(subItem, subIndex) in orderData.model.GuestList" :key="subIndex">
				<view style="margin: 10rpx 0 20rpx 0"> 游客{{ subIndex + 1 }} </view>
				<view class="form-items">
					<view class="label">游客姓名</view>
					<view class="jz_SureVal">{{ subItem.SurName }}{{ subItem.Name }}</view>
				</view>
				<view class="form-items">
					<view class="label">联系电话</view>
					<view class="jz_SureVal">{{ subItem.MobilePhone }}</view>
				</view>
				<view class="form-items">
					<view class="label">身份证</view>
					<view class="jz_SureVal">{{ subItem.IdCard }}</view>
				</view>
				<view class="form-items">
					<view class="label">学生</view>
					<view class="jz_SureVal">
						{{ subItem.IsHightSchool == 1 ? "是" : "否" }}
					</view>
				</view>
			</view>
			<view class="empty-block"></view>
		</template>
		<view class="jz_form" v-if="orderData.model.Remarks">
			<view class="form-items" style="border-bottom: 0">
				<view class="label">备注</view>
				<view class="jz_SureVal">{{ orderData.model.Remarks }}</view>
			</view>
		</view>
		<view class="empty-block"></view>
		<cancelProgress v-if="orderData.OrderStatus==5" :datas="orderData"></cancelProgress>
		<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">{{ orderData.model.GuestNum }}人</text>
						<text class="red">￥{{ orderData.model.PreferPrice }}</text>
					</view>
				</view>
				<view class="form-items" style="border-bottom: none">
					<view class="label"> 明细 </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">{{ orderData.model.ManNum }}人 × ¥{{
              orderData.model.Unit_Price
            }}</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="orderData.model.ChirdNeedBedNum > 0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">儿童(占床)</text>
					</view>
					<view style="text-align: right">{{ orderData.model.ChirdNeedBedNum }}人 × ¥{{
              orderData.model.Unit_Price +
              (orderData.modelPrice.ChildNeedPrice
                ? orderData.modelPrice.ChildNeedPrice
                : 0)
            }}</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="orderData.model.ChirdNum - orderData.model.ChirdNeedBedNum > 0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">儿童(不占床)</text>
					</view>
					<view style="text-align: right">{{ orderData.model.ChirdNum - orderData.model.ChirdNeedBedNum }}人
						× ¥{{
              orderData.model.Unit_Price -
              (orderData.modelPrice.ChildNoNeedPrice
                ? orderData.modelPrice.ChildNoNeedPrice
                : 0)
            }}</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="orderData.model.BabyNum > 0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">婴儿</text>
					</view>
					<view style="text-align: right">
						{{ orderData.model.BabyNum }}人 × ¥{{
              orderData.modelPrice.BabyPrice
                ? orderData.modelPrice.BabyPrice
                : 0
            }}</view>
				</view>
				<view class="flex f12 grey" style="margin-bottom: 40rpx" :key="index" v-if="
            orderData.model.ChirdNum > 0 &&
            orderData.modelPrice.BabyChargePrice &&
            orderData.modelPrice.BabyChargePrice > 0
          ">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">儿童(附加费)</text>
					</view>
					<view style="text-align: right">
						{{ orderData.model.ChirdNum }}人 × ¥{{
              orderData.modelPrice.BabyChargePrice
            }}</view>
				</view>

				<view class="flex f12" :style="{'color':mainColor+' !important'}" style="margin-bottom: 40rpx" v-if="orderData.model.DiscountMoney&&(orderData.model.DiscountMoney-orderData.model.DisValue)>0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">优惠金额</text>
					</view>
					<view style="text-align: right">
						-{{ orderData.model.DiscountMoney-orderData.model.DisValue}} </view>
				</view>
				<view class="flex f12" :style="{'color':mainColor+' !important'}" style="margin-bottom: 40rpx" v-if="orderData.model.RedEnvelopeMoney>0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">幸福存折</text>
					</view>
					<view style="text-align: right">
						-{{ orderData.model.RedEnvelopeMoney}} </view>
				</view>
				<view class="flex f12" :style="{'color':mainColor+' !important'}" style="margin-bottom: 40rpx" v-if="orderData.model.DisValue>0">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">VIP专享优惠</text>
					</view>
					<view style="text-align: right">
						-{{ orderData.model.DisValue}} </view>
				</view>
				<view class="flex f12" style="margin-bottom: 40rpx">
					<view style="flex: 1">
						<text style="margin-right: 30rpx">合计应收</text>
					</view>
					<view style="text-align: right;color: #ff3166;font-size:32rpx;font-weight: bold;">
						{{(orderData.model.PreferPrice-orderData.model.DiscountMoney-orderData.model.RedEnvelopeMoney).toFixed(2)}}
					</view>
				</view>
			</view>
		</view>
		<view class="empty-block"></view>
		<view style="padding: 50rpx 40rpx" v-if="Refund > 0 && orderStatus.code == -1">
			<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">{{ orderData.model.GuestNum }}人</text>
						<text class="red">￥{{ orderData.model.PreferPrice }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="jz_orderbox flex">
			<view style="display: flex" v-if="showPayBtn">
				<!-- #ifdef MP-DI -->
					<button v-if="orderData.OrderStatus==1||orderData.OrderStatus==2" class="jz_OrderReNow" @click="goCancelZK" 
					style="background: #fff; color: #111; border: 1px solid #111"
					:disabled="submitCancel"
					:loading="submitCancel">
						取消
					</button>
					<button v-if="orderData.OrderStatus==1" class="jz_OrderReNow" 
					style="margin-left: 20rpx;" 
					@click="submitGetCodeByOrderNo" :disabled="submit" :loading="submit">
						立即支付
					</button> 
				<!-- #endif -->
				<!-- #ifdef MP-AG -->
					<button v-if="((orderData.model.OrderState==2&&b2b_user.isGuideOrLeader==1&&orderData.model.Income==0)||(orderData.model.OrderState==2&&b2b_user.isGuideOrLeader!=1))" class="jz_OrderReNow" @click="goCancel" 
					style="background: #fff; color: #111; border: 1px solid #111"
					:disabled="submitCancel"
					:loading="submitCancel">
						取消
						<!-- <text v-if="!submitCancel">取消</text>
						<u-loading v-if="submitCancel" size="32" color="#111"></u-loading> -->
					</button>
					<button v-if="orderData.model.OrderState==2&&b2b_user.isGuideOrLeader==1&&orderData.model.Income==0" class="jz_OrderReNow" 
					style="margin-left: 20rpx;" 
					@click="submitGetCodeByOrderNo" :disabled="submit" :loading="submit">
						立即支付
					</button> 
				<!-- #endif -->
			</view>
			<view style="display: flex; margin-left: 30rpx">
			</view>
		</view>
		<coupons v-if="showCoupons" :coupon-message="couponMessage" @goLook="()=>showCoupons=false" @closeBtn="()=>showCoupons=false"></coupons>
		<cancelPrompt v-if="showModal"
		:showModal="showModal" 
		@cancel="cancelModal" 
		:orderNo="orderData.OrderNo"></cancelPrompt>
	</view>
</template>

<script>
</script>

<script>
	import coupons from "@/components/coupons/coupons.vue";
	import cancelPrompt from '@/components/cancelPrompt/cancelPrompt.vue'
	import cancelProgress from '@/components/cancelPrompt/cancelProgress.vue'
	export default {
		components: {coupons,cancelPrompt,cancelProgress},
		data() {
			return {
				pageTitle: "订单详情",
				msg: {
					pageIndex: 1,
					pageSize: 15,
					MiniAppUserId: 0,
				},
				orderData: null,
				orderStatus: {
					code: 0,
					text: '',
				},
				submit: false,
				submitCancel: false,
				showPayBtn: true,
				orderInfo:null,
				OrderNo: '',
				mainColor:'',
				orderId: 0,
				showCoupons:false,
				couponMessage:[],
				showModal: false,
				b2b_user: {},
				remainingSeconds: null,
				isExpired: false,
				countdownInterval: null,
				currentTime: Date.now(),
				endts:0,
				dielineTime: '',
			};
		},
		created() {},
		onLoad(option) {
			this.b2b_user = uni.getStorageSync("b2b_user");
			if (option.orderData) {
				this.orderData = JSON.parse(decodeURIComponent(option.orderData));
				this.orderId = this.orderData.model.OrderId
			} else if(option.OrderNo){
				this.OrderNo = option.OrderNo
				this.getOrderInfoHandler(this.OrderNo)
			} else if (option.orderId) {
				this.orderId = option.orderId
				this.initOrderInfo();
			}
			this.mainColor = this.$uiConfig.mainColor
			if (uni.getStorageSync('coupons')) {
				this.showCoupons = true;
				this.couponMessage = uni.getStorageSync('coupons');
			}
		},
		methods: {
			changeSeconds(seconds) {
				if(seconds<=0) {
					// #ifdef MP-AG
					this.orderData.model.OrderState = 4
					// #endif
					// #ifdef MP-DI
					this.orderData.OrderStatus = 4
					// #endif
					this.orderStatus.code = -1;
					this.orderStatus.text = "已取消";
					this.isExpired = true
				}else{
					const now = Date.now();
					const customStr = this.orderData.SelectStartTime
					const [date, time] = customStr.split(' ')
					const [year, month, day] = date.split('-')
					const [hours, minutes, seconds] = time.split(':')
					const parsedDate = new Date(year, month-1, day, hours, minutes, seconds)
					this.orderTime = parsedDate.getTime()

					const diff = this.orderTime + 30 * 60 * 1000 - now; 
					let remainingSeconds = Math.max(diff, 0); // 确保不出现负数
					this.remainingSeconds = Math.floor(remainingSeconds/1000)

					let endTime = new Date(this.orderData.SelectStartTime)
					endTime.setMinutes(endTime.getMinutes() + 30)
					this.endts = this.remainingSeconds
					this.dielineTime = `${endTime.getHours()}时${endTime.getMinutes()}分`
				}
			},
			getOrderTime(){
				const now = Date.now();
				const customStr = this.orderData.SelectStartTime
				const [date, time] = customStr.split(' ')
				const [year, month, day] = date.split('-')
				const [hours, minutes, seconds] = time.split(':')
				const parsedDate = new Date(year, month-1, day, hours, minutes, seconds)
				this.orderTime = parsedDate.getTime()
				
				const diff = this.orderTime + 30 * 60 * 1000 - now; 
				let remainingSeconds = Math.max(diff, 0); // 确保不出现负数
				this.remainingSeconds = Math.floor(remainingSeconds/1000)
				this.changeSeconds(this.remainingSeconds)
			},
			cancelModal(){
				this.showModal = false
			},
			submitGetCodeByOrderNo() {
				if (this.submit || this.submitCancel) return;
				this.submit = true
				this.apipost("GetCodeByOrderNo_post", {
					OrderNo: this.OrderNo,
					MallBaseId: uni.getStorageSync("mall_UserInfo").MallBaseId,
					OpenId: uni.getStorageSync("mall_UserInfo").OpenId,
				}, (res) => {
					if (res.resultCode == 1) {
						this.orderInfo =JSON.parse(res.data.sPayInfo)
						this.goPayHandler();
					} else {
						uni.showToast({
							title:res.message,
							icon:'none',
							duration:3000
						})
						this.submit = false;
					}
				},e=>{
					uni.showToast({
						title:'无法发起支付，请稍后',
						icon:'none',
						duration:3000
					})
					this.submit=false
				});
			},
			goPayHandler() {
				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.orderData.model.PreferPrice-that.orderData.model.DiscountMoney).toFixed(2) +
									"&isFrom=1",
							});
						}, 100);
					},
					fail: function(err) {
						console.log("fail:", err);
						that.submit = false;
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
					},
				});
			}, 
			getOrderInfoHandler(OrderNo){
				this.apipost("GetDetailsByOrderNo_post",{OrderNo},res=>{
					if(res.resultCode==1){
						this.OrderNo = res.data.OrderNo
						this.orderId = res.data.ErpOrderId
						this.orderData = {
							...res.data
						}
						this.getOrderTime()
						this.initOrderInfo();
						this.formatStatus(
							this.orderData.OrderStatus,
							null,
							null
						);
					}else{
						
					}
				})
			},
			getOrderInfoByIdAndType(){
				const parameter={ErpOrderId:this.orderId,OrderTypeStr:'DMC'}
				this.apipost("GetDetailsByErpOrderId_post",parameter,res=>{
					if(res.resultCode==1){
						this.orderData = {
							...this.orderData,
							...res.data
						}
						
						this.OrderNo = res.data.OrderNo
						// #ifdef MP-DI
						this.formatStatus(
							this.orderData.OrderStatus,
							null,
							null
						);
						// #endif
						// #ifdef MP-AG
						if (this.b2b_user.isGuideOrLeader==1&&this.orderData.OrderStatus==1&&this.orderData.SelectStartTime) {
							this.getOrderTime()
						};
						this.formatStatus(
							this.orderData.model.OrderState,
							this.orderData.IsChargeLossOrders,
							this.orderData.IsApplyForCancel
						);
						// #endif
							
					}else{
						
					}
				})
			},
			//跳转至详情
			goJzDetail() {
				let model = this.orderData.model;
				uni.navigateTo({
					url: "/pages/jiuzhai/jz_LineDetail?tcid=" + model.TCID 
				});
			},
			goback() {
				uni.navigateBack({
					delta: 1,
				});
			},
			goCancel() {
				let that = this
				if (this.submit || this.submitCancel) return;
				wx.showModal({
					title: '提示',
					content: '确定取消订单？',
					success: (tip) => {
						if (tip.confirm) {
							that.submitCancel = true;
							//未付款-调用后台取消
							if (that.orderData.model.OrderState == 2 || that.orderData.model.OrderState == 3) {
								that.apipost(
									"sellorder_post_B2BRemoveOrder", {
										ID: that.orderData.model.OrderId,
									},
									(res) => {
										if (res.resultCode == 1) {
											uni.showToast({
												title: "操作成功",
												icon: "success",
											});
											that.initOrderInfo();
											that.submitCancel = false
											// uni.navigateTo({
											// 	url: "/pages/AggregateOrders/AggregateOrdersList",
											// }); 
										}
										
									},
									(err) => {
										uni.showToast({
											title: err.message,
											icon: "none",
										});
										that.submitCancel = false
									}
								);
							} else {
								that.submitCancel = true
								let msg = {
									OrderId: that.orderData.model.OrderId,
									UserId: uni.getStorageSync("mall_UserInfo").UserId,
								};
								//已付款取消申请
								that.apipost(
									"sellorder_post_AppletUserCancelOrder",
									msg,
									(res) => {
										that.submitCancel = false
										if (res.resultCode == 1) {
											uni.showToast({
												title: "操作成功",
												icon: "success",
											});
											that.initOrderInfo();
											// uni.navigateTo({
											// 	url: "/pages/AggregateOrders/AggregateOrdersList",
											// });  
										}
									},
									(err) => {
										uni.showToast({
											title: err.message,
											icon: "none",
										});
										that.submitCancel = false
									}
								);
							}
						}
					}
				})
				
			},
			goCancelZK() {
				let that = this
				if(this.orderData.OrderStatus==2){
					return this.showModal = true
				}
				if (this.submit || this.submitCancel) return;
				wx.showModal({
					title: '提示',
					content: '确定取消订单？',
					success: (tip) => {
						if (tip.confirm) {
							that.submitCancel = true;
							this.apipost(
								"GetCancelOrder_post", {
									OrderNo: that.OrderNo
								},
								(res) => {
									if (res.resultCode == 1) {
										uni.showToast({
											title: "操作成功",
											icon: "success",
										});
										this.getOrderInfoHandler(this.OrderNo)
										// uni.navigateTo({
										// 	url: "/pages/AggregateOrders/AggregateOrdersList",
										// });  
									}
									that.submitCancel = false
								},
								(err) => {
									uni.showToast({
										title: err.message,
										icon: "none",
									});
									that.submitCancel = false
								}
							);
						}
					}
				})
				
			},
			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] + "日";
				}
			},
			initOrderInfo() {
				let msg = {
					ID: this.orderId,
					IsGetGuest: 1,
				};
				this.apipost(
					"sellorder_post_GetOrderEntity",
					msg,
					(res) => {
						if (res.resultCode == 1) {
							this.orderData = {
								...this.orderData,
								...res.data
							};
							// #ifdef MP-AG
								this.formatStatus(
									res.data.model.OrderState,
									res.data.model.IsChargeLossOrders,
									res.data.model.IsApplyForCancel
								);
								if(this.b2b_user.isGuideOrLeader==1&&res.data.model.OrderState==2){
									this.getOrderInfoByIdAndType()
								}
							// #endif
							// #ifdef MP-DI
								if(!this.OrderNo||!this.orderId){
									this.getOrderInfoByIdAndType()
								}
							// #endif
						}
					},
					(e) => {
						this.orderData = {
							result: -1,
						};
					}
				);
			},
			formatStatus(status, loss, isCancel) {
				// #ifdef MP-DI
					if(status==1){
						this.orderStatus.code = 0;
						this.orderStatus.text = "待付款";
						this.showPayBtn = true;
					}else if(status==2){
						this.orderStatus.code = 1;
						this.orderStatus.text = "待出行";
						this.showPayBtn = true;	
					}else if(status==3){
						this.orderStatus.code = 1;
						this.orderStatus.text = "已完成";
						this.showPayBtn = false;	
					}else if(status==4){
						this.orderStatus.code = -1;
						this.orderStatus.text = "已取消";
						this.showPayBtn = false;	
					}else if(status==5&&this.orderData.AfterSalesOrderStatus==1){
						this.orderStatus.code = -2;
						this.orderStatus.text = "等待审批";
						this.showPayBtn = false;	
					}else if(status==5&&this.orderData.AfterSalesOrderStatus==2){
						this.orderStatus.code = 0;
						this.orderStatus.text = "退款中";
						this.showPayBtn = false;	
					}else if(status==5&&this.orderData.AfterSalesOrderStatus==3){
						this.orderStatus.code = -1;
						this.orderStatus.text = "已原路退回";
						this.showPayBtn = false;	
					}
				// #endif
				// #ifdef MP-AG
					loss = loss ? loss : -1;
					//1、已申请；!=1未申请
					if (loss == 1 || status == 4) {
						this.orderStatus.code = -1;
						this.orderStatus.text = "已取消";
						this.showPayBtn = false;
					} else if (status == 2 && isCancel != 1) {
						this.orderStatus.code = 0;
						this.orderStatus.text = "待付款";
						this.showPayBtn = true;
					} else if (status == 3 && isCancel != 1) {
						this.orderStatus.code = 0;
						this.orderStatus.text = "候补中";
						this.showPayBtn = true;
					} else if (status == 2 && isCancel == 1) {
						this.orderStatus.code = -2;
						this.orderStatus.text = "审核中";
						this.showPayBtn = false;
					} else if (status == 1) {
						this.orderStatus.code = 1;
						this.orderStatus.text = "正常";
						this.showPayBtn = false;
					}
				// #endif
			},
			// #ifdef MP-WEIXIN
			goFukuan() {
				if (this.submit || this.submitCancel) return;
				var that = this;
				var tempData = uni.getStorageSync("basedata");
				var tempObj = [];
				if (tempData && tempData.mall && tempData.mall.wechatmessage) {
					tempObj = tempData.mall.wechatmessage;
				}
				var 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.goZhifu();
					},
				});
			},
			//支付
			goZhifu() {
				this.submit = true;
				let url = "/api/WeChatPay/GetTravlePayInfo";
				let GoodsName = this.orderData.model.Title;
				GoodsName = GoodsName.slice(0, 10);
				this.request2({
						url: url,
						data: {
							OrderId: this.orderData.model.OrderId,
							GoodsName: GoodsName,
							OrderPayType: 1,
							OpenId: uni.getStorageSync("mall_UserInfo").OpenId,
						},
					},
					(res) => {
						try {
							let orderInfo = JSON.parse(res.data);
							console.log(orderInfo);
							this.goPay(orderInfo);
						} catch (e) {
							uni.showToast({
								title: '无法正常拉取微信支付，你可以稍后重试或联系销售人员线下转款',
								icon: 'none'
							})
							setTimeout(() => {
								this.submit = false;
							}, 2000);
						}

					}
				);
			},
			goPay(orderInfo) {
				let that = this;
				uni.requestPayment({
					provider: "wxpay",
					timeStamp: orderInfo.timeStamp,
					nonceStr: orderInfo.nonceStr,
					package: orderInfo.package,
					signType: orderInfo.signType,
					paySign: orderInfo.sign,
					success: function(res) {
						console.log("success", res);
						uni.showToast({
							title: "支付成功",
						});
						that.submit = false;
						//todo
						that.initOrderInfo(that.orderData.model.OrderId);
					},
					fail: function(err) {
						console.log("fail:", err);
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
						that.submit = false;
						that.initOrderInfo(that.orderData.model.OrderId);
					},
				});
			},
			// #endif
			// #ifdef MP-ALIPAY
			//支付宝支付
			goZhifuAli() {
				this.submit = true;
				let that = this;
				uni.showLoading({
					title: "支付中",
				});
				let url = "/api/WeChatPay/GetTravlePayInfo";
				let GoodsName = this.orderData.model.Title;
				this.request2({
						url: url,
						data: {
							OrderId: this.orderData.model.OrderId,
							GoodsName: GoodsName,
							OrderPayType: 2,
							OpenId: uni.getStorageSync("mall_UserInfo").OpenId,
						},
					},
					(res) => {
						if (res.data) {
							this.$utils.SubscribeMsgAli(() => {
								that.goPayAli(res.data);
							});
						} else {
							uni.hideLoading();
							uni.showToast({
								title: "获取交易号失败",
								duration: 2000,
							});
						}
					}
				);
			},
			goPayAli(tradeNO) {
				let that = this;
				my.tradePay({
					tradeNO: tradeNO,
					success: function(res) {
						console.log("success", res);
						const list = ["9000"];
						if (list.includes(res.resultCode)) {
							let obj = {
								TradeNo: tradeNO,
								OrderNo: that.orderData.model.OrderNo,
								OrderId: that.orderData.model.OrderId,
								preferPrice: that.orderData.model.PreferPrice,
							};
							that.payAliCallback(obj);
						} else {
							uni.hideLoading();
							uni.showToast({
								title: "支付失败",
								icon: "none",
							});
						}
					},
					fail: function(err) {
						console.log("fail:", err);
						uni.hideLoading();
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
						that.submit = false;
						that.initOrderInfo(that.orderData.model.OrderId);
					},
				});
			},
			payAliCallback(obj) {
				let that = this;
				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) => {
						that.submit = false;
						uni.redirectTo({
							url: "/pages/jiuzhai/paysuccess?PreferPrice=" +
								obj.preferPrice +
								"&isFrom=1",
						});
						uni.hideLoading();
					},
					(err) => {
						console.log("err", err);
						uni.hideLoading();
						that.submit = false;
						uni.showToast({
							title: "支付失败",
							icon: "none",
						});
						that.initOrderInfo(that.orderData.model.OrderId);
					}
				);
			},
			// #endif
		},
	};
</script>
