<template>
	<view class="box">
		
		<!-- 自定义导航 -->
		<view class="zdyNavBox">
			<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
			<view class="zdyNav">
				<view class="zdyNavLeft">
					<image src="../../static/img/nav_icon_back.png" mode="aspectFit" class="backImg" @click="goback">
					</image>
		
				</view>
				<view class="zdyNavTitle">订单管理</view>
				<view style="width: 50px;"></view>
			</view>
		</view>
		<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
		<view style="height: 44px;"></view>
		<!-- 搜索框 -->
		<view class="newtop">
			<view class="searchBox">
			  <view class="searchInputBox">
				  <image src="../../static/img/icon_search.png" mode="" class="iconSimg"></image>
				  <input type="text" v-model="name" placeholder="订单号、手机号、联系人" class="searchInput" @confirm="searchCf">
			       <image v-if="name" @click="ssql" src="../../static/img/chahao.png" mode="" class="sschahao"></image>
			  </view>
			  <image @click="screenSHowBtn" src="../../static/img/icon_shai.png" mode="" class="iconShai"></image>
			</view>
			<view class="tab">
				<view class="tabLine" :class="{tabActive:tabIndex==0}" @click="tabClick(0)">全部</view>
				<view class="tabLine" :class="{tabActive:tabIndex==1}" @click="tabClick(1)">待付款</view>
				<view class="tabLine" :class="{tabActive:tabIndex==5}" @click="tabClick(5)">待成团</view>
				<view class="tabLine" :class="{tabActive:tabIndex==2}" @click="tabClick(2)">待服务</view>
				<view class="tabLine" :class="{tabActive:tabIndex==3}" @click="tabClick(3)">已完成</view>
			
			</view>
		</view>
		
		
		<view class="main">
			<view class="itemBg" v-for="(item,index) in items" @click="goDetail(item)">
				<view class="itemTop">
					<view class="itemType" v-if="item.SheetType==1">商城-商品订单</view>
					<view class="itemType" v-if="item.SheetType==2">商城-项目订单</view>
					<view class="itemType" v-if="item.SheetType==3">商城-套餐订单</view>
					<view class="itemType" v-if="item.SheetType==4">救援订单</view>
					<view class="itemType" v-if="item.SheetType==5">钣喷订单</view>
					<view class="itemType" v-if="item.SheetType==6">集客订单</view>

					<view class="itemSheetState redColor" v-if="item.SheetState==1">待付款</view>
					<view class="itemSheetState orangeColor" v-if="item.SheetState==2">待服务</view>
					<view class="itemSheetState greenColor" v-if="item.SheetState==3">已完成</view>
					<view class="itemSheetState" v-if="item.SheetState==4">已取消</view>
					<view class="itemSheetState redColor" v-if="item.SheetState==5">待成团</view>

				</view>
				<view class="itemShopBg">
					<view class="shopName">{{item.SheetContent}}</view>
					<view style="color: #333333;font-size: 22rpx;">￥<span class="price">{{item.RealMoney}}</span></view>
				</view>
                <view class="renBox" v-if="item.SheetType==6">
						<image src="../../static/img/icon_ren2.png" mode="" class="renimg"></image> 
						<view class="renMobilePhone">{{item.MobilePhone}}</view>
						<view class="renNickName">{{item.NickName?item.NickName:''}}</view>
                </view>
				<view class="itemName">{{item.CreateTime}}</view>
				<view class="itemName" style="padding-top: 2rpx;padding-bottom: 0;">{{item.ShopName}}</view>

			</view>
			
			<nodata v-show="items==''&&isload"></nodata>
		</view>
		<!-- 筛选弹框 -->
		<view class="screenBox" v-if="screenSHow" @click="screenHide">
		  <view class="screenCont" @click.stop="">
			  <view class="screenTitle">筛选</view>
			  <view class="screenBt">订单类型</view>
			<!--  <view class="typelineBox">
				  <view class="typeLine " :class="{typeactive:typeLineIndex==0}" @click="typeLineCk(0)">全部</view>
				  <view class="typeLine" :class="{typeactive:typeLineIndex==1}" @click="typeLineCk(1)">商城订单</view>
				  <view class="typeLine" :class="{typeactive:typeLineIndex==6}" @click="typeLineCk(6)">集客订单</view>
				  <view class="typeLine" :class="{typeactive:typeLineIndex==4}" @click="typeLineCk(4)">救援订单</view>
				  <view class="typeLine":class="{typeactive:typeLineIndex==5}" @click="typeLineCk(5)">钣喷订单</view>
			  </view> -->
			  <view class="typelineBox">
			  	  <view class="typeLine " v-for="(item,index) in tabList" 
				    :class="{typeactive:item.ck}" @click="typeLineCk2(item)">{{item.name}}
				  </view>
			  	 
			    </view>
			  <view class="screenBt">门店</view>
			  <view class="">
			  	   <picker @change="bindPickerChange" :value="pickerindex" :range-key="'shopName'" :range="pickerarray">
			  	 		<view class="uniPicker"> 
							<view class="uniPickerName">
							  {{shopName}}
							</view>
						   <image src="../../static/img/jt.png" mode=" " class="jtShopImg"></image>
						</view>
			  	   </picker>
			  </view>
			   <view class="screenBt">下单时间</view>
			   <view class="sdTimeBox">
				   <picker mode="date" :value="date1"  @change="bindDateChange1">
				   			<view class="dateinput">{{date1?date1:'选择日期'}}</view>
				   	</picker>
					<view class="timeHx">-</view>
					<picker mode="date" :value="date2"  @change="bindDateChange2">
								<view class="dateinput">{{date2?date2:'选择日期'}}</view>
						</picker>
			   </view>
			   <view class="screenBottom">
				   <view class="screenCz" @click="resetting">重置</view>
				   <view class="screenY" @click="sub">确定</view>
			   </view>
		  </view>
		</view>
	</view>
