sharePage.js 8.8 KB

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