detail.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. // pages/voyages/detail/detail.js
  2. import {
  3. postApi
  4. } from "../../../apis/api"
  5. Page({
  6. data: {
  7. id: '',
  8. tab: 4,
  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/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. this.setData({
  95. coordinates,
  96. medias,
  97. policys,
  98. voyage,
  99. waybills,
  100. currentPortId: voyage?.voyageDetails[0].portId
  101. })
  102. this.getCarLoadRecordList()
  103. this.getDischargeList()
  104. },
  105. subTimeStr(str) {
  106. if (!str || typeof str != "string") return;
  107. let index = str.indexOf(" ");
  108. return str.substring(0, index);
  109. },
  110. async getCarLoadRecordList(isScroll) {
  111. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  112. if (isScroll) {
  113. this.data.truckLoadCurrentPage += 1
  114. } else {
  115. this.data.truckLoadCurrentPage = 1
  116. }
  117. let res = await postApi("/voyage/getCarLoadRecordList", {
  118. portId: this.data.currentPortId,
  119. voyageId: this.data.id,
  120. size: this.data.pageSize,
  121. currentPage: this.data.truckLoadCurrentPage,
  122. isClient: wx.getStorageSync('isClient'),
  123. loginAccountId: wx.getStorageSync('loginAccountId')
  124. })
  125. this.setData({
  126. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  127. })
  128. if (0 == res.data.status) {
  129. if (isScroll) {
  130. let truckLoadList = [...this.data.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. } else {
  139. let truckLoadList = res.data.result
  140. for (let i of truckLoadList) {
  141. i.weighTime = this.cutTimeString(i.weighTime)
  142. }
  143. this.setData({
  144. truckLoadList,
  145. truckLoadTotal: res.data.total
  146. })
  147. }
  148. } else {
  149. // wx.showToast({
  150. // icon: 'none',
  151. // title: res.data.msg,
  152. // })
  153. }
  154. },
  155. async getDischargeList(isScroll) {
  156. if (isScroll) {
  157. this.data.shipDischargeCurrentPage += 1
  158. } else {
  159. this.data.shipDischargeCurrentPage = 1
  160. }
  161. let res = await postApi("/voyage/getDischargeList", {
  162. portId: this.data.currentPortId,
  163. voyageId: this.data.id,
  164. size: this.data.pageSize,
  165. currentPage: this.data.shipDischargeCurrentPage,
  166. isClient: wx.getStorageSync('isClient'),
  167. loginAccountId: wx.getStorageSync('loginAccountId')
  168. })
  169. this.setData({
  170. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  171. })
  172. if (0 == res.data.status) {
  173. if (isScroll) {
  174. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  175. for (let i of shipDischargeList) {
  176. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  177. }
  178. this.setData({
  179. shipDischargeList,
  180. shipDischargeTotal: res.data.total
  181. })
  182. } else {
  183. let shipDischargeList = res.data.result
  184. for (let i of shipDischargeList) {
  185. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  186. }
  187. this.setData({
  188. shipDischargeList,
  189. shipDischargeTotal: res.data.total
  190. })
  191. }
  192. } else {
  193. // wx.showToast({
  194. // icon: "none",
  195. // title: res.data.msg,
  196. // })
  197. }
  198. },
  199. previewImage(e) {
  200. let {
  201. src
  202. } = e.currentTarget.dataset
  203. wx.previewImage({
  204. current: src, // 当前显示图片的http链接
  205. urls: [src] // 需要预览的图片http链接列表
  206. })
  207. },
  208. changeInfoType(e) {
  209. let {
  210. type
  211. } = e.currentTarget.dataset
  212. this.setData({
  213. infoType: type,
  214. truckLoadCurrentPage: 1,
  215. shipDischargeCurrentPage: 1,
  216. shipDischargeList: [],
  217. truckLoadList: [],
  218. shipDischargeTotal: 0,
  219. truckLoadTotal: 0,
  220. })
  221. if (type == "ship") {
  222. this.getDischargeList()
  223. } else {
  224. this.getCarLoadRecordList()
  225. }
  226. },
  227. cutTimeString(str) {
  228. let index = str.indexOf(' ')
  229. return index == -1 ? str : str.substring(0, index)
  230. },
  231. changeBottomPage() {
  232. if (this.data.infoType == "ship") {
  233. this.getDischargeList(true)
  234. } else {
  235. this.getCarLoadRecordList(true)
  236. }
  237. },
  238. scrollShip() {
  239. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  240. this.getDischargeList(true)
  241. },
  242. scrollTruck() {
  243. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  244. this.getCarLoadRecordList(true)
  245. },
  246. changePort(e) {
  247. let currentPortId = e.target.dataset.id
  248. this.setData({
  249. currentPortId
  250. })
  251. if (this.data.infoType == "ship") {
  252. this.getDischargeList()
  253. } else {
  254. this.getCarLoadRecordList()
  255. }
  256. },
  257. onShareAppMessage() {
  258. let id = wx.getStorageSync('voyageDetailId')
  259. return {
  260. title: '真实 实时 精准',
  261. path: `/pages/sharePage/sharePage?id=${id}`
  262. }
  263. },
  264. onLoad(options) {
  265. let {
  266. id
  267. } = options
  268. wx.setStorageSync('voyageDetailId', id)
  269. this.setData({
  270. id
  271. })
  272. this.getVoyageDetail()
  273. },
  274. })