detail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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. if (res.data.status == 0) {
  57. let {
  58. coordinates,
  59. medias,
  60. policys,
  61. voyage,
  62. waybills
  63. } = res.data.result
  64. if (coordinates.length) {
  65. let points = []
  66. for (let i of coordinates) {
  67. points.push({
  68. latitude: i.latitude,
  69. longitude: i.longitude
  70. })
  71. }
  72. let {
  73. latitude,
  74. longitude
  75. } = points[points.length - 1]
  76. this.data.latitude = latitude
  77. this.data.longitude = longitude
  78. this.data.polyline[0].points = points
  79. let id = 1
  80. for (let i of points) {
  81. this.data.markers.push({
  82. id: id + 1,
  83. latitude: i.latitude,
  84. longitude: i.longitude,
  85. iconPath: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
  86. height: 20,
  87. width: 20
  88. })
  89. }
  90. this.setData({
  91. polyline: this.data.polyline,
  92. markers: this.data.markers,
  93. latitude: this.data.latitude,
  94. longitude: this.data.longitude,
  95. points
  96. })
  97. }
  98. voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime)
  99. voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime)
  100. voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime)
  101. voyage.setSailTime = this.subTimeStr(voyage.setSailTime)
  102. voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime)
  103. let dischargePortIds = voyage.dischargePortIds.split(',')
  104. let dischargePorts = voyage.dischargePorts.split(',')
  105. let discLength = dischargePortIds.length
  106. for (let item of voyage.voyageDetails) {
  107. item.setSailTime = this.subTimeStr(item.setSailTime)
  108. item.expectedArrivalTime = this.subTimeStr(item.expectedArrivalTime)
  109. item.actualArrivalTime = this.subTimeStr(item.actualArrivalTime)
  110. item.dischargeStartTime = this.subTimeStr(item.dischargeStartTime)
  111. item.dischargeEndTime = this.subTimeStr(item.dischargeEndTime)
  112. }
  113. this.setData({
  114. coordinates,
  115. medias,
  116. policys,
  117. ...voyage,
  118. waybills,
  119. currentPortId: voyage?.voyageDetails[0].portId,
  120. dischargePortIds,
  121. dischargePorts,
  122. discLength
  123. })
  124. this.getCarLoadRecordList()
  125. this.getDischargeList()
  126. } else {
  127. wx.showToast({
  128. title: '获取详情失败!',
  129. icon: "error"
  130. })
  131. }
  132. },
  133. subTimeStr(str) {
  134. if (!str || typeof str != "string") return;
  135. let index = str.indexOf(" ");
  136. return str.substring(0, index);
  137. },
  138. async getCarLoadRecordList(isScroll) {
  139. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  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 currentPortId = e.target.dataset.id
  274. this.setData({
  275. currentPortId,
  276. shipDischargeList: [],
  277. truckLoadList: [],
  278. })
  279. if (this.data.infoType == "ship") {
  280. this.getDischargeList()
  281. } else {
  282. this.getCarLoadRecordList()
  283. }
  284. },
  285. showAddDischargePortModal() {
  286. this.setData({
  287. dischargeModal: true
  288. })
  289. },
  290. onShareAppMessage() {
  291. let id = wx.getStorageSync('voyageDetailId')
  292. return {
  293. title: '真实 实时 精准',
  294. path: `/pages/sharePage/sharePage?id=${id}`
  295. }
  296. },
  297. doNothing() {
  298. },
  299. cancelAddDischargePort() {
  300. this.setData({
  301. currentDischargePortId: '',
  302. currentDischargePort: '',
  303. dischargeModal: false
  304. })
  305. },
  306. selectDischargePort(e) {
  307. this.setData({
  308. currentDischargePortId: e.detail.value,
  309. currentDischargePort: e.detail.label
  310. })
  311. },
  312. async addDischargePort() {
  313. let {
  314. currentDischargePortId,
  315. currentDischargePort
  316. } = this.data
  317. if (!currentDischargePortId || !currentDischargePort) {
  318. wx.showToast({
  319. title: '请选择港口',
  320. icon: "error"
  321. })
  322. return
  323. }
  324. let res = await postApi("/voyage/addNewPort", {
  325. loginAccountId: wx.getStorageSync('loginAccountId'),
  326. voyageId: this.data.id,
  327. portId: this.data.currentDischargePortId
  328. })
  329. this.getVoyageDetail()
  330. this.cancelAddDischargePort()
  331. },
  332. bindDischargePortChange(e) {
  333. let {
  334. index,
  335. param
  336. } = e.currentTarget.dataset
  337. this.data.voyageDetails[index][param] = e.detail.value
  338. this.setData({
  339. voyageDetails: this.data.voyageDetails
  340. })
  341. },
  342. changeDischargeTab(e) {
  343. let {
  344. index: currentDischargeIndex
  345. } = e.currentTarget.dataset
  346. this.setData({
  347. currentDischargeIndex
  348. })
  349. },
  350. async updateVoyage() {
  351. for (let i of this.data.voyageDetails) {
  352. Object.keys(i).forEach(function (key) {
  353. if ((typeof i[key]) == 'string') {
  354. i[key] = i[key].replaceAll('-', '/')
  355. if (i[key].length == 10) i[key] = i[key] + " 00:00:00"
  356. }
  357. })
  358. }
  359. if (this.data.arrivalLoadPortTime && this.data.arrivalLoadPortTime.length == 10) this.data.arrivalLoadPortTime = this.data.arrivalLoadPortTime + " 00:00:00"
  360. if (this.data.actualLoadTons && this.data.actualLoadTons.length == 10) this.data.actualLoadTons = this.data.actualLoadTons + " 00:00:00"
  361. if (this.data.actualLoadPieces && this.data.actualLoadPieces.length == 10) this.data.actualLoadPieces = this.data.actualLoadPieces + " 00:00:00"
  362. if (this.data.loadStartTime && this.data.loadStartTime.length == 10) this.data.loadStartTime = this.data.loadStartTime + " 00:00:00"
  363. if (this.data.loadEndTime && this.data.loadEndTime.length == 10) this.data.loadEndTime = this.data.loadEndTime + " 00:00:00"
  364. let res = await postApi("/voyage/update", {
  365. ...this.data,
  366. loginAccountId: wx.getStorageSync('loginAccountId')
  367. })
  368. if (res.data.status == 0) {
  369. wx.showToast({
  370. title: res.data.msg,
  371. })
  372. }
  373. this.getVoyageDetail()
  374. },
  375. async uploadBill(e) {
  376. let {
  377. type
  378. } = e.currentTarget.dataset
  379. let postData = {
  380. type,
  381. voyageId: this.data.id
  382. }
  383. let res = await uploadImage("/voyage/uploadVoyageWayBill", postData)
  384. this.getVoyageDetail()
  385. },
  386. async completeVoyage() {
  387. wx.showModal({
  388. title: "确认完成航次?",
  389. success: async e => {
  390. if (e.confirm) {
  391. let res = await postApi("/voyage/finish", {
  392. loginAccountId: wx.getStorageSync('loginAccountId'),
  393. voyageId: this.data.id
  394. })
  395. if (res.data.status == 0) {
  396. wx.showToast({
  397. title: '成功!',
  398. })
  399. this.getVoyageDetail()
  400. }
  401. }
  402. }
  403. })
  404. },
  405. async cancelVoyage() {
  406. wx.showModal({
  407. title: "确认取消航次?",
  408. success: async e => {
  409. if (e.confirm) {
  410. let res = await postApi("/voyage/cancel", {
  411. loginAccountId: wx.getStorageSync('loginAccountId'),
  412. id: this.data.id
  413. })
  414. if (res.data.status == 0) {
  415. wx.showToast({
  416. title: '取消成功!',
  417. })
  418. wx.switchTab({
  419. url: '/pages/voyageManage/voyageManage',
  420. })
  421. }
  422. }
  423. }
  424. })
  425. },
  426. goTo(e) {
  427. let {
  428. url
  429. } = e.currentTarget.dataset
  430. let {
  431. id,
  432. currentPortId
  433. } = this.data
  434. wx.navigateTo({
  435. url: `${url}?voyageId=${id}&portId=${currentPortId}`,
  436. })
  437. },
  438. uploadBillCanvas() {
  439. wx.navigateTo({
  440. url: `/pages/voyageManage/takeBill/takeBill?type=1&voyageId=${this.data.id}`,
  441. })
  442. },
  443. onLoad(options) {
  444. let {
  445. id
  446. } = options
  447. wx.setStorageSync('voyageDetailId', id)
  448. this.setData({
  449. id
  450. })
  451. this.getVoyageDetail()
  452. },
  453. onShow() {
  454. if (wx.getStorageSync('addStatus') == "success") {
  455. this.getVoyageDetail()
  456. wx.removeStorageSync('addStatus')
  457. }
  458. }
  459. })