voyages.js 3.6 KB

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