voyages.js 2.7 KB

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