repairs.js 4.1 KB

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