| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- 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
- }
- })
- }
- }
- })
|