<template>
	<view class="box">
		<homenav :iStatusBarHeight="iStatusBarHeight" :title="'我的订单'" :cj="3"></homenav>
		<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 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==5">待成团</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>
				<view class="itemShopBg">
					<view class="shopName">{{item.SheetContent}}</view>
					<view style="color: #333333;font-size: 22rpx;">￥<span class="price">{{item.PayType==1?item.RealMoney:0}}</span></view>
				</view>
                 <view class="renBox" v-if="item.SheetType==6">
					<image src="../../../static/timg/icon_ren.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="authorizBox" v-if="authorizShow" @click="authorizShow=false">
				<view class="authorizCont" @click.stop="">
					<view class="authorizName">{{wxOpenData.miniAppName}}</view>
					<view class="authorizMs">未注册的手机号登录后将自动创会员账号,如果您不同意授权获取手机号，会影响您使用我们的产品和服务。</view>
					<button class="authorizContbutton" type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">授权</button>
				</view>
				<view style="text-align: center;padding-top: 56rpx;">
					<image src="../../../static/timg/icon_guanbi@2x.png" mode="" class="authorizCloseImg"></image>
				</view>
			</view>
	</view>
</template>

<script>
	import nodata from '@/components/nodata/nodata.vue'
	import homenav from "@/components/homenav/nav.vue"
	export default {
		components: {
			nodata,homenav
		},
		data() {
			return {
				page: 1,
				tabIndex: '',
				items: [],
				isload: false,
                iStatusBarHeight:'',
				userInfo:'',
				ext:'',
				wxOpenData:'',
				themeColor:'',
				authorizShow:false,
				code:'',
			}
		},
		onLoad(opt) {
            this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.tabIndex = opt.num;
            this.userInfo=this.$store.state.userInfo;
            this.ext=this.$common.getExtStoreId();
			this.themeColor = uni.getStorageSync("themeColor");
            if(this.userInfo){
            	this.getData()
            }else{
            	this.$common.automaticlogin().then(val => {
            		this.userInfo=this.$store.state.userInfo;
            		this.wxOpenData=this.$store.state.wxOpenData;
					this.themeColor = uni.getStorageSync("themeColor");
            		this.getData();
            		if(!this.userInfo){
            			this.authorizShow=true
            		}
            	})
            }
			
		},
		onShow() {
			console.log(this.tabIndex)

			this.getData()

		},
		methods: {
           decryptPhoneNumber: function(e) {
             console.log(e);
             this.code=e.detail.code
             this.wxPhoneLogin()
             this.authorizShow=false;
           },
           wxPhoneLogin(){
           		 var that=this;
           		 this.$http('miniApp2/sys/wxPhoneLogin', {
           		   appId:this.ext.appId,
           		   unionId:this.ext.unionId,
           		   code:this.code,
           		   openId:this.wxOpenData.openid
           		  },'POST').then(res => {
           			var data = res.data;
           			if(data.loginInfo){
           				this.userInfo=data.loginInfo.openUser;
           				this.wxOpenData=data.loginInfo;
           				this.$store.commit('mutationswxOpenData', data)
           				this.$store.commit('mutationsuserInfo', this.userInfo)
           			    this.getData()
           			}	
           		  })
           },


			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
					})
				}
				else if (item.SheetType==5){
					uni.navigateTo({
						url: "paintOrderDetail?id=" + item.ID
					})
				}
				else if (item.SheetType==6){
					uni.navigateTo({
						url: "activityOrderDetail?id=" + item.ID//+'&sx=1'
					})
				}
			},
			getData() {
				uni.showLoading({
					title: '加载中'
				});
				this.isload = false;
				var padata = {
					page: this.page,
					limit: 10,
					sheetState: this.tabIndex > 0 ? this.tabIndex : ''
				}

				this.$http('openOrderManagement/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>
	.box {
		min-height: 100vh;
		background: #F4F5F7;
	}
   .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;
   }
	.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: 92rpx;
		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;
	}
	.authorizBox{
			width: 100vw;
			height: 100vh;
			background: rgba(0, 0, 0, 0.5);
			position: fixed;
			top: 0;
			left: 0;
		}
		.authorizCont{
			margin-top: 30vh;
			width: 564rpx;
			height: 408rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			margin-left: 93rpx;
			position: relative;
		}
		.authorizCloseImg{
			width: 62rpx;
			height: 62rpx;
		}
		.sqLogoBox{
			width: 180rpx;
			height: 180rpx;
			background: #FFFFFF;
			border-radius: 90rpx;
			text-align: center;
			position: absolute;
			top: -50rpx;
			left: 192rpx;
		}
		.authorizName{
			color: #333333;
			line-height: 42rpx;
			font-size: 30rpx;
			text-align: center;
			padding-top: 58rpx;
		}
		.authorizMs{
			color: #999999;
			line-height: 36rpx;
			font-size: 26rpx;
			width: 452rpx;
			padding-top: 24rpx;
			text-align: center;
			margin-left: 56rpx;
		}
		.authorizContbutton{
			width: 422rpx;
			height: 88rpx;
			background: #D53533;
			border-radius: 44rpx;
			line-height: 88rpx;
			text-align: center;
			font-size:30rpx;
			color: #FFFFFF;
			margin-top: 62rpx;
			margin-left:71rpx;
		}
		.shopBoxpt{
			margin-top: 20rpx;
		}
		button::after{
		 	border: none;
		}
		button{
			position: relative;
			display: block;
			margin-left: 0;
			margin-right: 0;
			padding-left: 0px;
			padding-right: 0px;
			box-sizing: border-box;
			// font-size: 18px;
			text-align: center;
			text-decoration: none;
			// line-height: 1;
			line-height: 1.35;
			// border-radius: 5px;
			-webkit-tap-highlight-color: transparent;
			overflow: hidden;
			color: #000000;
			background-color: #fff;
			
			height: 100%;
			}
</style>
