formatFuc.sjs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 formatGender(value) {
  110. var result='';
  111. if(value==1){
  112. result="先生";
  113. }else if(value==2){
  114. result="女士";
  115. }
  116. return result;
  117. }
  118. function formatOverTime(time){
  119. var minute='00';
  120. var second='00';
  121. if(time>0){
  122. minute=(Math.floor(time/60)<10?('0'+Math.floor(time/60)):Math.floor(time/60));
  123. second=(Number(time%60).toFixed(0)<10?('0'+Number(time%60).toFixed(0)):Number(time%60).toFixed(0));
  124. }
  125. var result="00:"+minute+":"+second;
  126. return result;
  127. }
  128. function servciceName(index){
  129. var modelText = '';
  130. switch (index) {
  131. case 0:
  132. modelText = '一';
  133. break;
  134. case 1:
  135. modelText = '二';
  136. break;
  137. case 2:
  138. modelText = '三';
  139. break;
  140. case 3:
  141. modelText = '四';
  142. break;
  143. case 4:
  144. modelText = '五';
  145. break;
  146. case 5:
  147. modelText = '六';
  148. break;
  149. case 6:
  150. modelText = '七';
  151. break;
  152. case 7:
  153. modelText = '八';
  154. break;
  155. default:
  156. modelText = '';
  157. }
  158. return modelText;
  159. }
  160. function getNotServiceTimes(total,serviced ){
  161. var result=total;
  162. if(serviced){
  163. result=total-serviced;
  164. }
  165. return result;
  166. }
  167. function formatDistance(value){
  168. var result=Number(value).toFixed(0);
  169. return result;
  170. }
  171. module.exports = {
  172. formatTime: formatTime,
  173. formatNumber: formatNumber,
  174. formatDate: formatDate,
  175. sliceFun: sliceFun,
  176. numToReg: numToReg,
  177. regD: regD,
  178. defineIndexOf: defineIndexOf,
  179. includeItem: includeItem,
  180. serviceModel: serviceModel,
  181. sliceStr: sliceStr,
  182. formatGender:formatGender,
  183. formatOverTime:formatOverTime,
  184. servciceName:servciceName,
  185. getNotServiceTimes:getNotServiceTimes,
  186. formatDistance:formatDistance
  187. };