</template>

<script>
	import nodata from '@/components/nodata/nodata.vue'
	export default {
		components: {
			nodata
		},
		data() {
			return {
				page: 1,
				tabIndex: 0,
				items: [],
				isload: false,
				name:'',
				pickerindex:0,
				pickerarray: [],
				screenSHow:false,
				shopName:'',
				date1:'',
				date2:'',
				typeLineIndex:0,
				sheetTypeList:'',
				shopId:'',
				mrshopId:'',
				mrshopName:'',
				tabList:[
					{
					  name:'全部',ck:true,sheetType:'',
					},
					{
					  name:'商城订单',ck:false,sheetType:'1,2,3',
					},
					{
					  name:'集客订单',ck:false,sheetType:'6',
					},
					{
					  name:'救援订单',ck:false,sheetType:'4',
					},
					{
					  name:'钣喷订单',ck:false,sheetType:'5',
					}
				]
			}
		},
		onLoad(opt) {
			
			//this.getData();
			this.getShopinfo();
			
		},
		onShow() {
			console.log(this.tabIndex)
            this.getShopinfo();
			//this.getData();
			

		},
		
		methods: {
			ssql(){
				this.name='';
				this.getData();
			},
			sub(){
				this.screenSHow=false;
				var arr=[]
				this.items=[]
				this.tabList.forEach(item=>{
					if(item.ck){
						arr.push(item.sheetType)
					}
				})
				this.sheetTypeList=arr.join(',');
				console.log(this.sheetTypeList)
				this.getData();
			},
			resetting(){
				this.date1='';
				this.date2='';
				this.typeLineIndex='';
				this.shopName=this.mrshopName;
				this.shopId=this.mrshopId;
				this.sheetTypeList=''
				this.tabList[0].ck=true
				this.tabList[1].ck=false
				this.tabList[2].ck=false
				this.tabList[3].ck=false
				this.tabList[4].ck=false
			},
			typeLineCk(num){
				this.typeLineIndex=num;
				if(num==1){
					this.sheetTypeList='1,2,3'
				}else{
					this.sheetTypeList=num
				}
				if(num==0){
					this.sheetTypeList=''
				}
			},
			typeLineCk2(item){
				if(item.name=='全部'){
					item.ck=true;
					this.tabList[1].ck=false
					this.tabList[2].ck=false
					this.tabList[3].ck=false
					this.tabList[4].ck=false
				}else{
					this.tabList[0].ck=false
					item.ck=!item.ck;
				}
				
			},
			screenSHowBtn(){
				this.screenSHow=true;
			},
			screenHide(){
				this.screenSHow=false;
			},
			bindDateChange1(e){
				console.log(e)
				this.date1=e.detail.value
			},
			bindDateChange2(e){
				this.date2=e.detail.value
			},
			bindPickerChange(e){
				console.log(e)
				this.shopName=this.pickerarray[e.detail.value].shopName
				this.shopId=this.pickerarray[e.detail.value].id
			},
			getShopinfo(){
				this.$http('openH5SetTheGuest/getShopInfo',{},'GET').then(res => {
						this.shopName=res.data.shopName;
						this.mrshopId=res.data.id;
						this.mrshopName=res.data.shopName;
						this.shopId=this.mrshopId
						this.getShopList();
						this.getData()
				 })
			},
			getShopList(){
						 
				   this.$http('openH5SetTheGuest/getShopList', {
					 
					},'GET').then(res => {
						
						this.pickerarray=res.data;
						/* this.pickerarray.forEach((item,index)=>{
							
							if(this.mrshopId==item.id){
								this.pickerindex=index;
								
							}
						}) */
						//console.log(this.pickerarray[this.pickerindex])
					})
			},
			goback(){
				
					//app交互
					var standalone = window.navigator.standalone
					var userAgent = window.navigator.userAgent.toLowerCase()
					var safari = /safari/.test(userAgent)
					var ios = /iphone|ipod|ipad|mac/.test(userAgent)
					var android = /android/.test(userAgent)
					if (ios) {
									 if ( true) {//!standalone&& !safari
									   window.webkit.messageHandlers.goMyNav.postMessage(null)
									 }
					} else if (android) {
									 window.android.postMessage()
					}
				
			   
			},

			tabClick(num) {
				this.tabIndex = num;


				this.page = 1;
				this.getData()
			},
			goDetail(item) {
				//SheetType 1 商品2项目3套餐4救援5钣喷6集客
				if((item.SheetType==1)||(item.SheetType==2)||(item.SheetType==3)){
					uni.navigateTo({
						url: "mallOrderDetail?id=" + item.ID +"&SheetType=" + item.SheetType+'&back=1'
					})
				}
				else if (item.SheetType==5){
					uni.navigateTo({
						url: "paintOrderDetail?id=" + item.ID+'&back=1'
					})
				}
				else if (item.SheetType==6){
					uni.navigateTo({
						url: "activityOrderDetail?id=" + item.ID+'&back=1'
					})
				}
			},
			searchCf(){
				this.items=[]
				this.getData()
			},
			getData() {
				uni.showLoading({
					title: '加载中'
				});
				this.isload = false;
				var padata = {
					page: this.page,
					limit: 10,
					sheetState: this.tabIndex > 0 ? this.tabIndex : '',
					name:this.name,
					starCreateTime:this.date1+ ' 00:00:00',
					endCreateTime:this.date2+ ' 23:59:59',
					sheetType:this.sheetTypeList,
					shopName:this.shopId,
				}

				this.$http('openH5Indent/getOpenSheetList', padata, 'GET').then(res => {
					uni.hideLoading();
					this.isload = true;

					var list = res.data.Items;

					if (this.page == 1) {
						this.items = list
					} else {
						this.items = this.items.concat(list)
					}

				})
			},

		},
		onReachBottom() {
			this.page++;

			this.getData()
		},
		onPullDownRefresh() {
			this.page = 1;
			this.getData()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		}
	}
