pass.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. const api = require('../../../utils/api.js');
  2. Page({
  3. data: {
  4. year: 0,
  5. month: 0,
  6. date: ['日', '一', '二', '三', '四', '五', '六'],
  7. dateArr: [],
  8. isToday: 0,
  9. isTodayWeek: false,
  10. todayIndex: 0
  11. },
  12. onLoad: function () {
  13. wx.showLoading({
  14. title: '正在加载',
  15. })
  16. let now = new Date();
  17. let year = now.getFullYear();
  18. let month = now.getMonth() + 1;
  19. this.dateInit();
  20. this.req(year + '-' + month + '-' + now.getDate())
  21. this.setData({
  22. year: year,
  23. month: month,
  24. isToday: '' + year + month + now.getDate()
  25. })
  26. },
  27. dateInit: function (setYear, setMonth) {
  28. //全部时间的月份都是按0~11基准,显示月份才+1
  29. let dateArr = []; //需要遍历的日历数组数据
  30. let arrLen = 0; //dateArr的数组长度
  31. let now = setYear ? new Date(setYear, setMonth) : new Date();
  32. let year = setYear || now.getFullYear();
  33. let nextYear = 0;
  34. let month = setMonth || now.getMonth(); //没有+1方便后面计算当月总天数
  35. let nextMonth = (month + 1) > 11 ? 1 : (month + 1);
  36. let startWeek = new Date(year + '/' + (month + 1) + '/' + 1).getDay();
  37. // let startWeek = new Date(year + ',' + (month + 1) + ',' + 1).getDay(); //目标月1号对应的星期
  38. let dayNums = new Date(year, nextMonth, 0).getDate(); //获取目标月有多少天
  39. let obj = {};
  40. let num = 0;
  41. if (month + 1 > 11) {
  42. nextYear = year + 1;
  43. dayNums = new Date(nextYear, nextMonth, 0).getDate();
  44. }
  45. arrLen = startWeek + dayNums;
  46. for (let i = 0; i < arrLen; i++) {
  47. if (i >= startWeek) {
  48. num = i - startWeek + 1;
  49. obj = {
  50. isToday: '' + year + (month + 1) + num,
  51. dateNum: num,
  52. weight: 5
  53. }
  54. } else {
  55. obj = {};
  56. }
  57. dateArr[i] = obj;
  58. }
  59. this.setData({
  60. dateArr: dateArr
  61. })
  62. let nowDate = new Date();
  63. let nowYear = nowDate.getFullYear();
  64. let nowMonth = nowDate.getMonth() + 1;
  65. let nowWeek = nowDate.getDay();
  66. let getYear = setYear || nowYear;
  67. let getMonth = setMonth >= 0 ? (setMonth + 1) : nowMonth;
  68. if (nowYear == getYear && nowMonth == getMonth) {
  69. this.setData({
  70. isTodayWeek: true,
  71. todayIndex: nowWeek
  72. })
  73. } else {
  74. this.setData({
  75. isTodayWeek: false,
  76. todayIndex: -1
  77. })
  78. }
  79. },
  80. lastMonth: function () {
  81. //全部时间的月份都是按0~11基准,显示月份才+1
  82. let year = this.data.month - 2 < 0 ? this.data.year - 1 : this.data.year;
  83. let month = this.data.month - 2 < 0 ? 11 : this.data.month - 2;
  84. this.setData({
  85. year: year,
  86. month: (month + 1)
  87. })
  88. this.dateInit(year, month);
  89. },
  90. nextMonth: function () {
  91. //全部时间的月份都是按0~11基准,显示月份才+1
  92. let year = this.data.month > 11 ? this.data.year + 1 : this.data.year;
  93. let month = this.data.month > 11 ? 0 : this.data.month;
  94. this.setData({
  95. year: year,
  96. month: (month + 1)
  97. })
  98. this.dateInit(year, month);
  99. },
  100. check(e){
  101. wx.showLoading({
  102. title: '正在加载',
  103. })
  104. this.setData({
  105. isToday: e.currentTarget.dataset.year + '' + e.currentTarget.dataset.month + '' + e.currentTarget.dataset.day
  106. })
  107. this.req(e.currentTarget.dataset.year + '-' + e.currentTarget.dataset.month + '-' + e.currentTarget.dataset.day)
  108. },
  109. req(time){
  110. let that=this
  111. wx.request({
  112. url: api.getAccessInfo,
  113. method: 'GET',
  114. data: { 'loginId': wx.getStorageSync('loginId'), 'time': time },
  115. success(res) {
  116. wx.hideLoading()
  117. if (res.data.data.length==0){
  118. that.setData({
  119. dataList: res.data.data
  120. })
  121. return false
  122. }
  123. for (let index in res.data.data){
  124. var date = new Date(res.data.data[index].openTime);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  125. var h = date.getHours() < 10 ? '0' + date.getHours()+':' : date.getHours() + ':';
  126. var m = date.getMinutes() < 10 ? '0' + date.getMinutes()+':' : date.getMinutes() + ':';
  127. var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  128. res.data.data[index].openTime = h + m + s;
  129. }
  130. that.setData({
  131. dataList: res.data.data
  132. })
  133. }
  134. })
  135. }
  136. })