maritime.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, msg } = data;
  19. if (status == 0) {
  20. if (isScroll) {
  21. list = [...list, ...data.result];
  22. } else {
  23. list = data.result;
  24. }
  25. } else {
  26. wx.showToast({
  27. title: msg,
  28. icon: "none",
  29. });
  30. if (!isScroll) {
  31. list = [];
  32. }
  33. }
  34. this.setData({
  35. list,
  36. total,
  37. isFreshing: false,
  38. });
  39. },
  40. async openFile(e) {
  41. try {
  42. wx.showLoading({
  43. title: "正在加载...",
  44. });
  45. let { downloadUrl: url, suffixName } = e.currentTarget.dataset.item;
  46. wx.downloadFile({
  47. url,
  48. success: ({ tempFilePath: filePath }) => {
  49. wx.hideLoading();
  50. wx.openDocument({
  51. filePath,
  52. fileType: suffixName.toLowerCase(),
  53. });
  54. },
  55. });
  56. } catch (error) {
  57. wx.showToast({
  58. title: "系统繁忙",
  59. icon: "error",
  60. });
  61. wx.hideLoading();
  62. }
  63. },
  64. onPullDownRefresh() {
  65. this.setData({
  66. list: [],
  67. currentPage: 1,
  68. total: 0,
  69. });
  70. this.getList();
  71. },
  72. scrollList() {
  73. if (
  74. this.data.total == 0 ||
  75. this.data.total <= this.data.size * this.data.currentPage
  76. )
  77. return;
  78. this.data.currentPage += 1;
  79. this.getList(true);
  80. },
  81. scrollDownList() {
  82. this.setData({
  83. total: 0,
  84. currentPage: 1,
  85. list: [],
  86. });
  87. this.getList();
  88. },
  89. onLoad(options) {},
  90. onShow() {
  91. if (typeof this.getTabBar === "function" && this.getTabBar()) {
  92. this.getTabBar().setData({
  93. selected: 4,
  94. });
  95. }
  96. console.log("show");
  97. this.setData({
  98. list: [],
  99. currentPage: 1,
  100. size: 10,
  101. });
  102. this.getList();
  103. },
  104. });