<template>
	<view class="order_index">
		<w-picker mode="date" startYear="2000" endYear="2100" v-model="datevalue" :current="true" :fields="showtype" @confirm="onConfirm($event)"
		 @cancel="onCancel" :disabled-after="false" ref="date"></w-picker>
		<z-navbar>
			<view slot="title" @click="chooseDate(stateTab)">
				{{dataYearMonth}}
			</view>
			<view slot="right"  class="iconfont iconjuxing5" @click="gotoSearch"></view>
		</z-navbar>
	
		<z-tabs :tabs="['咨询提醒','预定提醒']" v-if="!hideStateTab" v-model="stateTab" @change="changeTabs"></z-tabs>
		
		<consultation v-if="stateTab==0" :refresh="refresh" @getDateInfo="getDateInfo"></consultation>
		<reserve v-else @getDateInfo="getDateInfo" :refresh="refresh"></reserve>
		<view class="add_order flex-n fac fjc" @click="addConsultation">
			<view class="iconfont iconjia"></view>
		</view>
		<z-tabbar></z-tabbar>
	</view>
</template>

<script>
	import consultation from './consultation.vue';
	import reserve from './reserve.vue'

	export default {
		components: {
			consultation,
			reserve
		},
	
		data() {
			
			return {
				dataYearMonth: '2020.04',
				showtype:'day',
				datevalue:'',
				stateTab: 0,
				refresh:false,
				hideStateTab:false
			};
		},
		mounted() {
			uni.hideTabBar();
			this.getMenu();
		},
		onShow() {
			this.getMenu();
			this.refresh=true;
		},
		onHide(){
			this.refresh=false;
		},
		computed: {
		
		},
		methods: {
			getMenu(){
				uni.getStorage({
					key:'menu',
					success:(res)=>{
						console.log(res)
						if(res.data.indexOf('101')==-1){
							this.hideStateTab=true;
							this.stateTab=1;
						}
						if(res.data.indexOf('102')==-1){
							this.hideStateTab=true;
							this.stateTab=0;
						}
					}
				})
			},
			getDateInfo(date){
				this.dataYearMonth=date.yy+'.'+(date.mm>9?date.mm:('0'+date.mm))
				this.datevalue=date.date;
			},
			addConsultation(){
				if(this.stateTab==0)
				uni.navigateTo({
					url: '../manage/index?type=0',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
				else{
					uni.navigateTo({
						url: '../../book/manage/index?type=0',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			gotoSearch(){
				if(this.stateTab==0){
					uni.navigateTo({
						url: '../../search/index?type=0',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}else{
					uni.navigateTo({
						url: '../../search/index?type=1',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
				
			},
			onConfirm(e) {
				console.log(e)
				this.datevalue=e.value;
				var a = e.value.split("-");
				this.dataYearMonth = a[0] + '.' + a[1];
				this.$store.state.searchDate = e.value;
			},
			onCancel() {
				console.log(this.$refs.date.value,this.$refs.date.pickVal)
			},
			chooseDate:function(state){
				if(state!=3){
					this.showtype='day';
				}else{
					this.showtype='month';	
				}
				
				this.$refs.date.show();
			},
		
			changeTabs(idx) {
				this.stateTab = idx;
				this.refresh=true;
			},
		}
	}
</script>

<style scoped lang="scss">
	.month-height {
		height: calc(100vh - 280rpx - var(--status-bar-height));
	}
	.day-height{
		height: calc(100vh - 280rpx - var(--status-bar-height));
	}
	.order_index {
		.add_order {
			position: fixed;
			width: 82rpx;
			height: 82rpx;
			background: #2481EE;
			border-radius: 50%;
			right: 51rpx;
			bottom: 143rpx;

			view {
				width: 49rpx;
				height: 49rpx;
				font-size: 49rpx;
				line-height: 49rpx;
				color: white;
				z-index: 300;
			}

			color: white;
			box-shadow:10rpx 10rpx 30rpx 0rpx #C6E0FF;
		}
	}
</style>