voyages.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. },
  21. methods: {
  22. async getVoyageList(isScroll) {
  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. } else {
  61. this.setData({
  62. cargoOwnerId
  63. })
  64. }
  65. let res = await postApi('/voyage/list', {
  66. cargoOwnerId: wx.getStorageSync('cargoOwnerId'),
  67. term: this.data.term,
  68. status: this.data.status,
  69. currentPage: this.data.currentPage,
  70. size: this.data.size
  71. })
  72. this.setData({
  73. currentPage: this.data.currentPage
  74. })
  75. if (res.data.status == 0) {
  76. if (isScroll) {
  77. this.setData({
  78. list: [...this.data.list, ...res.data.result],
  79. total: res.data.total
  80. })
  81. } else {
  82. this.setData({
  83. list: res.data.result,
  84. total: res.data.total
  85. })
  86. }
  87. } else {
  88. wx.showToast({
  89. icon: "none",
  90. title: res.data.msg,
  91. })
  92. }
  93. },
  94. changeStatus(e) {
  95. let {
  96. status
  97. } = e.currentTarget.dataset
  98. this.setData({
  99. status,
  100. currentPage: 1,
  101. size: 20,
  102. total: 0
  103. })
  104. this.getVoyageList()
  105. },
  106. goToDetail(e) {
  107. let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
  108. if (!cargoOwnerId) {
  109. wx.showToast({
  110. icon: "none",
  111. title: '为了保证数据安全,请注册或登录',
  112. })
  113. return
  114. }
  115. let {
  116. id
  117. } = e.currentTarget.dataset
  118. wx.navigateTo({
  119. url: `/pages/voyages/detail/detail?id=${id}`,
  120. })
  121. },
  122. scrollList() {
  123. if (this.data.total == 0 || this.data.total <= this.data.size * this.data.currentPage) return
  124. this.data.currentPage += 1
  125. this.getVoyageList(true)
  126. }
  127. }
  128. })