feedback.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // pages/feedback/feedback.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. screenHeight: '', //屏幕可视高度
  9. areaID: 0, //区域id
  10. value1: 0, //第一个显示什么
  11. option1: [],
  12. curPage: 0, //tab切换 【1 已读 0未读】
  13. feedList: [], //用户反馈列表
  14. page: 1,
  15. option1: [],
  16. navBarHeight: app.globalData.navBarHeight, // 导航栏高度
  17. menuRight: app.globalData.menuRight, // 胶囊距右方间距(方保持左、右间距一致)
  18. menuTop: app.globalData.menuTop, // 胶囊距底部间距(保持底部间距一致)
  19. menuHeight: app.globalData.menuHeight, // 胶囊高度(自定义内容可与胶囊高度保证一致)
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. let that = this;
  26. that.setData({
  27. screenHeight: app.globalData.screenHeight,
  28. option1: wx.getStorageSync('allArea'),
  29. })
  30. let curVal = wx.getStorageSync('curVal');
  31. if (curVal) {
  32. that.setData({
  33. value1: curVal
  34. })
  35. }
  36. let areaID = wx.getStorageSync('curId')
  37. if (areaID) {
  38. that.setData({
  39. areaID
  40. })
  41. } else {
  42. let id = that.data.option1[0].areaID
  43. that.setData({
  44. areaID: id
  45. })
  46. }
  47. that.menu = that.selectComponent("#menu");
  48. that.menu.changeTitle(that.data.option1[that.data.value1].text);
  49. this.getFeed();
  50. },
  51. goTop: function (e) { // 一键回到顶部
  52. if (wx.pageScrollTo) {
  53. wx.pageScrollTo({
  54. scrollTop: 0
  55. })
  56. }
  57. },
  58. //获取反馈列表
  59. getFeed() {
  60. wx.showLoading({
  61. title: '加载中',
  62. })
  63. let areaID = this.data.areaID;
  64. let is_read = this.data.curPage;
  65. app.request('user/feedback?is_read=' + is_read + '&area_id=' + areaID, '', 'GET').then(res => {
  66. wx.hideLoading()
  67. console.log(res.data.data);
  68. let feed = res.data.data;
  69. if (feed) {
  70. this.setData({
  71. feedList: res.data.data
  72. })
  73. } else {
  74. wx.showToast({
  75. title: '暂无反馈信息~',
  76. icon: 'none'
  77. })
  78. }
  79. })
  80. },
  81. //标记为已读
  82. markRead(e) {
  83. let id = e.currentTarget.dataset.id;
  84. app.request('user/feedback/read?id=' + id, '', 'GET').then(res => {
  85. console.log(res);
  86. if (res.statusCode == 200) {
  87. this.getFeed();
  88. }
  89. })
  90. },
  91. //返回键
  92. back() {
  93. wx.navigateBack({
  94. delta: 1
  95. })
  96. },
  97. //选择区域
  98. change: function (e) {
  99. let that = this;
  100. let index = e.detail.value
  101. wx.setStorageSync('curVal', index)
  102. wx.setStorageSync('curId', that.data.option1[index].areaID)
  103. this.setData({
  104. areaID: that.data.option1[index].areaID,
  105. value1:index
  106. })
  107. this.getFeed();
  108. this.goTop();
  109. },
  110. //tab 切换
  111. choose(e) {
  112. let idx = e.currentTarget.dataset.idx;
  113. this.setData({
  114. curPage: idx
  115. })
  116. this.getFeed();
  117. this.goTop();
  118. },
  119. moreFeed() {
  120. wx.showLoading({
  121. title: '加载中...',
  122. })
  123. let that = this;
  124. var page = that.data.page + 1;
  125. let read = that.data.curPage;
  126. let areaID = that.data.areaID;
  127. app.request('user/feedback?is_read=' + read + '&page=' + page + '&area_id=' + areaID, '', 'GET').then(res => {
  128. wx.hideLoading();
  129. if (res.statusCode == 200) {
  130. wx.hideLoading();
  131. if (res.data.data.length > 0) {
  132. console.log(res)
  133. this.setData({
  134. feedList: this.data.feedList.concat(res.data.data)
  135. })
  136. } else {
  137. wx.showToast({
  138. title: '没有更多数据了~',
  139. icon: 'none'
  140. })
  141. }
  142. }
  143. })
  144. },
  145. /**
  146. * 生命周期函数--监听页面初次渲染完成
  147. */
  148. onReady: function () {
  149. },
  150. /**
  151. * 生命周期函数--监听页面显示
  152. */
  153. onShow: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面隐藏
  157. */
  158. onHide: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload: function () {
  164. },
  165. /**
  166. * 页面相关事件处理函数--监听用户下拉动作
  167. */
  168. onPullDownRefresh: function () {
  169. },
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom: function () {
  174. wx.showLoading({
  175. title: '加载中',
  176. })
  177. this.moreFeed();
  178. },
  179. /**
  180. * 用户点击右上角分享
  181. */
  182. onShareAppMessage: function () {
  183. }
  184. })