detail.js 13 KB

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