<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:[],//未排号站点列表
      merchantCode:'',//商家编号
      channelName:'',//渠道名称
      productName:'',//产品名称
    }
  },
  methods: {
    //---查询订单
    query(){
      if(!this.search){
        uni.showToast({
				  title:'请输入手机号或者身份证号',
				  icon: 'none'
        })
        return
      }
      let data={
        search:this.search
      }
      uni.showLoading({
        title:'加载中'
      })
      this.$request('order/userOrder/findOrderPageListByCode',data).then((res)=>{
			  if(res.code=='00'){
			    let list=res.data||[]
          this.merchantCode=list[0].merchantCode
          this.channelName=list[0].channelName
          this.productName=list[0].productName
          if(list.length==0){
            this.showMark=true
          }else{
            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'){
          let list=res.data[0].timeAreas||[]
          let sorts=res.data[0].sorts||[]
          let uses=res.data[0].uses||[]
          //获取所有站点列表
          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.showToast({
						  title: '该订单没有排号站点信息',
						  icon: 'none'
            })
          }
          if(this.noNumberList.length==1){
            let chooseArea=JSON.stringify(this.noNumberList[0])
            uni.navigateTo({
              url:`/pages/my/takeNumber/rowNumber/rowNumber?chooseArea=${chooseArea}&merchantCode=${this.merchantCode}&productName=${this.productName}&channelName=${this.channelName}`
            })
          }
          if(this.noNumberList.length>1){
            let list=JSON.stringify(this.noNumberList)
            uni.navigateTo({
						  url:`/pages/my/takeNumber/numberChoose/numberChoose?list=${list}&merchantCode=${this.merchantCode}&productName=${this.productName}&channelName=${this.channelName}`
            })
          }
			  }else{
			    uni.showToast({
			      title: res.message,
			      icon: 'none'
			    })
			  }
      })
    }
  }
}
</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>
