detail.js 9.2 KB

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