list.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. const app = getApp()
  2. const util = require("../../../utils/util");
  3. const api = require('../../../api/api.js');
  4. import todo from '../../../lib/calendar/plugins/todo'
  5. import selectable from '../../../lib/calendar/plugins/selectable'
  6. import solarLunar from '../../../lib/calendar/plugins/solarLunar/index'
  7. import timeRange from '../../../lib/calendar/plugins/time-range'
  8. import week from '../../../lib/calendar/plugins/week'
  9. import holidays from '../../../lib/calendar/plugins/holidays/index'
  10. import plugin from '../../../lib/calendar/plugins/index'
  11. var calendar;
  12. plugin.use(todo).use(solarLunar).use(selectable).use(week).use(timeRange).use(holidays)
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. hasLogin: false,
  19. calendarConfig: {
  20. theme: 'elegant'
  21. },
  22. list: [],
  23. curDate: util.formatDate(new Date()).substring(0, 7),
  24. selected: ''
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. },
  31. getList(month) {
  32. let that = this;
  33. that.setData({
  34. curDate: month
  35. })
  36. wx.showLoading();
  37. util.request(api.NucleicList, {
  38. 'month': month
  39. }).then(res => {
  40. //console.info(res.data)
  41. wx.hideLoading();
  42. that.setData({
  43. list: res.data
  44. })
  45. that.setScheduling();
  46. }).catch(res => {
  47. wx.hideLoading();
  48. util.showErrorToast(res.errmsg);
  49. })
  50. },
  51. goNucleic() {
  52. wx.navigateTo({
  53. url: '/pages/servant/nucleic/index',
  54. })
  55. },
  56. setScheduling() { //设置日历显示
  57. let that = this;
  58. //获取当月的所有日期
  59. if (typeof (calendar) == 'undefined') {
  60. return;
  61. }
  62. //赋值显示 同一日期 合并成一条显示(采样时间+体温)
  63. let todos = [];
  64. that.data.list.forEach(item => {
  65. console.log("item:"+JSON.stringify(item)+",books:"+JSON.stringify(todos));
  66. let books = todos.filter(f => {
  67. return f.nucleicDate == item.nucleicDate
  68. });
  69. if (books.length == 0) {
  70. todos.push({
  71. nucleicDate: item.nucleicDate,
  72. books: [item]
  73. });
  74. }
  75. else{
  76. books[0].books.push(item);
  77. }
  78. })
  79. console.info(todos)
  80. todos.forEach(todo => {
  81. that.calenderTodo(todo.nucleicDate, todo.books)
  82. });
  83. },
  84. whenChangeMonth(e) {
  85. console.log('whenChangeMonth', e.detail)
  86. const {
  87. year,
  88. month
  89. } = calendar.getCurrentYM();
  90. let m = month;
  91. if (m < 10) m = String(0) + m;
  92. this.getList(year + '-' + m);
  93. },
  94. whenChangeWeek(e) {
  95. console.log('whenChangeWeek', e.detail)
  96. },
  97. takeoverTap(e) {
  98. console.log('takeoverTap', e.detail)
  99. },
  100. afterCalendarRender(e) {
  101. console.log('afterCalendarRender', e);
  102. //初始化完成后,将插件变量赋值
  103. calendar = this.selectComponent('#calendar').calendar;
  104. const {
  105. year,
  106. month
  107. } = calendar.getCurrentYM();
  108. let m = month;
  109. if (m < 10) m = String(0) + m;
  110. this.getList(year + '-' + m);
  111. },
  112. afterTapDate(e) { //选中某个日期
  113. console.log('afterTapDate', e.detail.date)
  114. let that = this;
  115. let selected = '';
  116. var date = String(e.detail.date);
  117. this.data.list.forEach(item => {
  118. if (Number(item.nucleicDate.substring(8,10))== date&&selected=='') {
  119. selected = item;
  120. }
  121. })
  122. that.setData({
  123. selected: selected
  124. })
  125. },
  126. onSwipe(e) {
  127. console.log('onSwipe', e)
  128. },
  129. calendarSetEnabledDates(dates) { //设置可选择的日期
  130. },
  131. calenderTodo(date, title) { //设置指定日期
  132. const {
  133. year,
  134. month
  135. } = calendar.getCurrentYM();
  136. const dates = [{
  137. year,
  138. month,
  139. date: date,
  140. todoText: title
  141. }]
  142. calendar['setTodos']({
  143. showLabelAlways: false,
  144. dates
  145. })
  146. //console.log('set todo: ', dates) ;
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function () {
  157. this.getList(this.data.curDate);
  158. },
  159. /**
  160. * 生命周期函数--监听页面隐藏
  161. */
  162. onHide: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面卸载
  166. */
  167. onUnload: function () {
  168. },
  169. /**
  170. * 页面相关事件处理函数--监听用户下拉动作
  171. */
  172. onPullDownRefresh: function () {
  173. },
  174. /**
  175. * 页面上拉触底事件的处理函数
  176. */
  177. onReachBottom: function () {
  178. },
  179. /**
  180. * 用户点击右上角分享
  181. */
  182. onShareAppMessage: function () {
  183. }
  184. })