<template >
	<view>
		<u-toast ref="uToast"  />
		<u-loading :show="false"></u-loading>
		<u-modal v-model="show" :content="content" :confirm-text="confirmtext?confirmtext:'确定'" @confirm="confirmBtn" :title="title?title:'提示'"></u-modal>
		<u-modal v-model="show2" :show-cancel-button="true" :content="content" :confirm-text="confirmtext?confirmtext:'确定'" :cancel-text="canceltext?canceltext:'取消'" @confirm="confirmBtn" @cancel="cancelBtn" :title="title?title:'提示'"></u-modal>
		
		<u-navbar v-if="mytitle" :title="mytitle" :is-back="noback" :border-bottom="!noback">
				<view class="slot-wrap"></view>	
		</u-navbar>
		<view v-show="false"  :login="islogin()" ></view>	
 		
	</view>
</template>

<script>
	import * as API from '@/apis/common.js'
	
 	export default {
		name:"Common",
		props:{
			login: {
				require: false,
				default: false,
			},
			noback:{
				require: false,
				default: true,
			},
			mytitle: {
				require: false,
				default: false,
			},
		},
		data() {
			return {
				
				isloginBl:true,
				show:false,
				show2:false,
				fnc:null,
				fncCancel:null,
				fncBl:false,
				content:null,
				confirmtext:null,
				title:null,
				canceltext:null,
			};
			
		},methods:{
			
			
			islogin(){
				if(this.login){
					if (!this.carhelp.getPersonInfo()) {
						var route_path = window.location.href.split("#")[1];
						
						uni.reLaunch({
							url: '/pages/car/login'
						})
					}
				}
			},
			goError(message){
				this.setFnc(function(){
					uni.switchTab({
					    url: '/pages/index/index'
					});
				})
				this.alert2(message?message:'访问链接异常','前往首页')
				
			},
			setFnc(fnc,fncCancel){
				
				this.fnc=fnc;
				this.fncCancel=fncCancel;
				this.fncBl=true
			},
			alert2(content,confirmtext,title){
				this.show=true;
				this.content=content;
				this.confirmtext=confirmtext;
				this.title=title;
				 uni.hideLoading();
			},
			confirm(content,confirmtext,title,canceltext){
				this.show2=true;
				this.content=content;
				this.confirmtext=confirmtext;
				this.canceltext=canceltext;
				this.title=title;
				 uni.hideLoading();
			},
			cancelBtn(){
				if(this.fncCancel){
					this.fncCancel()
					this.fncBl=false;	
				}
			},
			confirmBtn(){
				
				if(this.fncBl){
					this.fnc()
					this.fncBl=false;	
				}
			},
			showLoading(bl,message){
				if(bl==null ||bl){
					// request  要改同步改
					uni.showLoading({
						mask:true,title:'加载中...'
					})
				}else{
					  uni.hideLoading();
					  if(message){
						  this.alert(message)
					  }
				}
				
			},
			alert(message,fnc){
				this.$refs.uToast.show({
					title: message,
					type:'default',
					position:'bottom',
					callback:fnc
				})
			}
		},mounted(){
				
		},destroyed(){
			
		}
		
	}
</script>

<style>
	.navbar-right {
				display: flex;
				margin-right: 20rpx;
				span{
					color:rgb(96, 98, 102);
					margin-left: 3px;
				}
			}
			.slot-wrap {
					display: flex;
					align-items: center;
					flex: 1;
				}
</style>
