sharePage.js 8.8 KB

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