<template>
	<view class="box">
		<homenav :iStatusBarHeight="iStatusBarHeight" :title="'我的预约'" ></homenav>
		<view class="itemHistory" v-for="(item,index) in itemData" :key="index" @click="goDetail(item.ID)">

			<view class="carPlate">
				<view class="time">{{item.BillDate}}</view>
				<view class="mileage" v-if="item.SheetState == 0" style="color: #FF0000">待确认</view>
				<view class="mileage" v-if="item.SheetState == 1" style="color: #3F90F7">预约中</view>
				<view class="mileage" v-if="item.SheetState == 2" style="color: #00A040;">已到店</view>
				<view class="mileage" v-if="item.SheetState == 3">已取消</view>
			</view>

			<view class="plate">{{item.PlateNumber}}</view>

			<view class="shopName">{{item.ShopName}}</view>

			<view class="itemN">
				<view class="itemContent" v-if="item.OrderItem.length != 0">{{item.OrderItem}}</view>
			</view>


		</view>

		<!-- 上拉 加载更多 -->
		<view class="noMore" v-if="noMoreShow && (itemData.length!=0)">没有更多数据</view>
		<!-- 无数据空白页 -->
		<nodata v-if="itemData.length==0"></nodata>
        <!-- 手机号授权 -->
        	<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,
				itemData: [],
				noMoreShow: false,
				iStatusBarHeight:'',
				userInfo:'',
				ext:'',
				wxOpenData:'',
				themeColor:'',
				authorizShow:false,
				code:'',
			}
		},
		onLoad() {
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.page = 1
			//this.myOrderCoupon()
			this.userInfo=this.$store.state.userInfo;
			this.ext=this.$common.getExtStoreId();
			this.themeColor = uni.getStorageSync("themeColor");
			if(this.userInfo){
				this.myOrderCoupon()
			}else{
				this.$common.automaticlogin().then(val => {
					this.userInfo=this.$store.state.userInfo;
					this.wxOpenData=this.$store.state.wxOpenData;
					this.themeColor = uni.getStorageSync("themeColor");
					this.myOrderCoupon();
					if(!this.userInfo){
						this.authorizShow=true
					}
				})
			}
		},
		onShow() {
			this.page = 1
			this.myOrderCoupon()
		},
		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.myOrderCoupon()
						}	
					  })
			},
			goDetail(id) {
				uni.navigateTo({
					url: 'bespeakDetail?id=' + id
				})
			},
			myOrderCoupon() {
				uni.showLoading({
					title: '加载中'
				})
				this.$http('openreservation/listOrderSheet', {

					// page: this.page,
					// limit: 10,
				}, 'GET').then(res => {
					uni.hideLoading();
					// var list = res.data.Items
					var list = res.data

					// 处理 undefined和null转为空白字符串
					// list.forEach((item, index) => {
					// 	for (const key in item) {
					// 		item[key] = this.$praseStrEmpty(item[key])
					// 	}
					// })

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

					if (list.length < 10) {
						this.noMoreShow = true
					} else {
						this.noMoreShow = false
					}





				})
			},


		},

		// 下拉刷新 
		onPullDownRefresh() {
			this.page = 1
			this.myOrderCoupon()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},

		// 上拉加载更多
		onReachBottom() {
			// this.page++;
			this.myOrderCoupon()
		},
	}
</script>

<style scoped lang="scss">
	.box {
		min-height: 100vh;
		background-color: #F4F5F7;
		padding-top: 20rpx;
	}

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

	}

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

	.carPlate {
		margin-bottom: 22rpx;

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

	.plate {
		font-size: 30rpx;
		color: #3C3C3C;
		font-weight: bold;
		margin-right: 20rpx;
	}

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

	}

	.itemN {
		display: flex;

	}

	.shopName{
		color: #666666;
		font-size: 24rpx;
		margin: 16rpx 0rpx;
		/* 隐藏文字显示 ...不换行 */
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	.itemContent {
		color: #666666;
		font-size: 24rpx;
		
		/* 隐藏文字显示 ...不换行 */
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.noMore {
		text-align: center;
		line-height: 50rpx;
		color: #999999;
		font-size: 28rpx;
	}
	.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>
