<template>
	<view class="wrap">
		<view>
			<view class="first">
				<input placeholder="请输入购票预留手机号/身份证号" v-model="search" />
			</view>
			<view class="query">
				<text class="button" @click="query()">查询订单</text>
			</view>
		</view>

		<view class="mark-box" v-if="showMark">
			<view style="width: 100%;">
				<view class="mark-content">
					<view class="mark-title"> 获取失败 </view>
					<view class="mark-tip"> 查无该订单，请咨询购票渠道！</view>
					<!-- <view class="mark-btn">
						<text class="btn">重试</text>
					</view> -->
				</view>
				
				<view class="mark-close" @click="showMark=false">
					<u-icon name="close-circle" size='60' color='#ffffff'></u-icon>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
export default {
  data() {
    return {
      showMark: false ,//是否显示遮罩层
      search:'',//输入框的值
      noNumberList:[],//未排号站点列表
      orderId:'',//订单Id
    }
  },
  methods: {
    //---查询订单
    query(){
      if(!this.search){
        uni.showToast({
				  title:'请输入手机号或者身份证号',
				  icon: 'none'
        })
        return
      }
      let data={
        search:this.search,
        userId:uni.getStorageSync('openid')||''
      }
      uni.showLoading({
        title:'加载中'
      })
      this.$request('order/userOrder/findOrderPageListByCode',data).then((res)=>{
			  if(res.code=='00'){
			    let list=res.data||[]
          if(list.length==0){
            this.showMark=true
          }else{
            this.orderId=list[0].id
            let thirdId=list[0].thirdOrderId||''
            let merchantId=list[0].merchantId||''
            this.getFetchInfo(thirdId,merchantId)
          }
			  }else{
			    uni.showToast({
			      title: res.message,
			      icon: 'none'
			    })
			  }
      })
    },
    //---获取排号信息
    getFetchInfo(thirdId,merchantId){
      let data={
			  thirdId,
        merchantId
      }
      this.noNumberList=[]
      this.$request('distribution/distribution/getFetchInfoOta',data).then((res)=>{
			  if(res.code=='00'){
          //sortFair=3时可重排，排号状态:0-等待中,1-可进入,2-已过号,３-可重排,4-可返程取号(仅胖丁显示),5-第一次取号(仅胖丁显示),6-已过闸
          //计算时去除可重排的
          let sorts=[]
          if(res.data[0].sorts&&res.data[0].sorts.length>0){
            res.data[0].sorts.forEach(item=>{
              if(item.sortFair!=3){
                sorts.push(item)
              }
            })
          }
          let uses=res.data[0].uses||[]
          let list=res.data[0].timeAreas||[]
          //获取所有站点列表
          let areaList=[]
          list.forEach(item=>{
            if(!areaList.find(item2=>item2.projectIds==item.projectIds)){
              //去重，并且为排号区的才放入数组
              if(item.areaId==1){
                areaList.push({
								  projectIds:item.projectIds,
								  projectName:item.projectName
                })
              }
            }
          })
          //获取已使用和已排号站点信息之和
          let usedList=sorts.concat(uses)
          let usedNewArr=[]
			    usedList.forEach(item=>{
			      if(!usedNewArr.find(item2=>item2.projectId==item.projectId)){
			        usedNewArr.push({
			          projectId:item.projectId,
			          projectName:item.projectName
			        })
			      }
			    })
          //获取未排号的站点列表
          this.noNumberList=JSON.parse(JSON.stringify(areaList)) 
          this.noNumberList.forEach((item,index)=>{
            usedNewArr.forEach(item2=>{
              if(item.projectIds==item2.projectId){
                delete this.noNumberList[index]
              }
            })
          })
          this.noNumberList=this.noNumberList.filter(function (val) {
        	return val
          })
          if(this.noNumberList.length==0){
            uni.navigateTo({
            	url:`/pages/my/order/electronicTicket/electronicTicket?orderId=${this.orderId}`
            })
          }
          if(this.noNumberList.length==1){
            let chooseArea=JSON.stringify(this.noNumberList[0])
            uni.navigateTo({
              url:`/pages/my/takeNumber/rowNumber/rowNumber?chooseArea=${chooseArea}&orderId=${this.orderId}`
            })
          }
          if(this.noNumberList.length>1){
            let list=JSON.stringify(this.noNumberList)
            uni.navigateTo({
						  url:`/pages/my/takeNumber/numberChoose/numberChoose?list=${list}&orderId=${this.orderId}`
            })
          }
			  }else{
			    uni.showToast({
			      title: res.message,
			      icon: 'none',
            duration:4000
			    })
			  }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.wrap {
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(180deg, #3688ff 0%, #2abbd7 100%);
}
.first input {
	width: 600rpx;
	height: 88rpx;
	background: #fff;
	border-radius: 8rpx;
	padding: 0 24rpx;
}
.query {
	margin-top: 48rpx;
	display: flex;
	justify-content: center;
}
.button {
	display: inline-block;
	width: 440rpx;
	height: 80rpx;
	line-height: 80rpx;
	background: #3688ff;
	border-radius: 40rpx;
	text-align: center;
	color: #fff;
	font-size: 32rpx;
	font-weight: bold;
}
// 遮罩层
.mark-box {
	position: fixed;
	z-index: 100;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.6);
	display: flex;
	align-items: center;
	justify-content: center;
}
.mark-content{
	background: #ffffff;
	margin: 0 48rpx;
	border-radius: 16rpx;
	padding: 64rpx 0;
	text-align: center;
}
.mark-title{
	font-size: 40rpx;
	font-weight: bold;
	color: #191919;
}
.mark-tip{
	font-size: 32rpx;
	margin-top: 24rpx;
}
.mark-btn{
	margin-top: 48rpx;
	.btn{
		width: 212rpx;
		height: 80rpx;
		line-height: 60rpx;
		font-size: 32rpx;
		background: #3688FF;
		border-radius: 40rpx;
	}
}
.mark-close{
	margin-top: 60rpx;
	text-align: center;
}
</style>
