maritime.js 5.9 KB

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