
function date(time,format){
  var date = getDate(time);
  return date.getFullYear() + '-' + date.getMonth() + 1 + '-'+ date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' +date.getSeconds();
}

function toPercent(num, total) { 
   return (Math.round(num / total * 10000) / 100.00 + "%");// 小数点后两位百分比
}
function phoneFormat(phone) {
  var curPhone = phone.toString()
  var mphone = curPhone.substring(0, 7) + 'xxxx'
  return mphone
};

function numberFormat(val,d){
  if(val){
    return val.toFixed(d || 2);
  } else {
    return '0.00'
  }
}

function handerNickName (nickName,limitLength) {
  if (nickName && nickName.length > limitLength ) {
    return nickName.slice(0,limitLength) + '...'
  }
  return nickName || ''
}

// 处理 http 地址
function formateUrl(url, BASE_IMG_URL){
    if(url){
      url = url.indexOf('http') > -1 ? url : BASE_IMG_URL + url;
    }
    return url;
}

// 授权路径 我的/购物车/我的奖励/邀请好友/推广商品/我的地址/我的订单
function hanlerLinkNeedAuth(link){
  var flag = false
  if(typeof(link) != undefined && link) {
    if(link.indexOf('pages/my/my') > -1 || 
      link.indexOf('pages/cart/cart') > -1 || 
      link.indexOf('subPackage/page/pages/orderBenefit/orderBenefit') > -1 || 
      link.indexOf('subPackage/page/pages/myInvite/myInvite') > -1 || 
      link.indexOf('pages/extendProduct/extendProduct') > -1 || 
      link.indexOf('pages/myAddress/myAddress') > -1 || 
      link.indexOf('pages/order/order') > -1) {
      flag = true
    }
  }
  return flag
}


module.exports = {
  toPercent:toPercent,
  phoneFormat: phoneFormat,
  formateUrl:formateUrl,
  numberFormat: numberFormat,
  date: date,
  handerNickName: handerNickName,
  hanlerLinkNeedAuth: hanlerLinkNeedAuth
}
