baoxiuList.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. const app=getApp();
  2. const utils = require("../../utils/util.js")
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. noticeList: [],
  9. imageList: [], // 存储图片路径的数组
  10. // 添加维修类型映射
  11. repairTypeMap: [
  12. {name: '换表', value: '1'},
  13. {name: '换前阀', value: '2'},
  14. {name: '换后阀', value: '3'},
  15. {name: '换前后阀', value: '4'},
  16. {name: '其他', value: '5'}
  17. ],
  18. previewImage: '',
  19. currentImageIndex: 0,
  20. showPreview: false,
  21. previewImages: [],
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. this.getNoticeList()
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady() {
  33. },
  34. /**
  35. * 生命周期函数--监听页面隐藏
  36. */
  37. onHide() {
  38. },
  39. /**
  40. * 生命周期函数--监听页面卸载
  41. */
  42. onUnload() {
  43. },
  44. /**
  45. * 页面相关事件处理函数--监听用户下拉动作
  46. */
  47. onPullDownRefresh() {
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom() {
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage() {
  58. },
  59. // 获取列表数据
  60. getNoticeList() {
  61. const _this = this;
  62. wx.showLoading({
  63. title: '获取中...',
  64. mask: true,
  65. });
  66. // debugger;
  67. wx.request({
  68. url: app.globalData.interfaceUrls.mineRepair,
  69. method: 'POST',
  70. header: {
  71. 'content-type': 'application/json', // 默认值
  72. 'token': app.globalData.userWxInfo.token,
  73. 'source': "wc",
  74. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  75. },
  76. success(res) {
  77. debugger
  78. wx.hideLoading();
  79. let apiReturnData = res.data;
  80. let listData = apiReturnData.data;
  81. listData.forEach(data => {
  82. // 处理创建日期
  83. data.createdate = data.createdate ? data.createdate.slice(0, 10) : '';
  84. // 处理图片数据
  85. let imgs = [];
  86. if (data.images && typeof data.images === 'string' && data.images.trim() !== '') {
  87. imgs = data.images.split(',').filter(img => img).map(img => {
  88. return app.globalData.weChatImgPreviewUrl + 'REPAIR/' + img;
  89. });
  90. }
  91. // 设置附件相关属性
  92. data.hasAttachment = imgs.length > 0;
  93. data.attachments = imgs;
  94. // 处理回复状态
  95. data.isReplied = data.iscompleted === '1';
  96. // 处理恢复日期
  97. if (data.recoverydate) {
  98. data.recoverydate = data.recoverydate.slice(0, 10);
  99. } else {
  100. data.recoverydate = '';
  101. }
  102. // 转换维修类型值为名称
  103. if (data.repairtype) {
  104. const repairTypeItem = _this.data.repairTypeMap.find(item => item.name === data.repairtype);
  105. data.repairtype = repairTypeItem ? repairTypeItem.name : '未知类型';
  106. } else {
  107. data.repairtype = '未知类型';
  108. }
  109. });
  110. app.globalData.mineRepairList = listData;
  111. _this.setData({
  112. noticeList: listData,
  113. })
  114. debugger
  115. },
  116. fail(error) {
  117. wx.hideLoading()
  118. utils.simleInfo('获取报修记录,请稍后再试')
  119. }
  120. });
  121. },
  122. // 预览图片
  123. previewImage(e) {
  124. const { id, index } = e.currentTarget.dataset;
  125. const { noticeList } = this.data;
  126. // 如果是点击列表项的预览按钮
  127. if (id) {
  128. const item = noticeList.find(item => item.id === id);
  129. if (item && item.attachments && item.attachments.length > 0) {
  130. wx.previewImage({
  131. current: item.attachments[0], // 当前显示图片的链接
  132. urls: item.attachments // 需要预览的图片链接列表
  133. });
  134. }
  135. }
  136. // 如果是点击图片列表中的图片
  137. else if (typeof index !== 'undefined') {
  138. const { imageList } = this.data;
  139. wx.previewImage({
  140. current: imageList[index], // 当前显示图片的链接
  141. urls: imageList // 需要预览的图片链接列表
  142. });
  143. }
  144. },
  145. // 关闭预览
  146. closePreview() {
  147. this.setData({
  148. showPreview: false,
  149. currentImageIndex: 0,
  150. previewImages: []
  151. });
  152. },
  153. // 上一张图片
  154. prevImage() {
  155. const { currentImageIndex, previewImages } = this.data;
  156. if (currentImageIndex > 0) {
  157. this.setData({
  158. currentImageIndex: currentImageIndex - 1
  159. });
  160. }
  161. },
  162. // 下一张图片
  163. nextImage() {
  164. const { currentImageIndex, previewImages } = this.data;
  165. if (currentImageIndex < previewImages.length - 1) {
  166. this.setData({
  167. currentImageIndex: currentImageIndex + 1
  168. });
  169. }
  170. },
  171. // 处理滑动事件
  172. swiperChange(e) {
  173. const current = e.detail.current;
  174. this.setData({
  175. currentImageIndex: current
  176. });
  177. },
  178. // 防止点击图片内容时关闭预览
  179. preventBubble() {
  180. return;
  181. },
  182. // 跳转到详情页
  183. goToDetail(e) {
  184. const id = e.currentTarget.dataset.id;
  185. const item = this.data.noticeList.find(item => item.id === id);
  186. // 统一使用预览模式,传递isReplied参数
  187. wx.navigateTo({
  188. url: `/pages/baoxiudj/baoxiudj?id=${id}&mode=preview&isReplied=${item.isReplied ? 'true' : 'false'}`
  189. });
  190. },
  191. // 跳转到表单页
  192. goToForm() {
  193. wx.navigateTo({
  194. url: '/pages/baoxiudj/baoxiudj'
  195. })
  196. },
  197. // 返回上一页
  198. goBack() {
  199. wx.navigateBack()
  200. },
  201. })