sharePage.js 8.6 KB

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