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