myLab.js 2.5 KB

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