cusClearance.vue 16.3 KB
Newer Older
lanbaoming's avatar
lanbaoming committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
<template>
  <div>
    <el-form ref="cusClearanceForm" :rules="rules" :model="cusClearanceObj" label-width="160px">
      <el-form-item :label="$t('清关情况')" prop="arriveType">
        <el-radio-group v-model="cusClearanceObj.clearanceType">
          <el-radio :label="0">{{ $t('一次清关') }}</el-radio>
          <el-radio :label="1">{{ $t('多次清关') }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item :label="$t('选择订单')" prop="clearanceOrderIdList" v-show="cusClearanceObj.clearanceType == 1">
        <span v-for="order in selectOrders" :key="order.id">{{ order.orderNo }} </span>
        <el-button type="primary" @click="orderdialogVisible = true">{{ $t('订单列表') }}</el-button>
      </el-form-item>
      <el-form-item :label="$t('已清关订单')" v-show="cusClearanceObj.clearanceType == 1">
        <span v-for="order in cusClearanceObj.clearanceOrderList" :key="order.id">{{ order.orderNo }} </span>
      </el-form-item>

      <div v-if="cusClearanceObj.clearanceType == 1">
        <el-form ref="airArrivalForm" :rules="airArrivalrules" :model="airArrivalInfo" label-width="160px">
          <el-form-item :label="$t('实际二程起飞时间')" prop="actSecondTime">
            <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="airArrivalInfo.actSecondTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
          <el-form-item :label="$t('预计到港时间')" prop="estTime">
            <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="airArrivalInfo.estTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
          <el-form-item :label="$t('实际到港时间')" prop="actTime">
            <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="airArrivalInfo.actTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
        </el-form>
      </div>

      <el-form-item :label="$t('预计清关时间')" prop="clEstTime">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="cusClearanceObj.clEstTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('清关时间')" prop="clClearTime">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="cusClearanceObj.clClearTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
        <p class="message-area" v-show="showMsg">
          {{ $t('清关时间与预计时间不符,如有异常请登记') }}
        </p>
      </el-form-item>
    </el-form>

    <el-row class="operate-button">
      <el-button type="primary" @click="onSubmit(1)">{{ $t('保存') }}</el-button>
      <el-button type="success" @click="onSubmit(2)">{{ $t('提交') }}</el-button>
      <el-button @click="cancel">{{ $t('关闭') }}</el-button>
      <el-button type="primary" @click="exceptionReg" :disabled="!showMsg">{{ $t('异常登记') }}</el-button>
    </el-row>

    <!-- 对话框 -->
    <el-dialog custom-class="shipping-dialog" :title="$t('票异常')" :visible.sync="dialogVisible" width="700px" :modal-append-to-body="false" append-to-body destroy-on-close>
      <regError @closeDialog="dialogVisible = false" v-bind="$attrs" />
    </el-dialog>
    <!-- 订单列表 -->
    <el-dialog width="70%" :title="$t('选择订单')" :visible.sync="orderdialogVisible" :modal-append-to-body="false" append-to-body destroy-on-close>
      <el-row :gutter="10">
        <el-col :span="7">
          {{ $t('关键字:') }}
          <el-input style="width: 300px" v-model="searchForm.orderKeyword" :placeholder="$t('请输入订单号、提单号、唛头')" />
        </el-col>
        <el-col :span="5">
          {{ $t('到港状态') }}
          <el-select v-model="searchForm.orderPortStatus">
            <el-option :value="0" :label="$t('未到港')" />
            <el-option :value="1" :label="$t('已到港')" />
          </el-select>
        </el-col>
        <el-col :span="5">
          {{ $t('清关状态') }}
          <el-select v-model="searchForm.orderCustomsClearanceStatus">
            <el-option :value="0" :label="$t('未清关')" />
            <el-option :value="1" :label="$t('已清关')" />
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="searchOrderList"> {{ $t('查询') }}</el-button>
          <el-button type="primary" @click="reloafSearch"> {{ $t('重置') }}</el-button>
        </el-col>
      </el-row>
      <div style="margin-top: 10px">
        <el-button type="primary" @click="multipleSelect">
          {{ $t('批量选择') }}
        </el-button>
      </div>
      <el-table style="margin-top: 10px" :data="statusOrderList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column :label="$t('序号')" type="index" width="50"> </el-table-column>
        <el-table-column :label="$t('订单号')" prop="orderNo" />
        <el-table-column :label="$t('唛头')" prop="marks" />
        <el-table-column :label="$t('提单号')" prop="tidanNo" />
        <el-table-column width="150" :label="$t('总箱数/入仓箱数')">
          <template slot-scope="scope"> {{ scope.row.totalNum }}/{{ scope.row.sumNum }} </template>
        </el-table-column>
        <el-table-column :label="$t('体积/重量')" prop="">
          <template slot-scope="scope"> {{ scope.row.sumVolume }}/{{ scope.row.sumWeight }} </template>
        </el-table-column>
        <el-table-column :label="$t('到港状态')" prop="arrival" />
        <el-table-column :label="$t('清关状态')" prop="clear" />
        <el-table-column :label="$t('控货')">
          <template slot-scope="scope">
            {{ cargoControlStatus[scope.row.cargoControlStatus] }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('订单状态')" prop="statusMsg" />
        <el-table-column :label="$t('操作')">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="selectOrder(scope.row)">{{ $t('选择') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import regError from '../../regError'
import dayjs from 'dayjs'
import { clearanceCreate } from '@/api/ecw/boxSea'
import { shipmentOrderList } from '@/api/ecw/boxAir'
import { formatDateStr, serviceMsg, formatDate } from '../utils'
import { createOrderArrival } from '@/api/ecw/boxAir'

/**
 * 清关
 */
export default {
  name: 'cusClearance',
  inheritAttrs: false,
  components: {
    regError
  },
  data() {
    return {
      // 清关对象
      cusClearanceObj: {},
      // 校验
      rules: {
        clEstTime: [{ required: true, message: this.$t('必填'), trigger: 'change' }],
        clClearTime: [{ required: true, message: this.$t('必填'), trigger: 'change' }]
      },
      airArrivalrules: {
        actSecondTime: [{ required: true, message: this.$t('必填'), trigger: 'change' }],
        actTime: [{ required: true, message: this.$t('必填'), trigger: 'change' }]
      },
      // 弹窗配置
      dialogVisible: false,
      // 提示消息
      showMsg: false,
      orderList: [],
      arrivalOrderList: [],
      clearanceOrderList: [],
      airArrivalInfo: {},
      orderdialogVisible: false,
      selectOrders: [],
      multipleSelectOrder: [],
      cargoControlStatus: [this.$t('控货中'), this.$t('已放完货'), this.$t('部分控货')],
      searchForm: {
        orderKeyword: null,
        orderPortStatus: null,
        orderCustomsClearanceStatus: null
      },
      searchFormFilter: {}
    }
  },
  created() {
    const voName = this.$attrs.currNode.voName
    let oldData = { ...this.$attrs.shipmentObj[voName] }
    oldData = formatDateStr(oldData, ['clEstTime'])
    oldData = formatDateStr(oldData, ['clClearTime'], 'YYYY-MM-DD HH:mm:ss')
    this.cusClearanceObj = oldData
    if (!this.cusClearanceObj.clearanceType) this.$set(this.cusClearanceObj, 'clearanceType', 0)
    this.$set(this.cusClearanceObj, 'clearanceOrderIdList', [])
    if (typeof this.$attrs.shipmentObj.airArrivalInfo?.arrivalOrderList != 'undefined' && this.$attrs.shipmentObj.airArrivalInfo.arrivalOrderList) this.arrivalOrderList = this.$attrs.shipmentObj.airArrivalInfo.arrivalOrderList
    if (typeof this.$attrs.shipmentObj.clearanceInfo?.clearanceOrderList != 'undefined' && this.$attrs.shipmentObj.clearanceInfo.clearanceOrderList) this.clearanceOrderList = this.$attrs.shipmentObj.clearanceInfo.clearanceOrderList
    shipmentOrderList(this.$attrs.shipmentObj.id).then((r) => {
      this.orderList = r.data ?? []
    })
  },
  watch: {
    // 预计清关时间
    'cusClearanceObj.clEstTime'(val) {
      this.compareDate(val, this.cusClearanceObj.clClearTime)
    },
    // 清关时间
    'cusClearanceObj.clClearTime'(val) {
      this.compareDate(this.cusClearanceObj.clEstTime, val)
    },
    'cusClearanceObj.clearanceType'(val) {
      if (val == 1) {
        this.$set(this.cusClearanceObj, 'clEstTime', null)
        this.$set(this.cusClearanceObj, 'clClearTime', null)
      } else {
        let oldData = {
          ...this.$attrs.shipmentObj[this.$attrs.currNode.voName]
        }
        oldData = formatDateStr(oldData, ['clEstTime', 'clClearTime'], 'YYYY-MM-DD HH:mm:ss')
        this.$set(this.cusClearanceObj, 'clClearTime', oldData.clClearTime)
        this.$set(this.cusClearanceObj, 'clEstTime', oldData.clEstTime)
      }
    }
  },
  computed: {
    statusOrderList() {
      let data = []
      this.orderList.forEach((item) => {
        let json = {
          orderId: item.orderId,
          orderNo: item.orderNo,
          tidanNo: item.tidanNo,
          marks: item.marks,
          sumNum: item.sumNum,
          totalNum: item.totalNum,
          sumVolume: item.sumVolume,
          sumWeight: item.sumWeight,
          statusMsg: item.statusMsg,
          cargoControlStatus: item.cargoControlStatus
        }
        let clearindex = this.cusClearanceObj.clearanceOrderList ? this.cusClearanceObj.clearanceOrderList.findIndex((p) => p.orderId == item.orderId) : -1
        if (clearindex != -1) {
          json.clear = this.$t('已清关')
          json.clearValue = 1
        } else {
          json.clear = this.$t('未清关')
          json.clearValue = 0
        }
        let arrivalindex = this.arrivalOrderList ? this.arrivalOrderList.findIndex((p) => p.orderId == item.orderId) : -1
        if (arrivalindex != -1) {
          json.arrival = this.$t('已到港')
          json.arrivalValue = 1
        } else {
          json.arrival = this.$t('未到港')
          json.arrivalValue = 0
        }
        data.push(json)
      })
      if (this.searchFormFilter.orderKeyword && this.searchFormFilter.orderKeyword != '') {
        data = data.filter((item) => {
          return (item.orderNo && item.orderNo.indexOf(this.searchFormFilter.orderKeyword) > -1) || (item.tidanNo && item.tidanNo.indexOf(this.searchFormFilter.orderKeyword) > -1) || (item.marks && item.marks.indexOf(this.searchFormFilter.orderKeyword) > -1)
        })
      }
      if (this.searchFormFilter.orderPortStatus != null) {
        data = data.filter((item) => {
          return item.arrivalValue == this.searchFormFilter.orderPortStatus
        })
      }
      if (this.searchFormFilter.orderCustomsClearanceStatus != null) {
        data = data.filter((item) => {
          return item.clearValue == this.searchFormFilter.orderCustomsClearanceStatus
        })
      }
      return data
    }
  },
  methods: {
    formatDate,
    searchOrderList() {
      this.searchFormFilter = JSON.parse(JSON.stringify(this.searchForm))
    },
    reloafSearch() {
      this.searchForm = {}
      this.searchOrderList()
    },
    selectOrder(val) {
      this.selectOrders = []
      this.selectOrders.push(val)
      let arr = this.arrivalOrderList.find((item) => item.orderId == val.orderId)
      if (arr) {
        this.$set(this.airArrivalInfo, 'actSecondTime', formatDate(arr.actSecondTime))
        this.$set(this.airArrivalInfo, 'estTime', formatDate(arr.estTime))
        this.$set(this.airArrivalInfo, 'actTime', formatDate(arr.actTime))
      }
      let clear = this.clearanceOrderList.find((item) => item.orderId == val.orderId)
      if (clear) {
        this.$set(this.cusClearanceObj, 'clEstTime', formatDate(clear.clEstTime))
        this.$set(this.cusClearanceObj, 'clClearTime', formatDate(clear.clClearTime))
      }
      this.orderdialogVisible = false
      this.cusClearanceObj.clearanceOrderIdList.push(val.orderId)
    },
    handleSelectionChange(val) {
      this.multipleSelectOrder = val
    },
    multipleSelect() {
      if (this.multipleSelectOrder.length == 0) {
        this.$message.error(this.$t('请先选择订单'))
        return
      }
      this.selectOrders = []
      this.selectOrders = this.multipleSelectOrder
      if (this.multipleSelectOrder.length == 1) {
        let arr = this.arrivalOrderList.find((item) => item.orderId == this.multipleSelectOrder[0].orderId)
        if (arr) {
          this.$set(this.airArrivalInfo, 'actSecondTime', formatDate(arr.actSecondTime))
          this.$set(this.airArrivalInfo, 'estTime', formatDate(arr.estTime))
          this.$set(this.airArrivalInfo, 'actTime', formatDate(arr.actTime))
        }
        let clear = this.clearanceOrderList.find((item) => item.orderId == this.multipleSelectOrder[0].orderId)
        if (clear) {
          this.$set(this.cusClearanceObj, 'clEstTime', formatDate(clear.clEstTime))
          this.$set(this.cusClearanceObj, 'clClearTime', formatDate(clear.clClearTime))
        }
      } else {
        this.$set(this.airArrivalInfo, 'actSecondTime', null)
        this.$set(this.airArrivalInfo, 'estTime', null)
        this.$set(this.airArrivalInfo, 'actTime', null)
        this.$set(this.cusClearanceObj, 'clEstTime', null)
        this.$set(this.cusClearanceObj, 'clClearTime', null)
      }
      this.orderdialogVisible = false
      this.cusClearanceObj.clearanceOrderIdList = this.multipleSelectOrder.map((item) => item.orderId)
    },
    getClAgent(type) {
      const agentId = this.$attrs.shipmentObj.agentInfo.agentId
      if (type === 'label') {
        const selected = this.$attrs.allSupplier.find((item) => item.id === agentId)
        return this.$l(selected, 'company') ?? agentId
      }
      return agentId
    },
    // 时间比较
    compareDate(clEstTime, clClearTime) {
      this.showMsg = false
      let date1 = null,
        date2 = null
      if (clEstTime) date1 = dayjs(clEstTime)
      if (clClearTime) date2 = dayjs(clClearTime)
      if (date1 && date2 && !date2.isSame(date1)) {
        this.showMsg = true
      }
    },
    // 异常登记
    exceptionReg() {
      this.dialogVisible = true
    },
    /** 提交 */
    onSubmit(operateType) {
      this.$refs['cusClearanceForm'].validate((valid) => {
        if (valid) {
          if (this.cusClearanceObj.clearanceType == 1) {
            this.$refs['airArrivalForm'].validate((arrvalid) => {
              if (arrvalid) {
                createOrderArrival({
                  ...this.airArrivalInfo,
                  shipmentId: this.$attrs.shipmentObj.id,
                  arriveOrderIdList: this.cusClearanceObj.clearanceOrderIdList,
                  arriveType: 1,
                  operateType: 2
                }).then(() => {
                  clearanceCreate({
                    ...this.cusClearanceObj,
                    shipmentId: this.$attrs.shipmentObj.id,
                    clAgentId: this.getClAgent(),
                    operateType
                  }).then((res) => {
                    serviceMsg(res, this).then(() => {
                      this.cancel('submit')
                    })
                  })
                })
              }
            })
          } else {
            clearanceCreate({
              ...this.cusClearanceObj,
              shipmentId: this.$attrs.shipmentObj.id,
              clAgentId: this.getClAgent(),
              operateType
            }).then((res) => {
              serviceMsg(res, this).then(() => {
                this.cancel('submit')
              })
            })
          }
        }
      })
    },
    /** 取消 */
    cancel(type) {
      this.$emit('closeDialog', type)
    }
  }
}
</script>

<style lang="scss" scoped>
.message-area {
  margin: 0;
  color: red;
}
</style>