detail.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // pages/voyages/detail/detail.js
  2. import {
  3. postApi
  4. } from "../../../apis/api"
  5. Page({
  6. data: {
  7. id: '',
  8. tab: 1,
  9. shipDischargeCurrentPage: 1,
  10. truckLoadCurrentPage: 1,
  11. coordinates: [],
  12. medias: [],
  13. policys: [],
  14. voyage: [],
  15. waybills: [],
  16. infoType: 'ship',
  17. shipDischargeList: [],
  18. truckLoadList: [],
  19. shipDischargeTotal: 0,
  20. truckLoadTotal: 0,
  21. polyline: [{
  22. points: [],
  23. width: 2,
  24. dottedLine: true,
  25. color: "#eb2f06"
  26. }],
  27. markers: [],
  28. points: [],
  29. pageSize: 20,
  30. latitude: 31.891992,
  31. longitude: 120.551369,
  32. },
  33. changeTab(e) {
  34. let {
  35. tab
  36. } = e.currentTarget.dataset
  37. this.setData({
  38. tab
  39. })
  40. },
  41. async getVoyageDetail() {
  42. let res = await postApi("/voyage/detail", {
  43. voyageId: this.data.id,
  44. })
  45. let {
  46. coordinates,
  47. medias,
  48. policys,
  49. voyage,
  50. waybills
  51. } = res.data.result
  52. if (coordinates.length) {
  53. let points = []
  54. for (let i of coordinates) {
  55. points.push({
  56. latitude: i.latitude,
  57. longitude: i.longitude
  58. })
  59. }
  60. let {
  61. latitude,
  62. longitude
  63. } = points[points.length - 1]
  64. this.data.latitude = latitude
  65. this.data.longitude = longitude
  66. this.data.polyline[0].points = points
  67. let id = 1
  68. for (let i of points) {
  69. this.data.markers.push({
  70. id: id + 1,
  71. latitude: i.latitude,
  72. longitude: i.longitude,
  73. iconPath: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
  74. height: 20,
  75. width: 20
  76. })
  77. }
  78. this.setData({
  79. polyline: this.data.polyline,
  80. markers: this.data.markers,
  81. // latitude: this.data.latitude,
  82. // longitude: this.data.lo fngitude,
  83. points
  84. })
  85. }
  86. voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime)
  87. voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime)
  88. voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime)
  89. voyage.setSailTime = this.subTimeStr(voyage.setSailTime)
  90. voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime)
  91. this.setData({
  92. coordinates,
  93. medias,
  94. policys,
  95. voyage,
  96. waybills,
  97. })
  98. },
  99. subTimeStr(str) {
  100. if (!str || typeof str != "string") return;
  101. let index = str.indexOf(" ");
  102. return str.substring(0, index);
  103. },
  104. async getCarLoadRecordList(isScroll) {
  105. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  106. if (isScroll) {
  107. this.data.truckLoadCurrentPage += 1
  108. } else {
  109. this.data.truckLoadCurrentPage = 1
  110. }
  111. let res = await postApi("/voyage/getCarLoadRecordList", {
  112. voyageId: this.data.id,
  113. size: this.data.pageSize,
  114. currentPage: this.data.truckLoadCurrentPage
  115. })
  116. this.setData({
  117. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  118. })
  119. if (0 == res.data.status) {
  120. if (isScroll) {
  121. let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
  122. for (let i of truckLoadList) {
  123. i.weighTime = this.cutTimeString(i.weighTime)
  124. }
  125. this.setData({
  126. truckLoadList,
  127. truckLoadTotal: res.data.total
  128. })
  129. } else {
  130. let truckLoadList = res.data.result
  131. for (let i of truckLoadList) {
  132. i.weighTime = this.cutTimeString(i.weighTime)
  133. }
  134. this.setData({
  135. truckLoadList,
  136. truckLoadTotal: res.data.total
  137. })
  138. }
  139. } else {
  140. // wx.showToast({
  141. // icon: 'none',
  142. // title: res.data.msg,
  143. // })
  144. }
  145. },
  146. async getDischargeList(isScroll) {
  147. if (isScroll) {
  148. this.data.shipDischargeCurrentPage += 1
  149. } else {
  150. this.data.shipDischargeCurrentPage = 1
  151. }
  152. let res = await postApi("/voyage/getDischargeList", {
  153. voyageId: this.data.id,
  154. size: this.data.pageSize,
  155. currentPage: this.data.shipDischargeCurrentPage
  156. })
  157. this.setData({
  158. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  159. })
  160. if (0 == res.data.status) {
  161. if (isScroll) {
  162. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  163. for (let i of shipDischargeList) {
  164. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  165. }
  166. this.setData({
  167. shipDischargeList,
  168. shipDischargeTotal: res.data.total
  169. })
  170. } else {
  171. let shipDischargeList = res.data.result
  172. for (let i of shipDischargeList) {
  173. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  174. }
  175. this.setData({
  176. shipDischargeList,
  177. shipDischargeTotal: res.data.total
  178. })
  179. }
  180. } else {
  181. // wx.showToast({
  182. // icon: "none",
  183. // title: res.data.msg,
  184. // })
  185. }
  186. },
  187. previewImage(e) {
  188. let {
  189. src
  190. } = e.currentTarget.dataset
  191. wx.previewImage({
  192. current: src, // 当前显示图片的http链接
  193. urls: [src] // 需要预览的图片http链接列表
  194. })
  195. },
  196. changeInfoType(e) {
  197. let {
  198. type
  199. } = e.currentTarget.dataset
  200. this.setData({
  201. infoType: type,
  202. truckLoadCurrentPage: 1,
  203. shipDischargeCurrentPage: 1,
  204. shipDischargeList: [],
  205. truckLoadList: [],
  206. shipDischargeTotal: 0,
  207. truckLoadTotal: 0,
  208. })
  209. if (type == "ship") {
  210. this.getDischargeList()
  211. } else {
  212. this.getCarLoadRecordList()
  213. }
  214. },
  215. cutTimeString(str) {
  216. let index = str.indexOf(' ')
  217. return index == -1 ? str : str.substring(0, index)
  218. },
  219. changeBottomPage() {
  220. if (this.data.infoType == "ship") {
  221. this.getDischargeList(true)
  222. } else {
  223. this.getCarLoadRecordList(true)
  224. }
  225. },
  226. scrollShip() {
  227. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  228. this.getDischargeList(true)
  229. },
  230. scrollTruck() {
  231. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  232. this.getCarLoadRecordList(true)
  233. },
  234. onShareAppMessage() {
  235. let id = wx.getStorageSync('voyageDetailId')
  236. return {
  237. title: '真实 实时 精准',
  238. path: `/pages/sharePage/sharePage?id=${id}`
  239. }
  240. },
  241. onLoad(options) {
  242. let {
  243. id
  244. } = options
  245. wx.setStorageSync('voyageDetailId', id)
  246. this.setData({
  247. id
  248. })
  249. this.getVoyageDetail()
  250. this.getCarLoadRecordList()
  251. this.getDischargeList()
  252. },
  253. })