myLab.js 2.8 KB

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