baoxiuList.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. /**
  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.mineRepair,
  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. let imgs=data.images.split(',').map(img=>{
  79. return app.globalData.weChatImgPreviewUrl+'REPAIR/'+img;
  80. });
  81. data.hasAttachment=imgs.length>0;
  82. data.attachments=imgs;
  83. data.isReplied=data.iscompleted=='1';
  84. if((data.recoverydate||"")!=''){
  85. data.recoverydate=data.recoverydate.slice(0,10);
  86. }
  87. })
  88. app.globalData.mineRepairList=listData;
  89. _this.setData({
  90. noticeList: listData,
  91. })
  92. },
  93. fail(error) {
  94. wx.hideLoading()
  95. utils.simleInfo('获取报修记录,请稍后再试')
  96. }
  97. });
  98. },
  99. previewImage: function (e) {
  100. // 获取当前点击项的id
  101. const id = e.currentTarget.dataset.id;
  102. // 根据id找到对应的投诉建议项
  103. const item = this.data.noticeList.find(item => item.id === id);
  104. debugger;
  105. // 确保有附件
  106. if (item && item.hasAttachment && item.attachments.length > 0) {
  107. this.setData({
  108. showCustomPreview: true,
  109. currentPreviewImages: item.attachments,
  110. currentPreviewIndex: 0
  111. });
  112. } else {
  113. console.log('没有找到附件或附件为空');
  114. }
  115. },
  116. // 关闭预览
  117. closePreview: function () {
  118. this.setData({
  119. showCustomPreview: false
  120. });
  121. },
  122. // 切换预览图片
  123. changePreviewImage: function (e) {
  124. const direction = e.currentTarget.dataset.direction;
  125. let newIndex = this.data.currentPreviewIndex;
  126. if (direction === 'prev') {
  127. newIndex = newIndex > 0 ? newIndex - 1 : this.data.currentPreviewImages.length - 1;
  128. } else {
  129. newIndex = newIndex < this.data.currentPreviewImages.length - 1 ? newIndex + 1 : 0;
  130. }
  131. this.setData({
  132. currentPreviewIndex: newIndex
  133. });
  134. },
  135. // 防止点击图片内容时关闭预览
  136. preventBubble: function () {
  137. return;
  138. },
  139. // 跳转到详情页
  140. goToDetail(e) {
  141. const id = e.currentTarget.dataset.id;
  142. const item = this.data.noticeList.find(item => item.id === id);
  143. // 统一使用预览模式,传递isReplied参数
  144. wx.navigateTo({
  145. url: `/pages/baoxiudj/baoxiudj?id=${id}&mode=preview&isReplied=${item.isReplied ? 'true' : 'false'}`
  146. });
  147. },
  148. // 跳转到表单页
  149. goToForm() {
  150. wx.navigateTo({
  151. url: '/pages/baoxiudj/baoxiudj'
  152. })
  153. },
  154. // 返回上一页
  155. goBack() {
  156. wx.navigateBack()
  157. },
  158. })