detail.js 5.4 KB

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