maritime.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // pages/maritime/maritime.js
  2. import { postApi } from "../../apis/api";
  3. Page({
  4. data: {
  5. list: [],
  6. total: "",
  7. currentPage: 1,
  8. size: 10,
  9. },
  10. async getList(isScroll) {
  11. let { list, currentPage, size } = this.data;
  12. let { data } = await postApi("/maritime/notice/getFileList", {
  13. currentPage,
  14. size,
  15. shipId: wx.getStorageSync("shipId"),
  16. userId: wx.getStorageSync("userId"),
  17. });
  18. let { total, status } = data;
  19. if (status == 0) {
  20. if (isScroll) {
  21. list = [...list, ...data.result];
  22. } else {
  23. list = data.result;
  24. }
  25. } else {
  26. if (!isScroll) {
  27. list = [];
  28. }
  29. }
  30. this.setData({
  31. list,
  32. total,
  33. });
  34. },
  35. async openFile(e) {
  36. try {
  37. wx.showLoading({
  38. title: "正在加载...",
  39. });
  40. let { downloadUrl: url, suffixName } = e.currentTarget.dataset.item;
  41. wx.downloadFile({
  42. url,
  43. success: ({ tempFilePath: filePath }) => {
  44. wx.hideLoading();
  45. wx.openDocument({
  46. filePath,
  47. fileType: suffixName.toLowerCase(),
  48. });
  49. },
  50. });
  51. } catch (error) {
  52. wx.showToast({
  53. title: "系统繁忙",
  54. icon: "error",
  55. });
  56. wx.hideLoading();
  57. }
  58. },
  59. onPullDownRefresh() {
  60. this.setData({
  61. list: [],
  62. currentPage: 1,
  63. total: 0,
  64. });
  65. this.getList();
  66. },
  67. scrollList() {
  68. if (
  69. this.data.total == 0 ||
  70. this.data.total <= this.data.size * this.data.currentPage
  71. )
  72. return;
  73. this.data.currentPage += 1;
  74. this.getList(true);
  75. },
  76. scrollDownList() {
  77. this.setData({
  78. total: 0,
  79. currentPage: 1,
  80. list: [],
  81. });
  82. this.getList();
  83. },
  84. onLoad(options) {},
  85. onShow() {
  86. console.log("show");
  87. this.setData({
  88. list: [],
  89. currentPage: 1,
  90. size: 10,
  91. });
  92. this.getList();
  93. },
  94. });