repairs.js 4.6 KB

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