PutIn.vue 17.6 KB
Newer Older
dragondean@qq.com's avatar
dragondean@qq.com committed
1 2 3 4 5 6
<template>
  <!-- 放入弹层 -->
  <el-dialog :title="$t('入仓记录放入确认')" :visible="show" :before-close="closeDialog" :close-on-click-modal="false" width="1500px" :append-to-body="appendToBody">
    <el-card>
      <div slot="header">{{$t('可拆出入仓记录')}}</div>
      <el-table :data="[warehouseRecord]">
7
        <el-table-column :label="$t('箱数')" prop="cartonsNum">
dragondean@qq.com's avatar
dragondean@qq.com committed
8
          <template slot-scope="{row}">{{Math.min(row.cartonsNum, maxNum)}}</template>
9
        </el-table-column>
dragondean@qq.com's avatar
dragondean@qq.com committed
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
        <el-table-column :label="$t('入仓类型')" prop="specificationType">
          <template slot-scope="{row}">
            <dict-tag :type="DICT_TYPE.WAREHOUSING_SPECIFICATION_TYPE" :value="row.specificationType" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('包装类型')" prop="unit">
          <template slot-scope="{row}">
            <dict-tag :type="DICT_TYPE.ECW_PACKAGING_TYPE" :value="row.unit" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('长')" prop="boxGauge">
          <template slot-scope="{row}">
            {{row.boxGauge.split('*')[0]}}
          </template>
        </el-table-column>
        <el-table-column :label="$t('宽')" prop="boxGauge" >
          <template slot-scope="{row}">
            {{row.boxGauge.split('*')[1]}}
          </template>
        </el-table-column>
        <el-table-column :label="$t('高')" prop="boxGauge" >
          <template slot-scope="{row}">
            {{row.boxGauge.split('*')[2]}}
          </template>
        </el-table-column>
        <el-table-column :label="$t('体积') + '(m³)'" prop="volume" />
        <el-table-column :label="$t('重量') + '(kg)'" prop="weight" />
        <el-table-column :label="$t('数量(个)')" prop="quantityAll" />
dragondean@qq.com's avatar
dragondean@qq.com committed
38
        <el-table-column :label="$t('入仓快递单号')" prop="expressNo" />
dragondean@qq.com's avatar
dragondean@qq.com committed
39 40 41 42 43 44 45 46 47
        <el-table-column :label="$t('首次入仓时间')" prop="inTime" >
          <template slot-scope="{row}">{{row.inTime|parseTime}}</template>
        </el-table-column>
        <el-table-column :label="$t('储位')" prop="orderLocationBackVOList" >
          <template slot-scope="{row}">
            {{getLocationName(row.orderLocationBackVOList)}}
          </template>
        </el-table-column>
      </el-table>
48
      <div>
dragondean@qq.com's avatar
dragondean@qq.com committed
49 50
        {{$t('可拆')}}:
        {{maxSplitNum}}{{$t('箱')}},
51 52
        {{$t('体积')}}:{{leftData('volume')}}m³,
        {{$t('重量')}}:{{leftData('weight')}}kg,
dragondean@qq.com's avatar
dragondean@qq.com committed
53
        {{$t('数量')}}:{{leftData('quantity')}}{{$t('个')}}
54
      </div>
dragondean@qq.com's avatar
dragondean@qq.com committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    </el-card>
    <el-card class="box-card mt-10">
      <div slot="header" class="clearfix">
        <span>{{ $t('新入仓记录') }}</span>
        <el-button style="float: right;margin-left: 15px" size="mini" type="primary" icon="el-icon-minus" circle @click="deleteRow" :disabled="form.list.length <= 1"></el-button>
        <el-button style="float: right" size="mini" type="primary" icon="el-icon-plus" circle @click="addRow"></el-button>
      </div>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
      <el-table
        :data="form.list"
        style="width: 100%">
        <el-table-column :label="$t('箱数')" width="200px">
          <template v-slot:header>
            <span style="color: red">*</span>{{ $t('箱数') }}
          </template>
          <template v-slot="{row,$index}">
            <el-form-item class="flex" label-width="0"
                          :prop="`list.${$index}.num`"
                          :rules="{required: true, message: $t('不能为空'), trigger: 'blur'}">
dragondean@qq.com's avatar
dragondean@qq.com committed
74 75
              <!--需求方要求输入后马上计算其他数据,el组件无法绑定keyup事件,所以用原生的input-->
              <!--<el-input-number controls-position="right" :min="0" class="w-75 tight" v-model="row.num" :max="warehouseRecord.cartonsNum" @keyup.native="calc(row)"></el-input-number>-->
