InboundMaterialModal.vue 5.96 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="lot">
              <a-input v-model="model.lot" placeholder="请输入生产批号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="32">
            <a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stockInCode">
              <a-select
                show-search
                placeholder="请选择物料编码"
                option-filter-prop="children"
                @change="getQty()"
                v-model="model.stockInCode">
                <a-select-option
                  v-for="item in materialCodeList"
                  :key="item.stockInCode"
                  :value="item.stockInCode">
                  {{ item.name }}
                </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 v-model="model.qty" placeholder="请输入入库数量"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入库类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <a-select
                show-search
                placeholder="请选择入库类型"
                option-filter-prop="children"
                v-model="model.type">
                <a-select-option
                  v-for="item in receiptTypeList"
                  :key="item.code"
                  :value="item.code">
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

import {httpAction} from '@/api/manage'
import {validateDuplicateValue} from '@/utils/util'
import {
  createEmptyOut, createInboundTask,
  getCompanyList,
  getMaterialList,
  getMaterialLot,
  getQty,
  getReceiptTypeList,
  getSupplierList
} from '@/api/api'
import {selectOutPort} from '@/api/api'
import JSelectMultiEmptyContainer from "@comp/jeecgbiz/JSelectMultiEmptyContainer";

export default {
  name: "InboundMaterialModal",
  components: {JSelectMultiEmptyContainer},
  data() {
    return {
      title: "操作",
      width: 800,
      portList: [],
      querySource: {},
      receiptTypeList: [],
      materialCodeList: [],
      materialOptions: [],
      visible: false,
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },

      confirmLoading: false,
      validatorRules: {
        stockInCode: [
          {required: true, message: '请输入物料编码!'},
        ],
        lot: [
          {required: true, message: '请输入生产批号!'},
        ],
        qty: [
          {required: true, message: '请输入数量!'},
        ],
        type: [
          {required: true, message: '请输入入库类型!'},
        ],
      },
      url: {
        add: "/task/taskHeader/createEmptyOut",
      }

    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    this.loadFrom();
  },
  methods: {
    add() {
      // $("select").change(function() {	alert("选项已被改变");	console.log($('select').val());});
      this.edit(this.modelDefault);
    },
    loadFrom() {
      getReceiptTypeList().then((res) => {
        if (res.success) {
          this.receiptTypeList = res.result;
        }
      });
      getMaterialList().then((res) => {
        if (res.success) {
          this.materialCodeList = res.result;
        }
      });
      getMaterialLot().then((res) => {
        if (res.success) {
          this.model.lot = res.result
        }
      });
    },
    edit() {
      // let record={type: this.receiptTypeList[2].code}
      // this.getPortList();
      // this.model = Object.assign({}, record);
      let record={lot: this.model.lot, type: this.receiptTypeList[2].code};
      this.model = Object.assign({}, record);
      this.visible = true;
      // this.$forceUpdate();
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.$refs.form.clearValidate();
    },
    getQty() {
      this.querySource.stockInCode = this.model.stockInCode;
      getQty(this.querySource).then((res) => {
        if (res.success) {
          this.model.qty = res.result;
          this.$forceUpdate();
        }
      });
    },
    getPortList() {
      this.querySource.containerCode = this.model.containerCode;
      selectOutPort(this.querySource).then((res) => {
        if (res.success) {
          this.portList = res.result;
          if (this.portList.length == 1) {
            this.model.toPortCode = this.portList[0].code;
          }
        }
      });
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          createInboundTask(this.model).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },


  }
}
</script>