myLab.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const {
  2. postApi
  3. } = require("../../../../apis/api")
  4. // pages/voyageManage/myBills/myLab.js
  5. Page({
  6. data: {
  7. currentPortId: -1,
  8. currentPage: 1,
  9. size: 20,
  10. isFreshing: false,
  11. total: 0,
  12. labList: []
  13. },
  14. async getVoyageDetail() {
  15. let res = await postApi('voyage/detail', {
  16. voyageId: this.data.voyageId
  17. })
  18. let {
  19. voyage,
  20. } = res.data.result
  21. this.setData({
  22. ...voyage,
  23. currentPortId: voyage?.voyageDetails[0].portId
  24. })
  25. this.getLabList()
  26. },
  27. changePort(e) {
  28. let currentPortId = e.target.dataset.id
  29. this.setData({
  30. currentPortId,
  31. })
  32. this.getLabList()
  33. },
  34. scrollDownList() {
  35. this.setData({
  36. total: 0,
  37. currentPage: 1,
  38. labList: []
  39. })
  40. this.getLabList()
  41. },
  42. scrollList() {
  43. if (this.data.total == 0 || this.data.total <= this.data.size * this.data.currentPage) return
  44. this.data.currentPage += 1
  45. this.getLabList(true)
  46. },
  47. async getLabList(isScroll) {
  48. this.setData({
  49. isFreshing: true
  50. })
  51. let res = await postApi('voyage/getLabList', {
  52. voyageId: this.data.voyageId,
  53. portId: this.data.currentPortId,
  54. currentPage: this.data.currentPage,
  55. size: this.data.size
  56. })
  57. this.setData({
  58. currentPage: this.data.currentPage,
  59. isFreshing: false
  60. })
  61. if (res.data.status == 0) {
  62. console.log(res.data.result)
  63. for (let i of res.data.result) {
  64. i.billingDate = i.billingDate.substring(0, 10)
  65. }
  66. if (isScroll) {
  67. this.setData({
  68. labList: [...this.data.labList, ...res.data.result],
  69. total: res.data.total
  70. })
  71. } else {
  72. this.setData({
  73. labList: res.data.result,
  74. total: res.data.total
  75. })
  76. }
  77. } else {
  78. this.setData({
  79. labList: [],
  80. total: 0
  81. })
  82. wx.showToast({
  83. icon: "none",
  84. title: res.data.msg,
  85. })
  86. }
  87. },
  88. onLoad(options) {
  89. let {
  90. id: voyageId
  91. } = options
  92. this.setData({
  93. voyageId
  94. })
  95. this.getVoyageDetail()
  96. },
  97. })