dragondean@qq.com's avatar
dragondean@qq.com committed
76
              <input class="input" v-model="row.num" type="number" @keyup="calc(row)" @change="calc(row)" :min="1" :max="maxSplitNum"></input>
dragondean@qq.com's avatar
dragondean@qq.com committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
              <dict-selector class="w-75" :type="DICT_TYPE.WAREHOUSING_SPECIFICATION_TYPE" v-model="row.specificationType" defaultable></dict-selector>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('包装类型')" width="100px">
          <template v-slot:header>
            <span style="color: red">*</span>{{ $t('包装类型') }}
          </template>
          <template v-slot="{row,$index}">
            <el-form-item  label-width="0">
              <dict-selector :type="DICT_TYPE.ECW_PACKAGING_TYPE" v-model="row.unit" defaultable></dict-selector>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="长(cm)">
          <template v-slot:header>
            <span>{{ $t('') }}</span>(cm)
          </template>
          <template v-slot="{row,$index}">
            <el-form-item  label-width="0">
97 98
              <input class="input" v-model="row.boxGauge1" type="number" @keyup="calcVolume(row)" @change="calcVolume(row)" :min="0"></input>
              <!--<el-input-number controls-position="right" :min="0" class="w-100 tight"  v-model="row.boxGauge1" @blur="calcVolume(row)"/>-->
dragondean@qq.com's avatar
dragondean@qq.com committed
99 100 101 102 103 104 105 106 107
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="宽(cm)">
          <template v-slot:header>
            <span>{{ $t('') }}</span>(cm)
          </template>
          <template v-slot="{row,$index}">
            <el-form-item  label-width="0">
108 109
              <input class="input" v-model="row.boxGauge2" type="number" @keyup="calcVolume(row)" @change="calcVolume(row)" :min="0"></input>
              <!--<el-input-number controls-position="right" :min="0" class="w-100 tight" v-model="row.boxGauge2" @blur="calcVolume(row)" />-->
dragondean@qq.com's avatar
dragondean@qq.com committed
110 111 112 113 114 115 116 117 118
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="高(cm)">
          <template v-slot:header>
            <span>{{ $t('') }}</span>(cm)
          </template>
          <template v-slot="{row,$index}">
            <el-form-item  label-width="0">
119 120
              <input class="input" v-model="row.boxGauge3" type="number" @keyup="calcVolume(row)" @change="calcVolume(row)" :min="0"></input>
              <!--<el-input-number controls-position="right" :min="0" class="w-100 tight" v-model="row.boxGauge3" @blur="calcVolume(row)"/>-->
dragondean@qq.com's avatar
dragondean@qq.com committed
121 122 123 124 125 126 127 128 129 130 131
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="入仓体积(m³)">
          <template v-slot:header>
            <span style="color: red">*</span> <span>{{ $t('体积') }}</span>(m³)
          </template>
          <template v-slot="{row,$index}">
            <el-form-item label-width="0"
                          :prop="`list.${$index}.volume`"
                          :rules="{required: true, message: $t('不能为空'), trigger: 'blur'}">
132
              <el-input-number controls-position="right" :min="0.01" :max="warehouseRecord.volume" class="w-100 tight" v-model="row.volume"/>
dragondean@qq.com's avatar
dragondean@qq.com committed
133 134 135
            </el-form-item>
          </template>
        </el-table-column>
136
        <!--<el-table-column label="收费体积(m³)">
dragondean@qq.com's avatar
dragondean@qq.com committed
137 138 139 140 141 142 143 144 145 146
          <template v-slot:header>
            <span style="color: red">*</span> <span>{{ $t('收费体积') }}</span>(m³)
          </template>
          <template v-slot="{row,$index}">
            <el-form-item label-width="0"
                          :prop="`list.${$index}.chargeVolume`"
                          :rules="{required: true, message: $t('不能为空'), trigger: 'blur'}">
              <el-input-number controls-position="right" :min="0" class="w-100 tight" v-model="row.chargeVolume"/>
            </el-form-item>
          </template>
147
        </el-table-column>-->
dragondean@qq.com's avatar
dragondean@qq.com committed
148 149 150 151 152 153 154 155
        <el-table-column label="入仓重量(Kg)">
          <template v-slot:header>
            <span style="color: red">*</span> <span>{{ $t('入仓重量') }}</span>(Kg)
          </template>
          <template v-slot="{row,$index}">
            <el-form-item label-width="0"
                          :prop="`list.${$index}.weight`"
                          :rules="{required: true, message: $t('不能为空'), trigger: 'blur'}">
