shipmentDialog.vue 9.36 KB
<!-- 发货弹窗 -->
<template>
  <GLDialog bigTitle="发货" width="1300px" :visible.sync="dialogVisible" :hasFooter="true" :before-close="handleClose" class="shipmentDialog" mode="big" okText="确认" cancelText="取消" @onCancel="handleClose" @onOk="submit">
    <div>
      <div class="header" slot="header" style="padding: 10px 20px"></div>
      <div class="d2-container-content">
        <div class="address-info">
          <div class="info-item" v-for="(item, index) in infoList" :key="index" :class="{ 'remark-item': item.isRemark }">
            <span class="label-name">{{ item.label }}:</span>
            <ellipsis-tooltip class="label-value" :content="paramsObj[item.prop]" />
          </div>
        </div>
        <div class="table-class">
          <GLTable ref="purchaseOrderDetailTable" :hasPage="false" :table-params="tableParams" :table-data="tableList">
            <template slot="nowPurNum" slot-scope="scope">
              <div>
                <el-input :class="{ 'border-red': !nowPurNumList[scope.index] && isSubmit }" placeholder="请输入" v-model="nowPurNumList[scope.index]" @input="e => handleInput(e, scope)"></el-input>
              </div>
            </template>
          </GLTable>
        </div>

        <div class="form-content">
          <el-form label-width="100px" :rules="dialogRules" :model="dialogData" ref="delivery-dialog-form">
            <el-form-item label="承运单号:" prop="deliveryNumber">
              <el-input maxlength="50" placeholder="请输入承运物流单号" v-model.trim="dialogData.deliveryNumber" class="dis-in-block" @input="deliveryNumberInput" />
            </el-form-item>
            <el-form-item label="承运公司:" prop="deliveryCompany">
              <el-input placeholder="请输入承运物流公司" maxlength="20" v-model.trim="dialogData.deliveryCompany" class="dis-in-block" />
            </el-form-item>
            <el-form-item label="发货时间:" prop="deliveryDate">
              <el-date-picker class="dis-in-block" v-model="dialogData.deliveryDate" type="datetime" placeholder="请选择发货时间"></el-date-picker>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </GLDialog>
</template>

<script>
import * as dayjs from 'dayjs'
import { limitPrice } from '@/common/format'
import EllipsisTooltip from './EllipsisTooltip.vue'

