| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- import { checkToken } from "../../utils/utils";
- Page({
- data: {
- notices: [],
- legalOrg: {
- name: "",
- photoUrl: "",
- introduction: "",
- },
- aidRequest: "",
- currentPage: 1,
- pageSize: 10,
- totalPages: 0,
- isLoading: false,
- hasMore: true,
- isRefreshing: false,
- },
- // 获取海事公告列表
- getNoticeList(isRefresh = false) {
- if (this.data.isLoading || (!isRefresh && !this.data.hasMore)) return;
- this.setData({ isLoading: true });
- const currentPage = isRefresh ? 1 : this.data.currentPage;
- // 导入API配置
- const { api } = require("../../apis/apiConfig.js");
- api(
- "/maritime/safety/notice/list",
- {
- currentPage: currentPage,
- size: this.data.pageSize,
- },
- "POST"
- )
- .then((res) => {
- if (res.data.status === 0) {
- const newNotices = res.data.result.map((item) => ({
- id: item.id,
- title: item.fileName,
- date: item.createTime.split(" ")[0],
- unit: "",
- fileKey: item.fileKey,
- downloadUrl: item.downloadUrl,
- }));
- this.setData({
- notices: isRefresh
- ? newNotices
- : [...this.data.notices, ...newNotices],
- currentPage: currentPage + 1,
- totalPages: Math.ceil(res.data.total / this.data.pageSize),
- hasMore:
- currentPage < Math.ceil(res.data.total / this.data.pageSize),
- });
- } else {
- wx.showToast({
- title: res.data.msg || "获取公告列表失败",
- icon: "none",
- });
- }
- })
- .catch(() => {
- wx.showToast({
- title: "网络异常,请稍后重试",
- icon: "none",
- });
- })
- .finally(() => {
- this.setData({ isLoading: false });
- wx.stopPullDownRefresh();
- });
- },
- // 获取法律援助机构信息
- getLegalAidInfo() {
- const { api } = require("../../apis/apiConfig.js");
- api("/maritime/safety/legal/aid/introduce", {}, "GET")
- .then((res) => {
- if (res.data.status === 0 && res.data.result) {
- const { legalAidIntroduce, lawyerIntroduce } = res.data.result;
- this.setData({
- legalOrg: {
- name: legalAidIntroduce.title || "法律援助机构",
- photoUrl:
- lawyerIntroduce.imageUrl || "../../images/new-version/pic.png",
- introduction:
- legalAidIntroduce.imageUrl ||
- legalAidIntroduce.textContent ||
- "",
- },
- });
- }
- })
- .catch(() => {
- wx.showToast({
- title: "获取法律援助信息失败",
- icon: "none",
- });
- });
- },
- handleInputChange(e) {
- this.setData({
- aidRequest: e.detail.value,
- });
- },
- submitAidRequest() {
- if (!checkToken("尚未登录")) return;
- if (!this.data.aidRequest.trim()) {
- wx.showToast({
- title: "请输入法律援助需求",
- icon: "none",
- });
- return;
- }
- const { api } = require("../../apis/apiConfig.js");
- api(
- "/maritime/safety/legal/aid/request",
- {
- requestContent: this.data.aidRequest,
- },
- "POST"
- )
- .then((res) => {
- if (res.data && res.data.status === 0) {
- wx.showToast({
- title: "申请提交成功",
- icon: "success",
- });
- this.setData({
- aidRequest: "",
- });
- } else {
- wx.showToast({
- title: res.data.msg || "申请提交失败",
- icon: "none",
- });
- }
- })
- .catch(() => {
- wx.showToast({
- title: "网络异常,请稍后重试",
- icon: "none",
- });
- });
- },
- onLoad() {
- this.getNoticeList(true);
- this.getLegalAidInfo();
- },
- onShow() {
- if (typeof this.getTabBar === "function" && this.getTabBar()) {
- this.getTabBar().setData({
- selected: 2,
- });
- }
- },
- // 下拉刷新
- onPullDownRefresh() {
- this.setData({
- currentPage: 1,
- hasMore: true,
- isRefreshing: true,
- });
- this.getNoticeList(true);
- },
- // 处理scroll-view的滚动到底部事件
- onScrollToLower() {
- if (this.data.hasMore && !this.data.isLoading) {
- this.getNoticeList();
- }
- },
- // 页面上拉触底事件(保留但不再使用,改为使用scroll-view的bindscrolltolower)
- onReachBottom() {
- // 页面的上拉触底事件已被scroll-view的bindscrolltolower替代
- },
- // 查看公告详情
- viewNoticeDetail(e) {
- const id = e.currentTarget.dataset.id;
- const notice = this.data.notices.find((item) => item.id === id);
- if (notice && notice.downloadUrl) {
- wx.showLoading({
- title: "加载中",
- });
- // 获取API配置
- const { apiUrl } = require("../../apis/apiConfig.js");
- // 检查downloadUrl是否已包含完整URL
- // 打开文件预览
- wx.downloadFile({
- url: notice.downloadUrl,
- success: function (res) {
- const filePath = res.tempFilePath;
- console.log("文件路径:", res);
- wx.openDocument({
- filePath: filePath,
- fileType: "pdf",
- success: function () {
- console.log("打开文档成功");
- },
- fail: function () {
- wx.showToast({
- title: "无法打开文件",
- icon: "none",
- });
- },
- complete: function () {
- wx.hideLoading();
- },
- });
- },
- fail: function () {
- wx.hideLoading();
- wx.showToast({
- title: "文件下载失败",
- icon: "none",
- });
- },
- });
- } else {
- wx.showToast({
- title: "无法获取公告详情",
- icon: "none",
- });
- }
- },
- });
|