sharePage.js 9.1 KB

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