detail.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/web-static/ship-red-icon.png",
  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. this.setData({
  83. coordinates,
  84. medias,
  85. policys,
  86. voyage,
  87. waybills,
  88. })
  89. },
  90. async getCarLoadRecordList(isScroll) {
  91. if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
  92. if (isScroll) {
  93. this.data.truckLoadCurrentPage += 1
  94. } else {
  95. this.data.truckLoadCurrentPage = 1
  96. }
  97. let res = await postApi("/voyage/getCarLoadRecordList", {
  98. voyageId: this.data.id,
  99. size: this.data.pageSize,
  100. currentPage: this.data.truckLoadCurrentPage
  101. })
  102. this.setData({
  103. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  104. })
  105. if (0 == res.data.status) {
  106. if (isScroll) {
  107. let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
  108. for (let i of truckLoadList) {
  109. i.weighTime = this.cutTimeString(i.weighTime)
  110. }
  111. this.setData({
  112. truckLoadList,
  113. truckLoadTotal: res.data.total
  114. })
  115. } else {
  116. let 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. }
  125. } else {
  126. wx.showToast({
  127. icon: 'none',
  128. title: res.data.msg,
  129. })
  130. }
  131. },
  132. async getDischargeList(isScroll) {
  133. if (isScroll) {
  134. this.data.shipDischargeCurrentPage += 1
  135. } else {
  136. this.data.shipDischargeCurrentPage = 1
  137. }
  138. let res = await postApi("/voyage/getDischargeList", {
  139. voyageId: this.data.id,
  140. size: this.data.pageSize,
  141. currentPage: this.data.shipDischargeCurrentPage
  142. })
  143. this.setData({
  144. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  145. })
  146. if (0 == res.data.status) {
  147. if (isScroll) {
  148. let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
  149. for (let i of shipDischargeList) {
  150. i.dischargeTime = this.cutTimeString(i.dischargeTime)
  151. }
  152. this.setData({
  153. shipDischargeList,
  154. shipDischargeTotal: res.data.total
  155. })
  156. } else {
  157. let 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. }
  166. } else {
  167. wx.showToast({
  168. icon: "none",
  169. title: res.data.msg,
  170. })
  171. }
  172. },
  173. previewImage(e) {
  174. let {
  175. src
  176. } = e.currentTarget.dataset
  177. wx.previewImage({
  178. current: src, // 当前显示图片的http链接
  179. urls: [src] // 需要预览的图片http链接列表
  180. })
  181. },
  182. changeInfoType(e) {
  183. let {
  184. type
  185. } = e.currentTarget.dataset
  186. this.setData({
  187. infoType: type,
  188. truckLoadCurrentPage: 1,
  189. shipDischargeCurrentPage: 1,
  190. shipDischargeList: [],
  191. truckLoadList: [],
  192. shipDischargeTotal: 0,
  193. truckLoadTotal: 0,
  194. })
  195. if (type == "ship") {
  196. this.getDischargeList()
  197. } else {
  198. this.getCarLoadRecordList()
  199. }
  200. },
  201. cutTimeString(str) {
  202. let index = str.indexOf(' ')
  203. return index == -1 ? str : str.substring(0, index)
  204. },
  205. changeBottomPage() {
  206. if (this.data.infoType == "ship") {
  207. this.getDischargeList(true)
  208. } else {
  209. this.getCarLoadRecordList(true)
  210. }
  211. },
  212. scrollShip() {
  213. if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
  214. this.getDischargeList(true)
  215. },
  216. scrollTruck() {
  217. if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
  218. this.getCarLoadRecordList(true)
  219. },
  220. onLoad(options) {
  221. let {
  222. id
  223. } = options
  224. wx.setStorageSync('voyageDetailId', id)
  225. this.setData({
  226. id
  227. })
  228. this.getVoyageDetail()
  229. this.getCarLoadRecordList()
  230. this.getDischargeList()
  231. },
  232. })