| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // pages/maritime/maritime.js
- import { postApi } from "../../apis/api";
- Page({
- data: {
- list: [],
- total: "",
- currentPage: 1,
- size: 10,
- },
- async getList(isScroll) {
- let { list, currentPage, size } = this.data;
- let { data } = await postApi("/maritime/notice/getFileList", {
- currentPage,
- size,
- shipId: wx.getStorageSync("shipId"),
- userId: wx.getStorageSync("userId"),
- });
- let { total, status, msg } = data;
- if (status == 0) {
- if (isScroll) {
- list = [...list, ...data.result];
- } else {
- list = data.result;
- }
- } else {
- wx.showToast({
- title: msg,
- icon: "none",
- });
- if (!isScroll) {
- list = [];
- }
- }
- this.setData({
- list,
- total,
- isFreshing: false,
- });
- },
- async openFile(e) {
- try {
- wx.showLoading({
- title: "正在加载...",
- });
- let { downloadUrl: url, suffixName } = e.currentTarget.dataset.item;
- wx.downloadFile({
- url,
- success: ({ tempFilePath: filePath }) => {
- wx.hideLoading();
- wx.openDocument({
- filePath,
- fileType: suffixName.toLowerCase(),
- });
- },
- });
- } catch (error) {
- wx.showToast({
- title: "系统繁忙",
- icon: "error",
- });
- wx.hideLoading();
- }
- },
- onPullDownRefresh() {
- this.setData({
- list: [],
- currentPage: 1,
- total: 0,
- });
- this.getList();
- },
- scrollList() {
- if (
- this.data.total == 0 ||
- this.data.total <= this.data.size * this.data.currentPage
- )
- return;
- this.data.currentPage += 1;
- this.getList(true);
- },
- scrollDownList() {
- this.setData({
- total: 0,
- currentPage: 1,
- list: [],
- });
- this.getList();
- },
- onLoad(options) {},
- onShow() {
- if (typeof this.getTabBar === "function" && this.getTabBar()) {
- this.getTabBar().setData({
- selected: 4,
- });
- }
- console.log("show");
- this.setData({
- list: [],
- currentPage: 1,
- size: 10,
- });
- this.getList();
- },
- });
|