<template>
	<view class="wrap">
		<!-- 联票电子门票 -->
		<view class="top">
			<text>
				{{orderInfo.productName}}X{{orderInfo.orderNum}}份
			</text>
			<text>
				¥{{orderInfo.totalMoney}}
			</text>
		</view>
		
		<view class="middle">
			<view class="productInfo" v-for="(item,index) in orderInfo.childs" :key="index">
				<view class="product-top">
					<view class="product-name">
						<text>{{item.productName}}</text>
						<text>{{item.orderStatus|orderStatus}}</text>
					</view>
					<view class="product-datetime">
						<view>
							<text>使用日期</text>
							<text style="color: #FE6600;">{{item.playDate}}</text>
						</view>
						<view>
							<text>入园时间</text>
							<text>{{item.startPlayTime?item.startPlayTime.substr(0,5):''}}-{{item.endPlayTime?item.endPlayTime.substr(0,5):''}}</text>
						</view>
					</view>
				</view>
				<!-- 只有等于全部退货退款时才显示 -->
				<view class="product-refund" v-if="item.orderStatus==8">
					<view class="product-refund-detail" @click="refundDetailChange(item)">
						<view style="color: #FE6600;">退订详情</view>
						<view style="display: flex;">
							查看详情
							<u-icon name='arrow-up' v-if="item.showRefundDetail"></u-icon>
							<u-icon name='arrow-down' v-else></u-icon>
						</view>
					</view>
					<view class="product-refund-list" v-if="item.showRefundDetail" v-for="(item2,a) in item.orderRefundList" :key='a'>
						<view>{{item2.refundStatusName}}</view>
						<view>{{item2.refundReason}}</view>
						<view style="color: #666666;">{{item2.refundDate}}</view>
					</view>
				</view>
				
				<template v-else>
					<!-- 等于1为需要排号的景区 -->
					<view class="product-number" v-if="item.showSortInfo==true" v-for="(item2,a) in item.sorts" :key='a'>
						<!-- 1可进入等候区 -->
						<view v-if="item2.sortFair==1" style="background: #31AA6B;color: #ffffff;border: none;">
							<view class="my-number" >
								<view>
									<view>我的排队号</view>
									<view>
									{{item2.sortNo}} 
									<text class="my-number-name">({{item2.projectName}})</text>
									</view>
								</view>
								<view>
									<view>预计进入时间</view>
									<view>{{item2.sortNoTime}}</view>
								</view>
							</view>
							<view class="current-number">
								当前排队区间
								<text>{{item2.showStart}}-{{item2.showEnd}}</text>
								<text>({{item2.projectName}})</text>
							</view>
							<view class="number-notice" style="color: #9ed9ba;">
								<view>
									温馨提示：{{item2.config.paRowNumHint}}
								</view>
								<!-- 可以进入排队区提示 -->
								<view>
									{{item2.config.paArrivalNumHint}}
								</view>
							</view>
						</view>
						<!-- 2已过号不可重排，3已过号可重排 -->
						<view v-else-if="item2.sortFair==2||item2.sortFair==3" style="background: #F53F3F;color: #ffffff;">
							<!-- 等于1为过号允许再次排号 -->
							<view class="my-number" v-if="item2.config.paPassedNumEnable==1">
								<view >
									<view>我的排队号</view>
									<view>
										{{item2.sortNo}}
										<text class="my-number-name">({{item2.projectName}})</text>
									</view>
								</view>
								<view>
									<view>您排队号已过</view>
									<view v-show="item2.sortFair==3">
										<!-- 1为过号提示确定后重新排号 -->
										<text class="number-btn" v-if="item2.config.paPassedNumTakeType==1" @click="clickSortAgain(item)">
											重新取号
										</text>
										<!-- 0为过号直接重新排号 -->
										<text class="number-btn" v-else @click="sortAgain(item)">重新取号</text>
									</view>
								</view>
							</view>
							<!-- 等于0过号不允许再次排号，只进行提示 -->
							<view v-if="item2.config.paPassedNumEnable==0">
								<view>{{item2.config.paPassedNumHint}}</view>
							</view>
							<view class="current-number">
								当前排队区间
								<text>{{item2.showStart}}-{{item2.showEnd}}</text>
								<text>({{item2.projectName}})</text>
							</view>
						</view>
						<!-- 4-可返程取号(仅胖丁显示),5-第一次取号(仅胖丁显示)-->
						<view v-else-if="item2.sortFair==4||item2.sortFair==5" style="padding-top: 16rpx;">
							<view class="current-number">
								当前排队区间
								<text style="color: #FE6600;">{{item2.showStart}}-{{item2.showEnd}}</text>
								<text style="color: #FE6600;">({{item2.projectName}})</text>
							</view>
							<!-- 1购票返程允许取号 -->
							<view v-if="item2.config.paReturnTripNumEnable==1" style="margin-top: 30rpx;" >
								<text v-if="canTakeNumber" @click="sortAgain(item)" class="number-btn2">取号</text>
								<text v-else>
									<text style="color: #FE6600;font-weight: bold;">{{minute}}</text>分
									<text style="color: #FE6600;font-weight: bold;">{{second}}</text>秒后可取号
								</text>
							</view>
							<!-- 1购票返程不允许取号,仅提示 -->
							<view v-if="item2.config.paReturnTripNumEnable==0" style="margin-top: 30rpx;">
								{{item.config.paReturnTripHint}}
							</view>
						</view>
						<!-- 6已过闸 -->
						<view v-else-if="item2.sortFair==6" style="color: #FE6600;">
							温馨提示：您已过闸
						</view>
						<!-- 7提前通知-->
						<view v-else-if="item2.sortFair==7">
							<view class="my-number" >
								<!-- 0显示排队号，1隐藏排队号 -->
								<view v-if="item2.config.paHideNum!=1">
									<view>我的排队号</view>
									<view style="color: #FE6600;">
										{{item2.sortNo}} 
										<text class="my-number-name">({{item2.projectName}})</text>
									</view>
								</view>
								<!-- 0显示预计时间，1隐藏预计时间 -->
								<view v-if="item2.config.paHideEstimatedTime!=1">
									<view >预计进入时间</view>
									<view style="color: #FE6600;">{{item2.sortNoTime}}</view>
								</view>
							</view>
							<view class="current-number">
								当前排队区间
								<text style="color: #FE6600;">{{item2.showStart}}-{{item2.showEnd}}</text>
								<text style="color: #FE6600;">({{item2.projectName}})</text>
							</view>
							<view class="number-notice">
								<view style="color: #666666;">
									温馨提示：{{item2.config.paRowNumHint}}
								</view>
								<view style="color: #FE6600;">
									<text v-if="item2.config.paAdvanceNoticeDisplay">
											{{item2.config.paAdvanceNoticeDisplay}}
									</text>
									<text v-else>
										请尽快赶到现场等候，避免错过游玩时间。
									</text>
								</view>
							</view>
						</view>
						<!-- 未到号 -->
						<view v-else>
							<view class="my-number" >
								<view>
									<view>我的排队号</view>
									<view style="color: #FE6600;">
										{{item2.sortNo}}
										<text class="my-number-name">({{item2.projectName}})</text>
									</view>
								</view>
								<view>
									<view>预计进入时间</view>
									<view style="color: #FE6600;">{{item2.sortNoTime}}</view>
								</view>
							</view>
							<view class="current-number">
								当前排队区间
								<text style="color: #FE6600;">{{item2.showStart}}-{{item2.showEnd}}</text>
								<text style="color: #FE6600;">({{item2.projectName}})</text>
							</view>
							<view class="number-notice" style="color: #666666;">
								温馨提示：{{item2.config.paRowNumHint}}
							</view>
						</view>
					</view>
					<!-- 后端返回了二维码才显示下面内容 -->
					<view class="product-code" v-if="item.orderTicketDetailList.length>0&&item.orderTicketDetailList[0].ticketCode">
						<view class="code-title">
							凭「入园码」直接入园
						</view>
						<view class="code-image">
							<image :src="item.codeImage"></image>
						</view>
						<view class="code-number">
							<text>
								{{item.orderTicketDetailList[0].ticketCode}}
							</text>
							<text @click="copyText(item.orderTicketDetailList[0].ticketCode)">
								复制
							</text>
						</view>
						<view class="code-tip" v-if="item.exchangeMode==4||item.exchangeMode==5">
							二维码自动更新,截屏无效
						</view>
					</view>
					<view class="product-useknow">
						<view class="useknow-list" v-if="item.showUseknow" v-for="(item2,a) in item.orderExtendList" :key="a">
						  <text>{{item2.title}}</text>
						  <text>{{item2.content}}</text>
						</view>
						<view class="useknow-bottom" v-if="item.orderExtendList.length>0" @click="useknowChange(item)">
							使用须知
							<u-icon name='arrow-down' v-if="item.showUseknow==false"></u-icon>
							<u-icon name='arrow-up' v-else></u-icon>
						</view>
					</view>
				</template>
				
			</view>
			
			<view class="rufundRule">
				<!-- 等于3退票规则以子订单为准 -->
				<view style="padding: 32rpx 32rpx 0 32rpx;" v-if="orderInfo.isRefund==3">
					<view v-for="(item,index) in orderInfo.childs" :key="index" >
						<view class="rule-title">
							{{item.productName}}退改规则
						</view>
						<view class="rule-type">
							<text v-if="item.isRefund==0">不可退</text>
							<text v-if="item.isRefund==1">有条件退</text>
							<text v-if="item.isRefund==2">随时可退</text>
						</view>
						<view class="rule-list">
							<view v-for="(item2,a) in item.orderRefundRuleList" :key="a" v-if="item.isRefund==1" style="margin-top: 20rpx;">
								<!--已配置文字内容 -->
								<text v-if="item2.refundShowMessage">
									{{item2.refundShowMessage}}
								</text>
								<!-- 未配置文字内容 -->
								<template v-else>
									<!-- 使用日期前 -->
									<text v-if="item2.refundTimeRule==1">
										<text v-if="item2.refundDay==0">
											使用日期当天{{item2.refundTime}}之前可退
										</text>
										<text v-else>
											使用日期前{{item2.refundDay}}天{{item2.refundTime}}之前可退
										</text>
									</text>
									<!-- 过期 -->
									<text v-if="item2.refundTimeRule==2">
										<text v-if="item2.refundDay==0">
											过期当天{{item2.refundTime}}之前可退
										</text>
										<text v-else>
											过期后{{item2.refundDay}}天{{item2.refundTime}}之前可退
										</text>
									</text>
								</template>
								
							</view>
						</view>
					</view>
				</view>
				<!-- 不等于3退票规则以主订单为准 -->
				<view style="padding: 32rpx;" v-else>
					<view class="rule-title">
						退改规则
					</view>
					<view class="rule-type">
						<text v-if="orderInfo.isRefund==0">不可退</text>
						<text v-if="orderInfo.isRefund==1">有条件退</text>
						<text v-if="orderInfo.isRefund==2">随时可退</text>
					</view>
					<view class="rule-list">
						<view v-for="(item,index) in orderInfo.orderRefundRuleList" :key="index" v-if="orderInfo.isRefund==1" style="margin-top: 20rpx;">
							<!--已配置文字内容 -->
							<text v-if="item.refundShowMessage">
								{{item.refundShowMessage}}
							</text>
							<!-- 未配置文字内容 -->
							<template v-else>
								<!-- 使用日期前 -->
								<text v-if="item.refundTimeRule==1">
									<text v-if="item.refundDay==0">
										使用日期当天{{item.refundTime}}之前可退
									</text>
									<text v-else>
										使用日期前{{item.refundDay}}天{{item.refundTime}}之前可退
									</text>
								</text>
								<!-- 过期 -->
								<text v-if="item.refundTimeRule==2">
									<text v-if="item.refundDay==0">
										过期当天{{item.refundTime}}之前可退
									</text>
									<text v-else>
										过期后{{item.refundDay}}天{{item.refundTime}}之前可退
									</text>
								</text>
							</template>
							
						</view>
					</view>
				</view>
				<view class="rule-service" @click="makePhone('4000720368')">
					<u-icon name='kefu-ermai'></u-icon>
					<text style="margin-left: 12rpx;">联系客服</text>
				</view>
			</view>
			<view class="orderInfo">
				<view class="order-title">
					订单信息
				</view>
				<view class="order-middle">
					<view>
						<text style="flex-shrink: 0;">订单编号</text>
						<view class="order-id">
							<text class="one-txt-cut" style="flex: 1;text-align: right;">
								{{orderInfo.id?orderInfo.id.substr(0,8)+"****"+orderInfo.id.substr(orderInfo.id.length-8,8):''}}
							</text>
							<text class="order-btn">复制</text>
						</view>
					</view>
					
					<view>
						<text>支付时间</text>
						<text>{{orderInfo.paymentTime}}</text>
					</view>
					
					<view>
						<text>联系信息</text>
						<text>
							<text>{{orderInfo.ticketPhone}}</text>
						</text>
					</view>
				</view>
				<!-- <view class="order-bottom">
					收起
					<u-icon name='arrow-up'></u-icon>
				</view> -->
			</view>
		</view>
		
		<view class="bottom">
			<!-- 以主订单为准 -->
			<text v-if="mainRefundBtn" @click="mainRefund(orderInfo.id)">申请退票</text>
			<!-- 以子订单为准 -->
			<text v-if="subRefundBtn" @click="showSubRefund()">申请退票</text>
			<text @click="orderAgain()">再次预订</text>
		</view>
		<!-- 是否重新排号 -->
		<u-modal 
		:show="showModal" 
		@confirm="sortAgain(sortAgainData)" 
		@cancel="showModal=false" 
		showCancelButton 
		:title="sortAgainData.config.paPassedNumTakeTypeHint||'是否重新排号'" >
		</u-modal>
		<!-- 子产品退票列表弹窗 -->
		<u-popup :show="refundPop" :round="20" @close="refundPop=false"  closeable>
			<view class="subtitle">
				申请退票
			</view>
			<radio-group @change="radioChange">
				<label class="subradio" v-if="item.ifRefund" v-for="(item,index) in orderInfo.childs" :key="index">
					<text>{{item.productName}}</text>
					<radio :value="item.id" :checked="refundOrderId==item.id"/>
				</label>
			</radio-group>
			<view class="subBottom" @click="subRefund()">
				<text>确定</text>
			</view>
		</u-popup>
	</view>
