detail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. },
  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. tab2disabled: voyage.voyageStatus == 2
  125. })
  126. this.getCarLoadRecordList()
  127. this.getDischargeList()
  128. } else {
  129. wx.showToast({
  130. title: '获取详情失败!',
  131. icon: "error"
  132. })
  133. }
  134. },
  135. subTimeStr(str) {
  136. if (!str || typeof str != "string") return;
  137. let index = str.indexOf(" ");
  138. return str.substring(0, index);
  139. },
  140. async getCarLoadRecordList(isScroll) {
  141. if (isScroll) {
  142. this.data.truckLoadCurrentPage += 1
  143. } else {
  144. this.data.truckLoadCurrentPage = 1
  145. }
  146. let res = await postApi("/voyage/getCarLoadRecordList", {
  147. portId: this.data.currentPortId,
  148. voyageId: this.data.id,
  149. size: this.data.pageSize,
  150. currentPage: this.data.truckLoadCurrentPage,
  151. loginAccountId: wx.getStorageSync('loginAccountId')
  152. })
  153. this.setData({
  154. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  155. })
  156. if (0 == res.data.status) {
  157. if (isScroll) {
  158. let truckLoadList = [...this.data.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. } else {
  167. let truckLoadList = res.data.result
  168. for (let i of truckLoadList) {
  169. i.weighTime = this.cutTimeString(i.weighTime)
  170. }
  171. this.setData({
  172. truckLoadList,
  173. truckLoadTotal: res.data.total
  174. })
  175. }
  176. } else {
  177. // wx.showToast({
  178. // icon: 'none',
  179. // title: res.data.msg,
  180. // })
  181. }
  182. },
  183. async getDischargeList(isScroll) {
  184. if (isScroll) {
  185. this.data.shipDischargeCurrentPage += 1
  186. } else {
  187. this.data.shipDischargeCurrentPage = 1
  188. }
  189. let res = await postApi("/voyage/getDischargeList", {
  190. portId: this.data.currentPortId,
  191. voyageId: this.data.id,
  192. size: this.data.pageSize,
  193. currentPage: this.data.shipDischargeCurrentPage,
  194. loginAccountId: wx.getStorageSync('loginAccountId')
  195. })
  196. this.setData({
  197. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  198. })
  199. if (0 == res.data.status) {
  200. if (isScroll) {
  201. let shipDischargeList = [...this.data.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. } else {
  210. let shipDischargeList = res.data.result
  211. for (let i of shipDischargeList) {
  212. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  213. }
  214. this.setData({
  215. shipDischargeList,
  216. shipDischargeTotal: res.data.total
  217. })
  218. }
  219. } else {
  220. // wx.showToast({
  221. // icon: "none",
  222. // title: res.data.msg,
  223. // })
  224. }
  225. },
  226. previewImage(e) {
  227. let {
  228. src,
  229. files
  230. } = e.currentTarget.dataset
  231. let urls = []
  232. if (this.data.infoType == "ship" && this.data.tab == 3) {
  233. urls = files.map(item => {
  234. return item.viewUrl
  235. })
  236. } else {
  237. urls = [src]
  238. }
  239. wx.previewImage({
  240. current: src, // 当前显示图片的http链接
  241. urls // 需要预览的图片http链接列表
  242. })
  243. },
  244. changeInfoType(e) {
  245. let {
  246. type
  247. } = e.currentTarget.dataset
  248. this.setData({
  249. infoType: type,
  250. truckLoadCurrentPage: 1,
  251. shipDischargeCurrentPage: 1,
  252. shipDischargeList: [],
  253. truckLoadList: [],
  254. shipDischargeTotal: 0,
  255. truckLoadTotal: 0,
  256. })
  257. if (type == "ship") {
  258. this.getDischargeList()
  259. } else {
  260. this.getCarLoadRecordList()
  261. }
  262. },
  263. cutTimeString(str) {
  264. let index = str.indexOf(' ')
  265. return index == -1 ? str : str.substring(0, index)
  266. },
  267. changeBottomPage() {
  268. if (this.data.infoType == "ship") {
  269. this.getDischargeList(true)
  270. } else {
  271. this.getCarLoadRecordList(true)
  272. }
  273. },
  274. scrollShip() {
  275. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  276. this.getDischargeList(true)
  277. },
  278. scrollTruck() {
  279. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  280. this.getCarLoadRecordList(true)
  281. },
  282. changePort(e) {
  283. let tab3CurrentDischargeIndex = e.detail
  284. this.setData({
  285. tab3CurrentDischargeIndex,
  286. currentPortId: this.data.voyageDetails[tab3CurrentDischargeIndex].portId,
  287. shipDischargeList: [],
  288. truckLoadList: [],
  289. })
  290. if (this.data.infoType == "ship") {
  291. this.getDischargeList()
  292. } else {
  293. this.getCarLoadRecordList()
  294. }
  295. },
  296. showAddDischargePortModal() {
  297. console.log(1)
  298. this.setData({
  299. dischargeModal: true
  300. })
  301. },
  302. onShareAppMessage() {
  303. let id = wx.getStorageSync('voyageDetailId')
  304. return {
  305. title: '真实 实时 精准',
  306. path: `/pages/sharePage/sharePage?id=${id}`
  307. }
  308. },
  309. doNothing() {
  310. },
  311. cancelAddDischargePort() {
  312. this.setData({
  313. currentDischargePortId: '',
  314. currentDischargePort: '',
  315. dischargeModal: false
  316. })
  317. },
  318. selectDischargePort(e) {
  319. if (e.detail.label == this.data.loadPort) {
  320. wx.showToast({
  321. title: '不能同装货港',
  322. icon: "error"
  323. })
  324. return
  325. }
  326. this.setData({
  327. currentDischargePortId: e.detail.value,
  328. currentDischargePort: e.detail.label
  329. })
  330. this.addDischargePort()
  331. },
  332. async addDischargePort() {
  333. let {
  334. currentDischargePortId,
  335. currentDischargePort
  336. } = this.data
  337. if (!currentDischargePortId || !currentDischargePort) {
  338. wx.showToast({
  339. title: '请选择港口',
  340. icon: "error"
  341. })
  342. return
  343. }
  344. let res = await postApi("/voyage/addNewPort", {
  345. loginAccountId: wx.getStorageSync('loginAccountId'),
  346. voyageId: this.data.id,
  347. portId: this.data.currentDischargePortId
  348. })
  349. this.getVoyageDetail()
  350. this.cancelAddDischargePort()
  351. },
  352. bindDischargePortChange(e) {
  353. let {
  354. index,
  355. param
  356. } = e.currentTarget.dataset
  357. this.data.voyageDetails[index][param] = e.detail.value
  358. this.setData({
  359. voyageDetails: this.data.voyageDetails
  360. })
  361. },
  362. changeDischargeTab(e) {
  363. let {
  364. detail: currentDischargeIndex
  365. } = e
  366. this.setData({
  367. currentDischargeIndex
  368. })
  369. },
  370. async updateVoyage() {
  371. for (let i of this.data.voyageDetails) {
  372. Object.keys(i).forEach(function (key) {
  373. if ((typeof i[key]) == 'string') {
  374. i[key] = i[key].replaceAll('-', '/')
  375. if (i[key].length == 10) i[key] = i[key] + " 00:00:00"
  376. }
  377. })
  378. }
  379. if (this.data.arrivalLoadPortTime && this.data.arrivalLoadPortTime.length == 10) this.data.arrivalLoadPortTime = this.data.arrivalLoadPortTime + " 00:00:00"
  380. if (this.data.actualLoadTons && this.data.actualLoadTons.length == 10) this.data.actualLoadTons = this.data.actualLoadTons + " 00:00:00"
  381. if (this.data.actualLoadPieces && this.data.actualLoadPieces.length == 10) this.data.actualLoadPieces = this.data.actualLoadPieces + " 00:00:00"
  382. if (this.data.loadStartTime && this.data.loadStartTime.length == 10) this.data.loadStartTime = this.data.loadStartTime + " 00:00:00"
  383. if (this.data.loadEndTime && this.data.loadEndTime.length == 10) this.data.loadEndTime = this.data.loadEndTime + " 00:00:00"
  384. let res = await postApi("/voyage/update", {
  385. ...this.data,
  386. loginAccountId: wx.getStorageSync('loginAccountId')
  387. })
  388. if (res.data.status == 0) {
  389. wx.showToast({
  390. title: res.data.msg,
  391. })
  392. }
  393. this.getVoyageDetail()
  394. },
  395. async uploadBill(e) {
  396. let {
  397. type
  398. } = e.currentTarget.dataset
  399. let postData = {
  400. type,
  401. voyageId: this.data.id
  402. }
  403. let res = await uploadImage("/voyage/uploadVoyageWayBill", postData)
  404. this.getVoyageDetail()
  405. },
  406. async completeVoyage() {
  407. wx.showModal({
  408. title: "确认完成航次?",
  409. success: async e => {
  410. if (e.confirm) {
  411. let res = await postApi("/voyage/finish", {
  412. loginAccountId: wx.getStorageSync('loginAccountId'),
  413. voyageId: this.data.id
  414. })
  415. if (res.data.status == 0) {
  416. wx.showToast({
  417. title: '成功!',
  418. })
  419. this.getVoyageDetail()
  420. }
  421. }
  422. }
  423. })
  424. },
  425. async cancelVoyage() {
  426. wx.showModal({
  427. title: "确认取消航次?",
  428. success: async e => {
  429. if (e.confirm) {
  430. let res = await postApi("/voyage/cancel", {
  431. loginAccountId: wx.getStorageSync('loginAccountId'),
  432. id: this.data.id
  433. })
  434. if (res.data.status == 0) {
  435. wx.showToast({
  436. title: '取消成功!',
  437. })
  438. wx.switchTab({
  439. url: '/pages/voyageManage/voyageManage',
  440. })
  441. }
  442. }
  443. }
  444. })
  445. },
  446. goTo(e) {
  447. let {
  448. url
  449. } = e.currentTarget.dataset
  450. let {
  451. id,
  452. currentPortId
  453. } = this.data
  454. wx.navigateTo({
  455. url: `${url}?voyageId=${id}&portId=${currentPortId}`,
  456. })
  457. },
  458. uploadBillCanvas() {
  459. wx.navigateTo({
  460. url: `/pages/voyageManage/takeBill/takeBill?type=1&voyageId=${this.data.id}`,
  461. })
  462. },
  463. loadEndTimeChange(e) {
  464. if (!this.data.voyageDetails[0].setSailTime) this.data.voyageDetails[0].setSailTime = e.detail.value
  465. this.setData({
  466. voyageDetails: this.data.voyageDetails
  467. })
  468. },
  469. onLoad(options) {
  470. let {
  471. id
  472. } = options
  473. wx.setStorageSync('voyageDetailId', id)
  474. this.setData({
  475. id
  476. })
  477. this.getVoyageDetail()
  478. },
  479. onShow() {
  480. if (wx.getStorageSync('addStatus') == "success") {
  481. this.getVoyageDetail()
  482. wx.removeStorageSync('addStatus')
  483. }
  484. }
  485. })