feedback.js 3.9 KB

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