detail.js 13 KB

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