detail.js 9.7 KB

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