detail.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // pages/voyages/detail/detail.js
  2. import {
  3. postApi
  4. } from "../../../apis/api"
  5. Page({
  6. data: {
  7. id: '',
  8. tab: 1,
  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. isClient: wx.getStorageSync('isClient'),
  45. loginAccountId: wx.getStorageSync('loginAccountId'),
  46. })
  47. let {
  48. coordinates,
  49. medias,
  50. policys,
  51. voyage,
  52. waybills
  53. } = res.data.result
  54. if (coordinates.length) {
  55. let points = []
  56. for (let i of coordinates) {
  57. points.push({
  58. latitude: i.latitude,
  59. longitude: i.longitude
  60. })
  61. }
  62. let {
  63. latitude,
  64. longitude
  65. } = points[points.length - 1]
  66. this.data.latitude = latitude
  67. this.data.longitude = longitude
  68. this.data.polyline[0].points = points
  69. let id = 1
  70. for (let i of points) {
  71. this.data.markers.push({
  72. id: id + 1,
  73. latitude: i.latitude,
  74. longitude: i.longitude,
  75. iconPath: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
  76. height: 20,
  77. width: 20
  78. })
  79. }
  80. this.setData({
  81. polyline: this.data.polyline,
  82. markers: this.data.markers,
  83. // latitude: this.data.latitude,
  84. // longitude: this.data.lo fngitude,
  85. points
  86. })
  87. }
  88. voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime)
  89. voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime)
  90. voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime)
  91. voyage.setSailTime = this.subTimeStr(voyage.setSailTime)
  92. voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime)
  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. onLoad(options) {
  248. let {
  249. id
  250. } = options
  251. wx.setStorageSync('voyageDetailId', id)
  252. this.setData({
  253. id
  254. })
  255. this.getVoyageDetail()
  256. this.getCarLoadRecordList()
  257. this.getDischargeList()
  258. },
  259. })