detail.js 5.0 KB

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