</template>

<script>
import QRCode from '@/common/weapp-qrcode.js'
export default {
  filters:{
    orderStatus(i){//订单状态
      switch(i){
      case 0:return '待支付'
        break
      case 1:return '出票中'
        break
      case 2:return '出票成功'
        break
      case 3:return '出票失败'
        break
      case 4:return '核销中'
        break
      case 5:return '核销完成'
        break
      case 6:return '退款中'
        break
      case 7:return '部分退货退款'
        break
      case 8:return '全部退货退款'
        break
      case 9:return '已取消'
        break
      case 10:return '已完成 '
        break
      case 11:return '已过期 '
        break
      case 12:return '退票审核中 '
        break
      }
    }
  },
  data() {
    return {
      detailTimer:null,//详情时间函数
      codeTimer:null,//动态二维码时间函数
      numberTimer:null,//获取排号信息时间函数
      codeFlag:null,//动态二维码函数
      countFlag:null,//倒计时时间函数
      numberFlag:null,////获取排号信息时间函数2
      Brightness:'',//屏幕亮度
      openid:uni.getStorageSync('openid')||'',//openid
      companyId:'',//公司Id
      orderId:'',//订单Id
      orderInfo:'',//订单信息
      nowCodeNo:'',//当前动态二维码编号
      showModal:false,//重排号弹窗显示隐藏
      sortAgainData:'',//重排号数据
      canTakeNumber:false,//返程或者第一次取号时，是否可以显示取号按钮
      minute:'',//倒计时分钟
      second:'',//倒计时秒
      mainRefundBtn:false,//以主订单为准
      subRefundBtn:false,//以子订单为准
      refundPop:false,//子订单产品退票列表弹窗
      refundOrderId:'',//退款订单Id
    }
  },
  onLoad(option) {
    this.orderId= option.orderId
  },
  onShow() {
    this.getDetail()
	  uni.getScreenBrightness({
	    success:(res)=>{
	      // 这里是把获取到的手机屏幕亮度，存储到data里面，方便给到页面生命周期隐藏和卸载方法里面用
				 this.Brightness = res.value
				 if(res.value != 1){
	        uni.setScreenBrightness({
	          value: 1
	        })
	      }
	    }
	  })
  },
  onHide() {
    //切换后台周期函数
    //由于该页面用户需要频繁的查看排号和电子门票信息，为性能考虑，在onHide生命周期函数里面也进行计时器清理
    //timer结尾是用的setTimeout,Flag结尾是用的setInterval
    //清除详情函数
    if(this.detailTimer) {
      clearTimeout(this.detailTimer)
      this.detailTimer = null
    } 
    //清除动态二维码函数
    if(this.codeTimer) {
      clearTimeout(this.codeTimer)
      this.codeTimer = null
    } 
    //清除排号信息函数
    if(this.numberTimer) {
      clearTimeout(this.numberTimer)
      this.numberTimer = null
    } 
    //清除排号信息函数2
    if(this.numberFlag) {
      clearInterval(this.numberFlag)
      this.numberFlag = null
    } 
    //清除倒计时函数
    if(this.countFlag) {
      clearInterval(this.countFlag)
      this.countFlag = null
    }
    //清除动态二维码函数
    if(this.codeFlag) {
      clearInterval(this.codeFlag)
      this.codeFlag = null
    }
	  uni.setScreenBrightness({// 恢复之前屏幕亮度
	    value: this.Brightness
	  })
  },
  onUnload() {
    //页面切换周期函数
    //timer结尾是用的setTimeout,Flag结尾是用的setInterval
    //清除详情函数
    if(this.detailTimer) {
		  clearTimeout(this.detailTimer)
		  this.detailTimer = null
    } 
    //清除动态二维码函数
    if(this.codeTimer) {
		  clearTimeout(this.codeTimer)
		  this.codeTimer = null
    } 
    //清除排号信息函数
    if(this.numberTimer) {
		  clearTimeout(this.numberTimer)
		  this.numberTimer = null
    } 
    //清除排号信息函数2
    if(this.numberFlag) {
		  clearInterval(this.numberFlag)
		  this.numberFlag = null
    } 
    //清除倒计时函数
    if(this.countFlag) {
		  clearInterval(this.countFlag)
		  this.countFlag = null
    }
    //清除动态二维码函数
    if(this.codeFlag) {
		  clearInterval(this.codeFlag)
		  this.codeFlag = null
    }
	  uni.setScreenBrightness({// 恢复之前屏幕亮度
	    value: this.Brightness
	  })
  },
  methods: {
    //---加载订单详情
    getDetail(){
      let data={
			  orderId:this.orderId,//订单ID
			  userId:this.openid,//用户Id
      }
		  this.$request('order/userOrder/findOrderDetail',data).then((res)=>{
		    if(res.code=='00'){
          //防止代码bug进入catch里面，一直请求接口影响性能
          try{
            this.orderInfo=res.data
            let orderInfo=res.data
            this.orderInfo.childs.forEach(item=>{
            //默认不显示使用须知
              item.showUseknow=false
              //默认不显示退票详情
              item.showRefundDetail=false
              if(item.orderStatus==2||item.orderStatus==4||item.orderStatus==5||item.orderStatus==7){
                //订单状态为2、4、5、7时才获取排号信息
                if(item.isFetch=='1'){
                  //为了提高性能，游玩时间等于今天才获取排号信息
								  if(item.playDate.substr(0,10)==this.$commonjs.today()){
								  //获取排号信息
								    this.getSortInfo(item)
								    //每两分钟刷新一次
								    this.numberFlag=setInterval(()=>{
									  this.getSortInfo(item)
								    },120*1000)
								  }
                }
              }
              
              //subOrderType 子订单类型(0-胖丁分销，1-扫码购，2-自助机，3-组合，4-扫码牌，5-预订，6-反扫，7-收银机，8-码同步，9-押金，94-公众号,96-胖丁分销,99-酒店自营)
              //exchangeMode 验证方式：1胖丁二维码,2第三方二维码,3短信,4身份证
              if(item.subOrderType!=4&&item.subOrderType!=5){
                //为了提高性能，游玩时间等于今天才获取排号信息
                if(item.playDate.substr(0,10)==this.$commonjs.today()){
                  if(item.exchangeMode==4||item.exchangeMode==5){
                  //多个二维码
                    if(item.orderStatus==2||item.orderStatus==4||item.orderStatus==5||item.orderStatus==7){
                      //订单状态为2、4、5、7时才获取动态二维码
                      this.getCodeList(item)
                    }
                  }
                }
                if(item.exchangeMode==1){
                //一个二维码
                  this.getCode(item)
                }
              }
              //根据退款状态修改退款列表的退款名称
              item.orderRefundList.forEach((item2,index)=>{
						  if(item2.refundStatus==0){
						    item2['refundStatusName'] = '退款中'
						  }else if(item2.refundStatus==1){
						    item2['refundStatusName'] = '退款成功'
						  }else if(item2.refundStatus==2){
						    item2['refundStatusName'] = '退款失败'
						  }else if(item2.refundStatus==3){
						    item2['refundStatusName'] = '退票中'
						  }else if(item2.refundStatus==4){
						    item2['refundStatusName'] = '退票确认'
						  }else if(item2.refundStatus==5){
						    item2['refundStatusName'] = '退货完成'
						  }else if(item2.refundStatus==6){
						    item2['refundStatusName'] = '退票审核中'
						  }else if(item2.refundStatus==7){
						    item2['refundStatusName'] = '退票失败'
						  }
              })
            })
            if(orderInfo.isRefund==3){
					  // 退票规则以子订单为准
              this.orderInfo.childs.forEach(item=>{
                if(item.orderStatus==2||item.orderStatus==7){
                  //等于2出票成功，7部分退货退款
                  if(item.isRefund==2){
                    //随时可退
                    this.subRefundBtn=true
                    //增加字段用于弹窗展示该产品是否可退
                    item.ifRefund=true
                  }
                  if(item.isRefund==1){
                    //1为条件退
                    item.orderRefundRuleList.forEach(item2=>{
                      //refundVisitorApply游客是否能自己申请退（0不能1可以）
                      if(item2.refundVisitorApply==1){
                        //当前时间戳
                        let nowTimeNumber=new Date().getTime()
                        //退票时间戳
                        let refundTime=''
                        if(item2.refundDay){
                          //1使用日期前
                          if(item2.refundTimeRule==1){
                            let playDate = this.getNewDate(orderInfo.playDate,-item2.refundDay)
                            refundTime = playDate+' '+item2.refundTime
                          }
                          //2过期后
                          if(item2.refundTimeRule==2){
                            let playDate = this.getNewDate(orderInfo.playDate,item2.refundDay)
                            refundTime = playDate+' '+item2.refundTime
                          }
                        }else{
                          refundTime = orderInfo.playDate+' '+item2.refundTime
                        }
                        let refundTimeNumber=new Date(refundTime.replace(/-/g, '/')).getTime()
                        // refundDateType退款时间0之前,1至(用于区间),2之后
                        if(item2.refundDateType==0){
                          if(nowTimeNumber<refundTimeNumber){
                            this.subRefundBtn=true
                            //增加字段用于弹窗展示该产品是否可退
                            item.ifRefund=true
                          }else{
                            this.subRefundBtn=false
                          }
                        }
                        if(item2.refundDateType==1){
												  let refundEndTime=''
												  if(item2.refundDay){
												    let playDate = this.getNewDate(orderInfo.playDate,-item2.refundDay)
												    refundEndTime = playDate+' '+item2.refundEndTime
												  }else{
												    refundEndTime = orderInfo.playDate+' '+item2.refundEndTime
												  }
												  if(refundTime<nowTime<refundEndTime){
												    this.subRefundBtn=true
												    //增加字段用于弹窗展示该产品是否可退
												    item.ifRefund=true
												  }else{
												    this.subRefundBtn=false
												  }
                        }
                        if(item2.refundDateType==2){
                          if(nowTimeNumber>refundTimeNumber){
                            this.subRefundBtn=true
                            //增加字段用于弹窗展示该产品是否可退
                            item.ifRefund=true
                          }else{
                            this.subRefundBtn=false
                          }
                        }
                      }
                    })
                  }
                }
              })
            }else{
					  // 退票规则以主订单为准
              if(orderInfo.orderStatus==2||orderInfo.orderStatus==7){
              //等于2出票成功，7部分退货退款
                if(orderInfo.isRefund==2){
                //随时可退
                  this.mainRefundBtn=true
                }
                if(orderInfo.isRefund==1){
                //1为条件退
                  orderInfo.orderRefundRuleList.forEach(item=>{
                  //refundVisitorApply游客是否能自己申请退（0不能1可以）
                    if(item.refundVisitorApply==1){
                    //当前时间戳
                      let nowTimeNumber=new Date().getTime()
                      //退票时间戳
                      let refundTime=''
                      if(item.refundDay){
                      //1使用日期前
                        if(item.refundTimeRule==1){
                          let playDate = this.getNewDate(orderInfo.playDate,-item.refundDay)
                          refundTime = playDate+' '+item.refundTime
                        }
                        //2过期后
                        if(item.refundTimeRule==2){
                          let playDate = this.getNewDate(orderInfo.playDate,item.refundDay)
                          refundTime = playDate+' '+item.refundTime
                        }
                      }else{
                        refundTime = orderInfo.playDate+' '+item.refundTime
                      }
                      let refundTimeNumber=new Date(refundTime.replace(/-/g, '/')).getTime()
                      // refundDateType退款时间0之前,1至(用于区间),2之后
                      if(item.refundDateType==0){
                        if(nowTimeNumber<refundTimeNumber){
                          this.mainRefundBtn=true
                        }else{
                          this.mainRefundBtn=false
                        }
                      }
                      if(item.refundDateType==1){
											  let refundEndTime=''
											  if(item.refundDay){
											    let playDate = this.getNewDate(orderInfo.playDate,-item.refundDay)
											    refundEndTime = playDate+' '+item.refundEndTime
											  }else{
											    refundEndTime = orderInfo.playDate+' '+item.refundEndTime
											  }
											  if(refundTime<nowTime<refundEndTime){
											    this.mainRefundBtn=true
											  }else{
											    this.mainRefundBtn=false
											  }
                      }
                      if(item.refundDateType==2){
                        if(nowTimeNumber>refundTimeNumber){
                          this.mainRefundBtn=true
                        }else{
                          this.mainRefundBtn=false
                        }
                      }
                      
                    }
                  })
                }
              }
            }
          }catch(e){
            uni.showToast({
              title: e,
              icon: 'none'
            })
          }
		    }else{
		      uni.showToast({
		        title: res.message,
		        icon: 'none'
		      })
		    }
		  }).catch((err) => {
		      this.detailTimer = setTimeout(() => {
		        this.getDetail()
		      }, 2000)
		  })
    },
    //---当前时间加上天数获取新的日期
    getNewDate:function(date,day) {
		  var dd = new Date(date)
		  dd.setDate(dd.getDate() + day)
		  var y = dd.getFullYear()
		  var m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1
		  var d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate()
		  return y + '-' + m + '-' + d
    },
    //---二维码刷新
    dynamicCodeRefresh(item){
      let codeList=item.codeList
      let codeStart=item.codeStart
		  // 获取当前显示第几个二维码
		  let nowTime = (new Date().getTime() - codeStart)/1000
		  let code = null
		  // 寻找到当前时间的二维码
		  for(let i = 0 ; i < codeList.length ; i++ ){
		    let item2 = codeList[i]
		    nowTime -= item2.timeout
		    if(nowTime <= 0 ){
		      code = item2
		      break
		    }
		  }
		  // 全部遍历完成后，需要重新获取新的二维码
		  if(code == null){
		    this.getCodeList(item)
		  } else {
        if(code.code != this.nowCodeNo){
          this.nowCodeNo=code.code||''
          if(this.nowCodeNo){
            item.codeImage= QRCode.drawImg(this.nowCodeNo, {
						  typeNumber: 3,//码点大小 1-40，数字越大，码点越小，二维码会显得越密集
						  errorCorrectLevel: 'H',//纠错等级 H等级最高(30%) 简单来说，就是二维码被覆盖了多少仍然能被识别出来 详见qrcode.js
						  size: 180
            })
          }
          this.$forceUpdate()
        }
		  }
    },
    //---获取动态二维码列表
    getCodeList(item){
      let codeNo=''
      if(item.orderTicketDetailList.length>0){
        codeNo=item.orderTicketDetailList[0].ticketCode
      }
		  let data={
		    codeNo,//二维码编号
		    orderId:item.id,//订单号
		    userId:this.openid//openid
		  }
		  clearInterval(this.codeFlag)
		  this.$request('distribution/distribution/getAutoCode',data).then((res)=>{
		    if(res.code == '00'){
		      item.codeList = res.data.codes
		      if(item.codeList.length==0){
		        uni.showToast({
						  title: '网络异常，请退出重试',
						  icon: 'none'
		        })
            return
		      }
		      item.codeStart = new Date().getTime()
		      this.codeFlag = setInterval(()=>{
		        this.dynamicCodeRefresh(item)
		      },300)
		    }else{
		      uni.showToast({
		        title: res.message,
		        icon: 'none'
		      })
		    }
		  }).catch((err)=>{
		    this.codeTimer=setTimeout(()=>{
		      this.getCodeList(item)
		    },2000)
		  })
    },
    //---生成二维码
    getCode(item){
      //生成二维码码取值verifyCode，页面显示取值ticketCode--生成二维码比页面显示多一个TBD
      let verifyCode=''
      if(item.orderTicketDetailList.length>0){
        verifyCode=item.orderTicketDetailList[0].verifyCode||''
      }
      if(verifyCode){
        item.codeImage= QRCode.drawImg(verifyCode, {
          typeNumber: 3,//码点大小 1-40，数字越大，码点越小，二维码会显得越密集
          errorCorrectLevel: 'H',//纠错等级 H等级最高(30%) 简单来说，就是二维码被覆盖了多少仍然能被识别出来 详见qrcode.js
          size: 180
        })
      }
    },
    //---获取排号信息
    getSortInfo(item){
      let data={
        areaCode:item.areaCode,//站点编号
        orderNum:item.orderNum,//订单数量
        userId:this.openid,//openid
        orderId:item.id,//订单id
        thirdId:item.thirdOrderId,//三方订单id
        againNumber:0//首次排号
      }
		  this.$request('distribution/distribution/getNewFetchInfo',data).then((res)=>{
		    if(res.code=='00'){
		      if(res.data.length>0){
            //防止代码bug进入catch里面，一直请求接口影响性能
            try{
              let dataObj=res.data[0]
              //由于页面不显示历史排号，所以只取第一个最新的排号信息
              item.sorts=dataObj.sorts.slice(0,1)||[]
              item.sorts.forEach(item2=>{
                //sceneSortStatus，1上架
                if(item2.config.sceneSortStatus==1){
								  //显示排号信息
								  item.showSortInfo=true
                }
                if(item2.sortFair==4||item2.sortFair==5){
								  //时间判断，用于返程或第一次取号时，是否可以显示取号按钮
								  let presentTime = new Date().getTime()
								  let time1=new Date((item2.createDate).replace(/-/g, '/')).getTime()
								  let time2=parseInt((item2.config.paReturnTripTime)*60*1000) 
								  let takeNumberTime=time1+time2
								  if(presentTime>takeNumberTime){
								    this.canTakeNumber =true
								  }else{
								    //倒计时
								    //1.先计算时间差多少秒
								    let number=parseInt((takeNumberTime-presentTime)/1000)
								    this.countFlag=setInterval(()=>{
								      number-=1
								      if(number<0){
											  this.canTakeNumber =true
											  clearInterval(this.countFlag)
								        return
								      }
								      this.minute=parseInt(number/60) 
								      this.second=parseInt(number-this.minute*60)
								    },1000)
								  }
                }
              })
              //子产品获取公司Id,用于重排号传参
              if(dataObj.pays.length>0){
							  item.merchantCodeCopy = dataObj.pays[0].companyId
              }
              //子产品获取三方Id,用于重排号传参
              item.thirdIdCopy=dataObj.order.orderId
              //子产品获取站点编码,用于重排号传参
              if(item.sorts.length>0){
                item.areaCodeCopy=item.sorts[0].projectId
              }
              this.$forceUpdate() 
            }catch(e){
              uni.showToast({
                title: e,
                icon: 'none'
              })
            }  
		      }
		    }else{
		      uni.showToast({
		        title: res.message,
		        icon: 'none'
		      })
		    }
		  }).catch((err)=>{
		    this.numberTimer=setTimeout(()=>{
		      this.getSortInfo(item)
		    },2000)
		  })
    },
    //---点击重新取号，显示弹窗
    clickSortAgain(item){
      this.showModal=true
      this.sortAgainData=item
    },
    //---重新排队
    sortAgain(item){
		  let data={
		    againNumber:1,
		    thirdId:item.thirdIdCopy,//三方订单id
		    areaCode:item.areaCodeCopy,//站点
		    userId:this.openid,
		    merchantCode:item.merchantCodeCopy,
		  }
		  this.$request('distribution/distribution/newFetchNumber',data).then((res)=>{
		    if(res.code=='00'){
          this.showModal=false
		      this.getSortInfo(item)
		    }else{
		      uni.showToast({
		        title: res.message,
		        icon: 'none'
		      })
		    }
		  })
    },
    //---使用须知切换
    useknowChange(item){
      item.showUseknow=!item.showUseknow
      this.$forceUpdate()
    },
    //---退票详情切换
    refundDetailChange(item){
		  item.showRefundDetail=!item.showRefundDetail
      this.$forceUpdate()
    },
    //---复制内容
    copyText(value){
		  uni.setClipboardData({
		    data:value,
		    success:function(){
		      uni.showToast({
		        title: '复制成功',
		        icon: 'none'
		      })
		    }
		  })
    },
    //---拨打电话
    makePhone(phoneNumber) {
      uni.makePhoneCall({
        phoneNumber
      })
    },
    //---主订单点击申请退票
    mainRefund(orderId){
      uni.navigateTo({
        url: '/pages/my/order/afterSale/applyAfterSale/applyAfterSale?orderId='+orderId
      })
    },
    //---子订单弹窗显示
    showSubRefund(){
      this.refundPop=true
      this.refundOrderId=''
    },
    //---子订单单选框变化
    radioChange(e){
      this.refundOrderId=e.detail.value
    },
    //---子订单为准点击退票
    subRefund(){
      if(!this.refundOrderId){
        uni.showToast({
				  title: '请选择退票产品',
				  icon: 'none'
        })
        return
      }
      this.refundPop=false
      uni.navigateTo({
			  url: '/pages/my/order/afterSale/applyAfterSale/applyAfterSale?orderId='+this.refundOrderId
      })
    },
    //---再次预订
    orderAgain(){
      let query = '?merchantId='+this.orderInfo.merchantId+'&productId=' +this.orderInfo.productId +'&orderSource=3'
      uni.navigateTo({
        url: '/pages/scenic/scenicJointOrder/scenicJointOrder' + query
      })
    }
  }
}
</script>

