sharePage.js 6.7 KB

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