detail.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // pages/voyages/detail/detail.js
  2. import {
  3. postApi
  4. } from "../../../apis/api"
  5. Page({
  6. data: {
  7. id: '',
  8. tab: 1,
  9. recordCurrentPage: 1,
  10. dischargeCurrentPage: 1,
  11. coordinates: [],
  12. medias: [],
  13. policys: [],
  14. voyage: [],
  15. waybills: [],
  16. infoType: 'ship',
  17. shipDischargeList: [],
  18. truckLoadList: [],
  19. polyline: {}
  20. },
  21. changeTab(e) {
  22. let {
  23. tab
  24. } = e.currentTarget.dataset
  25. this.setData({
  26. tab
  27. })
  28. },
  29. async getVoyageDetail() {
  30. let res = await postApi("/voyage/detail", {
  31. voyageId: this.data.id,
  32. })
  33. let {
  34. coordinates,
  35. medias,
  36. policys,
  37. voyage,
  38. waybills
  39. } = res.data.result
  40. let points = []
  41. for (let i of coordinates) {
  42. points.push({
  43. latitude: i.latitude,
  44. longitude: i.longitude
  45. })
  46. }
  47. let polyline = {
  48. points,
  49. color: "#ff454d"
  50. }
  51. this.setData({
  52. coordinates,
  53. medias,
  54. policys,
  55. voyage,
  56. waybills,
  57. polyline
  58. })
  59. },
  60. async getCarLoadRecordList(isScroll) {
  61. if (isScroll) {
  62. this.data.recordCurrentPage += 1
  63. } else {
  64. this.data.recordCurrentPage = 1
  65. }
  66. let res = await postApi("/voyage/getCarLoadRecordList", {
  67. voyageId: this.data.id,
  68. size: 50,
  69. currentPage: this.data.recordCurrentPage
  70. })
  71. if (0 == res.data.status) {
  72. if (isScroll) {
  73. let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
  74. for (let i of truckLoadList) {
  75. i.weighTime = this.cutTimeString(i.weighTime)
  76. }
  77. this.setData({
  78. truckLoadList
  79. })
  80. } else {
  81. let truckLoadList = res.data.result
  82. for (let i of truckLoadList) {
  83. i.weighTime = this.cutTimeString(i.weighTime)
  84. }
  85. this.setData({
  86. truckLoadList
  87. })
  88. }
  89. } else {
  90. this.setData({
  91. truckLoadList: []
  92. })
  93. }
  94. },
  95. async getDischargeList(isScroll) {
  96. if (isScroll) {
  97. this.data.dischargeCurrentPage += 1
  98. } else {
  99. this.data.dischargeCurrentPage = 1
  100. }
  101. let res = await postApi("/voyage/getDischargeList", {
  102. voyageId: this.data.id,
  103. size: 50,
  104. currentPage: this.data.dischargeCurrentPage
  105. })
  106. if (0 == res.data.status) {
  107. if (isScroll) {
  108. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  109. for (let i of shipDischargeList) {
  110. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  111. }
  112. this.setData({
  113. shipDischargeList
  114. })
  115. } else {
  116. let shipDischargeList = res.data.result
  117. for (let i of shipDischargeList) {
  118. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  119. }
  120. this.setData({
  121. shipDischargeList
  122. })
  123. }
  124. } else {
  125. this.setData({
  126. shipDischargeList: []
  127. })
  128. }
  129. },
  130. previewImage(e) {
  131. let {
  132. src
  133. } = e.currentTarget.dataset
  134. wx.previewImage({
  135. current: src, // 当前显示图片的http链接
  136. urls: [src] // 需要预览的图片http链接列表
  137. })
  138. },
  139. changeInfoType(e) {
  140. let {
  141. type
  142. } = e.currentTarget.dataset
  143. this.setData({
  144. infoType: type
  145. })
  146. },
  147. cutTimeString(str) {
  148. let index = str.indexOf(' ')
  149. return index == -1 ? str : str.substring(0, index)
  150. },
  151. changeBottomPage() {
  152. if (this.data.infoType == "ship") {
  153. this.getDischargeList(true)
  154. } else {
  155. this.getCarLoadRecordList(true)
  156. }
  157. },
  158. onLoad(options) {
  159. this.setData({
  160. id: options.id
  161. })
  162. this.getVoyageDetail()
  163. this.getCarLoadRecordList()
  164. this.getDischargeList()
  165. },
  166. })