formatFuc.wxs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 formatOverTime(time) {
  110. var minute = '00';
  111. var second = '00';
  112. if (time > 0) {
  113. minute = (Math.floor(time / 60) < 10 ? ('0' + Math.floor(time / 60)) : Math.floor(time / 60));
  114. second = Number(time % 60).toFixed(0) < 10 ? ('0' + Number(time % 60).toFixed(0)) : Number(time % 60).toFixed(
  115. 0);
  116. }
  117. var result = "00:" + minute + ":" + second;
  118. return result;
  119. }
  120. function getNotServiceTimes(total, serviced) {
  121. var result = total;
  122. if (serviced) {
  123. result = total - serviced;
  124. }
  125. return result;
  126. }
  127. function formatDistance(val) {
  128. var result = val;
  129. result = Number(val).toFixed(0);
  130. return result;
  131. }
  132. function servciceName(index) {
  133. var modelText = '';
  134. switch (index) {
  135. case 0:
  136. modelText = '一';
  137. break;
  138. case 1:
  139. modelText = '二';
  140. break;
  141. case 2:
  142. modelText = '三';
  143. break;
  144. case 3:
  145. modelText = '四';
  146. break;
  147. case 4:
  148. modelText = '五';
  149. break;
  150. case 5:
  151. modelText = '六';
  152. break;
  153. case 6:
  154. modelText = '七';
  155. break;
  156. case 7:
  157. modelText = '八';
  158. break;
  159. case 8:
  160. modelText = '九';
  161. break;
  162. case 9:
  163. modelText = '十';
  164. break;
  165. case 10:
  166. modelText = '十一';
  167. break;
  168. case 11:
  169. modelText = '十二';
  170. break;
  171. case 12:
  172. modelText = '十三';
  173. break;
  174. case 13:
  175. modelText = '十四';
  176. break;
  177. case 14:
  178. modelText = '十五';
  179. break;
  180. case 15:
  181. modelText = '十六';
  182. break;
  183. case 16:
  184. modelText = '十七';
  185. break;
  186. case 17:
  187. modelText = '十八';
  188. break;
  189. case 18:
  190. modelText = '十九';
  191. break;
  192. case 19:
  193. modelText = '二十';
  194. break;
  195. default:
  196. modelText = '';
  197. }
  198. return modelText;
  199. }
  200. module.exports = {
  201. formatTime: formatTime,
  202. formatNumber: formatNumber,
  203. formatDate: formatDate,
  204. sliceFun: sliceFun,
  205. numToReg: numToReg,
  206. regD: regD,
  207. defineIndexOf: defineIndexOf,
  208. includeItem: includeItem,
  209. serviceModel: serviceModel,
  210. sliceStr: sliceStr,
  211. formatOverTime: formatOverTime,
  212. getNotServiceTimes: getNotServiceTimes,
  213. formatDistance: formatDistance,
  214. servciceName: servciceName
  215. }
  216. // 截取文字*号代替