waterabnormal.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // pages/waterabnormal/waterabnormal.js
  2. const app = getApp();
  3. let moment = require('../../utils/moment.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. monthValue: moment().format('YYYY-MM'),
  10. monthTxt: moment().format('YYYY年MM月'),
  11. monthStart: '1990-01',
  12. monthEnd: moment().format('YYYY-MM'),
  13. weeks: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
  14. curDay: moment().format('YYYYMMDD'),
  15. selectedDay: moment().format('YYYYMMDD'),
  16. dateArr: [],
  17. abnormalList: [],
  18. },
  19. toSettings() {
  20. wx.navigateTo({
  21. url: '/pages/waterabnormal/settings/settings',
  22. })
  23. },
  24. dayTap(e) {
  25. const {
  26. dateStr
  27. } = e.currentTarget.dataset.info;
  28. if (dateStr) {
  29. this.setData({
  30. selectedDay: dateStr
  31. })
  32. this.getList();
  33. };
  34. },
  35. bindDateChange(e) {
  36. const {
  37. value
  38. } = e.detail;
  39. this.setData({
  40. monthTxt: moment(value).format('YYYY年MM月'),
  41. })
  42. const arr = value.split('-'),
  43. year = arr[0],
  44. month = arr[1];
  45. //获取本月
  46. const endDate = moment(year, "YYYY").month(month - 1, 'MM').endOf('month').format("YYYYMMDD");
  47. const now = this.data.selectedDay.substr(6);
  48. const end = endDate.substr(6);
  49. if (now > end) {
  50. this.setData({
  51. selectedDay: endDate
  52. })
  53. } else {
  54. this.setData({
  55. selectedDay: `${year}${month}${now}`
  56. })
  57. }
  58. this.getDaysArray(year, month);
  59. },
  60. getDaysArray(year, month) {
  61. let dateArr = []; //需要遍历的日历数组数据
  62. let arrLen = 0; //dateArr的数组长度
  63. let startWeek = moment(`${year}/${month}/01`, 'YYYY/MM/DD').day();; //目标月1号对应的星期
  64. let dayNums = moment(`${year}/${month}`, 'YYYY/MM').daysInMonth(); //获取目标月有多少天
  65. let obj = {};
  66. arrLen = startWeek + dayNums;
  67. for (let i = 0; i < arrLen; i++) {
  68. if (i >= startWeek) {
  69. const dateNo = (i - startWeek + 1).toString().padStart(2, '0');
  70. const dateStr = `${year}${month}${dateNo}`;
  71. obj = {
  72. dateStr,
  73. dateNo
  74. }
  75. } else {
  76. obj = {};
  77. }
  78. dateArr[i] = obj;
  79. }
  80. this.setData({
  81. dateArr: dateArr
  82. })
  83. this.getDateArr();
  84. },
  85. getList() {
  86. app.$http.get('/warningMessage/getPage', {
  87. date: this.data.selectedDay
  88. }).then(({
  89. status,
  90. data = []
  91. }) => {
  92. if (status == 0) {
  93. data.forEach(v => {
  94. v.time = moment(v.dateCreate).format('HH:mm:ss')
  95. })
  96. this.setData({
  97. abnormalList: data
  98. })
  99. }
  100. })
  101. },
  102. getDateArr() {
  103. app.showLoading();
  104. app.$http.get('/warningMessage/getDateStatus', {
  105. date: moment(this.data.monthTxt, 'YYYY年MM月').format('YYYYMM')
  106. }).then(({
  107. status,
  108. data = []
  109. }) => {
  110. if (status == 0) {
  111. this.data.dateArr.forEach(v => {
  112. const info = data.find(d => d.days == v.dateStr);
  113. if (info) {
  114. v.isAbnormal = info.feedbackStatus == 0;
  115. v.isHandled = info.feedbackStatus != 0;
  116. }
  117. })
  118. this.setData({
  119. dateArr: this.data.dateArr
  120. })
  121. this.getList();
  122. }
  123. app.hideLoading();
  124. }).catch(() => {
  125. app.hideLoading();
  126. })
  127. },
  128. touchstart: function (e) {
  129. const {
  130. feedbackStatus
  131. } = e.currentTarget.dataset.item;
  132. if (feedbackStatus) return
  133. //开始触摸时 重置所有删除
  134. let data = app.$touch._touchstart(e, this.data.abnormalList) //将修改过的list setData
  135. this.setData({
  136. abnormalList: data
  137. })
  138. },
  139. //滑动事件处理
  140. touchmove: function (e) {
  141. const {
  142. feedbackStatus
  143. } = e.currentTarget.dataset.item;
  144. if (feedbackStatus) return
  145. let data = app.$touch._touchmove(e, this.data.abnormalList, 'id') //将修改过的list setData
  146. this.setData({
  147. abnormalList: data
  148. })
  149. },
  150. toFeedback(e) {
  151. const {id} = e.currentTarget.dataset.item;
  152. wx.navigateTo({
  153. url: `/pages/waterabnormal/feedback/feedback?id=${id}`,
  154. })
  155. },
  156. onShow() {
  157. const arr = this.data.monthValue.split('-');
  158. this.getDaysArray(arr[0], arr[1]);
  159. }
  160. })