liuying
2024-04-23 f74f6ce835a413d14e37c89163a2af7309bd31e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
  <a-modal
    title="新增物料信息"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <!-- tab -->
      <a-tabs default-active-key="1" @change="callback">
        <a-tab-pane key="1" tab="基本信息">
         <add-form ref="addForm" @ok="handleOk" />
        </a-tab-pane>
        <a-tab-pane key="2" tab="控制属性" force-render>
          Content of Tab Pane 2
        </a-tab-pane>
        <a-tab-pane key="3" tab="批次属性">
          Content of Tab Pane 3
        </a-tab-pane>
        <a-tab-pane key="4" tab="替代品管理">
          Content of Tab Pane 4
        </a-tab-pane>
        <a-tab-pane key="5" tab="客户">
          <add-form-base-customer ref="addFormBaseCustomer" @ok="handleOk" />
        </a-tab-pane>
 
        <a-tab-pane key="7" tab="包装关系">
          <add-form-container-packaging ref="addFormContainerPackaging" @ok="handleOk" />
        </a-tab-pane>
      </a-tabs>
 
    </a-spin>
  </a-modal>
</template>
 
<script>
import { WmsMaterialAdd, GetAreas, GetStations } from '@/api/modular/main/WmsMaterialManage'
import addForm from './tabItem/addForm.vue'
import addFormBaseCustomer from './tabItem/addFormBaseCustomer.vue'
import addFormContainerPackaging from './tabItem/addFormContainerPackaging.vue'
 
export default {
  components: {
    // STable,
    addForm,
    addFormBaseCustomer,
    addFormContainerPackaging,
  },
  data() {
    return {
      labelCol: {
        // xs: { span: 24 },
        // sm: { span: 5 }
        span: 8
      },
      wrapperCol: {
        // xs: { span: 24 },
        // sm: { span: 15 }
        span: 13
      },
      inspectionMethodData: [],
      materialTypeData: [],
      areaNameParameterData: [],
      stationNameParameterData: [],
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this)
    }
  },
  methods: {
    // 初始化方法
    add(record) {
      this.visible = true
      this.$nextTick(() => {
        this.getSelects()
      })
      const materialTypeOption = this.$options
      this.materialTypeData = materialTypeOption.filters['dictData']('material_type')
      const inspectionMethodOption = this.$options
      this.inspectionMethodData = inspectionMethodOption.filters['dictData']('material_inspection')
    },
    getSelects() {
      if (this.areaNameParameterData.length <= 0 || this.stationNameParameterData.length <= 0) {
        this.confirmLoading = true
        Promise.all([GetAreas(), GetStations()])
          .then(response => {
            this.areaNameParameterData = response[0].data || []
            this.stationNameParameterData = response[1].data || []
            this.confirmLoading = false
          })
          .catch(() => {
            this.confirmLoading = false
          })
      }
    },
    /**
     * 提交表单
     */
    handleSubmit() {
      const {
        form: { validateFields }
      } = this
      this.confirmLoading = true
      validateFields((errors, values) => {
        if (!errors) {
          if (this.$getObjectType(values.areas) === 'array') {
            values.areaIds = values.areas.join(',')
            values.areaNameParameterArr = values.areas.map(val => {
              return this.parseSelectName(val, 'areaId', 'areaName', 'areaNameParameterData')
            })
            values.areaNameParameter = values.areaNameParameterArr.join(',')
          }
          if (this.$getObjectType(values.stations) === 'array') {
            values.stationIds = values.stations.join(',')
            values.stationNameParameterArr = values.stations.map(val => {
              return this.parseSelectName(val, 'stationId', 'stationName', 'stationNameParameterData')
            })
            values.stationNameParameter = values.stationNameParameterArr.join(',')
          }
          WmsMaterialAdd(values)
            .then(res => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败:' + JSON.stringify(res.message))
              }
            })
            .finally(res => {
              this.confirmLoading = false
            })
        } else {
          this.confirmLoading = false
        }
      })
    },
    parseSelectName(val, field, nfield, pfield) {
      let res = val
      for (let i = 0; i < this[pfield].length; i++) {
        if (val === this[pfield][i][field]) {
          res = this[pfield][i][nfield]
          break
        }
      }
      return res
    },
    handleCancel() {
      this.form.resetFields()
      this.visible = false
    }
  }
}
</script>