voyages.js 2.8 KB

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