detail.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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/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. let dischargePortIds = voyage.dischargePortIds.split(',')
  95. let dischargePorts = voyage.dischargePorts.split(',')
  96. let discLength = dischargePortIds.length
  97. for (let item of voyage.voyageDetails) {
  98. item.setSailTime = this.subTimeStr(item.setSailTime)
  99. item.expectedArrivalTime = this.subTimeStr(item.expectedArrivalTime)
  100. item.actualArrivalTime = this.subTimeStr(item.actualArrivalTime)
  101. item.dischargeStartTime = this.subTimeStr(item.dischargeStartTime)
  102. item.dischargeEndTime = this.subTimeStr(item.dischargeEndTime)
  103. }
  104. this.setData({
  105. coordinates,
  106. medias,
  107. policys,
  108. voyage,
  109. waybills,
  110. currentPortId: voyage?.voyageDetails[0].portId,
  111. dischargePortIds,
  112. dischargePorts,
  113. discLength
  114. })
  115. this.getCarLoadRecordList()
  116. this.getDischargeList()
  117. },
  118. subTimeStr(str) {
  119. if (!str || typeof str != "string") return;
  120. let index = str.indexOf(" ");
  121. return str.substring(0, index);
  122. },
  123. async getCarLoadRecordList(isScroll) {
  124. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  125. if (isScroll) {
  126. this.data.truckLoadCurrentPage += 1
  127. } else {
  128. this.data.truckLoadCurrentPage = 1
  129. }
  130. let res = await postApi("/voyage/getCarLoadRecordList", {
  131. portId: this.data.currentPortId,
  132. voyageId: this.data.id,
  133. size: this.data.pageSize,
  134. currentPage: this.data.truckLoadCurrentPage,
  135. isClient: wx.getStorageSync('isClient'),
  136. loginAccountId: wx.getStorageSync('loginAccountId')
  137. })
  138. this.setData({
  139. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  140. })
  141. if (0 == res.data.status) {
  142. if (isScroll) {
  143. let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
  144. for (let i of truckLoadList) {
  145. i.weighTime = this.cutTimeString(i.weighTime)
  146. }
  147. this.setData({
  148. truckLoadList,
  149. truckLoadTotal: res.data.total
  150. })
  151. } else {
  152. let truckLoadList = res.data.result
  153. for (let i of truckLoadList) {
  154. i.weighTime = this.cutTimeString(i.weighTime)
  155. }
  156. this.setData({
  157. truckLoadList,
  158. truckLoadTotal: res.data.total
  159. })
  160. }
  161. } else {
  162. // wx.showToast({
  163. // icon: 'none',
  164. // title: res.data.msg,
  165. // })
  166. }
  167. },
  168. async getDischargeList(isScroll) {
  169. if (isScroll) {
  170. this.data.shipDischargeCurrentPage += 1
  171. } else {
  172. this.data.shipDischargeCurrentPage = 1
  173. }
  174. let res = await postApi("/voyage/getDischargeList", {
  175. portId: this.data.currentPortId,
  176. voyageId: this.data.id,
  177. size: this.data.pageSize,
  178. currentPage: this.data.shipDischargeCurrentPage,
  179. isClient: wx.getStorageSync('isClient'),
  180. loginAccountId: wx.getStorageSync('loginAccountId')
  181. })
  182. this.setData({
  183. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  184. })
  185. if (0 == res.data.status) {
  186. if (isScroll) {
  187. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  188. for (let i of shipDischargeList) {
  189. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  190. }
  191. this.setData({
  192. shipDischargeList,
  193. shipDischargeTotal: res.data.total
  194. })
  195. } else {
  196. let shipDischargeList = res.data.result
  197. for (let i of shipDischargeList) {
  198. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  199. }
  200. this.setData({
  201. shipDischargeList,
  202. shipDischargeTotal: res.data.total
  203. })
  204. }
  205. } else {
  206. // wx.showToast({
  207. // icon: "none",
  208. // title: res.data.msg,
  209. // })
  210. }
  211. },
  212. previewImage(e) {
  213. let {
  214. src
  215. } = e.currentTarget.dataset
  216. wx.previewImage({
  217. current: src, // 当前显示图片的http链接
  218. urls: [src] // 需要预览的图片http链接列表
  219. })
  220. },
  221. changeInfoType(e) {
  222. let {
  223. type
  224. } = e.currentTarget.dataset
  225. this.setData({
  226. infoType: type,
  227. truckLoadCurrentPage: 1,
  228. shipDischargeCurrentPage: 1,
  229. shipDischargeList: [],
  230. truckLoadList: [],
  231. shipDischargeTotal: 0,
  232. truckLoadTotal: 0,
  233. })
  234. if (type == "ship") {
  235. this.getDischargeList()
  236. } else {
  237. this.getCarLoadRecordList()
  238. }
  239. },
  240. cutTimeString(str) {
  241. let index = str.indexOf(' ')
  242. return index == -1 ? str : str.substring(0, index)
  243. },
  244. changeBottomPage() {
  245. if (this.data.infoType == "ship") {
  246. this.getDischargeList(true)
  247. } else {
  248. this.getCarLoadRecordList(true)
  249. }
  250. },
  251. scrollShip() {
  252. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  253. this.getDischargeList(true)
  254. },
  255. scrollTruck() {
  256. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  257. this.getCarLoadRecordList(true)
  258. },
  259. changePort(e) {
  260. let currentPortId = e.target.dataset.id
  261. this.setData({
  262. currentPortId,
  263. shipDischargeList: [],
  264. truckLoadList: [],
  265. })
  266. if (this.data.infoType == "ship") {
  267. this.getDischargeList()
  268. } else {
  269. this.getCarLoadRecordList()
  270. }
  271. },
  272. selectDiscPort(e) {
  273. this.data.dischargePortIds[e.currentTarget.dataset.index] = e.detail.value
  274. this.data.dischargePorts[e.currentTarget.dataset.index] = e.detail.label
  275. this.setData({
  276. dischargePorts: this.data.dischargePorts,
  277. dischargePortIds: this.data.dischargePortIds
  278. })
  279. },
  280. addDischargePort() {
  281. let dischargePorts = this.data.dischargePorts
  282. let dischargePortIds = this.data.dischargePortIds
  283. dischargePorts.push('')
  284. dischargePortIds.push('')
  285. this.setData({
  286. dischargePortIds,
  287. dischargePorts
  288. })
  289. },
  290. deleteDischargePort(e) {
  291. let dischargePorts = this.data.dischargePorts
  292. let dischargePortIds = this.data.dischargePortIds
  293. if (dischargePorts.length == 1) {
  294. dischargePortIds = ['']
  295. dischargePorts = ['']
  296. } else {
  297. dischargePorts.splice(e.currentTarget.dataset.index, 1)
  298. dischargePortIds.splice(e.currentTarget.dataset.index, 1)
  299. }
  300. this.setData({
  301. dischargePortIds,
  302. dischargePorts
  303. })
  304. },
  305. onShareAppMessage() {
  306. let id = wx.getStorageSync('voyageDetailId')
  307. return {
  308. title: '真实 实时 精准',
  309. path: `/pages/sharePage/sharePage?id=${id}`
  310. }
  311. },
  312. onLoad(options) {
  313. let {
  314. id
  315. } = options
  316. wx.setStorageSync('voyageDetailId', id)
  317. this.setData({
  318. id
  319. })
  320. this.getVoyageDetail()
  321. },
  322. })