<script>
	export default {
		globalData: {  
			host: 'http://wy2.jiliyilian.com/wap',
			serverUrl: 'http://wy2.jiliyilian.com/api/h5/',
			uploadServerUrl: 'http://wy2.jiliyilian.com/api/h5/',
			appId: 'wx439b9d9527727911',
			redirectUri: 'http://wy2.jiliyilian.com/wap/ph/#/pages/index/wechat',
			storagePre: 'ph_',
			userinfo:{}
		},
		onLaunch: function() {
            var app = getApp();
            var orgId = this.getUrlCode('orgId');
			 // var orgId = 3;
            //alert('当前url:'+window.location.href+'参数：'+orgId);
			if(orgId){
				uni.setStorageSync(app.globalData.storagePre+'orgId',orgId);
				app.globalData.userinfo.orgId = orgId;
			}else{
				orgId = uni.getStorageSync(app.globalData.storagePre+'orgId');
				if(orgId){
					app.globalData.userinfo.orgId = orgId;
				}else{
					uni.showToast({
						title: '参数错误',
						icon: 'none',
						duration: 2000
					})
				}
			}
			
			let token = uni.getStorageSync(app.globalData.storagePre+'token');
			if(token){
				app.globalData.userinfo.token = token;
				app.globalData.userinfo.userId = uni.getStorageSync(app.globalData.storagePre+'userId');
			}
			if(orgId){
				app.globalData.userinfo.orgId = orgId;
			}else{
				app.globalData.userinfo.orgId = 0;
			}
		// app.globalData.userinfo.orgId = 3;
		// app.globalData.userinfo.token = '4914243105615';
		// app.globalData.userinfo.userId = 4;
			this.checkLogin();
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			getUrlCode (name) {
				return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
			},
			checkLogin: function(){ // 陪护调度端
				var app = getApp();
				var token = app.globalData.userinfo.token;
				if(!token){
					uni.reLaunch({ //关闭所有页面，跳转到闪屏页
						url: '/pages/index/wechat'
					})
				}
			},
			checkCode:function(code){
			    if(code == -100){
					uni.showToast({
						title: '登录超时,请重新登录',
						icon: 'none',
						duration: 2000
					})
					var app = getApp();
					uni.removeStorageSync(app.globalData.storagePre+'token');
					uni.removeStorageSync(app.globalData.storagePre+'userId');
					setTimeout(function(){
						uni.reLaunch({ //关闭所有页面，打开到应用内的某个页面
							url: '/pages/index/wechat'
						})
					},2000);
					return false;
			    }
			    return true;
			},
			ajax: function(params){
			    if (!params.type) {
					var type = 'POST';
			    }else{
					var type = params.type;
			    }
			    if (!params.apiname) {
					var apiname = '1';
			    } else {
					var apiname = params.apiname;
			    }
			    if (!params.data) {
					var data = [];
			    }else{
					var data = params.data;
			    }
			    var app = getApp();
			    var token = app.globalData.userinfo.token;
				var userId = app.globalData.userinfo.userId;
			    if (!token || token == undefined) { //未登录
					uni.showToast({
						title: '未登录',
						icon: 'none',
						duration: 2000
					});
					uni.removeStorageSync(app.globalData.storagePre+'token');
					uni.removeStorageSync(app.globalData.storagePre+'userId');
					setTimeout(function () {
						uni.reLaunch({ //关闭所有页面，跳转到闪屏页
							url: '/pages/index/wechat'
						})
					}, 2000);
			      return false;
			    }
			    data['token'] = token;
				data['userId'] = userId;
				
				var orgId = app.globalData.userinfo.orgId;
				if(orgId){
					data['orgId'] = orgId;
				}
				
			  //   uni.showLoading({
					// title: '加载中',
					// mask: true
			  //   });
			    
			    uni.request({
					url: params.url,
					data: data,
					method: type,
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function (res) {
						uni.hideLoading();
						uni.stopPullDownRefresh();
						var ret = app.checkCode(res.data.code); //检查token是否失效
						if(ret == false){
							return false;
						}
			
						if (res.data.code == 0) {
							if (app.ajaxReadyCallback) { //在onShow中调用数据的,添加在onShow方法内,防止不同页面覆盖
								res.data['apiname'] = apiname;
								app.ajaxReadyCallback(res)
							}
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none',
								duration: 2000
							})
						}
					},
					fail: function (err) {
						uni.hideLoading();
						uni.showToast({
							title: '请求失败',
							icon: 'none',
							duration: 2000
						})
					}
			    })
			},
			ajaxUnlogin: function(params){
			    if (!params.type) {
					var type = 'POST';
			    }else{
					var type = params.type;
			    }
			    if (!params.apiname) {
					var apiname = '1';
			    } else {
					var apiname = params.apiname;
			    }
			    if (!params.data) {
					var data = [];
			    }else{
					var data = params.data;
			    }
			    var app = getApp();	
				var orgId = app.globalData.userinfo.orgId;
				if(orgId){
					data['orgId'] = orgId;
				}
				
			  //   uni.showLoading({
					// title: '加载中',
					// mask: true
			  //   });
			    
			    uni.request({
					url: params.url,
					data: data,
					method: type,
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function (res) {
						uni.hideLoading();
						uni.stopPullDownRefresh();
						var ret = app.checkCode(res.data.code); //检查token是否失效
						if(ret == false){
							return false;
						}
			
						if (res.data.code == 0) {
							if (app.ajaxReadyCallback) { //在onShow中调用数据的,添加在onShow方法内,防止不同页面覆盖
								res.data['apiname'] = apiname;
								app.ajaxReadyCallback(res)
							}
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none',
								duration: 2000
							})
						}
					},
					fail: function (err) {
						uni.hideLoading();
						uni.showToast({
							title: '请求失败',
							icon: 'none',
							duration: 2000
						})
					}
			    })
			}
		}
		
		
	}
