filter.wxs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. var formatNumber = function (n) {
  2. n = n.toString()
  3. return n[1] ? n : '0' + n
  4. }
  5. /**
  6. * 将时间戳(1570550400)格式转为 yyyy-MM-dd格式
  7. */
  8. //时间戳转时间
  9. function formatDate(time, flag) {
  10. if (!time) {
  11. return
  12. }
  13. if (time == '1') {
  14. return "终身使用"
  15. }
  16. var time = time * 1
  17. var t = getDate(time);
  18. var tf = function (i) {
  19. return (i < 10 ? '0' : '') + i
  20. };
  21. var year = t.getFullYear();
  22. var month = tf(t.getMonth() + 1);
  23. var day = tf(t.getDate());
  24. var hour = tf(t.getHours());
  25. var minute = tf(t.getMinutes());
  26. if (flag == 1) {
  27. return year + '-' + month + '-' + day + '' + ' ' + hour + ':' + minute;
  28. } else if (flag == 2) {
  29. return year + '.' + month + '.' + day
  30. } else if (flag == 3) {
  31. return month + '-' + day + ' ' + hour + ':' + minute;
  32. } else if (flag == 4) {
  33. return year + '年' + month + '月' + day + '日';
  34. } else if (flag == 5) {
  35. return year + '-' + month + '-' + day;
  36. } else if (flag == 6) {
  37. return day;
  38. }
  39. }
  40. function gradeFilter(grade) {
  41. if (!grade) {
  42. return '暂无'
  43. }
  44. var gradeObj = {
  45. "PRESCHOOL": "学前班",
  46. "PRIMARY_FIRST_GRADE": "一年级",
  47. "PRIMARY_SECOND_GRADE": "二年级",
  48. "PRIMARY_THREE_GRADE": "三年级",
  49. "PRIMARY_SENIOR_GRADE": "四年级",
  50. "PRIMARY_FIVE_GRADE": "五年级",
  51. "PRIMARY_SIX_GRADE": "六年级",
  52. }
  53. return gradeObj[grade]
  54. }
  55. // 数字满万补w
  56. function numFilter(num) {
  57. if (!num) {
  58. return 0
  59. }
  60. if (num < 10000) {
  61. return num
  62. }
  63. return Math.floor(num / 100) / 100 + 'w'
  64. }
  65. // 四舍五入保留两位小数
  66. function twoDecimal(num) {
  67. return (num / 100).toFixed(2)
  68. }
  69. // 切换旗帜图片
  70. function showPennant(count, num) {
  71. if (count >= num) {
  72. if (num <= 2) {
  73. return '/static/2q.png'
  74. } else if (num <= 5) {
  75. return '/static/5q.png'
  76. } else if (num <= 10) {
  77. return '/static/10q.png'
  78. } else if (num <= 15) {
  79. return '/static/15q.png'
  80. } else if (num <= 30) {
  81. return '/static/30q.png'
  82. } else if (num <= 60) {
  83. return '/static/60q.png'
  84. }
  85. } else {
  86. return '/static/pennant.png'
  87. }
  88. }
  89. function textSlice(text) {
  90. return text.slice(5)
  91. }
  92. module.exports = {
  93. formatDate: formatDate,
  94. gradeFilter: gradeFilter,
  95. numFilter: numFilter,
  96. twoDecimal: twoDecimal,
  97. textSlice: textSlice,
  98. showPennant: showPennant
  99. }