baoxiuList.js 4.4 KB

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