156
              <el-input-number controls-position="right" :min="0.01" :max="warehouseRecord.weight" class="w-75 tight" v-model="row.weight"/>
dragondean@qq.com's avatar
dragondean@qq.com committed
157 158 159
            </el-form-item>
          </template>
        </el-table-column>
160
        <!--<el-table-column label="收费重量(Kg)">
dragondean@qq.com's avatar
dragondean@qq.com committed
161 162 163 164 165 166 167 168 169 170
          <template v-slot:header>
            <span style="color: red">*</span> <span>{{ $t('收费重量') }}</span>(Kg)
          </template>
          <template v-slot="{row,$index}">
            <el-form-item label-width="0"
                          :prop="`list.${$index}.chargeWeight`"
                          :rules="{required: true, message: $t('不能为空'), trigger: 'blur'}">
              <el-input-number controls-position="right" :min="0" class="w-75 tight" v-model="row.chargeWeight" type="number"/>
            </el-form-item>
          </template>
171
        </el-table-column>-->
dragondean@qq.com's avatar
dragondean@qq.com committed
172 173 174 175
        <el-table-column :label="$t('数量')" width="130px">
          <template v-slot="{row,$index}">
            <el-form-item label-width="0"
                          :prop="`list.${$index}.quantity`"
dragondean@qq.com's avatar
dragondean@qq.com committed
176 177
                          :rules="{required: false, message: $t('不能为空'), trigger: 'blur'}">
              <el-input-number controls-position="right" :min="0" :max="warehouseRecord.quantityAll > 0 ? warehouseRecord.quantityAll : null" class="w-75 tight" v-model.number="row.quantity" />{{ $t('') }}
dragondean@qq.com's avatar
dragondean@qq.com committed
178 179 180
            </el-form-item>
          </template>
        </el-table-column>
dragondean@qq.com's avatar
dragondean@qq.com committed
181
        <el-table-column :label="$t('快递单号')">
dragondean@qq.com's avatar
dragondean@qq.com committed
182 183 184 185 186
          <template v-slot="{row,$index}">
            <el-form-item label-width="0">
              <el-input v-model="row.expressNo"></el-input>
            </el-form-item>
          </template>
dragondean@qq.com's avatar
dragondean@qq.com committed
187
        </el-table-column>
