const { postApi } = require("../../../apis/api") const app = getApp() // pages/voyageManage/createVoyage/createVoyage.js Page({ data: { defaultParams: { }, dischargePorts: [{}], voyage: {}, startTime: '', currentCargoOwnerId: 0, currentShipName: '' }, selectShip(e) { this.data.voyage.shipId = e.detail.value this.setData({ currentShipName: e.detail.label }) }, selectCargoOwner(e) { this.data.voyage.cargoOwnerId = e.detail.value this.setData({ currentCargoOwnerId: this.data.voyage }) let cargoCmp = this.selectComponent('#cargoCmp'); cargoCmp._getList({ cargoOwnerId: e.detail.value }) }, selectCargo(e) { console.log(e) this.data.voyage.cargoId = e.detail.value this.data.voyage.cargo = e.detail.label }, selectLoadPort(e) { this.data.voyage.loadPortId = e.detail.value this.data.voyage.loadPort = e.detail.label this.setData({ loadPort: e.detail.label }) }, selectDiscPort(e) { console.log(e) let { label: dischargePort, value: id } = e.detail if (e.currentTarget.dataset.index || e.currentTarget.dataset.index == 0) { this.data.dischargePorts[e.currentTarget.dataset.index] = { dischargePort, id, reasonableUnloadingDays: 0 } } else { this.data.dischargePorts.push({ dischargePort, id, reasonableUnloadingDays: 0 }) } this.setData({ dischargePorts: this.data.dischargePorts, }) }, addDischargePort() { let dischargePorts = this.data.dischargePorts dischargePorts.push({}) this.setData({ dischargePorts }) }, deleteDischargePort(e) { let dischargePorts = this.data.dischargePorts if (dischargePorts.length == 1) { dischargePorts = [{}] } else { dischargePorts.splice(e.currentTarget.dataset.index, 1) } this.setData({ dischargePorts }) }, checkData() { if (!this.data.voyage.shipId) { wx.showToast({ title: '请选择船舶', icon: "error" }) return } if (!this.data.voyage.cargoOwnerId) { wx.showToast({ title: '请选择货主', icon: "error" }) return } if (!this.data.voyage.cargo) { wx.showToast({ title: '请选择货种', icon: "error" }) return } if (!this.data.voyage.loadPort || !this.data.voyage.loadPortId) { wx.showToast({ title: '请选择装货港', icon: "error" }) return } if (!this.data.dischargePorts[0].id) { wx.showToast({ title: '请添加卸货港', icon: "error" }) return } if (!this.data.tons) { wx.showToast({ title: '请输入吨位', icon: "error" }) return } if (!this.data.reasonableUnloadingDays) { wx.showToast({ title: '请输入合理卸货天数', icon: "none" }) return } // if(!this.data.pieces){ // wx.showToast({ // title: '请输入件数', // icon:"error" // }) // return // } // if (!this.data.startTime) { // wx.showToast({ // title: '请选择开始时间', // icon: "error" // }) // return // } return true }, async createVoyage() { if (!this.checkData()) return wx.showLoading({ title: '正在提交...', mask: true, success: (res) => {}, fail: (res) => {}, complete: (res) => {}, }) let startTime = this.data.startTime.replaceAll('-', '/') let postData = { ...this.data.voyage, loginAccountId: wx.getStorageSync('loginAccountId'), dischargePorts: this.data.dischargePorts, startTime, tons: this.data.tons, pieces: this.data.pieces, reasonableUnloadingDays: this.data.reasonableUnloadingDays } let res = await postApi('/voyage/add', postData) wx.hideLoading({ success: (res) => {}, }) if (res.data.status == 0) { wx.showToast({ title: res.data.msg, }) app.globalData.maintab = 1 wx.switchTab({ url: '/pages/voyageManage/voyageManage', }) } else { wx.showToast({ title: res.data.msg, icon: "error" }) } }, onShow() { this.setData({ defaultParams: { loginAccountId: wx.getStorageSync('loginAccountId') } }) }, onLoad(options) { if (options) { let { shipName, shipId } = options this.setData({ currentShipName: shipName, voyage: { shipName, shipId } }) } } })