</script>

<style scoped>
	.screenBox{
		width: 100%;
		height: 100%;
		position: fixed;
		left: 0;
		top: 0;
		background: rgba(0 ,0,0,0.5);
		z-index: 999;
	}
	.screenBottom{
		width: 649rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0rpx -2rpx 10rpx 0rpx rgba(153,153,153,0.2);
		position: absolute;
		bottom: 0;
		right: 0;
		display: flex;
		justify-content: space-around;
	}
	.screenCz{
		width: 291rpx;text-align: center;margin-top: 22rpx;
		height: 74rpx;line-height: 74rpx;
		background: #F4F5F7;color: #000000;
		border-radius: 37rpx;font-size: 28rpx;
	}
	.screenY{
		width: 291rpx;text-align: center;margin-top: 22rpx;
		height: 74rpx;line-height: 74rpx;
		background: #D53533;color: #FFFFFF;
		border-radius: 37rpx;font-size: 28rpx;
	}
	.screenCont{
		width: 650rpx;
		height: 100%;
		background: #FFFFFF;
		margin-left: 100rpx;
	}
	.screenTitle{
		font-weight: 400;font-size: 24rpx;padding-top: 70rpx;padding-left: 20rpx;
		color: #333333;
	}
	.screenBt{
		font-weight: 400;font-size: 24rpx;
		color: #333333;padding-left: 20rpx;padding-top: 30rpx;
	}
	.iconShai{
		width: 36rpx;height: 39rpx;margin-top: 17rpx;
		margin-left: 30rpx;
	}
	.iconSimg{
		width: 40rpx;height: 40rpx;margin-top: 16rpx;margin-left: 20rpx;
	}
	.searchBox{
		display: flex;background: #FFFFFF;padding: 24rpx;   
		left: 0;
	}
	.typeLine{
		width: 178rpx;color: #3C3C3C;
		height: 64rpx;font-size: 24rpx;
		background: #F4F5F7;margin-top: 20rpx;
		border-radius: 36rpx;margin-right: 30rpx;
		text-align: center;
		line-height: 64rpx;
	}
	.typeactive{
		border: 2rpx solid #D53533;height: 60rpx;color: #D53533;background: #FFFFFF;width: 174rpx;
	}
	.typelineBox{
		display: flex;flex-wrap: wrap;padding-left: 20rpx;
	}
	.uniPicker{
		width: 606rpx;
		height: 64rpx;
		background: #F4F5F7;font-size: 24rpx;
		border-radius: 36rpx;color: #3C3C3C;
		display: flex;justify-content: space-between;
		margin-top: 20rpx;margin-left: 20rpx;
	}
	.jtShopImg{
		width: 24rpx;height: 24rpx;margin-top: 20rpx;margin-right: 26rpx;
		}
	.uniPickerName{
		padding-left: 20rpx;line-height: 64rpx;
		overflow:hidden;
		  white-space: nowrap;
		  text-overflow: ellipsis;
		  -o-text-overflow:ellipsis;
		  width: 500rpx;
	}
	.dateinput{
		width: 270rpx;color: #999999;
		height: 64rpx;font-size: 24rpx;line-height: 64rpx;
		background: #F4F5F7;padding-left: 20rpx;
		border-radius: 36rpx;
	}
	.sdTimeBox{
		display: flex;
		padding-top: 20rpx;padding-left: 20rpx;
	}
	.timeHx{
		font-weight: 400;line-height: 64rpx;padding: 0 4rpx;
		color: #DDDDDD;font-size: 24rpx;
	}
	.newtop{
		 position: fixed;z-index: 11;
	}
	.searchInputBox{
		width: 630rpx;
		height: 72rpx;
		background: #F4F5F7;
		border-radius: 36rpx;
		display: flex;
	}
	.searchInput{
		font-size: 28rpx;padding-left: 16rpx;height: 72rpx;line-height: 72rpx;
		width: 500rpx;
	}
	.box {
		min-height: 100vh;
		background: #F4F5F7;
	}
	
	.zdyNavBox {
		width: 100vw;
		background: #FFFFFF;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
	
	
	}
	
	.zdyNav {
		height: 44px;
		display: flex;
		justify-content: space-between;
	
		align-items: center;
	
	}
	
	.backImg {
		width: 44rpx;
		height: 44rpx;
		margin-left: 10rpx;
		margin-right: 20rpx;
	}
	
	.homeImg {
		width: 44rpx;
		height: 44rpx;
	
	}
	
	.zdyNavLeft {
		display: flex;
		align-items: center;
	}
	
	.zdyNavTitle {
	
		height: 44px;
		background: #FFFFFF;
		text-align: center;
		font-size: 34rpx;
		line-height: 44px;
	}
	
	

	.tab {
		background: #FFFFFF;
		display: flex;
		justify-content: space-between;
		line-height: 92rpx;
		/* position: fixed; */
		width: calc(100vw - 100rpx);
		padding-left: 50rpx;
		padding-right: 50rpx;
		height: 92rpx;
		z-index: 11;
	}

	.tabLine {

		font-size: 28rpx;
		color: #333333;
		text-align: center;
	}

	.tabActive {
		color: #FF0000;
		font-weight: bold;
		border-bottom: 4rpx solid #FF0000;

	}

	.main {
		padding-top: 210rpx;
		padding-bottom: 20rpx;
		background-color: #F4F5F7;
	}

	.itemBg {
		margin: 20rpx 24rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		padding: 20rpx;
	}

	.itemTop {
		display: flex;
		justify-content: space-between;
	}

	.itemType {
		color: #999999;
		font-size: 24rpx;
	}

	.itemSheetState {
		font-size: 24rpx;
		color: #999999
	}
	.redColor {
		color: #FF0000;
	}
	.orangeColor {
		color: #F19D01;
	}
	.greenColor {
		color: #00A040;
	}
	

	.itemShopBg {
		display: flex;
		justify-content: space-between;
		margin-top: 20rpx;
	}

	.shopName {
		color: #333333;
		font-size: 30rpx;
		font-weight: bold;
		/* 隐藏文字显示 ...不换行 */
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.price {
		color: #333333;
		font-weight: bold;
		font-size: 32rpx;
	}

	.itemName {
		color: #666666;
		font-size: 24rpx;
		padding: 16rpx 0;
		height: 30rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.plateBg {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.plateNumber {
		color: #666666;
		font-size: 24rpx;
		margin-bottom: 20rpx;
		display: flex;

	}

	.itemLineBottom {
		display: flex;
		justify-content: flex-end;

	}

	.itemBtn1 {
		width: 150rpx;
		height: 56rpx;
		border-radius: 36rpx;
		border: 2rpx solid #DDDDDD;
		text-align: center;
		line-height: 56rpx;
		font-size: 28rpx;
		color: #3C3C3C;
		margin-left: 40rpx;
	}

	.itemBtn2 {
		width: 150rpx;
		height: 56rpx;
		border-radius: 36rpx;
		border: 2rpx solid #FF4F00;
		text-align: center;
		line-height: 56rpx;
		font-size: 28rpx;
		color: #FF4F00;
		margin-left: 40rpx;
	}

	.orderState {
		color: #F19D01;
		font-size: 24rpx;
		padding-left: 20rpx;
	}
	.renBox{
		   color: #1A1A1A;
		   background: #F7F7F7;
		   border-radius: 10rpx;
		   display: flex;
		   padding: 20rpx;font-size: 24rpx;
		   line-height: 30rpx;
		   margin-top: 16rpx;
	}
	.renimg{
		   width: 30rpx;height: 30rpx;
	}
	.renMobilePhone{
		   padding-left: 13rpx;
	}
	.renNickName{
		   padding-left: 20rpx;
	}
	.sschahao{
		width: 40rpx;
		height: 40rpx;
		padding-top: 16rpx;
	}
</style>
