ShipmentDetailModal.vue 5.75 KB
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="物料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialCode">
              <a-select
                v-model="model.materialCode"
                show-search
                placeholder="请选择物料"
                :filter-option="false"
                @search="handleSearchMaterial"
                style="width: 100%"
                @change="getInventoryByShipmentDetail"
              >
                <a-select-option
                  v-for="item in materialOptions"
                  :key="item.code"
                  :value="item.code"
                >
                  {{ item.code }} {{ item.name }}
                  <span v-if="item.materialQuality"> | 材质:{{ item.materialQuality }}</span>
                  <span v-if="item.standardNo"> | 标准号:{{ item.standardNo }}</span>
                  <span v-if="item.productDesc"> | 说明:{{ item.productDesc }}</span>
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="单据数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qty">
              <a-input-number v-model="model.qty" placeholder="请输入单据数量" style="width: 100%"/>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="库存状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryStatus">
              <j-dict-select-tag
                type="list"
                v-model="model.inventoryStatus"
                dictCode="inventory_status"
                @change="getInventoryByShipmentDetail"
                placeholder="请选择库存状态"/>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="批次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batch">
              <a-input v-model="model.batch" placeholder="请输入批次" @change="getInventoryByShipmentDetail"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="库存数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryQty">
              <a-input-number v-model="model.inventoryQty" :disabled="true" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import { getInventoryByShipmentDetail } from '@/api/api'
import { searchMaterial } from '@/api/api'

export default {
  name: "ShipmentDetailModal",
  components: {},
  props: {
    mainId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      title: "操作",
      width: 800,
      visible: false,
      materialOptions: [],
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
      validatorRules: {
        materialCode: [{ required: true, message: '请选择物料!' }],
        qty: [{ required: true, message: '请输入单据数量!' }],
        inventoryStatus: [{ required: true, message: '请选择库存状态!' }],
      },
      url: {
        add: "/shipment/shipmentHeader/addShipmentDetail",
        edit: "/shipment/shipmentHeader/editShipmentDetail",
      }
    }
  },
  watch: {
    visible(newVal) {
      if (newVal) {
        this.handleSearchMaterial('')
      } else {
        this.materialOptions = []
      }
    }
  },
  created() {
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    // 物料搜索(同入库弹窗完全一致)
    handleSearchMaterial(keyword) {
      let params = { code: keyword }
      searchMaterial(params).then(res => {
        if (res.success) {
          this.materialOptions = res.result
        }
      })
    },
    add() {
      let record = { inventoryStatus:'good' }
      this.edit(record);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.$refs.form.clearValidate();
    },
    getInventoryByShipmentDetail() {
      if(!this.model.materialCode) return;
      this.model.shipmentId = this.mainId
      getInventoryByShipmentDetail(this.model).then(res => {
        if (res.success) {
          this.model = res.result;
        } else {
          this.model.inventoryQty = 0;
        }
      })
    },
    handleOk() {
      const that = this;
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = this.model.id ? this.url.edit : this.url.add
          let method = this.model.id ? 'put' : 'post'

          this.model.shipmentId = this.mainId
          httpAction(httpurl, this.model, method).then(res => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
              that.$emit('dataSearch');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>