MaterialReceiptModal.vue 5.08 KB
<template>
  <j-modal
    :title="title"
    :width="1800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <div style="padding: 10px 16px; text-align: left;">
      <a-button type="primary" @click="addCommonInput" icon="plus">
        添加
      </a-button>
    </div>

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model">
        <a-row :gutter="24">
          <a-col :span="4" v-for="(item, index) in fromPortList" :key="index">
            <div style="font-weight:bold; font-size:15px; margin-bottom:16px; text-align:center;">
              {{ item.label }}
            </div>

            <a-row :gutter="8" style="margin-bottom: 12px;">
              <a-col :span="8" style="line-height: 32px; text-align: right; padding-right: 8px;">
                物料编码
              </a-col>
              <a-col :span="16">
                <j-search-select-tag
                  v-model="model.list[index].materialCode"
                  :dictOptions="model.list[index].materialList"
                  placeholder="请选择物料编码"
                  @search="(val) => searchMaterial(val, index)"
                />
              </a-col>
            </a-row>
            <a-row
              v-for="(boxNo, boxIdx) in model.list[index].boxCount"
              :key="boxIdx"
              :gutter="8"
              style="margin-bottom: 12px;"
            >
              <a-col :span="8" style="line-height: 32px; text-align: right; padding-right: 8px;">
                第{{ boxNo }}箱
              </a-col>
              <a-col :span="16">
                <a-input v-model="model.list[index].boxList[boxIdx]" style="width: 100%;" />
              </a-col>
            </a-row>
<!--            <a-row v-for="n in 8" :key="`fixed-${n}`" :gutter="8" style="margin-bottom: 12px;">
              <a-col :span="8" style="line-height: 32px; text-align: right; padding-right: 8px;">
                第{{ n }}箱
              </a-col>
              <a-col :span="16">
                <a-input v-model="model.list[index][`input${n}`]" style="width: 100%;" />
              </a-col>
            </a-row>

            <a-row v-for="(inputKey, inputIdx) in dynamicInputKeys" :key="`dynamic-${inputIdx}`" :gutter="8" style="margin-bottom: 12px;">
              <a-col :span="8" style="line-height: 32px; text-align: right; padding-right: 8px;">
                第{{ 8 + inputIdx + 1 }}箱
              </a-col>
              <a-col :span="16">
                <a-input v-model="model.list[index][inputKey]" style="width: 100%;" />
              </a-col>
            </a-row>-->
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

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

export default {
  name: 'MaterialReceiptModal',
  data() {
    return {
      title: '辅料入库',
      width: 1600,
      visible: false,
      confirmLoading: false,
      fromPortList: [
        { label: '站台一(P31041)', code: 'P31041' },
        { label: '站台二(P31042)', code: 'P31042' },
        { label: '站台三(P31043)', code: 'P31043' },
        { label: '站台四(P31044)', code: 'P31044' },
        { label: '站台五(P31045)', code: 'P31045' },
      ],
      model: { list: [] },
      dynamicInputKeys: [],
      dynamicIndex: 1,
    }
  },
  created() {
    this.initForm()
  },
  methods: {
    searchMaterial(val) {
      try {
        searchMaterialByCode({ code: val }).then(res => {
          const list = res.result.filter(x => x.value === '000006' || x.value === '000002')
          this.model.list.forEach((item, i) => {
            this.model.list[i].materialList = list
          })
        })
      } catch (err) {
        this.model.list.forEach((item, i) => {
          this.model.list[i].materialList = []
        })
      }
    },
    initForm() {
      this.model.list = this.fromPortList.map(() => ({
        materialCode: null,
        materialList: [],
        boxCount: 8,
        boxList: ['', '', '', '', '', '', '', ''],
      }))
      this.searchMaterial()
    },
    addCommonInput() {
      this.model.list.forEach(item => {
        item.boxCount += 1
        item.boxList.push('')
      })
    },
    edit() {
      this.initForm()
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.$refs.form && this.$refs.form.clearValidate()
    },
    handleOk() {
      this.confirmLoading = true
      const params = this.model.list.map((item, index) => ({
        fromPortCode: this.fromPortList[index].code,
        materialCode: item.materialCode,
        batchList: item.boxList.filter(i => i),
      }))
      materialReceipt(params).then(res => {
        if (res.success) {
          this.$message.success('提交成功')
          this.$emit('ok')
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.confirmLoading = false
        this.close()
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>