detail.js 12 KB

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