repairs.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // pages/repairs/repairs.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. repairsList: [], //用户反馈列表
  14. page: 1, //页面加载
  15. bgColor: '#efefef'
  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.lookRepairs();
  46. },
  47. goTop: function (e) { // 一键回到顶部
  48. if (wx.pageScrollTo) {
  49. wx.pageScrollTo({
  50. scrollTop: 0
  51. })
  52. }
  53. },
  54. choose(e) { //已读未读切换
  55. let idx = e.currentTarget.dataset.idx;
  56. this.setData({
  57. curPage: idx,
  58. repairsList:[]
  59. })
  60. this.lookRepairs();
  61. this.goTop();
  62. },
  63. lookRepairs() { //获取报修列表
  64. wx.showLoading({
  65. title: '加载中...',
  66. })
  67. let cur = this.data.curPage;
  68. let areaID = this.data.areaID;
  69. app.request('user/userRepaired?status=' + cur + '&area_id=' + areaID, '', 'GET').then(res => {
  70. wx.hideLoading();
  71. if (res.statusCode == 200) {
  72. console.log(res, '报修列表')
  73. let list = res.data.data;
  74. if (list.length == 0) {
  75. this.setData({
  76. repairsList: [],
  77. bgColor: '#fff'
  78. })
  79. } else {
  80. this.setData({
  81. repairsList: res.data.data,
  82. bgColor: '#efefef'
  83. })
  84. }
  85. }
  86. })
  87. },
  88. markRead(e) { //标记为已读
  89. let id = e.currentTarget.dataset.id
  90. app.request('user/userRepaired/status?id=' + id, '', 'GET').then(res => {
  91. if (res.statusCode == 200) {
  92. this.lookRepairs();
  93. }
  94. })
  95. },
  96. morkRepairs() { //上拉加载更多
  97. wx.showLoading({
  98. title: '加载中...',
  99. })
  100. let that = this;
  101. var page = that.data.page + 1;
  102. let state = this.data.curPage;
  103. let areaID = this.data.areaID;
  104. app.request('user/userRepaired?&status=' + state + '&page=' + page + '&area_id=' + areaID, '', 'GET').then(res => {
  105. wx.hideLoading();
  106. if (res.statusCode == 200) {
  107. let list = res.data.data;
  108. if (list.length > 0) {
  109. this.setData({
  110. repairsList: that.data.repairsList.concat(list),
  111. bgColor: '#efefef',
  112. page
  113. })
  114. } else {
  115. wx.showToast({
  116. title: '到底啦~',
  117. icon: 'none'
  118. })
  119. }
  120. }
  121. })
  122. },
  123. //选择区域
  124. change: function (e) {
  125. let that = this;
  126. wx.setStorageSync('curVal', that.data.option1[e.detail].value)
  127. wx.setStorageSync('curId', that.data.option1[e.detail].areaID)
  128. this.setData({
  129. areaID: that.data.option1[e.detail].areaID
  130. })
  131. this.lookRepairs();
  132. this.goTop();
  133. },
  134. //点击可拨打电话
  135. phone(e){
  136. console.log(1111)
  137. wx.makePhoneCall({
  138. phoneNumber: e.currentTarget.dataset.phone
  139. })
  140. },
  141. //返回键
  142. back() {
  143. wx.navigateBack({
  144. delta: 1
  145. })
  146. },
  147. /**
  148. * 生命周期函数--监听页面初次渲染完成
  149. */
  150. onReady: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面显示
  154. */
  155. onShow: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide: function () {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload: function () {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh: function () {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom: function () {
  176. this.morkRepairs();
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage: function () {
  182. }
  183. })