baoxiuList.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. repairTypeMap: [
  14. {name: '换表', value: '1'},
  15. {name: '换前阀', value: '2'},
  16. {name: '换后阀', value: '3'},
  17. {name: '换前后阀', value: '4'},
  18. {name: '其他', value: '5'}
  19. ],
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. this.getNoticeList()
  26. },
  27. /**
  28. * 生命周期函数--监听页面初次渲染完成
  29. */
  30. onReady() {
  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. if (data.repairtype) {
  102. const repairTypeItem = _this.data.repairTypeMap.find(item => item.name === data.repairtype);
  103. data.repairtype = repairTypeItem ? repairTypeItem.name : '未知类型';
  104. } else {
  105. data.repairtype = '未知类型';
  106. }
  107. });
  108. app.globalData.mineRepairList = listData;
  109. _this.setData({
  110. noticeList: listData,
  111. })
  112. debugger
  113. },
  114. fail(error) {
  115. wx.hideLoading()
  116. utils.simleInfo('获取报修记录,请稍后再试')
  117. }
  118. });
  119. },
  120. previewImage: function (e) {
  121. // 获取当前点击项的id
  122. const id = e.currentTarget.dataset.id;
  123. // 根据id找到对应的投诉建议项
  124. const item = this.data.noticeList.find(item => item.id === id);
  125. debugger;
  126. // 确保有附件
  127. if (item && item.hasAttachment && item.attachments.length > 0) {
  128. this.setData({
  129. showCustomPreview: true,
  130. currentPreviewImages: item.attachments,
  131. currentPreviewIndex: 0
  132. });
  133. } else {
  134. console.log('没有找到附件或附件为空');
  135. }
  136. },
  137. // 关闭预览
  138. closePreview: function () {
  139. this.setData({
  140. showCustomPreview: false
  141. });
  142. },
  143. // 切换预览图片
  144. changePreviewImage: function (e) {
  145. const direction = e.currentTarget.dataset.direction;
  146. let newIndex = this.data.currentPreviewIndex;
  147. if (direction === 'prev') {
  148. newIndex = newIndex > 0 ? newIndex - 1 : this.data.currentPreviewImages.length - 1;
  149. } else {
  150. newIndex = newIndex < this.data.currentPreviewImages.length - 1 ? newIndex + 1 : 0;
  151. }
  152. this.setData({
  153. currentPreviewIndex: newIndex
  154. });
  155. },
  156. // 防止点击图片内容时关闭预览
  157. preventBubble: function () {
  158. return;
  159. },
  160. // 跳转到详情页
  161. goToDetail(e) {
  162. const id = e.currentTarget.dataset.id;
  163. const item = this.data.noticeList.find(item => item.id === id);
  164. // 统一使用预览模式,传递isReplied参数
  165. wx.navigateTo({
  166. url: `/pages/baoxiudj/baoxiudj?id=${id}&mode=preview&isReplied=${item.isReplied ? 'true' : 'false'}`
  167. });
  168. },
  169. // 跳转到表单页
  170. goToForm() {
  171. wx.navigateTo({
  172. url: '/pages/baoxiudj/baoxiudj'
  173. })
  174. },
  175. // 返回上一页
  176. goBack() {
  177. wx.navigateBack()
  178. },
  179. })