util.wxs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. module.exports = {
  2. formatImg:function(img, pic){
  3. console.log(pic.indexOf("noimg.png") == -1 ? img + pic : pic);
  4. return pic.indexOf("noimg.png") == -1 ? img + pic : pic;
  5. },
  6. formatDate: function (strDate, format = "yyyy-MM-dd hh:mm:ss") {
  7. if (strDate != undefined){
  8. var realDate = typeof (strDate) == 'number' ? getDate(strDate) : getDate(strDate.replace(getRegExp('-', 'g'), '/'));
  9. var regYear = getRegExp("(y+)", "i");
  10. var date = [
  11. ["M+", realDate.getMonth() + 1],
  12. ["d+", realDate.getDate()],
  13. ["h+", realDate.getHours()],
  14. ["m+", realDate.getMinutes()],
  15. ["s+", realDate.getSeconds()],
  16. ["q+", Math.floor((realDate.getMonth() + 3) / 3)],
  17. ["S+", realDate.getMilliseconds()],
  18. ];
  19. var reg1 = regYear.exec(format);
  20. if (reg1) {
  21. format = format.replace(reg1[1], (realDate.getFullYear() + '').substring(4 - reg1[1].length));
  22. }
  23. for (var i = 0; i < date.length; i++) {
  24. var reg2 = getRegExp("(" + date[i][0] + ")").exec(format);
  25. if (reg2) {
  26. format = format.replace(reg2[1], reg2[1].length == 1 ? v : ("00" + date[i][1]).substring(("" + date[i][1]).length));
  27. }
  28. }
  29. return format;
  30. }else{
  31. return strDate;
  32. }
  33. },
  34. getAge: function (beginStr, endStr) {
  35. if (beginStr == "" || endStr == "") return "";
  36. var beginArr = getDate(beginStr.replace(getRegExp('-', 'g'), '/')), endArr = getDate(endStr.replace(getRegExp('-', 'g'), '/')), year = 0, month = 0;
  37. month = month + ((endArr.getMonth() + 1) - (beginArr.getMonth() + 1));
  38. if (month < 0) {
  39. year = -1;
  40. month = 12 + month;
  41. }
  42. year = year + (endArr.getFullYear() - beginArr.getFullYear());
  43. return "宝贝" + (year > 0 ? year + "岁" : "") + (month > 0 ? month + "个月" : "");
  44. },
  45. letter: function(str){
  46. return str.toUpperCase();
  47. },
  48. // 任务图标选择
  49. getIcon:function(type){
  50. var iconName='';
  51. switch (type) {
  52. case 'saveCardInfo': //儿童证件信息
  53. iconName='icon-task-cardInfo';
  54. break;
  55. case 'buyArticle': //消费活动
  56. iconName='icon-coin-consumption';
  57. break;
  58. case 'share': //海报发圈
  59. iconName='icon-task-moments';
  60. break;
  61. case 'saveUserInfo': //购买信息
  62. iconName='icon-task-buyInfo';
  63. break;
  64. case 'comment': //评价活动
  65. iconName='icon-coin-comment';
  66. break;
  67. case 'companyVideo': //观看视频
  68. iconName='icon-task-video';
  69. break;
  70. case 'companyDesc': //品牌介绍
  71. iconName='icon-task-introduce';
  72. break;
  73. case 'browseArticle': //浏览活动
  74. iconName='icon-task-view';
  75. break;
  76. }
  77. return iconName;
  78. },
  79. // 分享家等级对应权益
  80. getSharerPower:function(level){
  81. var nextLevel=parseInt(level)+1,content='';
  82. switch (nextLevel) {
  83. case 1:
  84. content='2张100元活动无门槛现金券+免费领取勋章礼盒'
  85. break;
  86. case 2:
  87. content='2张100元活动无门槛现金券+免费领取勋章礼盒'
  88. break;
  89. case 3:
  90. content='2张200元活动无门槛现金券'
  91. break;
  92. case 4:
  93. content='2张200元活动无门槛现金券+1张400元活动现金券'
  94. break;
  95. case 5:
  96. content='2张300元冬夏令营万能券+1张400元单日活动券'
  97. break;
  98. case 6:
  99. content='2张300元冬夏令营万能券+1张400元单日活动券'
  100. break;
  101. }
  102. return content;
  103. }
  104. }