MaterialReceiptModal.vue 2.95 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">
        <a-row v-for="(item, index) in fromPortList" :key="index" :gutter="16"
               style="margin-bottom:10px;align-items:center;">
          <a-col :span="6">
            <a-form-model-item label>
              <span style="line-height:32px; font-weight:bold;">{{ item.label }}</span>
            </a-form-model-item>
          </a-col>
          <a-col :span="18">
            <a-form-model-item label="物料" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               :prop="`list[${index}].materialCode`" style="margin-bottom:0;">
              <j-search-select-tag
                v-model="model.list[index].materialCode"
                dict="material,name,code"
                placeholder="请选择物料编码"
                :pageSize="10"
                :async="true"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
import {materialReceipt} from '@/api/api'

export default {
  name: "MaterialReceiptModal",
  data() {
    return {
      title: "操作",
      width: 800,
      visible: false,
      fromPortList: [
        {label: '站台一', code: 'P31041'},
        {label: '站台二', code: 'P31042'},
        {label: '站台三', code: 'P31043'},
        {label: '站台四', code: 'P31044'},
        {label: '站台五', code: 'P31045'},
      ],
      model: {
        list: []
      },
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
    }
  },
  created() {
    this.model.list = this.fromPortList.map(item => ({
      materialCode: null,
      fromPortCode: item.code
    }))
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    edit() {
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
      if (this.$refs.form) {
        this.$refs.form.clearValidate();
      }
      this.model = JSON.parse(JSON.stringify(this.modelDefault));
    },
    handleOk() {
      const that = this;
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          materialReceipt(this.model.list).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();
          })
        }
      })
    },
    handleCancel() {
      this.close()
    },
  }
}
</script>