templateHelp-fybj.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //设置怀孕多久
  2. template.helper('setusedTime',function(o){
  3. var now = new Date()
  4. var nowTime = now.getFullYear()+'-'+(now.getMonth()+1)+'-'+now.getDate()+' 00:00:00'
  5. var oldTime = o.split(' ')[0]+' 00:00:00'
  6. var diff = (new Date(nowTime.replace(/\-/g,'/')).getTime() - new Date(oldTime.replace(/\-/g,'/')).getTime())/24/3600/1000
  7. var week = parseInt(diff/7)
  8. var day = diff%7
  9. if(week == 0 && day == 0){
  10. return day+'天'
  11. }else{
  12. if(week == 0){
  13. return day+'天'
  14. }else if(day == 0){
  15. return week+'周'
  16. }else{
  17. return week+'周'+day+'天'
  18. }
  19. }
  20. })
  21. //设置预产期
  22. template.helper('setExpectedTime',function(o){
  23. var now = new Date()
  24. var nowTime = now.getFullYear()+'-'+(now.getMonth()+1)+'-'+now.getDate()+' 00:00:00'
  25. var oldTime = o.split(' ')[0]+' 00:00:00'
  26. var diff = (new Date(oldTime.replace(/\-/g,'/')).getTime() - new Date(nowTime.replace(/\-/g,'/')).getTime())/24/3600/1000
  27. if(diff>0){
  28. var week = parseInt(diff/7)
  29. var day = diff%7
  30. if(week == 0){
  31. return '距离预产期还有<span>'+day+'</span> 天'
  32. }else if(day == 0){
  33. return '距离预产期还有 <span>'+week+'</span> 周'
  34. }else{
  35. return '距离预产期还有 <span>'+week+'</span> 周 <span>'+day+'</span> 天'
  36. }
  37. }else{
  38. if(diff == 0){
  39. return '已达到预产期'
  40. }else{
  41. var diff2 = Math.abs(diff)
  42. var week = parseInt(diff2/7)
  43. var day = diff2%7
  44. if(week == 0){
  45. return '已超出预产期<span class="red">'+day+'</span> 天'
  46. }else if(day == 0){
  47. return '已超出预产期 <span class="red">'+week+'</span> 周'
  48. }else{
  49. return '已超出预产期 <span class="red">'+week+'</span> 周 <span class="red">'+day+'</span> 天'
  50. }
  51. }
  52. }
  53. })
  54. //取前一部分时间
  55. template.helper('setTime',function(o){
  56. return o.split(' ')[0]
  57. })