detail.js 7.7 KB

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