baoxiuList.js 5.1 KB

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