tousujianyiList.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. const app= getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. noticeList: [ ],
  8. imageList: [], // 存储图片路径的数组
  9. description: '',
  10. content: '',
  11. contact: '',
  12. phone: '',
  13. replyTime: '',
  14. replyContent: '',
  15. showCustomPreview: false,
  16. currentPreviewIndex: 0,
  17. currentPreviewImages: []
  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, index } = e.currentTarget.dataset;
  106. // 如果是点击列表项的预览按钮
  107. if (id) {
  108. // 根据id找到对应的投诉建议项
  109. const item = this.data.noticeList.find(item => item.id === id);
  110. // 确保有附件
  111. if (item && item.hasAttachment && item.attachments.length > 0) {
  112. wx.previewImage({
  113. current: item.attachments[0], // 当前显示图片的链接
  114. urls: item.attachments // 需要预览的图片链接列表
  115. });
  116. } else {
  117. console.log('没有找到附件或附件为空');
  118. }
  119. }
  120. // 如果是点击图片列表中的图片
  121. else if (typeof index !== 'undefined') {
  122. const { imageList } = this.data;
  123. wx.previewImage({
  124. current: imageList[index], // 当前显示图片的链接
  125. urls: imageList // 需要预览的图片链接列表
  126. });
  127. }
  128. },
  129. // 关闭预览
  130. closePreview: function() {
  131. this.setData({
  132. showCustomPreview: false,
  133. currentPreviewIndex: 0,
  134. currentPreviewImages: []
  135. });
  136. },
  137. // 上一张图片
  138. prevImage: function() {
  139. const { currentPreviewIndex } = this.data;
  140. if (currentPreviewIndex > 0) {
  141. this.setData({
  142. currentPreviewIndex: currentPreviewIndex - 1
  143. });
  144. }
  145. },
  146. // 下一张图片
  147. nextImage: function() {
  148. const { currentPreviewIndex, currentPreviewImages } = this.data;
  149. if (currentPreviewIndex < currentPreviewImages.length - 1) {
  150. this.setData({
  151. currentPreviewIndex: currentPreviewIndex + 1
  152. });
  153. }
  154. },
  155. // 处理滑动事件
  156. swiperChange: function(e) {
  157. const current = e.detail.current;
  158. this.setData({
  159. currentPreviewIndex: current
  160. });
  161. },
  162. // 防止点击图片内容时关闭预览
  163. preventBubble: function() {
  164. return;
  165. },
  166. // 跳转到详情页
  167. goToDetail(e) {
  168. debugger;
  169. const id = e.currentTarget.dataset.id
  170. const item = this.data.noticeList.find(item => item.id === id);
  171. // 无论是否回复,都跳转到预览页面,但传递不同的回复状态参数
  172. wx.navigateTo({
  173. url: `/pages/tousujianyi/tousujianyi?id=${id}&mode=preview&isReplied=${item.isReplied}`
  174. })
  175. },
  176. // 跳转到表单页
  177. goToForm() {
  178. wx.navigateTo({
  179. url: '/pages/tousujianyi/tousujianyi'
  180. })
  181. },
  182. // 返回上一页
  183. goBack() {
  184. wx.navigateBack()
  185. },
  186. getDataById: function(id) {
  187. if (!id) {
  188. console.log('未获取到有效的ID');
  189. return;
  190. }
  191. const item = this.data.noticeList.find(item => item.id === id);
  192. if (item) {
  193. debugger
  194. this.setData({
  195. description: item.description,
  196. content: item.content,
  197. contact: item.contact,
  198. phone: item.phone,
  199. replyTime: item.recoverydate,
  200. replyContent: item.replycontent
  201. });
  202. }
  203. },
  204. })