voyages.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // components/voyages/Voyages.js
  2. import {
  3. postApi
  4. } from "../../apis/api"
  5. Component({
  6. properties: {
  7. height: {
  8. type: Number,
  9. value: 620,
  10. }
  11. },
  12. data: {
  13. term: '',
  14. status: 1,
  15. currentPage: 1,
  16. size: 20,
  17. list: [],
  18. total: 0,
  19. bottomText: '点击或滑动加载更多...'
  20. },
  21. methods: {
  22. async getVoyageList() {
  23. let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
  24. if (!cargoOwnerId) {
  25. this.setData({
  26. list: [{
  27. shipName: '体验船舶#1',
  28. loadPort: '南京',
  29. dischargeProt: "小池",
  30. cargo: '石油焦',
  31. tons: '10000',
  32. }, {
  33. shipName: '体验船舶#2',
  34. loadPort: '小池',
  35. dischargeProt: "武汉",
  36. cargo: '豆粕',
  37. tons: '15000',
  38. }, {
  39. shipName: '体验船舶#3',
  40. loadPort: '北仑港',
  41. dischargeProt: "小池",
  42. cargo: '煤炭',
  43. tons: '25000',
  44. }, {
  45. shipName: '体验船舶#4',
  46. loadPort: '张家港',
  47. dischargeProt: "汉口",
  48. cargo: '玉米',
  49. tons: '15000',
  50. }, {
  51. shipName: '体验船舶#5',
  52. loadPort: '武汉',
  53. dischargeProt: "小池",
  54. cargo: '大豆',
  55. tons: '3000',
  56. }],
  57. total: 1
  58. })
  59. return
  60. }
  61. let res = await postApi('/voyage/list', {
  62. cargoOwnerId: wx.getStorageSync('cargoOwnerId'),
  63. term: this.data.term,
  64. status: this.data.status,
  65. currentPage: this.data.currentPage,
  66. size: this.data.size
  67. })
  68. if (res.data.status == 0) {
  69. this.setData({
  70. list: res.data.result,
  71. total: res.data.total
  72. })
  73. } else {
  74. this.setData({
  75. list: [],
  76. total: 0,
  77. })
  78. }
  79. },
  80. changeStatus(e) {
  81. let {
  82. status
  83. } = e.currentTarget.dataset
  84. this.setData({
  85. status,
  86. currentPage: 1,
  87. size: 20,
  88. total: 0
  89. })
  90. this.getVoyageList()
  91. },
  92. goToDetail(e) {
  93. let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
  94. if (!cargoOwnerId) {
  95. wx.showToast({
  96. icon: "none",
  97. title: '为了保证数据安全,请注册或登录',
  98. })
  99. return
  100. }
  101. let {
  102. id
  103. } = e.currentTarget.dataset
  104. wx.navigateTo({
  105. url: `/pages/voyages/detail/detail?id=${id}`,
  106. })
  107. },
  108. scrollList() {
  109. if (this.data.total == 0 || this.data.total < this.data.size * this.data.currentPage) return
  110. this.data.currentPage += 1
  111. this.getVoyageList()
  112. }
  113. }
  114. })