detail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. // pages/voyages/detail/detail.js
  2. import {
  3. postApi
  4. } from "../../../apis/api"
  5. import {
  6. uploadImage
  7. } from "../../../utils/uploadImage"
  8. Page({
  9. data: {
  10. id: '',
  11. tab: 1,
  12. shipDischargeCurrentPage: 1,
  13. truckLoadCurrentPage: 1,
  14. coordinates: [],
  15. medias: [],
  16. policys: [],
  17. voyage: {},
  18. waybills: [],
  19. infoType: 'ship',
  20. shipDischargeList: [],
  21. truckLoadList: [],
  22. shipDischargeTotal: 0,
  23. truckLoadTotal: 0,
  24. polyline: [{
  25. points: [],
  26. width: 2,
  27. dottedLine: true,
  28. color: "#eb2f06"
  29. }],
  30. markers: [],
  31. points: [],
  32. pageSize: 20,
  33. latitude: 31.891992,
  34. longitude: 120.551369,
  35. currentPortId: 0,
  36. dischargeModal: false,
  37. currentDischargePortId: '',
  38. currentDischargePort: '',
  39. tab2disabled: false,
  40. currentDischargeIndex: 0
  41. },
  42. changeTab(e) {
  43. let {
  44. tab
  45. } = e.currentTarget.dataset
  46. this.setData({
  47. tab
  48. })
  49. },
  50. async getVoyageDetail() {
  51. let res = await postApi("/voyage/detail", {
  52. voyageId: this.data.id,
  53. loginAccountId: wx.getStorageSync('loginAccountId'),
  54. })
  55. let {
  56. coordinates,
  57. medias,
  58. policys,
  59. voyage,
  60. waybills
  61. } = res.data.result
  62. if (coordinates.length) {
  63. let points = []
  64. for (let i of coordinates) {
  65. points.push({
  66. latitude: i.latitude,
  67. longitude: i.longitude
  68. })
  69. }
  70. let {
  71. latitude,
  72. longitude
  73. } = points[points.length - 1]
  74. this.data.latitude = latitude
  75. this.data.longitude = longitude
  76. this.data.polyline[0].points = points
  77. let id = 1
  78. for (let i of points) {
  79. this.data.markers.push({
  80. id: id + 1,
  81. latitude: i.latitude,
  82. longitude: i.longitude,
  83. iconPath: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
  84. height: 20,
  85. width: 20
  86. })
  87. }
  88. this.setData({
  89. polyline: this.data.polyline,
  90. markers: this.data.markers,
  91. // latitude: this.data.latitude,
  92. // longitude: this.data.lo fngitude,
  93. points
  94. })
  95. }
  96. voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime)
  97. voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime)
  98. voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime)
  99. voyage.setSailTime = this.subTimeStr(voyage.setSailTime)
  100. voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime)
  101. let dischargePortIds = voyage.dischargePortIds.split(',')
  102. let dischargePorts = voyage.dischargePorts.split(',')
  103. let discLength = dischargePortIds.length
  104. for (let item of voyage.voyageDetails) {
  105. item.setSailTime = this.subTimeStr(item.setSailTime)
  106. item.expectedArrivalTime = this.subTimeStr(item.expectedArrivalTime)
  107. item.actualArrivalTime = this.subTimeStr(item.actualArrivalTime)
  108. item.dischargeStartTime = this.subTimeStr(item.dischargeStartTime)
  109. item.dischargeEndTime = this.subTimeStr(item.dischargeEndTime)
  110. }
  111. this.setData({
  112. coordinates,
  113. medias,
  114. policys,
  115. ...voyage,
  116. waybills,
  117. currentPortId: voyage?.voyageDetails[0].portId,
  118. dischargePortIds,
  119. dischargePorts,
  120. discLength
  121. })
  122. this.getCarLoadRecordList()
  123. this.getDischargeList()
  124. },
  125. subTimeStr(str) {
  126. if (!str || typeof str != "string") return;
  127. let index = str.indexOf(" ");
  128. return str.substring(0, index);
  129. },
  130. async getCarLoadRecordList(isScroll) {
  131. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  132. if (isScroll) {
  133. this.data.truckLoadCurrentPage += 1
  134. } else {
  135. this.data.truckLoadCurrentPage = 1
  136. }
  137. let res = await postApi("/voyage/getCarLoadRecordList", {
  138. portId: this.data.currentPortId,
  139. voyageId: this.data.id,
  140. size: this.data.pageSize,
  141. currentPage: this.data.truckLoadCurrentPage,
  142. loginAccountId: wx.getStorageSync('loginAccountId')
  143. })
  144. this.setData({
  145. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  146. })
  147. if (0 == res.data.status) {
  148. if (isScroll) {
  149. let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
  150. for (let i of truckLoadList) {
  151. i.weighTime = this.cutTimeString(i.weighTime)
  152. }
  153. this.setData({
  154. truckLoadList,
  155. truckLoadTotal: res.data.total
  156. })
  157. } else {
  158. let truckLoadList = res.data.result
  159. for (let i of truckLoadList) {
  160. i.weighTime = this.cutTimeString(i.weighTime)
  161. }
  162. this.setData({
  163. truckLoadList,
  164. truckLoadTotal: res.data.total
  165. })
  166. }
  167. } else {
  168. // wx.showToast({
  169. // icon: 'none',
  170. // title: res.data.msg,
  171. // })
  172. }
  173. },
  174. async getDischargeList(isScroll) {
  175. if (isScroll) {
  176. this.data.shipDischargeCurrentPage += 1
  177. } else {
  178. this.data.shipDischargeCurrentPage = 1
  179. }
  180. let res = await postApi("/voyage/getDischargeList", {
  181. portId: this.data.currentPortId,
  182. voyageId: this.data.id,
  183. size: this.data.pageSize,
  184. currentPage: this.data.shipDischargeCurrentPage,
  185. loginAccountId: wx.getStorageSync('loginAccountId')
  186. })
  187. this.setData({
  188. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  189. })
  190. if (0 == res.data.status) {
  191. if (isScroll) {
  192. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  193. for (let i of shipDischargeList) {
  194. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  195. }
  196. this.setData({
  197. shipDischargeList,
  198. shipDischargeTotal: res.data.total
  199. })
  200. } else {
  201. let shipDischargeList = res.data.result
  202. for (let i of shipDischargeList) {
  203. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  204. }
  205. this.setData({
  206. shipDischargeList,
  207. shipDischargeTotal: res.data.total
  208. })
  209. }
  210. } else {
  211. // wx.showToast({
  212. // icon: "none",
  213. // title: res.data.msg,
  214. // })
  215. }
  216. },
  217. previewImage(e) {
  218. let {
  219. src
  220. } = e.currentTarget.dataset
  221. wx.previewImage({
  222. current: src, // 当前显示图片的http链接
  223. urls: [src] // 需要预览的图片http链接列表
  224. })
  225. },
  226. changeInfoType(e) {
  227. let {
  228. type
  229. } = e.currentTarget.dataset
  230. this.setData({
  231. infoType: type,
  232. truckLoadCurrentPage: 1,
  233. shipDischargeCurrentPage: 1,
  234. shipDischargeList: [],
  235. truckLoadList: [],
  236. shipDischargeTotal: 0,
  237. truckLoadTotal: 0,
  238. })
  239. if (type == "ship") {
  240. this.getDischargeList()
  241. } else {
  242. this.getCarLoadRecordList()
  243. }
  244. },
  245. cutTimeString(str) {
  246. let index = str.indexOf(' ')
  247. return index == -1 ? str : str.substring(0, index)
  248. },
  249. changeBottomPage() {
  250. if (this.data.infoType == "ship") {
  251. this.getDischargeList(true)
  252. } else {
  253. this.getCarLoadRecordList(true)
  254. }
  255. },
  256. scrollShip() {
  257. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  258. this.getDischargeList(true)
  259. },
  260. scrollTruck() {
  261. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  262. this.getCarLoadRecordList(true)
  263. },
  264. changePort(e) {
  265. let currentPortId = e.target.dataset.id
  266. this.setData({
  267. currentPortId,
  268. shipDischargeList: [],
  269. truckLoadList: [],
  270. })
  271. if (this.data.infoType == "ship") {
  272. this.getDischargeList()
  273. } else {
  274. this.getCarLoadRecordList()
  275. }
  276. },
  277. showAddDischargePortModal() {
  278. this.setData({
  279. dischargeModal: true
  280. })
  281. },
  282. onShareAppMessage() {
  283. let id = wx.getStorageSync('voyageDetailId')
  284. return {
  285. title: '真实 实时 精准',
  286. path: `/pages/sharePage/sharePage?id=${id}`
  287. }
  288. },
  289. doNothing() {
  290. },
  291. cancelAddDischargePort() {
  292. this.setData({
  293. currentDischargePortId: '',
  294. currentDischargePort: '',
  295. dischargeModal: false
  296. })
  297. },
  298. selectDischargePort(e) {
  299. this.setData({
  300. currentDischargePortId: e.detail.value,
  301. currentDischargePort: e.detail.label
  302. })
  303. },
  304. async addDischargePort() {
  305. let {
  306. currentDischargePortId,
  307. currentDischargePort
  308. } = this.data
  309. if (!currentDischargePortId || !currentDischargePort) {
  310. wx.showToast({
  311. title: '请选择港口',
  312. icon: "error"
  313. })
  314. return
  315. }
  316. let res = await postApi("/voyage/backstage/addNewPort", {
  317. loginAccountId: wx.getStorageSync('loginAccountId'),
  318. voyageId: this.data.id,
  319. portId: this.data.currentDischargePortId
  320. })
  321. this.cancelAddDischargePort()
  322. },
  323. bindDischargePortChange(e) {
  324. let {
  325. index,
  326. param
  327. } = e.currentTarget.dataset
  328. this.data.voyageDetails[index][param] = e.detail.value
  329. this.setData({
  330. voyageDetails: this.data.voyageDetails
  331. })
  332. },
  333. changeDischargeTab(e) {
  334. let {
  335. index: currentDischargeIndex
  336. } = e.currentTarget.dataset
  337. this.setData({
  338. currentDischargeIndex
  339. })
  340. },
  341. async updateVoyage() {
  342. for (let i of this.data.voyageDetails) {
  343. Object.keys(i).forEach(function (key) {
  344. console.log(i[key])
  345. if ((typeof i[key]) == 'string') {
  346. i[key] = i[key].replaceAll('-', '/')
  347. if (i[key].length == 10) i[key] = i[key] + " 00:00:00"
  348. }
  349. })
  350. }
  351. if (this.data.arrivalLoadPortTime && this.data.arrivalLoadPortTime.length == 10) this.data.arrivalLoadPortTime = this.data.arrivalLoadPortTime + " 00:00:00"
  352. if (this.data.actualLoadTons && this.data.actualLoadTons.length == 10) this.data.actualLoadTons = this.data.actualLoadTons + " 00:00:00"
  353. if (this.data.actualLoadPieces && this.data.actualLoadPieces.length == 10) this.data.actualLoadPieces = this.data.actualLoadPieces + " 00:00:00"
  354. if (this.data.loadStartTime && this.data.loadStartTime.length == 10) this.data.loadStartTime = this.data.loadStartTime + " 00:00:00"
  355. if (this.data.loadEndTime && this.data.loadEndTime.length == 10) this.data.loadEndTime = this.data.loadEndTime + " 00:00:00"
  356. let res = await postApi("/voyage/backstage/update", {
  357. ...this.data,
  358. loginAccountId: wx.getStorageSync('loginAccountId')
  359. })
  360. console.log(res)
  361. },
  362. async uploadBill(e) {
  363. let {
  364. type
  365. } = e.currentTarget.dataset
  366. let postData = {
  367. type,
  368. voyageId: this.data.id
  369. }
  370. let res = await uploadImage("/voyage/uploadVoyageWayBill", postData)
  371. this.getVoyageDetail()
  372. console.log(res)
  373. },
  374. async completeVoyage() {
  375. wx.showModal({
  376. title: "确认完成航次?",
  377. success: async e => {
  378. if (e.confirm) {
  379. let res = await postApi("/voyage/backstage/finish", {
  380. loginAccountId: wx.getStorageSync('loginAccountId'),
  381. voyageId: this.data.id
  382. })
  383. if (res.data.status == 0) {
  384. wx.showToast({
  385. title: '成功!',
  386. })
  387. this.getVoyageDetail()
  388. }
  389. }
  390. }
  391. })
  392. },
  393. async cancelVoyage() {
  394. wx.showModal({
  395. title: "确认取消航次?",
  396. success: async e => {
  397. if (e.confirm) {
  398. let res = await postApi("/voyage/backstage/cancel", {
  399. loginAccountId: wx.getStorageSync('loginAccountId'),
  400. id: this.data.id
  401. })
  402. if (res.data.status == 0) {
  403. wx.showToast({
  404. title: '取消成功!',
  405. })
  406. wx.switchTab({
  407. url: '/pages/voyageManage/voyageManage',
  408. })
  409. }
  410. }
  411. }
  412. })
  413. },
  414. onLoad(options) {
  415. let {
  416. id
  417. } = options
  418. wx.setStorageSync('voyageDetailId', id)
  419. this.setData({
  420. id
  421. })
  422. this.getVoyageDetail()
  423. },
  424. })