module.exports = {
  formatImg:function(img, pic){
    console.log(pic.indexOf("noimg.png") == -1 ? img + pic : pic);
    return pic.indexOf("noimg.png") == -1 ? img + pic : pic;
    
  },
  formatDate: function (strDate, format = "yyyy-MM-dd hh:mm:ss") {
    if (strDate != undefined){
      var realDate = typeof (strDate) == 'number' ? getDate(strDate) : getDate(strDate.replace(getRegExp('-', 'g'), '/'));
      var regYear = getRegExp("(y+)", "i");
      var date = [
        ["M+", realDate.getMonth() + 1],
        ["d+", realDate.getDate()],
        ["h+", realDate.getHours()],
        ["m+", realDate.getMinutes()],
        ["s+", realDate.getSeconds()],
        ["q+", Math.floor((realDate.getMonth() + 3) / 3)],
        ["S+", realDate.getMilliseconds()],
      ];
      var reg1 = regYear.exec(format);
      if (reg1) {
        format = format.replace(reg1[1], (realDate.getFullYear() + '').substring(4 - reg1[1].length));
      }
      for (var i = 0; i < date.length; i++) {
        var reg2 = getRegExp("(" + date[i][0] + ")").exec(format);
        if (reg2) {
          format = format.replace(reg2[1], reg2[1].length == 1 ? v : ("00" + date[i][1]).substring(("" + date[i][1]).length));
        }
      }
      return format;
    }else{
      return strDate;
    }
  },
  getAge: function (beginStr, endStr) {
    if (beginStr == "" || endStr == "") return "";
    var beginArr = getDate(beginStr.replace(getRegExp('-', 'g'), '/')), endArr = getDate(endStr.replace(getRegExp('-', 'g'), '/')), year = 0, month = 0;
    month = month + ((endArr.getMonth() + 1) - (beginArr.getMonth() + 1));
    if (month < 0) {
      year = -1;
      month = 12 + month;
    }

    year = year + (endArr.getFullYear() - beginArr.getFullYear());
    return "宝贝" + (year > 0 ? year + "岁" : "") + (month > 0 ? month + "个月" : "");
  },
  letter: function(str){
    return str.toUpperCase();
  },
  // 任务图标选择
  getIcon:function(type){
    var iconName='';
    switch (type) {
      case 'saveCardInfo': //儿童证件信息
        iconName='icon-task-cardInfo';
        break;
      case 'buyArticle': //消费活动
        iconName='icon-coin-consumption';
        break;
      case 'share': //海报发圈
        iconName='icon-task-moments';
        break;
      case 'saveUserInfo': //购买信息
        iconName='icon-task-buyInfo';
        break;
      case 'comment': //评价活动
        iconName='icon-coin-comment';
        break;
      case 'companyVideo': //观看视频
        iconName='icon-task-video';
        break;
      case 'companyDesc': //品牌介绍
        iconName='icon-task-introduce';
        break;
      case 'browseArticle': //浏览活动
        iconName='icon-task-view';
        break;
    }
    return iconName;
  },
  // 分享家等级对应权益
  getSharerPower:function(level){
    var nextLevel=parseInt(level)+1,content='';
    switch (nextLevel) {
      case 1:
        content='2张100元活动无门槛现金券+免费领取勋章礼盒'
        break;
      case 2:
        content='2张100元活动无门槛现金券+免费领取勋章礼盒'
        break;
      case 3:
        content='2张200元活动无门槛现金券'
        break;
      case 4:
        content='2张200元活动无门槛现金券+1张400元活动现金券'
        break;
      case 5:
        content='2张300元冬夏令营万能券+1张400元单日活动券'
        break;
      case 6:
        content='2张300元冬夏令营万能券+1张400元单日活动券'
        break;
    }
    return content;
  }
}