sharePage.js 8.2 KB

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