detail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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: 3,
  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. },
  42. changeTab(e) {
  43. let {
  44. tab
  45. } = e.currentTarget.dataset
  46. this.setData({
  47. tab
  48. })
  49. },
  50. async getVoyageDetail() {
  51. let res = await postApi("/voyage/detail", {
  52. voyageId: this.data.id,
  53. isClient: wx.getStorageSync('isClient'),
  54. loginAccountId: wx.getStorageSync('loginAccountId'),
  55. })
  56. let {
  57. coordinates,
  58. medias,
  59. policys,
  60. voyage,
  61. waybills
  62. } = res.data.result
  63. if (coordinates.length) {
  64. let points = []
  65. for (let i of coordinates) {
  66. points.push({
  67. latitude: i.latitude,
  68. longitude: i.longitude
  69. })
  70. }
  71. let {
  72. latitude,
  73. longitude
  74. } = points[points.length - 1]
  75. this.data.latitude = latitude
  76. this.data.longitude = longitude
  77. this.data.polyline[0].points = points
  78. let id = 1
  79. for (let i of points) {
  80. this.data.markers.push({
  81. id: id + 1,
  82. latitude: i.latitude,
  83. longitude: i.longitude,
  84. iconPath: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
  85. height: 20,
  86. width: 20
  87. })
  88. }
  89. this.setData({
  90. polyline: this.data.polyline,
  91. markers: this.data.markers,
  92. // latitude: this.data.latitude,
  93. // longitude: this.data.lo fngitude,
  94. points
  95. })
  96. }
  97. voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime)
  98. voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime)
  99. voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime)
  100. voyage.setSailTime = this.subTimeStr(voyage.setSailTime)
  101. voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime)
  102. let dischargePortIds = voyage.dischargePortIds.split(',')
  103. let dischargePorts = voyage.dischargePorts.split(',')
  104. let discLength = dischargePortIds.length
  105. for (let item of voyage.voyageDetails) {
  106. item.setSailTime = this.subTimeStr(item.setSailTime)
  107. item.expectedArrivalTime = this.subTimeStr(item.expectedArrivalTime)
  108. item.actualArrivalTime = this.subTimeStr(item.actualArrivalTime)
  109. item.dischargeStartTime = this.subTimeStr(item.dischargeStartTime)
  110. item.dischargeEndTime = this.subTimeStr(item.dischargeEndTime)
  111. }
  112. this.setData({
  113. coordinates,
  114. medias,
  115. policys,
  116. ...voyage,
  117. waybills,
  118. currentPortId: voyage?.voyageDetails[0].portId,
  119. dischargePortIds,
  120. dischargePorts,
  121. discLength
  122. })
  123. this.getCarLoadRecordList()
  124. this.getDischargeList()
  125. },
  126. subTimeStr(str) {
  127. if (!str || typeof str != "string") return;
  128. let index = str.indexOf(" ");
  129. return str.substring(0, index);
  130. },
  131. async getCarLoadRecordList(isScroll) {
  132. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  133. if (isScroll) {
  134. this.data.truckLoadCurrentPage += 1
  135. } else {
  136. this.data.truckLoadCurrentPage = 1
  137. }
  138. let res = await postApi("/voyage/getCarLoadRecordList", {
  139. portId: this.data.currentPortId,
  140. voyageId: this.data.id,
  141. size: this.data.pageSize,
  142. currentPage: this.data.truckLoadCurrentPage,
  143. isClient: wx.getStorageSync('isClient'),
  144. loginAccountId: wx.getStorageSync('loginAccountId')
  145. })
  146. this.setData({
  147. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  148. })
  149. if (0 == res.data.status) {
  150. if (isScroll) {
  151. let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
  152. for (let i of truckLoadList) {
  153. i.weighTime = this.cutTimeString(i.weighTime)
  154. }
  155. this.setData({
  156. truckLoadList,
  157. truckLoadTotal: res.data.total
  158. })
  159. } else {
  160. let 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. }
  169. } else {
  170. // wx.showToast({
  171. // icon: 'none',
  172. // title: res.data.msg,
  173. // })
  174. }
  175. },
  176. async getDischargeList(isScroll) {
  177. if (isScroll) {
  178. this.data.shipDischargeCurrentPage += 1
  179. } else {
  180. this.data.shipDischargeCurrentPage = 1
  181. }
  182. let res = await postApi("/voyage/getDischargeList", {
  183. portId: this.data.currentPortId,
  184. voyageId: this.data.id,
  185. size: this.data.pageSize,
  186. currentPage: this.data.shipDischargeCurrentPage,
  187. isClient: wx.getStorageSync('isClient'),
  188. loginAccountId: wx.getStorageSync('loginAccountId')
  189. })
  190. this.setData({
  191. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  192. })
  193. if (0 == res.data.status) {
  194. if (isScroll) {
  195. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  196. for (let i of shipDischargeList) {
  197. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  198. }
  199. this.setData({
  200. shipDischargeList,
  201. shipDischargeTotal: res.data.total
  202. })
  203. } else {
  204. let shipDischargeList = res.data.result
  205. for (let i of shipDischargeList) {
  206. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  207. }
  208. this.setData({
  209. shipDischargeList,
  210. shipDischargeTotal: res.data.total
  211. })
  212. }
  213. } else {
  214. // wx.showToast({
  215. // icon: "none",
  216. // title: res.data.msg,
  217. // })
  218. }
  219. },
  220. previewImage(e) {
  221. let {
  222. src
  223. } = e.currentTarget.dataset
  224. wx.previewImage({
  225. current: src, // 当前显示图片的http链接
  226. urls: [src] // 需要预览的图片http链接列表
  227. })
  228. },
  229. changeInfoType(e) {
  230. let {
  231. type
  232. } = e.currentTarget.dataset
  233. this.setData({
  234. infoType: type,
  235. truckLoadCurrentPage: 1,
  236. shipDischargeCurrentPage: 1,
  237. shipDischargeList: [],
  238. truckLoadList: [],
  239. shipDischargeTotal: 0,
  240. truckLoadTotal: 0,
  241. })
  242. if (type == "ship") {
  243. this.getDischargeList()
  244. } else {
  245. this.getCarLoadRecordList()
  246. }
  247. },
  248. cutTimeString(str) {
  249. let index = str.indexOf(' ')
  250. return index == -1 ? str : str.substring(0, index)
  251. },
  252. changeBottomPage() {
  253. if (this.data.infoType == "ship") {
  254. this.getDischargeList(true)
  255. } else {
  256. this.getCarLoadRecordList(true)
  257. }
  258. },
  259. scrollShip() {
  260. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  261. this.getDischargeList(true)
  262. },
  263. scrollTruck() {
  264. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  265. this.getCarLoadRecordList(true)
  266. },
  267. changePort(e) {
  268. let currentPortId = e.target.dataset.id
  269. this.setData({
  270. currentPortId,
  271. shipDischargeList: [],
  272. truckLoadList: [],
  273. })
  274. if (this.data.infoType == "ship") {
  275. this.getDischargeList()
  276. } else {
  277. this.getCarLoadRecordList()
  278. }
  279. },
  280. showAddDischargePortModal() {
  281. this.setData({
  282. dischargeModal: true
  283. })
  284. },
  285. onShareAppMessage() {
  286. let id = wx.getStorageSync('voyageDetailId')
  287. return {
  288. title: '真实 实时 精准',
  289. path: `/pages/sharePage/sharePage?id=${id}`
  290. }
  291. },
  292. doNothing() {
  293. },
  294. cancelAddDischargePort() {
  295. this.setData({
  296. currentDischargePortId: '',
  297. currentDischargePort: '',
  298. dischargeModal: false
  299. })
  300. },
  301. selectDischargePort(e) {
  302. this.setData({
  303. currentDischargePortId: e.detail.value,
  304. currentDischargePort: e.detail.label
  305. })
  306. },
  307. async addDischargePort() {
  308. let {
  309. currentDischargePortId,
  310. currentDischargePort
  311. } = this.data
  312. if (!currentDischargePortId || !currentDischargePort) {
  313. wx.showToast({
  314. title: '请选择港口',
  315. icon: "error"
  316. })
  317. return
  318. }
  319. let res = await postApi("/voyage/backstage/addNewPort", {
  320. loginAccountId: wx.getStorageSync('loginAccountId'),
  321. voyageId: this.data.id,
  322. portId: this.data.currentDischargePortId
  323. })
  324. this.cancelAddDischargePort()
  325. },
  326. bindDischargePortChange(e) {
  327. let {
  328. index,
  329. param
  330. } = e.currentTarget.dataset
  331. this.data.voyageDetails[index][param] = e.detail.value
  332. this.setData({
  333. voyageDetails: this.data.voyageDetails
  334. })
  335. },
  336. changeDischargeTab(e) {
  337. let {
  338. index: currentDischargeIndex
  339. } = e.currentTarget.dataset
  340. this.setData({
  341. currentDischargeIndex
  342. })
  343. },
  344. async updateVoyage() {
  345. for (let i of this.data.voyageDetails) {
  346. Object.keys(i).forEach(function (key) {
  347. console.log(i[key])
  348. if ((typeof i[key]) == 'string') {
  349. i[key] = i[key].replaceAll('-', '/')
  350. if (i[key].length == 10) i[key] = i[key] + " 00:00:00"
  351. }
  352. })
  353. }
  354. if (this.data.arrivalLoadPortTime.length == 10) this.data.arrivalLoadPortTime = this.data.arrivalLoadPortTime + " 00:00:00"
  355. if (this.data.actualLoadTons.length == 10) this.data.actualLoadTons = this.data.actualLoadTons + " 00:00:00"
  356. if (this.data.actualLoadPieces.length == 10) this.data.actualLoadPieces = this.data.actualLoadPieces + " 00:00:00"
  357. if (this.data.loadStartTime.length == 10) this.data.loadStartTime = this.data.loadStartTime + " 00:00:00"
  358. if (this.data.loadEndTime.length == 10) this.data.loadEndTime = this.data.loadEndTime + " 00:00:00"
  359. let res = await postApi("/voyage/backstage/update", {
  360. ...this.data,
  361. loginAccountId: wx.getStorageSync('loginAccountId')
  362. })
  363. console.log(res)
  364. },
  365. async uploadBill(e) {
  366. let postData = {
  367. type: e.currentTarget.dataset.type,
  368. voyageId: this.data.id
  369. }
  370. let res = await uploadImage("/voyage/uploadVoyageWayBill", postData)
  371. console.log(res)
  372. },
  373. onLoad(options) {
  374. let {
  375. id
  376. } = options
  377. wx.setStorageSync('voyageDetailId', id)
  378. this.setData({
  379. id
  380. })
  381. this.getVoyageDetail()
  382. },
  383. })