detail.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // pages/voyages/detail/detail.js
  2. import { postApi } from "../../../apis/api";
  3. Page({
  4. data: {
  5. id: "",
  6. tab: 1,
  7. shipDischargeCurrentPage: 1,
  8. truckLoadCurrentPage: 1,
  9. coordinates: [],
  10. medias: [],
  11. policys: [],
  12. voyage: [],
  13. waybills: [],
  14. infoType: "ship",
  15. shipDischargeList: [],
  16. truckLoadList: [],
  17. shipDischargeTotal: 0,
  18. truckLoadTotal: 0,
  19. polyline: [
  20. {
  21. points: [],
  22. width: 2,
  23. dottedLine: true,
  24. color: "#eb2f06",
  25. },
  26. ],
  27. markers: [],
  28. points: [],
  29. pageSize: 20,
  30. latitude: 31.891992,
  31. longitude: 120.551369,
  32. currentPortId: 0,
  33. },
  34. changeTab(e) {
  35. let { tab } = e.currentTarget.dataset;
  36. this.setData({
  37. tab,
  38. });
  39. },
  40. async getVoyageDetail() {
  41. let res = await postApi("/voyage/wx/detail", {
  42. voyageId: this.data.id,
  43. isClient: wx.getStorageSync("isClient"),
  44. loginAccountId: wx.getStorageSync("loginAccountId"),
  45. });
  46. let { coordinates, medias, policys, voyage, waybills } = res.data.result;
  47. if (coordinates.length) {
  48. let points = [];
  49. for (let i of coordinates) {
  50. points.push({
  51. latitude: i.latitude,
  52. longitude: i.longitude,
  53. });
  54. }
  55. let { latitude, longitude } = points[points.length - 1];
  56. this.data.latitude = latitude;
  57. this.data.longitude = longitude;
  58. this.data.polyline[0].points = points;
  59. let id = 1;
  60. for (let i of points) {
  61. this.data.markers.push({
  62. id: id + 1,
  63. latitude: i.latitude,
  64. longitude: i.longitude,
  65. iconPath:
  66. "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
  67. height: 20,
  68. width: 20,
  69. });
  70. }
  71. this.setData({
  72. polyline: this.data.polyline,
  73. markers: this.data.markers,
  74. // latitude: this.data.latitude,
  75. // longitude: this.data.lo fngitude,
  76. points,
  77. });
  78. }
  79. voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime);
  80. voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime);
  81. voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime);
  82. voyage.setSailTime = this.subTimeStr(voyage.setSailTime);
  83. voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime);
  84. for (let item of voyage.voyageDetails) {
  85. item.setSailTime = this.subTimeStr(item.setSailTime);
  86. item.expectedArrivalTime = this.subTimeStr(item.expectedArrivalTime);
  87. item.actualArrivalTime = this.subTimeStr(item.actualArrivalTime);
  88. item.dischargeStartTime = this.subTimeStr(item.dischargeStartTime);
  89. item.dischargeEndTime = this.subTimeStr(item.dischargeEndTime);
  90. }
  91. this.setData({
  92. coordinates,
  93. medias,
  94. policys,
  95. voyage,
  96. waybills,
  97. currentPortId: voyage?.voyageDetails[0].portId,
  98. });
  99. this.getCarLoadRecordList();
  100. this.getDischargeList();
  101. },
  102. subTimeStr(str) {
  103. if (!str || typeof str != "string") return;
  104. let index = str.indexOf(" ");
  105. return str.substring(0, index);
  106. },
  107. async getCarLoadRecordList(isScroll) {
  108. if (
  109. this.data.truckLoadTotal != 0 &&
  110. this.data.truckLoadTotal <
  111. this.data.pageSize * this.data.truckLoadCurrentPage
  112. )
  113. return;
  114. if (isScroll) {
  115. this.data.truckLoadCurrentPage += 1;
  116. } else {
  117. this.data.truckLoadCurrentPage = 1;
  118. }
  119. let res = await postApi("/voyage/getCarLoadRecordList", {
  120. portId: this.data.currentPortId,
  121. voyageId: this.data.id,
  122. size: this.data.pageSize,
  123. currentPage: this.data.truckLoadCurrentPage,
  124. isClient: wx.getStorageSync("isClient"),
  125. loginAccountId: wx.getStorageSync("loginAccountId"),
  126. });
  127. this.setData({
  128. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  129. });
  130. if (0 == res.data.status) {
  131. if (isScroll) {
  132. let truckLoadList = [...this.data.truckLoadList, ...res.data.result];
  133. for (let i of truckLoadList) {
  134. i.weighTime = this.cutTimeString(i.weighTime);
  135. }
  136. this.setData({
  137. truckLoadList,
  138. truckLoadTotal: res.data.total,
  139. });
  140. } else {
  141. let truckLoadList = res.data.result;
  142. for (let i of truckLoadList) {
  143. i.weighTime = this.cutTimeString(i.weighTime);
  144. }
  145. this.setData({
  146. truckLoadList,
  147. truckLoadTotal: res.data.total,
  148. });
  149. }
  150. } else {
  151. // wx.showToast({
  152. // icon: 'none',
  153. // title: res.data.msg,
  154. // })
  155. }
  156. },
  157. async getDischargeList(isScroll) {
  158. if (isScroll) {
  159. this.data.shipDischargeCurrentPage += 1;
  160. } else {
  161. this.data.shipDischargeCurrentPage = 1;
  162. }
  163. let res = await postApi("/voyage/getDischargeList", {
  164. portId: this.data.currentPortId,
  165. voyageId: this.data.id,
  166. size: this.data.pageSize,
  167. currentPage: this.data.shipDischargeCurrentPage,
  168. isClient: wx.getStorageSync("isClient"),
  169. loginAccountId: wx.getStorageSync("loginAccountId"),
  170. });
  171. this.setData({
  172. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  173. });
  174. if (0 == res.data.status) {
  175. if (isScroll) {
  176. let shipDischargeList = [
  177. ...this.data.shipDischargeList,
  178. ...res.data.result,
  179. ];
  180. for (let i of shipDischargeList) {
  181. i.dischargeTime = this.cutTimeString(i.dischargeTime);
  182. }
  183. this.setData({
  184. shipDischargeList,
  185. shipDischargeTotal: res.data.total,
  186. });
  187. } else {
  188. let shipDischargeList = res.data.result;
  189. for (let i of shipDischargeList) {
  190. i.dischargeTime = this.cutTimeString(i.dischargeTime);
  191. }
  192. this.setData({
  193. shipDischargeList,
  194. shipDischargeTotal: res.data.total,
  195. });
  196. }
  197. } else {
  198. // wx.showToast({
  199. // icon: "none",
  200. // title: res.data.msg,
  201. // })
  202. }
  203. },
  204. previewImage(e) {
  205. let { src } = e.currentTarget.dataset;
  206. wx.previewImage({
  207. current: src, // 当前显示图片的http链接
  208. urls: [src], // 需要预览的图片http链接列表
  209. });
  210. },
  211. changeInfoType(e) {
  212. let { type } = e.currentTarget.dataset;
  213. this.setData({
  214. infoType: type,
  215. truckLoadCurrentPage: 1,
  216. shipDischargeCurrentPage: 1,
  217. shipDischargeList: [],
  218. truckLoadList: [],
  219. shipDischargeTotal: 0,
  220. truckLoadTotal: 0,
  221. });
  222. if (type == "ship") {
  223. this.getDischargeList();
  224. } else {
  225. this.getCarLoadRecordList();
  226. }
  227. },
  228. cutTimeString(str) {
  229. let index = str.indexOf(" ");
  230. return index == -1 ? str : str.substring(0, index);
  231. },
  232. changeBottomPage() {
  233. if (this.data.infoType == "ship") {
  234. this.getDischargeList(true);
  235. } else {
  236. this.getCarLoadRecordList(true);
  237. }
  238. },
  239. scrollShip() {
  240. if (
  241. this.data.shipDischargeTotal == 0 ||
  242. this.data.shipDischargeTotal <=
  243. this.data.pageSize * this.data.shipDischargeCurrentPage
  244. )
  245. return;
  246. this.getDischargeList(true);
  247. },
  248. scrollTruck() {
  249. if (
  250. this.data.truckLoadTotal == 0 ||
  251. this.data.truckLoadTotal <=
  252. this.data.pageSize * this.data.truckLoadCurrentPage
  253. )
  254. return;
  255. this.getCarLoadRecordList(true);
  256. },
  257. changePort(e) {
  258. let currentPortId = e.target.dataset.id;
  259. this.setData({
  260. currentPortId,
  261. shipDischargeList: [],
  262. truckLoadList: [],
  263. });
  264. if (this.data.infoType == "ship") {
  265. this.getDischargeList();
  266. } else {
  267. this.getCarLoadRecordList();
  268. }
  269. },
  270. onShareAppMessage() {
  271. let id = wx.getStorageSync("voyageDetailId");
  272. return {
  273. title: "真实 实时 精准",
  274. path: `/pages/sharePage/sharePage?id=${id}`,
  275. };
  276. },
  277. onLoad(options) {
  278. let { id } = options;
  279. wx.setStorageSync("voyageDetailId", id);
  280. this.setData({
  281. id,
  282. });
  283. this.getVoyageDetail();
  284. },
  285. });