| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- const {
- postApi
- } = require("../../../apis/api")
- const app = getApp()
- // pages/voyageManage/createVoyage/createVoyage.js
- Page({
- data: {
- defaultParams: {
- },
- dischargePorts: [''],
- dischargePortIds: [''],
- voyage: {},
- startTime: ''
- },
- selectShip(e) {
- console.log(e)
- this.data.voyage.shipId = e.detail.value
- },
- selectCargoOwner(e) {
- this.data.voyage.cargoOwnerId = e.detail.value
- },
- selectCargo(e) {
- this.data.voyage.cargo = e.detail.value
- },
- selectLoadPort(e) {
- this.data.voyage.loadPortId = e.detail.value
- this.data.voyage.loadPort = e.detail.label
- },
- selectDiscPort(e) {
- this.data.dischargePortIds[e.currentTarget.dataset.index] = e.detail.value
- this.data.dischargePorts[e.currentTarget.dataset.index] = e.detail.label
- this.setData({
- dischargePorts: this.data.dischargePorts,
- dischargePortIds: this.data.dischargePortIds
- })
- },
- addDischargePort() {
- let dischargePorts = this.data.dischargePorts
- let dischargePortIds = this.data.dischargePortIds
- dischargePorts.push('')
- dischargePortIds.push('')
- this.setData({
- dischargePortIds,
- dischargePorts
- })
- },
- deleteDischargePort(e) {
- let dischargePorts = this.data.dischargePorts
- let dischargePortIds = this.data.dischargePortIds
- if (dischargePorts.length == 1) {
- dischargePortIds = ['']
- dischargePorts = ['']
- } else {
- dischargePorts.splice(e.currentTarget.dataset.index, 1)
- dischargePortIds.splice(e.currentTarget.dataset.index, 1)
- }
- this.setData({
- dischargePortIds,
- 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.dischargePortIds.length || !this.data.dischargePorts.length) {
- wx.showToast({
- title: '请添加卸货港',
- icon: "error"
- })
- return
- }
- if (!this.data.tons) {
- wx.showToast({
- title: '请输入吨位',
- icon: "error"
- })
- 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 dischargePortIds = this.data.dischargePortIds.filter(item => {
- return item
- })
- let dischargePorts = this.data.dischargePorts.filter(item => {
- return item
- })
- let startTime = this.data.startTime.replaceAll('-', '/')
- let postData = {
- ...this.data.voyage,
- loginAccountId: wx.getStorageSync('loginAccountId'),
- dischargePortIds: dischargePortIds.join(','),
- dischargePorts: dischargePorts.join(','),
- startTime,
- tons: this.data.tons,
- pieces: this.data.pieces,
- }
- let res = await postApi('/voyage/backstage/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')
- }
- })
- }
- })
|