detail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. console.log(1)
  287. this.setData({
  288. dischargeModal: true
  289. })
  290. },
  291. onShareAppMessage() {
  292. let id = wx.getStorageSync('voyageDetailId')
  293. return {
  294. title: '真实 实时 精准',
  295. path: `/pages/sharePage/sharePage?id=${id}`
  296. }
  297. },
  298. doNothing() {
  299. },
  300. cancelAddDischargePort() {
  301. this.setData({
  302. currentDischargePortId: '',
  303. currentDischargePort: '',
  304. dischargeModal: false
  305. })
  306. },
  307. selectDischargePort(e) {
  308. this.setData({
  309. currentDischargePortId: e.detail.value,
  310. currentDischargePort: e.detail.label
  311. })
  312. this.addDischargePort()
  313. },
  314. async addDischargePort() {
  315. let {
  316. currentDischargePortId,
  317. currentDischargePort
  318. } = this.data
  319. if (!currentDischargePortId || !currentDischargePort) {
  320. wx.showToast({
  321. title: '请选择港口',
  322. icon: "error"
  323. })
  324. return
  325. }
  326. let res = await postApi("/voyage/addNewPort", {
  327. loginAccountId: wx.getStorageSync('loginAccountId'),
  328. voyageId: this.data.id,
  329. portId: this.data.currentDischargePortId
  330. })
  331. this.getVoyageDetail()
  332. this.cancelAddDischargePort()
  333. },
  334. bindDischargePortChange(e) {
  335. let {
  336. index,
  337. param
  338. } = e.currentTarget.dataset
  339. this.data.voyageDetails[index][param] = e.detail.value
  340. this.setData({
  341. voyageDetails: this.data.voyageDetails
  342. })
  343. },
  344. changeDischargeTab(e) {
  345. let {
  346. index: currentDischargeIndex
  347. } = e.currentTarget.dataset
  348. this.setData({
  349. currentDischargeIndex
  350. })
  351. },
  352. async updateVoyage() {
  353. for (let i of this.data.voyageDetails) {
  354. Object.keys(i).forEach(function (key) {
  355. if ((typeof i[key]) == 'string') {
  356. i[key] = i[key].replaceAll('-', '/')
  357. if (i[key].length == 10) i[key] = i[key] + " 00:00:00"
  358. }
  359. })
  360. }
  361. if (this.data.arrivalLoadPortTime && this.data.arrivalLoadPortTime.length == 10) this.data.arrivalLoadPortTime = this.data.arrivalLoadPortTime + " 00:00:00"
  362. if (this.data.actualLoadTons && this.data.actualLoadTons.length == 10) this.data.actualLoadTons = this.data.actualLoadTons + " 00:00:00"
  363. if (this.data.actualLoadPieces && this.data.actualLoadPieces.length == 10) this.data.actualLoadPieces = this.data.actualLoadPieces + " 00:00:00"
  364. if (this.data.loadStartTime && this.data.loadStartTime.length == 10) this.data.loadStartTime = this.data.loadStartTime + " 00:00:00"
  365. if (this.data.loadEndTime && this.data.loadEndTime.length == 10) this.data.loadEndTime = this.data.loadEndTime + " 00:00:00"
  366. let res = await postApi("/voyage/update", {
  367. ...this.data,
  368. loginAccountId: wx.getStorageSync('loginAccountId')
  369. })
  370. if (res.data.status == 0) {
  371. wx.showToast({
  372. title: res.data.msg,
  373. })
  374. }
  375. this.getVoyageDetail()
  376. },
  377. async uploadBill(e) {
  378. let {
  379. type
  380. } = e.currentTarget.dataset
  381. let postData = {
  382. type,
  383. voyageId: this.data.id
  384. }
  385. let res = await uploadImage("/voyage/uploadVoyageWayBill", postData)
  386. this.getVoyageDetail()
  387. },
  388. async completeVoyage() {
  389. wx.showModal({
  390. title: "确认完成航次?",
  391. success: async e => {
  392. if (e.confirm) {
  393. let res = await postApi("/voyage/finish", {
  394. loginAccountId: wx.getStorageSync('loginAccountId'),
  395. voyageId: this.data.id
  396. })
  397. if (res.data.status == 0) {
  398. wx.showToast({
  399. title: '成功!',
  400. })
  401. this.getVoyageDetail()
  402. }
  403. }
  404. }
  405. })
  406. },
  407. async cancelVoyage() {
  408. wx.showModal({
  409. title: "确认取消航次?",
  410. success: async e => {
  411. if (e.confirm) {
  412. let res = await postApi("/voyage/cancel", {
  413. loginAccountId: wx.getStorageSync('loginAccountId'),
  414. id: this.data.id
  415. })
  416. if (res.data.status == 0) {
  417. wx.showToast({
  418. title: '取消成功!',
  419. })
  420. wx.switchTab({
  421. url: '/pages/voyageManage/voyageManage',
  422. })
  423. }
  424. }
  425. }
  426. })
  427. },
  428. goTo(e) {
  429. let {
  430. url
  431. } = e.currentTarget.dataset
  432. let {
  433. id,
  434. currentPortId
  435. } = this.data
  436. wx.navigateTo({
  437. url: `${url}?voyageId=${id}&portId=${currentPortId}`,
  438. })
  439. },
  440. uploadBillCanvas() {
  441. wx.navigateTo({
  442. url: `/pages/voyageManage/takeBill/takeBill?type=1&voyageId=${this.data.id}`,
  443. })
  444. },
  445. onLoad(options) {
  446. let {
  447. id
  448. } = options
  449. wx.setStorageSync('voyageDetailId', id)
  450. this.setData({
  451. id
  452. })
  453. this.getVoyageDetail()
  454. },
  455. onShow() {
  456. if (wx.getStorageSync('addStatus') == "success") {
  457. this.getVoyageDetail()
  458. wx.removeStorageSync('addStatus')
  459. }
  460. }
  461. })