export default{
  getCurrentPageUrl(){//---获取当前页面url
    let pages = getCurrentPages() //获取加载的页面
    let currentPage = pages[pages.length-1] //获取当前页面的对象
    let url = currentPage.route //当前页面url
    let options = currentPage.options //如果要获取url中所带的参数可
    let queryTotal=''
    for (let key in options){
			 queryTotal+='&'+key+'='+options[key]
    }
    queryTotal=queryTotal.substr(1)
    let pageUrl=url+'?'+queryTotal//请求的全路径
    return pageUrl
  },
  today:function(){//默认当天
    var now = new Date()
    var day = ('0' + now.getDate()).slice(-2)
    var month = ('0' + (now.getMonth() + 1)).slice(-2)
    var today = now.getFullYear()+'-'+(month)+'-'+(day) 
    return today
  },
  todayTime:function(){
    var now = new Date()
    var hour = now.getHours()<10?'0'+now.getHours():now.getHours()
    var minutes = now.getMinutes()<10?'0'+now.getMinutes():now.getMinutes()
    var seconds = now.getSeconds()<10?'0'+now.getSeconds():now.getSeconds()
    var time = hour+':'+minutes+':'+seconds
    return time
  },
  dateDifference:function(start,end){//结束日期与开始日期相差几天
    var strSeparator = '-'
	    var oDate1= start.split(strSeparator)
	    var oDate2= end.split(strSeparator)
	    var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2])
	    var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2])
	    var iDays = parseInt((strDateE- strDateS) / 1000 / 60 / 60 /24)
	    return iDays
  },
  changeTime:function(option) {//把时间格式转化成数字
		 // currentTime当前时间，假设是 2019-7-2 19:03
		 var currentTime = option
		 var reg = new RegExp('-','g')//去掉时间里面的-
		 var a = currentTime.replace(reg,'')
		 var regs = new RegExp(' ','g')//去掉时间里面的空格
		 var b = a.replace(regs,'')
		 var regss = new RegExp(':','g')//去掉时间里面的:冒号
		 var c = b.replace(regss,'')
		 return c
  },
  phoneReg:function(){//手机正则
    return /^(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0-9]|19[0-9]|16[0-9])\d{8}$/
  },
  getUrlKey:function(name,url){//通过连接地址获取参数值
		 return(new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(decodeURIComponent(url)) || [, ''])[1].replace(/\+/g, '%20') || ''
  },
  /* 
		通过链接地址获取companyId，并保持在本地
		页面获取companyI方法 let companyId=this.$commonjs.getCompanyId()
	*/
  getCompanyId:function(option){
    let enterUrl=''
    //#ifdef MP-WEIXIN
    enterUrl=option.q
    //#endif
			
    //#ifdef MP-ALIPAY
    enterUrl=uni.getStorageSync('alipayQrCode')
    //#endif
    let companyId=''
    if(enterUrl){//普通二维码扫码进入
		  companyId=this.getUrlKey('companyId',enterUrl)||uni.getStorageSync('companyId')||''
    }else{//小程序页面跳转进入
		  companyId=option.companyId||uni.getStorageSync('companyId')||''
    }
    uni.setStorageSync('companyId',companyId)
    return companyId
  },
  //获取除companyId的其他参数
  getKey:function(option,query){
    let enterUrl=''
    //#ifdef MP-WEIXIN
    enterUrl=option.q
    //#endif
			
    //#ifdef MP-ALIPAY
    enterUrl=uni.getStorageSync('alipayQrCode')
    //#endif
    let key=''
    if(enterUrl){//普通二维码扫码进入
		  key=this.getUrlKey(`${query}`,enterUrl)||''
    }else{//小程序页面跳转进入
		  key=option[query]||''
    }
    return key
  }
}
//调用方法时--this.$commonjs.today()