<style scoped lang="scss">
.wrap{
	padding: 0 20rpx;
}
.top{
	display: flex;
	justify-content: space-between;
	padding: 48rpx 20rpx 0 20rpx;
	font-size: 36rpx;
	font-weight: 600;
	text:first-child{
		flex: 1;
		margin-right: 40rpx;
	}
}
.middle{
	margin-top: 32rpx;
	padding-bottom: 120rpx;
}
// 产品部分
.productInfo{
	margin-top: 20rpx;
	background: #ffffff;
	border-radius: 16rpx;
	padding: 40rpx 0 32rpx 0;
}
.product-refund-detail{
	display: flex;
	justify-content: space-between;
	padding: 20rpx 32rpx;
	border-bottom: 1px solid #EBEEF5;
}
.product-refund-list view{
	margin-top: 10rpx;
}
.product-top{
	padding: 0 32rpx;
}
.product-name{
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 36rpx;
	font-weight: 600;
	text:first-child{
		flex: 1;
		margin-right: 40rpx;
	}
	text:last-child{
		color: #00B42B;
		font-size: 28rpx;
	}
}
.product-datetime{
	display: flex;
	justify-content: space-between;
	margin-top: 20rpx;
	view text:last-child{
		font-weight: bold;
		margin-left: 20rpx;
	}
}
.product-number{
	padding: 0 20rpx;
	border-radius: 16rpx;
	background: #FFFFFF;
	margin-top: 20rpx;
	>view{
		padding: 32rpx;
		border-radius: 16rpx;
		border: 1px solid #dcdcdc;
	}
}
.my-number{
	display: flex;
	>view{
		view:last-child{
			margin-top: 10rpx;
			font-size: 52rpx;
			font-weight: 600;
			display: flex;
			align-items: center;
		}
	}
	>view:first-child{
		width: 52%;
	}
	>view:last-child{
		width: 48%;
	}
}
.my-number-name{
	font-size: 40rpx;
	margin-left: 10rpx;
}
.current-number{
	margin-top: 10rpx;
	display: flex;
	align-items: center;
	text{
		font-size: 40rpx;
		font-weight: 600;
		margin-left: 10rpx;
	}
}
.number-notice{
	font-size: 24rpx;
	margin-top: 20rpx;
	line-height: 34rpx;
}
.number-btn{
	display: inline-block;
	width: 140rpx;
	height: 64rpx;
	background: #ffffff;
	border-radius: 32rpx;
	text-align: center;
	line-height: 60rpx;
	color: #4561A1;
	font-size: 24rpx;
}
.number-btn2{
	display: inline-block;
	width: 140rpx;
	height: 64rpx;
	border-radius: 32rpx;
	text-align: center;
	line-height: 60rpx;
	background: #31AA6B;
	color: #ffffff;
	font-size: 28rpx;
}
.product-code{
	text-align: center;
	border-top: 1px solid #f5f5f5;
	margin-top: 40rpx;
}
.code-title{
	margin-top: 40rpx;
	font-size: 36rpx;
	font-weight: 600;
}
.code-number{
	margin-top: 20rpx;
	font-weight: 600;
	text:last-child{
		font-weight: bold;
		margin-left: 20rpx;
		color: #435FA0;
	}
}
.code-image{
	margin-top: 20rpx;
	image{
		width: 180px;
		height: 180px;
	}
}
.code-tip{
	margin-top: 20rpx;
	color: $red;
}
.product-useknow{
	padding: 0 32rpx;
}
.useknow-list{
	display: flex;
	margin-top: 28rpx;
	text:first-child{
		color: #777777;
		margin-right: 20rpx;
		flex-shrink: 0;
	}
}
.useknow-bottom{
	display: flex;
	justify-content: center;
	padding-top: 32rpx;
}
// 退票规则
.rufundRule{
	background: #ffffff;
	border-radius: 16rpx;
	margin-top: 20rpx;
}
.rule-title{
	font-size: 36rpx;
	font-weight: 600;
}
.rule-type{
	margin-top: 20rpx;
	text{
		font-size: 24rpx;
		color: $theme;
		border: 1px solid $theme;
		border-radius: 6rpx;
		padding: 4rpx 12rpx;
	}
}
.rule-list{
	margin:30rpx 0;
}
.rule-service{
	display: flex;
	align-items: center;
	padding: 36rpx 0;
	justify-content: center;
	border-top: 1px solid #EBEEF5;
}
// 订单信息
.orderInfo{
	margin-top: 20rpx;
	border-radius: 16rpx;
	background: #ffffff;
}
.order-title{
	font-size: 36rpx;
	font-weight: 600;
	padding: 32rpx;
}
.order-middle{
	color: #666666;
	>view{
		padding:32rpx;
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #EBEEF5;
	}
}
.order-id{
	flex: 1;
	margin-left: 40rpx;
	display: flex;
}

