detail.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. this.setData({
  87. coordinates,
  88. medias,
  89. policys,
  90. voyage,
  91. waybills,
  92. })
  93. },
  94. subTimeStr(str) {
  95. if (!str || typeof str != "string") return;
  96. let index = str.indexOf(" ");
  97. return str.substring(0, index);
  98. },
  99. async getCarLoadRecordList(isScroll) {
  100. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  101. if (isScroll) {
  102. this.data.truckLoadCurrentPage += 1
  103. } else {
  104. this.data.truckLoadCurrentPage = 1
  105. }
  106. let res = await postApi("/voyage/getCarLoadRecordList", {
  107. voyageId: this.data.id,
  108. size: this.data.pageSize,
  109. currentPage: this.data.truckLoadCurrentPage
  110. })
  111. this.setData({
  112. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  113. })
  114. if (0 == res.data.status) {
  115. if (isScroll) {
  116. let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
  117. for (let i of truckLoadList) {
  118. i.weighTime = this.cutTimeString(i.weighTime)
  119. }
  120. this.setData({
  121. truckLoadList,
  122. truckLoadTotal: res.data.total
  123. })
  124. } else {
  125. let 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. }
  134. } else {
  135. wx.showToast({
  136. icon: 'none',
  137. title: res.data.msg,
  138. })
  139. }
  140. },
  141. async getDischargeList(isScroll) {
  142. if (isScroll) {
  143. this.data.shipDischargeCurrentPage += 1
  144. } else {
  145. this.data.shipDischargeCurrentPage = 1
  146. }
  147. let res = await postApi("/voyage/getDischargeList", {
  148. voyageId: this.data.id,
  149. size: this.data.pageSize,
  150. currentPage: this.data.shipDischargeCurrentPage
  151. })
  152. this.setData({
  153. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  154. })
  155. if (0 == res.data.status) {
  156. if (isScroll) {
  157. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  158. for (let i of shipDischargeList) {
  159. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  160. }
  161. this.setData({
  162. shipDischargeList,
  163. shipDischargeTotal: res.data.total
  164. })
  165. } else {
  166. let shipDischargeList = res.data.result
  167. for (let i of shipDischargeList) {
  168. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  169. }
  170. this.setData({
  171. shipDischargeList,
  172. shipDischargeTotal: res.data.total
  173. })
  174. }
  175. } else {
  176. wx.showToast({
  177. icon: "none",
  178. title: res.data.msg,
  179. })
  180. }
  181. },
  182. previewImage(e) {
  183. let {
  184. src
  185. } = e.currentTarget.dataset
  186. wx.previewImage({
  187. current: src, // 当前显示图片的http链接
  188. urls: [src] // 需要预览的图片http链接列表
  189. })
  190. },
  191. changeInfoType(e) {
  192. let {
  193. type
  194. } = e.currentTarget.dataset
  195. this.setData({
  196. infoType: type,
  197. truckLoadCurrentPage: 1,
  198. shipDischargeCurrentPage: 1,
  199. shipDischargeList: [],
  200. truckLoadList: [],
  201. shipDischargeTotal: 0,
  202. truckLoadTotal: 0,
  203. })
  204. if (type == "ship") {
  205. this.getDischargeList()
  206. } else {
  207. this.getCarLoadRecordList()
  208. }
  209. },
  210. cutTimeString(str) {
  211. let index = str.indexOf(' ')
  212. return index == -1 ? str : str.substring(0, index)
  213. },
  214. changeBottomPage() {
  215. if (this.data.infoType == "ship") {
  216. this.getDischargeList(true)
  217. } else {
  218. this.getCarLoadRecordList(true)
  219. }
  220. },
  221. scrollShip() {
  222. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  223. this.getDischargeList(true)
  224. },
  225. scrollTruck() {
  226. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  227. this.getCarLoadRecordList(true)
  228. },
  229. onShareAppMessage() {
  230. let id = wx.getStorageSync('voyageDetailId')
  231. return {
  232. title: '真实 实时 精准',
  233. path: `/pages/sharePage/sharePage?id=${id}`
  234. }
  235. },
  236. onLoad(options) {
  237. let {
  238. id
  239. } = options
  240. wx.setStorageSync('voyageDetailId', id)
  241. this.setData({
  242. id
  243. })
  244. this.getVoyageDetail()
  245. this.getCarLoadRecordList()
  246. this.getDischargeList()
  247. },
  248. })