detail.js 15 KB

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