index.js 4.8 KB

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