</script>

<style>
	/*每个页面公共css */
	page{
		background-color: #F3F3F3;
		--themeColor:#023894;
	}
	.no-data{
		width: 100%;
		height: auto;
		margin: 0 auto;
		margin-top: 20%;
		text-align: center;
	}
	.no-data image{
		width: 430rpx;
		height: 316rpx;
	}
	.no-data .no-data-text{
		color: #C5C8D9;
		font-size: 25rpx;
	}
	
	.pull-right{
		float: right!important;
	}
	.text-red{
		color: var(--themeColor);
	}
	
	.container{
		padding: 20rpx;
	}
	.worker-box{
	  position: relative;
	  width: 670rpx;
	  height: auto;
	  margin-bottom: 20rpx;
	  /* overflow: hidden; */
	  padding: 0 20rpx;
	  background-color: #ffffff;
	  border-radius: 10rpx;
	}
	.worker-box.cur{
	  border: 4rpx solid var(--themeColor);
	}
	.worker-box .worker-box-select{
	  display: none;
	}
	.worker-box.cur .worker-box-select{
	  display: inline-block;
	  width: 66rpx;
	  height: 68rpx;
	  position: absolute;
	  z-index: 5;
	  top: -2rpx;
	  right: -2rpx;
	}
	.worker-box .worker-box-header{
	  height: 90rpx;
	  line-height: 90rpx;
	  font-size: 32rpx;
	  font-weight: bold;
	  color: #333333;
	  margin-bottom: 20rpx;
	}
	.worker-box .worker-box-info{
	  padding: 30rpx 0;
	  width: 100%;
	  height: 130rpx;
	  overflow: hidden;
	  
	}
	.worker-box .worker-box-info .worker-box-avator{
	  position: relative;
	  width: 130rpx;
	  height: 130rpx;
	  float: left;
	}
	.worker-box .worker-box-info .worker-box-avator image{
	  width: 100%;
	  height: 100%;
	  border-radius: 50%;
	}
	.worker-box .worker-box-info .worker-box-avator .worker-box-status{
	  position: absolute;
	  z-index: 10;
	  bottom: 0;
	  left: 0;
	  width: 100%;
	  height: 36rpx;
	  border-radius: 18rpx;
	  color: #ffffff;
	  background-color: var(--themeColor);
	  text-align: center;
	  font-size: 26rpx;
	}
	.worker-box .worker-box-info .worker-box-avator .worker-box-status.color2{
	  background-color: #23C1CF;
	}
	.worker-box .worker-box-info .worker-box-body{
	  width: 520rpx;
	  height: 130rpx;
	  float: right;
	}
	.worker-box .worker-box-info .worker-box-body .worker-box-title{
	  color: #333333;
	  font-size: 30rpx;
	  font-weight: bold;
	  line-height: 50rpx;
	}
	.worker-box .worker-box-info .worker-box-body .worker-box-star{
	  display: inline-block;
	  width: auto;
	  float: right;
	}
	.worker-box .worker-box-info .worker-box-body .worker-box-desc{
	  color: #999999;
	  font-size: 26rpx;
	  line-height: 40rpx;
	  height: 40rpx;
	  overflow: hidden; 
	  text-overflow: ellipsis;
	  white-space:nowrap; 
	}
	.worker-box .worker-box-footer{
	  line-height: 99rpx;
	  height: 99rpx;
	  border-top: 1rpx solid #D9D9D9;
	}
	.worker-box .worker-box-footer image{
	  width: 36rpx;
	  height: 36rpx;
	  vertical-align: middle;
	}
	.worker-box .worker-box-footer .worker-box-footer-money{
	  vertical-align: middle;
	  padding: 0 10rpx;
	  font-size: 34rpx;
	  color: #FF3F40;
	}
	.worker-box .worker-box-footer .worker-box-footer-btn{
	  display: inline-block;
	  width: 130rpx;
	  height: 60rpx;
	  line-height: 60rpx;
	  color: #ffffff;
	  background-color: var(--themeColor);
	  border-radius: 30rpx;
	  text-align: center;
	  font-size: 30rpx;
	  float: right;
	  margin-top: 20rpx;
	  margin-left: 10rpx;
	}
	.worker-box .worker-box-footer .worker-box-footer-btn-cancel{
	  display: inline-block;
	  width: 158rpx;
	  height: 60rpx;
	  line-height: 60rpx;
	  color: #999999;
	  border: 1rpx solid #B3B3B3;
	  border-radius: 30rpx;
	  text-align: center;
	  font-size: 30rpx;
	  float: right;
	  margin-top: 20rpx;
	  margin-left: 10rpx;
	}
	
	
	.form-box{
	  width: 670rpx;
	  height: 90rpx;
	  line-height: 90rpx;
	  background-color: #ffffff;
	  border-radius: 10rpx;
	  padding: 0 20rpx;
	  margin-bottom: 20rpx;
	  overflow: hidden;
	}
	.form-box2{
	  min-height:200rpx;
	  height: auto;
	}
	.form-box .form-box-label{
	  display: inline-block;
	  width: 250rpx;
	  float: left;
	  font-size: 34rpx;
	  font-weight: bold;
	  color: #333333;
	}
	.form-box .form-box-content{
	  display: inline-block;
	  width: 400rpx;
	  float: right;
	  text-align: right;
	}
	.form-box .form-box-content input{
	  height: 70rpx;
	  line-height: 70rpx;
	  vertical-align: middle;
	  margin-top: 10rpx;
	}
	.form-box .form-box-content image{
	  width: 24rpx;
	  height: 24rpx;
	  vertical-align: middle;
	}
	.form-box .form-box-content .form-box-content-text{
	  float: left;
	  display: inline-block;
	  width: 360rpx;
	  overflow: hidden;
	  font-size: 30rpx;
	  height: 90rpx;
	  text-overflow: ellipsis;
	  white-space:nowrap; 
	}
	.form-box .form-box-textarea{
	  width: 100%;
	  float: left;
	  padding-bottom: 20rpx;
	  overflow: hidden;
	}
	.form-box .form-box-textarea textarea{
	  width: 100%;
	  padding: 20rpx;
	  line-height: 40rpx;
	  background-color: #F7F7F7;
	}
	
	.form-box .form-box-sub{
	  width: 670rpx;
	  height: 90rpx;
	  line-height: 90rpx;
	  background-color: #ffffff;
	  border-radius: 10rpx;
	  padding: 0;
	  overflow: hidden;
	}

	.form-box3{
	  width: 100%;
	  height: 90rpx;
	  line-height: 90rpx;
	  background-color: #ffffff;
	  border-radius: 10rpx;
	  padding: 0 20rpx;
	  margin-bottom: 20rpx;
	  overflow: hidden;
	}
	.form-box3 .form-box-label{
	  display: inline-block;
	  width: 40%;
	  float: left;
	  font-size: 34rpx;
	  font-weight: bold;
	  color: #333333;
	}
	.form-box3 .form-box-content{
	  display: inline-block;
	  width: 50%;
	  float: left;
	  text-align: right;
	}
	.form-box3 .form-box-content input{
	  height: 70rpx;
	  line-height: 70rpx;
	  vertical-align: middle;
	  margin-top: 10rpx;
	}
	.form-box3 .form-box-content image{
	  width: 24rpx;
	  height: 24rpx;
	  vertical-align: middle;
	}
	.form-box3 .form-box-content .form-box-content-text{
	  // float: left;
	  display: inline-block;
	  width: 85%;
	  overflow: hidden;
	  font-size: 30rpx;
	  height: 90rpx;
	  text-overflow: ellipsis;
	  white-space:nowrap; 
	}
	.form-box3 .form-box-textarea{
	  width: 100%;
	  float: left;
	  padding-bottom: 20rpx;
	  overflow: hidden;
	}
	.form-box3 .form-box-textarea textarea{
	  width: 100%;
	  padding: 20rpx;
	  line-height: 40rpx;
	  background-color: #F7F7F7;
	}
</style>
