formatFuc.wxs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //时间格式化
  2. var formatTime = function (date) {
  3. var date = getDate(date)
  4. var year = date.getFullYear()
  5. var month = date.getMonth() + 1
  6. var day = date.getDate()
  7. var hour = date.getHours()
  8. var minute = date.getMinutes()
  9. var second = date.getSeconds()
  10. return [year, month, day].map(formatNumber).join('-')
  11. }
  12. var formatNumber = function (n) {
  13. n = n.toString()
  14. return n[1] ? n : '0' + n
  15. }
  16. // + ' ' + [hour, minute, second].map(formatNumber).join(':')
  17. //年月日时分
  18. var formatDate = function (date) {
  19. var date = getDate(date)
  20. var year = date.getFullYear()
  21. var month = date.getMonth() + 1
  22. var day = date.getDate()
  23. var hour = date.getHours()
  24. var minute = date.getMinutes()
  25. var second = date.getSeconds()
  26. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
  27. }
  28. //时分格式化
  29. var formatDateSF = function (date) {
  30. var date = getDate(date)
  31. var year = date.getFullYear()
  32. var month = date.getMonth() + 1
  33. var day = date.getDate()
  34. var hour = date.getHours()
  35. var minute = date.getMinutes()
  36. var second = date.getSeconds()
  37. return [hour, minute].map(formatNumber).join(':')
  38. }
  39. var numToReg = function (val) {
  40. return val.replace(getRegExp('[0-9]', 'g'), '*')
  41. }
  42. //截取返回时间到分钟
  43. var sliceFun = function (val) {
  44. return val.slice(0, 5)
  45. }
  46. //正则-逗号
  47. var regD = function (val) {
  48. return val.replace(getRegExp('[,]', 'g'), ' ')
  49. }
  50. var interceptStart = function (text) {
  51. var str = text.substr(1, 3).replace(str, "**");
  52. return str
  53. }
  54. function defineIndexOf(str, val) {
  55. return str.indexOf(val);
  56. }
  57. function includeItem(arr, week, val) {
  58. // let arrItem=arr.filter(item=>{return item.week==week});
  59. // let isInclude=arrItem.some(item=>{return item.time==val});
  60. // return isInclude;
  61. var length = arr.length;
  62. var timeList = [];
  63. for (var i = 0; i < length; i++) {
  64. if (arr[i].week == week) {
  65. timeList.push(arr[i]);
  66. }
  67. }
  68. var len2 = timeList.length;
  69. var isInclude = false;
  70. for (var j = 0; j < len2; j++) {
  71. if (timeList[j].time == val) {
  72. isInclude = true;
  73. break;
  74. }
  75. }
  76. return isInclude;
  77. }
  78. function serviceModel(type) {
  79. var modelText = '';
  80. switch (type) {
  81. case '1':
  82. modelText = '钟点工';
  83. break;
  84. case '2':
  85. modelText = '白班保姆';
  86. break;
  87. case '3':
  88. modelText = '住家保姆';
  89. break;
  90. case '4':
  91. modelText = '月嫂';
  92. break;
  93. case '5':
  94. modelText = '代班保姆-钟点工';
  95. break;
  96. case '6':
  97. modelText = '代班保姆-保姆';
  98. break;
  99. default:
  100. modelText = '';
  101. }
  102. return modelText;
  103. }
  104. module.exports = {
  105. formatTime: formatTime,
  106. formatNumber: formatNumber,
  107. formatDate: formatDate,
  108. sliceFun: sliceFun,
  109. numToReg: numToReg,
  110. regD: regD,
  111. defineIndexOf: defineIndexOf,
  112. includeItem: includeItem,
  113. serviceModel:serviceModel
  114. }
  115. // 截取文字*号代替