export default {
  name: 'ShipmentDialog',
  components: {
    EllipsisTooltip
  },
  data() {
    return {
      showOptionInput: false,
      addOptionValue: '',
      editOptionIndex: -1,
      editOptionValue: '',
      // userInfo: this.$store.state.d2admin.user.info,
      isSubmit: false,
      dialogData: {},
      deliveryCardList: [],
      oldPurNumList: [],
      nowPurNumList: [],
      orderInfo: {},
      hasPage: false,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '产品名称',
            prop: 'goodsName'
          },
          {
            label: '产品ID',
            prop: 'commodityCode'
          },
          {
            label: '产品编码',
            prop: 'productCode'
          },
          {
            label: '规格',
            prop: 'specificationData'
          },
          {
            label: '系列',
            prop: 'sourceMaterialName'
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName'
          },
          {
            label: '调拨数量',
            prop: 'allocateNumber',
            formatter: cellValue => {
              const qty = cellValue.allocateNumber ?? '-'
              const unit = this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件'
              return qty === '-' ? '-' : `${qty}${unit}`
            }
          },
          {
            label: '发货数量',
            prop: '',
            width: 124,
            addHtml: 'nowPurNum'
          },
          {
            label: '调入门店库存',
            prop: 'inStockQty',
            formatter: cellValue => {
              const qty = cellValue.inStockQty ?? '-'
              const unit = this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件'
              return qty === '-' ? '-' : `${qty}${unit}`
            }
          },
          {
            label: '调出门店库存',
            prop: 'outStockQty',
            formatter: cellValue => {
              const qty = cellValue.outStockQty ?? '-'
              const unit = this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件'
              return qty === '-' ? '-' : `${qty}${unit}`
            }
          },
          {
            label: '膜卷号',
            prop: 'filmRollNo'
          }
        ]
      },
      dialogRules: {
        deliveryCompany: [{ required: true, message: '请输入承运公司', trigger: 'blur' }],
        deliveryNumber: [{ required: true, message: '请输入承运单号', trigger: 'blur' }],
        deliveryDate: [{ required: true, message: '请选择发货时间', trigger: 'blur' }]
      },
      shippingWarehouseList: [],
      infoList: [
        { label: '调出仓库', prop: 'callOutYqMerchantName' },
        { label: '调出门店', prop: 'callOutMerchantName' },
        { label: '调入仓库', prop: 'callInYqMerchantName' },
        { label: '调入门店', prop: 'callInMerchantName' },
        { label: '备注', prop: 'remark', isRemark: true }
      ]
    }
  },

  props: {
    shipmentVisible: {
      type: Boolean,
      default: false
    },
    paramsObj: {
      type: Object,
      default: () => ({})
    },
    tableList: {
      type: Array,
      default: () => []
    }
  },

  computed: {
    dialogVisible: {
      get() {
        return this.shipmentVisible
      },
      set(val) {
        this.$emit('update:shipmentVisible', val)
      }
    }
  },

  filters: {
    formatCar(list) {
      let str = list
        .map(item => {
          return `${item.brandName}-${item.childName}-${item.seriesName}-${item.carTypeName}`
        })
        .join(',')
      return str.length > 15 ? str.substring(0, 15) + '...' : str
    }
  },

  methods: {
    handleClose() {
      this.$emit('shipmentClose')
    },
    deliveryNumberInput(event, index) {
      this.$set(this.dialogData, 'deliveryNumber', event.replace(/[^a-zA-Z0-9]/g, ''))
    },

    handleInput(val, scope) {
      const _row = scope.scope
      const _index = scope.index
      const _oldVal = this.oldPurNumList[_index] || 0
      const _maxVal = _row.allocateNumber - _row.deliveryNumber
      this.nowPurNumList[_index] = limitPrice(val, _oldVal, 9999, 0, 0, _maxVal) || (val ? _maxVal : '')
      this.oldPurNumList = JSON.parse(JSON.stringify(this.nowPurNumList))
    },

    submit() {
      this.isSubmit = true
      this.$refs['delivery-dialog-form'].validate(valid => {
        if (valid) {
          // 验证本次发货数量
          if (this.nowPurNumList.some(item => !item || item <= 0)) {
            this.$message({
              message: '发货数量必须全部填写且不能为0',
              type: 'error',
              customClass: 'message-Z-zinde'
            })

            return true
          }
          var params = {
            ...this.dialogData,
            deliveryDate: dayjs(this.dialogData.deliveryDate).format('YYYY-MM-DD HH:mm:ss'),
            orderCode: this.paramsObj.allocateCode,
            deliveryDetailList: []
          }
          for (let idx = 0; idx < this.tableList.length; idx++) {
            const item = this.tableList[idx]
            if (this.nowPurNumList[idx] && this.nowPurNumList[idx] != 0) {
              params.deliveryDetailList.push({
                id: item.detailId,
                purchaseNumber: this.nowPurNumList[idx]
              })
            }
          }
          this.$apis.stockManage
            .batchDelicery(params)
            .then(res => {
              if (res) {
                this.handleClose(true)
                this.$message.success('操作成功')
              }
            })
            .catch(() => {
              this.handleClose(false)
            })
        }
      })
    }
  },

  watch: {
    dialogVisible: {
      handler(val) {
        console.log(val, 'val')
        if (val) {
          this.$nextTick(() => {
            console.log(this.tableList, 'this.tableList')
            this.nowPurNumList = this.tableList?.map(() => '')
          })
        }
      },
      immediate: true
    }
  }
}
</script>

<style scoped lang="scss">
.shipmentDialog .el-dialog {
  margin-top: 20vh !important;
  min-width: 700px;
}

.address-info {
  display: flex;
  box-sizing: border-box;
  flex-wrap: wrap;
  width: 100%;
  padding: 0 20px;
  margin-top: 10px;
  font-size: 14px;
  color: #666666;

  .info-item {
    width: 33.33%;
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    padding-right: 15px;
    box-sizing: border-box;

    .label-name {
      white-space: nowrap;
      min-width: fit-content;
    }

    .label-value {
      flex: 1;
      color: #333333;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: block;
    }

    &.remark-item {
      flex-grow: 1;
      width: 33.33%;
    }
  }
}

.form-content {
  margin-top: 16px;

  .dis-in-block {
    width: 432px;
  }
}

.edit-order-dialog .el-input--medium.border-red .el-input__inner {
  border: 1px solid #eb4e4e;
}
</style>