maritime.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. Page({
  2. data: {
  3. notices: [],
  4. legalOrg: {
  5. name: "",
  6. photoUrl: "",
  7. introduction: "",
  8. },
  9. aidRequest: "",
  10. currentPage: 1,
  11. pageSize: 10,
  12. totalPages: 0,
  13. isLoading: false,
  14. hasMore: true,
  15. isRefreshing: false,
  16. },
  17. // 获取海事公告列表
  18. getNoticeList(isRefresh = false) {
  19. if (this.data.isLoading || (!isRefresh && !this.data.hasMore)) return;
  20. this.setData({ isLoading: true });
  21. const currentPage = isRefresh ? 1 : this.data.currentPage;
  22. // 导入API配置
  23. const { api } = require("../../apis/apiConfig.js");
  24. api(
  25. "/maritime/safety/notice/list",
  26. {
  27. currentPage: currentPage,
  28. size: this.data.pageSize,
  29. },
  30. "POST"
  31. )
  32. .then((res) => {
  33. if (res.data.status === 0) {
  34. const newNotices = res.data.result.map((item) => ({
  35. id: item.id,
  36. title: item.fileName,
  37. date: item.createTime.split(" ")[0],
  38. unit: "",
  39. fileKey: item.fileKey,
  40. downloadUrl: item.downloadUrl,
  41. }));
  42. this.setData({
  43. notices: isRefresh
  44. ? newNotices
  45. : [...this.data.notices, ...newNotices],
  46. currentPage: currentPage + 1,
  47. totalPages: Math.ceil(res.data.total / this.data.pageSize),
  48. hasMore:
  49. currentPage < Math.ceil(res.data.total / this.data.pageSize),
  50. });
  51. } else {
  52. wx.showToast({
  53. title: res.data.msg || "获取公告列表失败",
  54. icon: "none",
  55. });
  56. }
  57. })
  58. .catch(() => {
  59. wx.showToast({
  60. title: "网络异常,请稍后重试",
  61. icon: "none",
  62. });
  63. })
  64. .finally(() => {
  65. this.setData({ isLoading: false });
  66. wx.stopPullDownRefresh();
  67. });
  68. },
  69. // 获取法律援助机构信息
  70. getLegalAidInfo() {
  71. const { api } = require("../../apis/apiConfig.js");
  72. api("/maritime/safety/legal/aid/introduce", {}, "GET")
  73. .then((res) => {
  74. if (res.data.status === 0 && res.data.result) {
  75. const { legalAidIntroduce, lawyerIntroduce } = res.data.result;
  76. this.setData({
  77. legalOrg: {
  78. name: legalAidIntroduce.title || "法律援助机构",
  79. photoUrl:
  80. lawyerIntroduce.imageUrl || "../../images/new-version/pic.png",
  81. introduction:
  82. legalAidIntroduce.imageUrl ||
  83. legalAidIntroduce.textContent ||
  84. "",
  85. },
  86. });
  87. }
  88. })
  89. .catch(() => {
  90. wx.showToast({
  91. title: "获取法律援助信息失败",
  92. icon: "none",
  93. });
  94. });
  95. },
  96. handleInputChange(e) {
  97. this.setData({
  98. aidRequest: e.detail.value,
  99. });
  100. },
  101. submitAidRequest() {
  102. if (!this.data.aidRequest.trim()) {
  103. wx.showToast({
  104. title: "请输入法律援助需求",
  105. icon: "none",
  106. });
  107. return;
  108. }
  109. const { api } = require("../../apis/apiConfig.js");
  110. api(
  111. "/maritime/safety/legal/aid/request",
  112. {
  113. requestContent: this.data.aidRequest,
  114. },
  115. "POST"
  116. )
  117. .then((res) => {
  118. if (res.data && res.data.status === 0) {
  119. wx.showToast({
  120. title: "申请提交成功",
  121. icon: "success",
  122. });
  123. this.setData({
  124. aidRequest: "",
  125. });
  126. } else {
  127. wx.showToast({
  128. title: res.data.msg || "申请提交失败",
  129. icon: "none",
  130. });
  131. }
  132. })
  133. .catch(() => {
  134. wx.showToast({
  135. title: "网络异常,请稍后重试",
  136. icon: "none",
  137. });
  138. });
  139. },
  140. onLoad() {
  141. this.getNoticeList(true);
  142. this.getLegalAidInfo();
  143. },
  144. onShow() {
  145. if (typeof this.getTabBar === "function" && this.getTabBar()) {
  146. this.getTabBar().setData({
  147. selected: 2,
  148. });
  149. }
  150. },
  151. // 下拉刷新
  152. onPullDownRefresh() {
  153. this.setData({
  154. currentPage: 1,
  155. hasMore: true,
  156. isRefreshing: true,
  157. });
  158. this.getNoticeList(true);
  159. },
  160. // 处理scroll-view的滚动到底部事件
  161. onScrollToLower() {
  162. if (this.data.hasMore && !this.data.isLoading) {
  163. this.getNoticeList();
  164. }
  165. },
  166. // 页面上拉触底事件(保留但不再使用,改为使用scroll-view的bindscrolltolower)
  167. onReachBottom() {
  168. // 页面的上拉触底事件已被scroll-view的bindscrolltolower替代
  169. },
  170. // 查看公告详情
  171. viewNoticeDetail(e) {
  172. const id = e.currentTarget.dataset.id;
  173. const notice = this.data.notices.find((item) => item.id === id);
  174. if (notice && notice.downloadUrl) {
  175. wx.showLoading({
  176. title: "加载中",
  177. });
  178. // 获取API配置
  179. const { apiUrl } = require("../../apis/apiConfig.js");
  180. // 检查downloadUrl是否已包含完整URL
  181. // 打开文件预览
  182. wx.downloadFile({
  183. url: notice.downloadUrl,
  184. success: function (res) {
  185. const filePath = res.tempFilePath;
  186. console.log("文件路径:", res);
  187. wx.openDocument({
  188. filePath: filePath,
  189. fileType: "pdf",
  190. success: function () {
  191. console.log("打开文档成功");
  192. },
  193. fail: function () {
  194. wx.showToast({
  195. title: "无法打开文件",
  196. icon: "none",
  197. });
  198. },
  199. complete: function () {
  200. wx.hideLoading();
  201. },
  202. });
  203. },
  204. fail: function () {
  205. wx.hideLoading();
  206. wx.showToast({
  207. title: "文件下载失败",
  208. icon: "none",
  209. });
  210. },
  211. });
  212. } else {
  213. wx.showToast({
  214. title: "无法获取公告详情",
  215. icon: "none",
  216. });
  217. }
  218. },
  219. });