formatFuc.wxs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. if(date==null||date=='') return " "
  20. var date = getDate(date)
  21. var year = date.getFullYear()
  22. var month = date.getMonth() + 1
  23. var day = date.getDate()
  24. var hour = date.getHours()
  25. var minute = date.getMinutes()
  26. var second = date.getSeconds()
  27. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
  28. }
  29. //时分格式化
  30. var formatDateSF = function (date) {
  31. var date = getDate(date)
  32. var year = date.getFullYear()
  33. var month = date.getMonth() + 1
  34. var day = date.getDate()
  35. var hour = date.getHours()
  36. var minute = date.getMinutes()
  37. var second = date.getSeconds()
  38. return [hour, minute].map(formatNumber).join(':')
  39. }
  40. var numToReg = function (val) {
  41. return val.replace(getRegExp('[0-9]', 'g'), '*')
  42. }
  43. //截取返回时间到分钟
  44. var sliceFun = function (val) {
  45. return val.slice(0, 5)
  46. }
  47. //正则-逗号
  48. var regD = function (val) {
  49. return val.replace(getRegExp('[,]', 'g'), ' ')
  50. }
  51. var interceptStart = function (text) {
  52. var str = text.substr(1, 3).replace(str, "**");
  53. return str
  54. }
  55. function defineIndexOf(str, val) {
  56. return str.indexOf(val);
  57. }
  58. function includeItem(arr, week, val) {
  59. // let arrItem=arr.filter(item=>{return item.week==week});
  60. // let isInclude=arrItem.some(item=>{return item.time==val});
  61. // return isInclude;
  62. var length = arr.length;
  63. var timeList = [];
  64. for (var i = 0; i < length; i++) {
  65. if (arr[i].week == week) {
  66. timeList.push(arr[i]);
  67. }
  68. }
  69. var len2 = timeList.length;
  70. var isInclude = false;
  71. for (var j = 0; j < len2; j++) {
  72. if (timeList[j].time == val) {
  73. isInclude = true;
  74. break;
  75. }
  76. }
  77. return isInclude;
  78. }
  79. function serviceModel(type) {
  80. var modelText = '';
  81. switch (type) {
  82. case '1':
  83. modelText = '钟点工';
  84. break;
  85. case '2':
  86. modelText = '白班保姆';
  87. break;
  88. case '3':
  89. modelText = '住家保姆';
  90. break;
  91. case '4':
  92. modelText = '月嫂';
  93. break;
  94. case '5':
  95. modelText = '代班保姆-钟点工';
  96. break;
  97. case '6':
  98. modelText = '代班保姆-保姆';
  99. break;
  100. default:
  101. modelText = '';
  102. }
  103. return modelText;
  104. }
  105. function sliceStr(str,start,end){
  106. var result=str.substring(start,end);
  107. result=result.replace(getRegExp('-','g'),'.');
  108. return result;
  109. }
  110. function statusText(type) {
  111. var status = '';
  112. switch (type) {
  113. case 0:
  114. status = '未支付';
  115. break;
  116. case 1:
  117. status = '已支付';
  118. break;
  119. case 2:
  120. status = '已取消';
  121. break;
  122. case 3:
  123. status = '已退款';
  124. break;
  125. case 4:
  126. status = '待退款';
  127. break;
  128. default:
  129. status = '';
  130. }
  131. return status;
  132. }
  133. function specialStatusText(type) {
  134. var status = '';
  135. // 2 已生成待同意 3 已同意待发放(不需收集信息) ,4 不同意发放结束 5已同意待发放(已收集具体信息) 6 发放成功 7取消发放,8 发放失败 9 发放中
  136. switch (type) {
  137. case 2:
  138. status = '已生成待同意';
  139. break;
  140. case 3:
  141. status = '已同意待发放(不需收集信息)';
  142. break;
  143. case 4:
  144. status = '不同意';
  145. break;
  146. case 5:
  147. status = '已同意待发放(已收集具体信息)';
  148. break;
  149. case 6:
  150. status = '发放成功';
  151. break;
  152. case 7:
  153. status = '取消发放';
  154. break;
  155. case 8:
  156. status = '发放失败';
  157. break;
  158. case 9:
  159. status = '发放中';
  160. break;
  161. default:
  162. status = '';
  163. }
  164. return status;
  165. }
  166. module.exports = {
  167. formatTime: formatTime,
  168. formatNumber: formatNumber,
  169. formatDate: formatDate,
  170. sliceFun: sliceFun,
  171. numToReg: numToReg,
  172. regD: regD,
  173. defineIndexOf: defineIndexOf,
  174. includeItem: includeItem,
  175. serviceModel:serviceModel,
  176. sliceStr:sliceStr,
  177. statusText:statusText,
  178. specialStatusText:specialStatusText,
  179. }
  180. // 截取文字*号代替