voyages.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. cargoOwnerId: 0,
  20. isFreshing: false
  21. },
  22. methods: {
  23. async getVoyageList(isScroll) {
  24. let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
  25. if (!cargoOwnerId) {
  26. this.setData({
  27. list: [{
  28. shipName: '体验船舶#1',
  29. loadPort: '南京',
  30. dischargeProt: "小池",
  31. cargo: '石油焦',
  32. tons: '10000',
  33. }, {
  34. shipName: '体验船舶#2',
  35. loadPort: '小池',
  36. dischargeProt: "武汉",
  37. cargo: '豆粕',
  38. tons: '15000',
  39. }, {
  40. shipName: '体验船舶#3',
  41. loadPort: '北仑港',
  42. dischargeProt: "小池",
  43. cargo: '煤炭',
  44. tons: '25000',
  45. }, {
  46. shipName: '体验船舶#4',
  47. loadPort: '张家港',
  48. dischargeProt: "汉口",
  49. cargo: '玉米',
  50. tons: '15000',
  51. }, {
  52. shipName: '体验船舶#5',
  53. loadPort: '武汉',
  54. dischargeProt: "小池",
  55. cargo: '大豆',
  56. tons: '3000',
  57. }],
  58. total: 1
  59. })
  60. return
  61. } else {
  62. this.setData({
  63. cargoOwnerId,
  64. list: []
  65. })
  66. }
  67. this.setData({
  68. isFreshing: true
  69. })
  70. let res = await postApi('/voyage/list', {
  71. cargoOwnerId: wx.getStorageSync('cargoOwnerId'),
  72. term: this.data.term,
  73. status: this.data.status,
  74. currentPage: this.data.currentPage,
  75. size: this.data.size
  76. })
  77. this.setData({
  78. currentPage: this.data.currentPage,
  79. isFreshing: false
  80. })
  81. if (res.data.status == 0) {
  82. if (isScroll) {
  83. this.setData({
  84. list: [...this.data.list, ...res.data.result],
  85. total: res.data.total
  86. })
  87. } else {
  88. this.setData({
  89. list: res.data.result,
  90. total: res.data.total
  91. })
  92. }
  93. } else {
  94. wx.showToast({
  95. icon: "none",
  96. title: res.data.msg,
  97. })
  98. }
  99. },
  100. changeStatus(e) {
  101. let {
  102. status
  103. } = e.currentTarget.dataset
  104. this.setData({
  105. status,
  106. currentPage: 1,
  107. size: 20,
  108. total: 0
  109. })
  110. this.getVoyageList()
  111. },
  112. goToDetail(e) {
  113. let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
  114. if (!cargoOwnerId) {
  115. wx.showToast({
  116. icon: "none",
  117. title: '为了保证数据安全,请注册或登录',
  118. })
  119. return
  120. }
  121. let {
  122. id
  123. } = e.currentTarget.dataset
  124. wx.navigateTo({
  125. url: `/pages/voyages/detail/detail?id=${id}`,
  126. })
  127. },
  128. scrollList() {
  129. if (this.data.total == 0 || this.data.total <= this.data.size * this.data.currentPage) return
  130. this.data.currentPage += 1
  131. this.getVoyageList(true)
  132. },
  133. scrollDownList() {
  134. this.setData({
  135. total: 0,
  136. currentPage: 1,
  137. list: []
  138. })
  139. this.getVoyageList()
  140. }
  141. }
  142. })