tousujianyiList.js 5.3 KB

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