detail.js 6.5 KB

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