tousujianyiList.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. const app= getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. noticeList: [ ],
  8. imageList: [], // 存储图片路径的数组
  9. showCustomPreview: false, // 是否显示自定义预览
  10. currentPreviewImages: [], // 当前预览的图片数组
  11. currentPreviewIndex: 0 // 当前预览的图片索引
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  17. },
  18. /**
  19. * 生命周期函数--监听页面初次渲染完成
  20. */
  21. onReady() {
  22. this.getNoticeList()
  23. },
  24. /**
  25. * 生命周期函数--监听页面显示
  26. */
  27. onShow() {
  28. },
  29. /**
  30. * 生命周期函数--监听页面隐藏
  31. */
  32. onHide() {
  33. },
  34. /**
  35. * 生命周期函数--监听页面卸载
  36. */
  37. onUnload() {
  38. },
  39. /**
  40. * 页面相关事件处理函数--监听用户下拉动作
  41. */
  42. onPullDownRefresh() {
  43. },
  44. /**
  45. * 页面上拉触底事件的处理函数
  46. */
  47. onReachBottom() {
  48. },
  49. /**
  50. * 用户点击右上角分享
  51. */
  52. onShareAppMessage() {
  53. },
  54. // 获取列表数据
  55. getNoticeList() {
  56. const _this = this;
  57. wx.showLoading({
  58. title: '获取中...',
  59. mask: true,
  60. });
  61. // debugger;
  62. wx.request({
  63. url: app.globalData.interfaceUrls.mineFeedback,
  64. method: 'POST',
  65. header: {
  66. 'content-type': 'application/json', // 默认值
  67. 'token': app.globalData.userWxInfo.token,
  68. 'source': "wc",
  69. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  70. },
  71. success(res) {
  72. wx.hideLoading();
  73. let apiReturnData = res.data;
  74. let listData=apiReturnData.data;
  75. listData.forEach(data=>{
  76. data.createdate =data.createdate.slice(0,10);
  77. let imgs=data.file.split(',').map(img=>{
  78. return app.globalData.weChatImgPreviewUrl+'FEEDBACK/'+img;
  79. });
  80. data.hasAttachment=imgs.length>0;
  81. data.attachments=imgs;
  82. data.isReplied=data.iscompleted=='1';
  83. if((data.recoverydate||"")!=''){
  84. data.recoverydate=data.recoverydate.slice(0,10);
  85. }
  86. })
  87. app.globalData.mineRepairList=listData;
  88. _this.setData({
  89. noticeList: listData,
  90. })
  91. },
  92. fail(error) {
  93. wx.hideLoading()
  94. utils.simleInfo('获取报修记录,请稍后再试')
  95. }
  96. });
  97. },
  98. previewImage: function(e) {
  99. // 获取当前点击项的id
  100. const id = e.currentTarget.dataset.id;
  101. // 根据id找到对应的投诉建议项
  102. const item = this.data.noticeList.find(item => item.id === id);
  103. // 确保有附件
  104. if (item && item.hasAttachment && item.attachments.length > 0) {
  105. this.setData({
  106. showCustomPreview: true,
  107. currentPreviewImages: item.attachments,
  108. currentPreviewIndex: 0
  109. });
  110. } else {
  111. console.log('没有找到附件或附件为空');
  112. }
  113. },
  114. // 关闭预览
  115. closePreview: function() {
  116. this.setData({
  117. showCustomPreview: false
  118. });
  119. },
  120. // 切换预览图片
  121. changePreviewImage: function(e) {
  122. const direction = e.currentTarget.dataset.direction;
  123. let newIndex = this.data.currentPreviewIndex;
  124. if (direction === 'prev') {
  125. newIndex = newIndex > 0 ? newIndex - 1 : this.data.currentPreviewImages.length - 1;
  126. } else {
  127. newIndex = newIndex < this.data.currentPreviewImages.length - 1 ? newIndex + 1 : 0;
  128. }
  129. this.setData({
  130. currentPreviewIndex: newIndex
  131. });
  132. },
  133. // 防止点击图片内容时关闭预览
  134. preventBubble: function() {
  135. return;
  136. },
  137. // 跳转到详情页
  138. goToDetail(e) {
  139. debugger;
  140. const id = e.currentTarget.dataset.id
  141. const item = this.data.noticeList.find(item => item.id === id);
  142. if (item.isReplied) {
  143. // 如果已回复,跳转到预览页面
  144. wx.navigateTo({
  145. url: `/pages/tousujianyi/tousujianyi?id=${id}&mode=preview`
  146. })
  147. } else {
  148. // 如果未回复,跳转到普通详情页
  149. wx.navigateTo({
  150. url: `/pages/tousujianyiDetail/tousujianyiDetail?id=${id}`
  151. })
  152. }
  153. },
  154. // 跳转到表单页
  155. goToForm() {
  156. wx.navigateTo({
  157. url: '/pages/tousujianyi/tousujianyi'
  158. })
  159. },
  160. // 返回上一页
  161. goBack() {
  162. wx.navigateBack()
  163. },
  164. // 假设您从服务器获取数据的函数
  165. getDataFromServer: function() {
  166. // 示例:从服务器获取数据
  167. wx.request({
  168. url: 'your_api_url',
  169. success: (res) => {
  170. // 假设返回的数据中包含图片数组
  171. const images = res.data.images || [];
  172. this.setData({
  173. imageList: images
  174. });
  175. }
  176. });
  177. }
  178. })