voyages.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. isClient: wx.getStorageSync('isClient'),
  81. })
  82. this.setData({
  83. currentPage: this.data.currentPage,
  84. isFreshing: false
  85. })
  86. if (res.data.status == 0) {
  87. if (isScroll) {
  88. this.setData({
  89. list: [...this.data.list, ...res.data.result],
  90. total: res.data.total
  91. })
  92. } else {
  93. this.setData({
  94. list: res.data.result,
  95. total: res.data.total
  96. })
  97. }
  98. } else {
  99. wx.showToast({
  100. icon: "none",
  101. title: res.data.msg,
  102. })
  103. }
  104. },
  105. changeStatus(e) {
  106. let {
  107. status
  108. } = e.currentTarget.dataset
  109. this.setData({
  110. status,
  111. currentPage: 1,
  112. size: 20,
  113. total: 0
  114. })
  115. this.getVoyageList()
  116. },
  117. goToDetail(e) {
  118. let loginAccountId = wx.getStorageSync('loginAccountId')
  119. if (!loginAccountId) {
  120. wx.showToast({
  121. icon: "none",
  122. title: '为了保证数据安全,请注册或登录',
  123. })
  124. return
  125. }
  126. let rolePermission = wx.getStorageSync('rolePermission')
  127. if (rolePermission.indexOf('VOYAGEDETAIL') == -1) {
  128. wx.showToast({
  129. icon: "none",
  130. title: '暂无权限,请联系管理员',
  131. })
  132. return
  133. }
  134. let {
  135. id
  136. } = e.currentTarget.dataset
  137. wx.navigateTo({
  138. url: `/pages/voyages/detail/detail?id=${id}`,
  139. })
  140. },
  141. scrollList() {
  142. if (this.data.total == 0 || this.data.total <= this.data.size * this.data.currentPage) return
  143. this.data.currentPage += 1
  144. this.getVoyageList(true)
  145. },
  146. scrollDownList() {
  147. this.setData({
  148. total: 0,
  149. currentPage: 1,
  150. list: []
  151. })
  152. this.getVoyageList()
  153. }
  154. }
  155. })