formatFuc.wxs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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(0);
  115. }
  116. var result="00:"+minute+":"+second;
  117. return result;
  118. }
  119. function getNotServiceTimes(total,serviced ){
  120. var result=total;
  121. if(serviced){
  122. result=total-serviced;
  123. }
  124. return result;
  125. }
  126. function formatDistance(val){
  127. var result=val;
  128. result=Number(val).toFixed(0);
  129. return result;
  130. }
  131. function servciceName(index){
  132. var modelText = '';
  133. switch (index) {
  134. case 0:
  135. modelText = '一';
  136. break;
  137. case 1:
  138. modelText = '二';
  139. break;
  140. case 2:
  141. modelText = '三';
  142. break;
  143. case 3:
  144. modelText = '四';
  145. break;
  146. case 4:
  147. modelText = '五';
  148. break;
  149. case 5:
  150. modelText = '六';
  151. break;
  152. case 6:
  153. modelText = '七';
  154. break;
  155. case 7:
  156. modelText = '八';
  157. break;
  158. default:
  159. modelText = '';
  160. }
  161. return modelText;
  162. }
  163. module.exports = {
  164. formatTime: formatTime,
  165. formatNumber: formatNumber,
  166. formatDate: formatDate,
  167. sliceFun: sliceFun,
  168. numToReg: numToReg,
  169. regD: regD,
  170. defineIndexOf: defineIndexOf,
  171. includeItem: includeItem,
  172. serviceModel:serviceModel,
  173. sliceStr:sliceStr,
  174. formatOverTime:formatOverTime,
  175. getNotServiceTimes:getNotServiceTimes,
  176. formatDistance:formatDistance,
  177. servciceName:servciceName
  178. }
  179. // 截取文字*号代替