dragondean@qq.com's avatar
dragondean@qq.com committed
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
        <el-table-column :label="$t('储位')" prop="orderLocationBackVOList">
          <template v-slot="{ row, column, $index }">
            <!--<el-button type="primary" size="mini" @click="showLocation(row, $index)">{{ $t('选择储位') }}</el-button>-->
            <warehouse-area-select
              v-model="row.orderLocationList"
              :warehouse-id="warehouseId"
            ></warehouse-area-select>
          </template>
        </el-table-column>
        <el-table-column :label="$t('操作')">
          <template v-slot="{ row, column, $index}">
            <el-popconfirm
              v-if="$index > 0"
              :title="$t('确定要删除该行入仓记录吗?')"
              @confirm="deleteRow($index)"
            >
              <template v-slot:reference>
                <el-button size="mini" type="danger">删除</el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      </el-form>
    </el-card>
    <div slot="footer">
      <el-button type="primary" @click="submit">{{ $t('确定') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import WarehouseAreaSelect from "@/components/WarehouseAreaSelect/index.vue";
import {parseTime} from '@/utils/ruoyi'
import Decimal from 'decimal.js'
223
import Template from "@/views/cms/template/index.vue";
dragondean@qq.com's avatar
dragondean@qq.com committed
224
export default {
dragondean@qq.com's avatar
dragondean@qq.com committed
225
  name: "Putin",
dragondean@qq.com's avatar
dragondean@qq.com committed
226
  filters:{parseTime},
227
  components: {Template, WarehouseAreaSelect},
dragondean@qq.com's avatar
dragondean@qq.com committed
228 229 230 231 232
  props:{
    warehouseRecord:Object,
    appendToBody: Boolean,
    // 仓库ID,选择储位要用到
    warehouseId: Number,
233
    // 数量是否必须
dragondean@qq.com's avatar
dragondean@qq.com committed
234 235
    quantityshow: Boolean,
    // 最大可拆箱数,装柜拆单用
dragondean@qq.com's avatar
dragondean@qq.com committed
236
    maxNum: Number,
dragondean@qq.com's avatar
dragondean@qq.com committed
237 238 239 240 241 242 243 244 245 246 247
  },
  data(){
    return {
      show: false,
      // 拆出的入仓记录
      form:{
        list:[]
      }
    }
  },
  computed:{
dragondean@qq.com's avatar
dragondean@qq.com committed
248
    // 计算当前添加的多条入仓记录总拆出数据
dragondean@qq.com's avatar
dragondean@qq.com committed
249 250 251 252 253 254 255 256
    splitTotal(){
      return field => {
        let total = new Decimal(0)
        this.form.list.forEach(item => {
          total = total.plus(new Decimal(item[field] || 0))
        })
        return total.toNumber()
      }
257
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
258 259 260 261 262 263 264 265 266 267 268 269
    // 计算此入仓记录全部拆出的数量,包含其他拆单订单的
    totalSplitSum(){
      return field => {
        let total = new Decimal(0)
        if(this.warehouseRecord.specsRecordVOList && this.warehouseRecord.specsRecordVOList.length){
          this.warehouseRecord.specsRecordVOList.forEach(item => {
            total = total.plus(new Decimal(item[field] || 0))
          })
        }
        return total.plus(new Decimal(this.splitTotal('num'))).toNumber()
      }
    },
270 271
    // 剩余数据
    leftData(){
272
      return (field, containNew = false) => {
273
        // 入仓记录跟拆单记录的箱数字段不同,要做特殊处理
dragondean@qq.com's avatar
dragondean@qq.com committed
274 275 276 277
        let warehouseField = field
        if(field == 'num') warehouseField = 'cartonsNum'
        if(field == 'quantity') warehouseField = 'quantityAll'
        let left = new Decimal(this.warehouseRecord[warehouseField] || 0)
278
        // 累减已拆记录
279 280 281 282 283 284 285 286 287 288 289 290 291
        if(this.warehouseRecord.specsRecordVOList && this.warehouseRecord.specsRecordVOList.length){
          this.warehouseRecord.specsRecordVOList.forEach(item => {
            left = left.minus(new Decimal(item[field] || 0))
          })
        }
        // 如果是包含新数据(本次放入数据)
        if(containNew){
          // 累减本页添加的入仓记录
          this.form.list.forEach(item => {
            left = left.minus(new Decimal(item[field] || 0))
          })
        }

292 293
        return left.toNumber()
      }
dragondean@qq.com's avatar
dragondean@qq.com committed
294 295 296 297
    },
    // 可拆箱数
    maxSplitNum(){
      return Math.min(this.maxNum, this.leftData('num'))
dragondean@qq.com's avatar
dragondean@qq.com committed
298 299 300 301 302 303 304 305 306
    }
  },
  mounted() {
    this.show = true
    this.$nextTick(this.addRow)
  },
  methods:{
    // 添加一行
    addRow(){
307
      let { specificationType, boxGauge1, boxGauge2, boxGauge3, expressNo, unit } = this.warehouseRecord
dragondean@qq.com's avatar
dragondean@qq.com committed
308
      let num = Math.min(this.leftData('num', true), this.maxSplitNum)
309 310 311 312
      let orderLocationList = this.warehouseRecord.orderLocationBackVOList
      if(this.form.list.length){
        orderLocationList = this.form.list[this.form.list.length - 1].orderLocationList
      }
dragondean@qq.com's avatar
dragondean@qq.com committed
313
      // 根据入仓记录添加一行
dragondean@qq.com's avatar
dragondean@qq.com committed
314
      let row = {
315
        warehouseInId: this.warehouseRecord.id,
316 317 318
        specificationType, boxGauge1, boxGauge2, boxGauge3, expressNo,unit,
        volume: 0,
        weight: 0,
dragondean@qq.com's avatar
dragondean@qq.com committed
319
        num: num,
320 321
        quantity: 0,
        orderLocationList
dragondean@qq.com's avatar
dragondean@qq.com committed
322
      }
dragondean@qq.com's avatar
dragondean@qq.com committed
323
      // 如果拆完了则剩下的全部放入,否则按照比例计算
324 325 326 327 328 329 330 331 332 333
      this.$nextTick(() =>{
        if(this.leftData('num', true) <= 0 ) {
          row.volume = this.leftData('volume', true)
          row.weight = this.leftData('weight', true)
          row.quantity = this.leftData('quantity', true)
        }else{
          // 按照比例计算重量体积和数量
          this.calc(row)
        }
      })
dragondean@qq.com's avatar
dragondean@qq.com committed
334

dragondean@qq.com's avatar
dragondean@qq.com committed
335
      this.form.list.push(row)
dragondean@qq.com's avatar
dragondean@qq.com committed
336 337 338 339 340 341 342 343
    },
    // 删除一行,可选参数index表上行号,参数不是数字则删除最后一行
    deleteRow(index){
      const spliceIndex = typeof index !== 'number' ? this.list - 1 : index
      this.form.list.splice(spliceIndex, 1)
    },
    // 计算体积
    calcVolume(row){
344 345 346
      // 改了规格后按照规格计算体积
      this.$set(row, 'calcVolumeByBoxGauge', 1)

dragondean@qq.com's avatar
dragondean@qq.com committed
347 348 349 350
      let volume = Decimal(row.boxGauge1 || 0)
        .times(Decimal(row.boxGauge2 || 0))
        .times(Decimal(row.boxGauge3 || 0)).div(1000000)
      // 如果是箱的单位要乘以箱数
351 352
      if(+row.specificationType === 1) {
        volume = volume.times(Decimal(row.num || 0))
dragondean@qq.com's avatar
dragondean@qq.com committed
353 354 355 356 357 358 359 360 361 362 363
      }

      // 最低0.01
      volume = Math.max(0.01, volume.toNumber().toFixed(2))
      this.$set(row, 'volume', volume)
    },
    // 获取储位名称
    getLocationName(locationArr){
      if(!locationArr || !locationArr.length) return ''
      let arr = []
      locationArr.forEach(item => {
364
        arr.push(`${item.areaName || ''}${item.locationName || ''}`)
dragondean@qq.com's avatar
dragondean@qq.com committed
365 366 367
      })
      return Array.from(new Set(arr)).join(",")
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
368 369 370
    // 根据箱数计算体积,重量,数量
    calc(row){
      const rate = row.num / this.warehouseRecord.cartonsNum
371

dragondean@qq.com's avatar
dragondean@qq.com committed
372 373
      row.volume = (this.warehouseRecord.volume * rate).toFixed(2)
      row.weight = (this.warehouseRecord.weight * rate).toFixed(2)
dragondean@qq.com's avatar
dragondean@qq.com committed
374
      row.quantity = (this.warehouseRecord.quantityAll * rate).toFixed(0)
375 376 377 378 379

      // 如果是按照规格计算体积,则重新计算
      if(row.calcVolumeByBoxGauge){
        this.calcVolume(row)
      }
dragondean@qq.com's avatar
dragondean@qq.com committed
380
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
381 382 383 384 385 386 387 388 389
    closeDialog(){
      this.show = false
      this.$emit('close');
    },
    submit(){
      this.$refs.form.validate(valid => {
        if(!valid){
          return false
        }
390

dragondean@qq.com's avatar
dragondean@qq.com committed
391 392
        if(this.splitTotal('num') > this.maxSplitNum){
          return this.$message.error("拆出箱数不能大于可拆箱数")
393 394 395 396 397 398
        }
        if(this.splitTotal('volume') > this.leftData('volume')){
          return this.$message.error("拆出体积不能大于剩余体积")
        }
        if(this.splitTotal('weight') > this.leftData('weight')){
          return this.$message.error("拆出重量不能大于剩余重量")
dragondean@qq.com's avatar
dragondean@qq.com committed
399 400 401 402 403 404 405
        }
        // 如果全拆(拆出箱数 == 原入仓箱数),则体积重量也需要全拆
        if(this.splitTotal('num') === this.warehouseRecord.cartonsNum){
          if(this.splitTotal('volume') !== this.warehouseRecord.volume){
            return this.$message.error("全拆拆出体积必须等于原入仓体积")
          }
          if(this.splitTotal('weight') !== this.warehouseRecord.weight){
406
            return this.$message.error("全拆拆出重量必须等于原入仓体积")
dragondean@qq.com's avatar
dragondean@qq.com committed
407 408 409 410 411 412 413 414 415 416 417
          }
        }
        this.$emit('submit', this.form.list)
      })

    }
  }
}
</script>

<style scoped>
dragondean@qq.com's avatar
dragondean@qq.com committed
418 419 420 421 422
.input{

  border: 1px solid #DCDFE6;
  padding: 5px 6px;
  border-radius: 5px;
dragondean@qq.com's avatar
dragondean@qq.com committed
423

dragondean@qq.com's avatar
dragondean@qq.com committed
424
}
dragondean@qq.com's avatar
dragondean@qq.com committed
425
</style>