detail.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. // pages/voyages/detail/detail.js
  2. import { postApi } from "../../../apis/api";
  3. import { uploadImage } from "../../../utils/uploadImage";
  4. Page({
  5. data: {
  6. id: "",
  7. tab: 1,
  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: 30,
  31. latitude: 31.891992,
  32. longitude: 120.551369,
  33. currentPortId: 0,
  34. dischargeModal: false,
  35. currentDischargePortId: "",
  36. currentDischargePort: "",
  37. tab2disabled: false,
  38. currentDischargeIndex: 0,
  39. tab3CurrentDischargeIndex: 0,
  40. uploadBillVisable: true,
  41. currentBeforePortIndex: 0,
  42. beforePorts: [],
  43. },
  44. changeTab(e) {
  45. let { tab } = e.currentTarget.dataset;
  46. this.setData({
  47. tab,
  48. });
  49. },
  50. async getVoyageDetail() {
  51. let res = await postApi("/voyage/detail", {
  52. voyageId: this.data.id,
  53. loginAccountId: wx.getStorageSync("loginAccountId"),
  54. });
  55. if (res.data.status == 0) {
  56. let { coordinates, medias, policys, voyage, waybills } = res.data.result;
  57. if (coordinates.length) {
  58. let points = [];
  59. for (let i of coordinates) {
  60. points.push({
  61. latitude: i.latitude,
  62. longitude: i.longitude,
  63. });
  64. }
  65. let { latitude, longitude } = points[points.length - 1];
  66. this.data.latitude = latitude;
  67. this.data.longitude = longitude;
  68. this.data.polyline[0].points = points;
  69. let id = 1;
  70. for (let i of points) {
  71. this.data.markers.push({
  72. id: id + 1,
  73. latitude: i.latitude,
  74. longitude: i.longitude,
  75. iconPath:
  76. "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
  77. height: 20,
  78. width: 20,
  79. });
  80. }
  81. this.setData({
  82. polyline: this.data.polyline,
  83. markers: this.data.markers,
  84. latitude: this.data.latitude,
  85. longitude: this.data.longitude,
  86. points,
  87. });
  88. }
  89. // voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime)
  90. // voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime)
  91. // voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime)
  92. // voyage.setSailTime = this.subTimeStr(voyage.setSailTime)
  93. // voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime)
  94. let dischargePortIds = voyage.dischargePortIds.split(",");
  95. let dischargePorts = voyage.dischargePorts.split(",");
  96. let discLength = dischargePortIds.length;
  97. for (let item of voyage.voyageDetails) {
  98. item.setSailTime = this.subTimeStr(item.setSailTime);
  99. item.expectedArrivalTime = this.subTimeStr(item.expectedArrivalTime);
  100. item.actualArrivalTime = this.subTimeStr(item.actualArrivalTime);
  101. item.dischargeStartTime = this.subTimeStr(item.dischargeStartTime);
  102. item.dischargeEndTime = this.subTimeStr(item.dischargeEndTime);
  103. }
  104. this.setData({
  105. coordinates,
  106. medias,
  107. policys,
  108. ...voyage,
  109. waybills,
  110. currentPortId: voyage?.voyageDetails[0].portId,
  111. dischargePortIds,
  112. dischargePorts,
  113. discLength,
  114. tab2disabled: voyage.voyageStatus == 2,
  115. });
  116. this.getCarLoadRecordList();
  117. this.getDischargeList();
  118. } else {
  119. wx.showToast({
  120. title: "获取详情失败!",
  121. icon: "error",
  122. });
  123. }
  124. },
  125. subTimeStr(str) {
  126. if (!str || typeof str != "string") return;
  127. let index = str.indexOf(" ");
  128. return str.substring(0, index);
  129. },
  130. async getCarLoadRecordList(isScroll) {
  131. if (isScroll) {
  132. this.data.truckLoadCurrentPage += 1;
  133. } else {
  134. this.data.truckLoadCurrentPage = 1;
  135. }
  136. let res = await postApi("/voyage/getCarLoadRecordList", {
  137. portId: this.data.currentPortId,
  138. voyageId: this.data.id,
  139. size: this.data.pageSize,
  140. currentPage: this.data.truckLoadCurrentPage,
  141. loginAccountId: wx.getStorageSync("loginAccountId"),
  142. });
  143. this.setData({
  144. truckLoadCurrentPage: this.data.truckLoadCurrentPage,
  145. });
  146. if (0 == res.data.status) {
  147. if (isScroll) {
  148. let truckLoadList = [...this.data.truckLoadList, ...res.data.result];
  149. for (let i of truckLoadList) {
  150. i.weighTime = this.cutTimeString(i.weighTime);
  151. }
  152. this.setData({
  153. truckLoadList,
  154. truckLoadTotal: res.data.total,
  155. });
  156. } else {
  157. let truckLoadList = res.data.result;
  158. for (let i of truckLoadList) {
  159. i.weighTime = this.cutTimeString(i.weighTime);
  160. }
  161. this.setData({
  162. truckLoadList,
  163. truckLoadTotal: res.data.total,
  164. });
  165. }
  166. } else {
  167. // wx.showToast({
  168. // icon: 'none',
  169. // title: res.data.msg,
  170. // })
  171. }
  172. },
  173. async getDischargeList(isScroll) {
  174. if (isScroll) {
  175. this.data.shipDischargeCurrentPage += 1;
  176. } else {
  177. this.data.shipDischargeCurrentPage = 1;
  178. }
  179. let res = await postApi("/voyage/getDischargeList", {
  180. portId: this.data.currentPortId,
  181. voyageId: this.data.id,
  182. size: this.data.pageSize,
  183. currentPage: this.data.shipDischargeCurrentPage,
  184. loginAccountId: wx.getStorageSync("loginAccountId"),
  185. });
  186. this.setData({
  187. shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
  188. });
  189. if (0 == res.data.status) {
  190. if (isScroll) {
  191. let shipDischargeList = [
  192. ...this.data.shipDischargeList,
  193. ...res.data.result,
  194. ];
  195. for (let i of shipDischargeList) {
  196. i.dischargeTime = this.cutTimeString(i.dischargeTime);
  197. }
  198. this.setData({
  199. shipDischargeList,
  200. shipDischargeTotal: res.data.total,
  201. });
  202. } else {
  203. let shipDischargeList = res.data.result;
  204. for (let i of shipDischargeList) {
  205. i.dischargeTime = this.cutTimeString(i.dischargeTime);
  206. }
  207. this.setData({
  208. shipDischargeList,
  209. shipDischargeTotal: res.data.total,
  210. });
  211. }
  212. } else {
  213. // wx.showToast({
  214. // icon: "none",
  215. // title: res.data.msg,
  216. // })
  217. }
  218. },
  219. previewImage(e) {
  220. let { src, files } = e.currentTarget.dataset;
  221. let urls = [];
  222. if (this.data.infoType == "ship" && this.data.tab == 3) {
  223. urls = files.map((item) => {
  224. return item.viewUrl;
  225. });
  226. } else {
  227. urls = [src];
  228. }
  229. wx.previewImage({
  230. current: src, // 当前显示图片的http链接
  231. urls, // 需要预览的图片http链接列表
  232. });
  233. },
  234. changeInfoType(e) {
  235. let { type } = e.currentTarget.dataset;
  236. this.setData({
  237. infoType: type,
  238. truckLoadCurrentPage: 1,
  239. shipDischargeCurrentPage: 1,
  240. shipDischargeList: [],
  241. truckLoadList: [],
  242. shipDischargeTotal: 0,
  243. truckLoadTotal: 0,
  244. });
  245. if (type == "ship") {
  246. this.getDischargeList();
  247. } else {
  248. this.getCarLoadRecordList();
  249. }
  250. },
  251. cutTimeString(str) {
  252. let index = str.indexOf(" ");
  253. return index == -1 ? str : str.substring(0, index);
  254. },
  255. changeBottomPage() {
  256. if (this.data.infoType == "ship") {
  257. this.getDischargeList(true);
  258. } else {
  259. this.getCarLoadRecordList(true);
  260. }
  261. },
  262. scrollShip() {
  263. if (
  264. this.data.shipDischargeTotal == 0 ||
  265. this.data.shipDischargeTotal <=
  266. this.data.pageSize * this.data.shipDischargeCurrentPage
  267. )
  268. return;
  269. this.getDischargeList(true);
  270. },
  271. scrollTruck() {
  272. if (
  273. this.data.truckLoadTotal == 0 ||
  274. this.data.truckLoadTotal <=
  275. this.data.pageSize * this.data.truckLoadCurrentPage
  276. )
  277. return;
  278. this.getCarLoadRecordList(true);
  279. },
  280. changePort(e) {
  281. let tab3CurrentDischargeIndex = e.detail;
  282. this.setData({
  283. tab3CurrentDischargeIndex,
  284. currentPortId: this.data.voyageDetails[tab3CurrentDischargeIndex].portId,
  285. shipDischargeList: [],
  286. truckLoadList: [],
  287. });
  288. if (this.data.infoType == "ship") {
  289. this.getDischargeList();
  290. } else {
  291. this.getCarLoadRecordList();
  292. }
  293. },
  294. showAddDischargePortModal() {
  295. let beforePorts = [
  296. {
  297. portName: this.data.loadPort,
  298. portId: 0,
  299. },
  300. ];
  301. for (let i in this.data.dischargePorts) {
  302. beforePorts.push({
  303. portName: this.data.dischargePorts[i],
  304. portId: this.data.dischargePortIds[i],
  305. });
  306. }
  307. this.setData({
  308. dischargeModal: true,
  309. beforePorts,
  310. });
  311. },
  312. onShareAppMessage() {
  313. let id = wx.getStorageSync("voyageDetailId");
  314. return {
  315. title: "真实 实时 精准",
  316. path: `/pages/sharePage/sharePage?id=${id}`,
  317. };
  318. },
  319. doNothing() {},
  320. cancelAddDischargePort() {
  321. this.setData({
  322. dischargeModal: false,
  323. currentDischargePortId: "",
  324. currentDischargePort: "",
  325. currentBeforePortIndex: 0,
  326. beforePorts: [],
  327. });
  328. },
  329. selectDischargePort(e) {
  330. if (this.checkPort(e.detail.label, this.data.beforePorts, "portName"))
  331. return;
  332. this.setData({
  333. currentDischargePortId: e.detail.value,
  334. currentDischargePort: e.detail.label,
  335. });
  336. },
  337. deleteDischargePort(e) {
  338. let { index } = e.currentTarget.dataset;
  339. wx.showModal({
  340. title: `确认删除: ${this.data.dischargePorts[index]}?`,
  341. content: `此操作会同时删除当前港口下的记录`,
  342. success: async (res) => {
  343. if (res.confirm) {
  344. let { data } = await postApi("/voyage/deletePort", {
  345. voyageId: this.data.id,
  346. portId: this.data.dischargePortIds[index],
  347. });
  348. if (data.status == 0) {
  349. wx.showToast({
  350. title: "删除成功",
  351. });
  352. }
  353. this.getVoyageDetail();
  354. }
  355. },
  356. });
  357. },
  358. checkPort(portName = -1, ports = [], attr) {
  359. let b = ports.some((item) => {
  360. return item[attr] == portName;
  361. });
  362. if (b) {
  363. wx.showToast({
  364. title: "港口已存在",
  365. icon: "error",
  366. });
  367. }
  368. return b;
  369. },
  370. async addDischargePort() {
  371. let { currentDischargePortId, currentDischargePort } = this.data;
  372. if (!currentDischargePortId || !currentDischargePort) {
  373. wx.showToast({
  374. title: "请选择港口",
  375. icon: "error",
  376. });
  377. return;
  378. }
  379. let res = await postApi("/voyage/addNewPort", {
  380. loginAccountId: wx.getStorageSync("loginAccountId"),
  381. voyageId: this.data.id,
  382. previousPortId: this.data.beforePorts[this.data.currentBeforePortIndex]
  383. .portId,
  384. portId: this.data.currentDischargePortId,
  385. });
  386. this.getVoyageDetail();
  387. this.cancelAddDischargePort();
  388. },
  389. bindDischargePortChange(e) {
  390. let { index, param } = e.currentTarget.dataset;
  391. this.data.voyageDetails[index][param] = e.detail.value;
  392. this.setData({
  393. voyageDetails: this.data.voyageDetails,
  394. });
  395. },
  396. changeDischargeTab(e) {
  397. let { detail: currentDischargeIndex } = e;
  398. this.setData({
  399. currentDischargeIndex,
  400. });
  401. },
  402. async updateVoyage() {
  403. for (let i of this.data.voyageDetails) {
  404. Object.keys(i).forEach(function (key) {
  405. if (typeof i[key] == "string") {
  406. i[key] = i[key].replaceAll("-", "/");
  407. if (i[key].length == 10) i[key] = i[key] + " 00:00:00";
  408. }
  409. });
  410. }
  411. if (
  412. this.data.arrivalLoadPortTime &&
  413. this.data.arrivalLoadPortTime.length == 10
  414. )
  415. this.data.arrivalLoadPortTime =
  416. this.data.arrivalLoadPortTime + " 00:00:00";
  417. if (this.data.actualLoadTons && this.data.actualLoadTons.length == 10)
  418. this.data.actualLoadTons = this.data.actualLoadTons + " 00:00:00";
  419. if (this.data.actualLoadPieces && this.data.actualLoadPieces.length == 10)
  420. this.data.actualLoadPieces = this.data.actualLoadPieces + " 00:00:00";
  421. if (this.data.loadStartTime && this.data.loadStartTime.length == 10)
  422. this.data.loadStartTime = this.data.loadStartTime + " 00:00:00";
  423. if (this.data.loadEndTime && this.data.loadEndTime.length == 10)
  424. this.data.loadEndTime = this.data.loadEndTime + " 00:00:00";
  425. let res = await postApi("/voyage/update", {
  426. ...this.data,
  427. loginAccountId: wx.getStorageSync("loginAccountId"),
  428. });
  429. if (res.data.status == 0) {
  430. wx.showToast({
  431. title: res.data.msg,
  432. });
  433. }
  434. this.getVoyageDetail();
  435. },
  436. async uploadBill(e) {
  437. let { type } = e.currentTarget.dataset;
  438. let postData = {
  439. type,
  440. voyageId: this.data.id,
  441. };
  442. let res = await uploadImage("/voyage/uploadVoyageWayBill", postData);
  443. this.getVoyageDetail();
  444. },
  445. async completeVoyage() {
  446. wx.showModal({
  447. title: "确认完成航次?",
  448. success: async (e) => {
  449. if (e.confirm) {
  450. let res = await postApi("/voyage/finish", {
  451. loginAccountId: wx.getStorageSync("loginAccountId"),
  452. voyageId: this.data.id,
  453. });
  454. if (res.data.status == 0) {
  455. wx.showToast({
  456. title: "成功!",
  457. });
  458. this.getVoyageDetail();
  459. }
  460. }
  461. },
  462. });
  463. },
  464. async cancelVoyage() {
  465. wx.showModal({
  466. title: "确认取消航次?",
  467. success: async (e) => {
  468. if (e.confirm) {
  469. let res = await postApi("/voyage/cancel", {
  470. loginAccountId: wx.getStorageSync("loginAccountId"),
  471. id: this.data.id,
  472. });
  473. if (res.data.status == 0) {
  474. wx.showToast({
  475. title: "取消成功!",
  476. });
  477. wx.switchTab({
  478. url: "/pages/voyageManage/voyageManage",
  479. });
  480. }
  481. }
  482. },
  483. });
  484. },
  485. goTo(e) {
  486. let { url } = e.currentTarget.dataset;
  487. let { id, currentPortId } = this.data;
  488. wx.navigateTo({
  489. url: `${url}?voyageId=${id}&portId=${currentPortId}`,
  490. });
  491. },
  492. uploadBillCanvas() {
  493. wx.navigateTo({
  494. url: `/pages/voyageManage/takeBill/takeBill?type=1&voyageId=${this.data.id}`,
  495. });
  496. },
  497. loadEndTimeChange(e) {
  498. if (!this.data.voyageDetails[0].setSailTime)
  499. this.data.voyageDetails[0].setSailTime = e.detail.value;
  500. this.setData({
  501. voyageDetails: this.data.voyageDetails,
  502. });
  503. },
  504. bindBeforePortChange(e) {
  505. this.setData({
  506. currentBeforePortIndex: e.detail.value,
  507. });
  508. },
  509. onLoad(options) {
  510. let { id } = options;
  511. wx.setStorageSync("voyageDetailId", id);
  512. this.setData({
  513. id,
  514. });
  515. this.getVoyageDetail();
  516. },
  517. onShow() {
  518. if (wx.getStorageSync("addStatus") == "success") {
  519. this.getVoyageDetail();
  520. wx.removeStorageSync("addStatus");
  521. }
  522. },
  523. });