detail.js 13 KB

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