| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- // pages/voyages/detail/detail.js
- import {
- postApi
- } from "../../../apis/api"
- import {
- uploadImage
- } from "../../../utils/uploadImage"
- Page({
- data: {
- id: '',
- tab: 1,
- shipDischargeCurrentPage: 1,
- truckLoadCurrentPage: 1,
- coordinates: [],
- medias: [],
- policys: [],
- voyage: {},
- waybills: [],
- infoType: 'ship',
- shipDischargeList: [],
- truckLoadList: [],
- shipDischargeTotal: 0,
- truckLoadTotal: 0,
- polyline: [{
- points: [],
- width: 2,
- dottedLine: true,
- color: "#eb2f06"
- }],
- markers: [],
- points: [],
- pageSize: 20,
- latitude: 31.891992,
- longitude: 120.551369,
- currentPortId: 0,
- dischargeModal: false,
- currentDischargePortId: '',
- currentDischargePort: '',
- tab2disabled: false,
- currentDischargeIndex: 0,
- uploadBillVisable: true
- },
- changeTab(e) {
- let {
- tab
- } = e.currentTarget.dataset
- this.setData({
- tab
- })
- },
- async getVoyageDetail() {
- let res = await postApi("/voyage/detail", {
- voyageId: this.data.id,
- loginAccountId: wx.getStorageSync('loginAccountId'),
- })
- let {
- coordinates,
- medias,
- policys,
- voyage,
- waybills
- } = res.data.result
- if (coordinates.length) {
- let points = []
- for (let i of coordinates) {
- points.push({
- latitude: i.latitude,
- longitude: i.longitude
- })
- }
- let {
- latitude,
- longitude
- } = points[points.length - 1]
- this.data.latitude = latitude
- this.data.longitude = longitude
- this.data.polyline[0].points = points
- let id = 1
- for (let i of points) {
- this.data.markers.push({
- id: id + 1,
- latitude: i.latitude,
- longitude: i.longitude,
- iconPath: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/red-circle.png?sign=6d208881376358fb4111aa6d7f1a7846&t=1647934972",
- height: 20,
- width: 20
- })
- }
- this.setData({
- polyline: this.data.polyline,
- markers: this.data.markers,
- // latitude: this.data.latitude,
- // longitude: this.data.lo fngitude,
- points
- })
- }
- voyage.arrivalLoadPortTime = this.subTimeStr(voyage.arrivalLoadPortTime)
- voyage.loadStartTime = this.subTimeStr(voyage.loadStartTime)
- voyage.loadEndTime = this.subTimeStr(voyage.loadEndTime)
- voyage.setSailTime = this.subTimeStr(voyage.setSailTime)
- voyage.expectedArrivalTime = this.subTimeStr(voyage.expectedArrivalTime)
- let dischargePortIds = voyage.dischargePortIds.split(',')
- let dischargePorts = voyage.dischargePorts.split(',')
- let discLength = dischargePortIds.length
- for (let item of voyage.voyageDetails) {
- item.setSailTime = this.subTimeStr(item.setSailTime)
- item.expectedArrivalTime = this.subTimeStr(item.expectedArrivalTime)
- item.actualArrivalTime = this.subTimeStr(item.actualArrivalTime)
- item.dischargeStartTime = this.subTimeStr(item.dischargeStartTime)
- item.dischargeEndTime = this.subTimeStr(item.dischargeEndTime)
- }
- this.setData({
- coordinates,
- medias,
- policys,
- ...voyage,
- waybills,
- currentPortId: voyage?.voyageDetails[0].portId,
- dischargePortIds,
- dischargePorts,
- discLength
- })
- this.getCarLoadRecordList()
- this.getDischargeList()
- },
- subTimeStr(str) {
- if (!str || typeof str != "string") return;
- let index = str.indexOf(" ");
- return str.substring(0, index);
- },
- async getCarLoadRecordList(isScroll) {
- if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
- if (isScroll) {
- this.data.truckLoadCurrentPage += 1
- } else {
- this.data.truckLoadCurrentPage = 1
- }
- let res = await postApi("/voyage/getCarLoadRecordList", {
- portId: this.data.currentPortId,
- voyageId: this.data.id,
- size: this.data.pageSize,
- currentPage: this.data.truckLoadCurrentPage,
- loginAccountId: wx.getStorageSync('loginAccountId')
- })
- this.setData({
- truckLoadCurrentPage: this.data.truckLoadCurrentPage,
- })
- if (0 == res.data.status) {
- if (isScroll) {
- let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
- for (let i of truckLoadList) {
- i.weighTime = this.cutTimeString(i.weighTime)
- }
- this.setData({
- truckLoadList,
- truckLoadTotal: res.data.total
- })
- } else {
- let truckLoadList = res.data.result
- for (let i of truckLoadList) {
- i.weighTime = this.cutTimeString(i.weighTime)
- }
- this.setData({
- truckLoadList,
- truckLoadTotal: res.data.total
- })
- }
- } else {
- // wx.showToast({
- // icon: 'none',
- // title: res.data.msg,
- // })
- }
- },
- async getDischargeList(isScroll) {
- if (isScroll) {
- this.data.shipDischargeCurrentPage += 1
- } else {
- this.data.shipDischargeCurrentPage = 1
- }
- let res = await postApi("/voyage/getDischargeList", {
- portId: this.data.currentPortId,
- voyageId: this.data.id,
- size: this.data.pageSize,
- currentPage: this.data.shipDischargeCurrentPage,
- loginAccountId: wx.getStorageSync('loginAccountId')
- })
- this.setData({
- shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
- })
- if (0 == res.data.status) {
- if (isScroll) {
- let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
- for (let i of shipDischargeList) {
- i.dischargeTime = this.cutTimeString(i.dischargeTime)
- }
- this.setData({
- shipDischargeList,
- shipDischargeTotal: res.data.total
- })
- } else {
- let shipDischargeList = res.data.result
- for (let i of shipDischargeList) {
- i.dischargeTime = this.cutTimeString(i.dischargeTime)
- }
- this.setData({
- shipDischargeList,
- shipDischargeTotal: res.data.total
- })
- }
- } else {
- // wx.showToast({
- // icon: "none",
- // title: res.data.msg,
- // })
- }
- },
- previewImage(e) {
- let {
- src
- } = e.currentTarget.dataset
- wx.previewImage({
- current: src, // 当前显示图片的http链接
- urls: [src] // 需要预览的图片http链接列表
- })
- },
- changeInfoType(e) {
- let {
- type
- } = e.currentTarget.dataset
- this.setData({
- infoType: type,
- truckLoadCurrentPage: 1,
- shipDischargeCurrentPage: 1,
- shipDischargeList: [],
- truckLoadList: [],
- shipDischargeTotal: 0,
- truckLoadTotal: 0,
- })
- if (type == "ship") {
- this.getDischargeList()
- } else {
- this.getCarLoadRecordList()
- }
- },
- cutTimeString(str) {
- let index = str.indexOf(' ')
- return index == -1 ? str : str.substring(0, index)
- },
- changeBottomPage() {
- if (this.data.infoType == "ship") {
- this.getDischargeList(true)
- } else {
- this.getCarLoadRecordList(true)
- }
- },
- scrollShip() {
- if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
- this.getDischargeList(true)
- },
- scrollTruck() {
- if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
- this.getCarLoadRecordList(true)
- },
- changePort(e) {
- let currentPortId = e.target.dataset.id
- this.setData({
- currentPortId,
- shipDischargeList: [],
- truckLoadList: [],
- })
- if (this.data.infoType == "ship") {
- this.getDischargeList()
- } else {
- this.getCarLoadRecordList()
- }
- },
- showAddDischargePortModal() {
- this.setData({
- dischargeModal: true
- })
- },
- onShareAppMessage() {
- let id = wx.getStorageSync('voyageDetailId')
- return {
- title: '真实 实时 精准',
- path: `/pages/sharePage/sharePage?id=${id}`
- }
- },
- doNothing() {
- },
- cancelAddDischargePort() {
- this.setData({
- currentDischargePortId: '',
- currentDischargePort: '',
- dischargeModal: false
- })
- },
- selectDischargePort(e) {
- this.setData({
- currentDischargePortId: e.detail.value,
- currentDischargePort: e.detail.label
- })
- },
- async addDischargePort() {
- let {
- currentDischargePortId,
- currentDischargePort
- } = this.data
- if (!currentDischargePortId || !currentDischargePort) {
- wx.showToast({
- title: '请选择港口',
- icon: "error"
- })
- return
- }
- let res = await postApi("/voyage/backstage/addNewPort", {
- loginAccountId: wx.getStorageSync('loginAccountId'),
- voyageId: this.data.id,
- portId: this.data.currentDischargePortId
- })
- this.cancelAddDischargePort()
- },
- bindDischargePortChange(e) {
- let {
- index,
- param
- } = e.currentTarget.dataset
- this.data.voyageDetails[index][param] = e.detail.value
- this.setData({
- voyageDetails: this.data.voyageDetails
- })
- },
- changeDischargeTab(e) {
- let {
- index: currentDischargeIndex
- } = e.currentTarget.dataset
- this.setData({
- currentDischargeIndex
- })
- },
- async updateVoyage() {
- for (let i of this.data.voyageDetails) {
- Object.keys(i).forEach(function (key) {
- console.log(i[key])
- if ((typeof i[key]) == 'string') {
- i[key] = i[key].replaceAll('-', '/')
- if (i[key].length == 10) i[key] = i[key] + " 00:00:00"
- }
- })
- }
- if (this.data.arrivalLoadPortTime && this.data.arrivalLoadPortTime.length == 10) this.data.arrivalLoadPortTime = this.data.arrivalLoadPortTime + " 00:00:00"
- if (this.data.actualLoadTons && this.data.actualLoadTons.length == 10) this.data.actualLoadTons = this.data.actualLoadTons + " 00:00:00"
- if (this.data.actualLoadPieces && this.data.actualLoadPieces.length == 10) this.data.actualLoadPieces = this.data.actualLoadPieces + " 00:00:00"
- if (this.data.loadStartTime && this.data.loadStartTime.length == 10) this.data.loadStartTime = this.data.loadStartTime + " 00:00:00"
- if (this.data.loadEndTime && this.data.loadEndTime.length == 10) this.data.loadEndTime = this.data.loadEndTime + " 00:00:00"
- let res = await postApi("/voyage/backstage/update", {
- ...this.data,
- loginAccountId: wx.getStorageSync('loginAccountId')
- })
- console.log(res)
- },
- async uploadBill(e) {
- let {
- type
- } = e.currentTarget.dataset
- let postData = {
- type,
- voyageId: this.data.id
- }
- let res = await uploadImage("/voyage/uploadVoyageWayBill", postData)
- this.getVoyageDetail()
- },
- async completeVoyage() {
- wx.showModal({
- title: "确认完成航次?",
- success: async e => {
- if (e.confirm) {
- let res = await postApi("/voyage/backstage/finish", {
- loginAccountId: wx.getStorageSync('loginAccountId'),
- voyageId: this.data.id
- })
- if (res.data.status == 0) {
- wx.showToast({
- title: '成功!',
- })
- this.getVoyageDetail()
- }
- }
- }
- })
- },
- async cancelVoyage() {
- wx.showModal({
- title: "确认取消航次?",
- success: async e => {
- if (e.confirm) {
- let res = await postApi("/voyage/backstage/cancel", {
- loginAccountId: wx.getStorageSync('loginAccountId'),
- id: this.data.id
- })
- if (res.data.status == 0) {
- wx.showToast({
- title: '取消成功!',
- })
- wx.switchTab({
- url: '/pages/voyageManage/voyageManage',
- })
- }
- }
- }
- })
- },
- goTo(e) {
- let {
- url
- } = e.currentTarget.dataset
- let {
- id,
- currentPortId
- } = this.data
- wx.navigateTo({
- url: `${url}?voyageId=${id}&portId=${currentPortId}`,
- })
- },
- onLoad(options) {
- let {
- id
- } = options
- wx.setStorageSync('voyageDetailId', id)
- this.setData({
- id
- })
- this.getVoyageDetail()
- },
- onShow() {
- if (wx.getStorageSync('addStatus') == "success") {
- this.getVoyageDetail()
- wx.removeStorageSync('addStatus')
- }
- }
- })
|