.order-btn{
	display: inline-block;
	text-align: center;
	line-height: 36rpx;
	width: 82rpx;
	height: 40rpx;
	background: #F7F8FA;
	border-radius: 20rpx;
	font-size: 24rpx;
	margin-left: 20rpx;
	color: #333333;
}
.bottom{
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	z-index: 1;
	background: #ffffff;
	height: 120rpx;
	display: flex;
	align-items: center;
	padding: 0 40rpx;
	justify-content:flex-end;
	border-top: 1px solid #EBEEF5;
	text{
		display: inline-block;
		width: 170rpx;
		height: 64rpx;
		border-radius: 32rpx;
		border: 1px solid #EDEDED;
		text-align: center;
		line-height: 60rpx;
		color: #666666;
		margin-left: 20rpx;
	}
}
.subtitle{
	font-size: 32rpx;
	font-weight: bold;
	text-align: center;
	padding: 20rpx;
}
.subradio{
	display: flex;
	justify-content: space-between;
	padding: 20rpx;
	border-bottom: 1px solid #EBEEF5;
}
.subBottom{
	padding: 40rpx 32rpx 20rpx 32rpx;
	text{
		display: inline-block;
		width: 100%;
		height: 88rpx;
		text-align: center;
		line-height: 85rpx;
		background: $red;
		color: #ffffff;
		font-size: 32rpx;
		border-radius: 44rpx;
	}
}
</style>
