formatFuc.wxs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. function sliceStr(str,start,end){
  105. var result=str.substring(start,end);
  106. result=result.replace(getRegExp('-','g'),'.');
  107. return result;
  108. }
  109. function statusText(type) {
  110. var status = '';
  111. switch (type) {
  112. case 0:
  113. status = '未支付';
  114. break;
  115. case 1:
  116. status = '已支付';
  117. break;
  118. case 2:
  119. status = '已取消';
  120. break;
  121. case 3:
  122. status = '已退款';
  123. break;
  124. case 4:
  125. status = '待退款';
  126. break;
  127. default:
  128. status = '';
  129. }
  130. return status;
  131. }
  132. module.exports = {
  133. formatTime: formatTime,
  134. formatNumber: formatNumber,
  135. formatDate: formatDate,
  136. sliceFun: sliceFun,
  137. numToReg: numToReg,
  138. regD: regD,
  139. defineIndexOf: defineIndexOf,
  140. includeItem: includeItem,
  141. serviceModel:serviceModel,
  142. sliceStr:sliceStr,
  143. statusText:statusText
  144. }
  145. // 截取文字*号代替