liuying
2024-04-24 ef2eff66971bdaa912cb7373446cc3b092785913
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<template>
  <a-modal title="新增物料信息" :width="900" :visible="visible" :confirmLoading="confirmLoading" @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- tab @change="callback"-->
      <a-tabs default-active-key="1">
        <a-tab-pane key="1" tab="基本信息">
          <add-form ref="addForm" @ok="handleOk" />
        </a-tab-pane>
        <a-tab-pane key="2" tab="控制属性" force-render>
          <add-control-rule ref="WmsControlRule" @ok="handleOk" />
        </a-tab-pane>
        <a-tab-pane key="3" tab="批次属性">
          需求待定
        </a-tab-pane>
        <a-tab-pane key="4" tab="替代品管理">
          <add-form-sub ref="addFormWmsSubstituteGood" @ok="handleOk" />
        </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/addFormBaseCustomer.vue'
import addFormContainerPackaging from './tabItem/WmsContainerPackaging/addFormContainerPackaging.vue'
import addFormSub from './tabItem/WmsSubstituteGood/addFormWmsSubstituteGood.vue'
import addControlRule from './tabItem/WmsControlRule/index.vue'
 
export default {
  components: {
    addForm,
    addFormBaseCustomer,
    addFormContainerPackaging,
    addFormSub,
    addControlRule
  },
  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: {
    handleOk() {
 
    },
    // 初始化方法
    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(',')
          }
          console.log(6666666666666)
          console.log()
          console.log(6666666666666 + '控制属性')
          console.log(this.$refs.WmsControlRule.selectedRows)
          var ControlRuleld = this.$refs.WmsControlRule.selectedRows[0].id;
 
          console.log(6666666666666 + '替代品')
          console.log(this.$refs.addFormWmsSubstituteGood.list)
 
          console.log(6666666666666 + '客户档案集合')
          console.log(this.$refs.addFormBaseCustomer.list)
 
          var param = {
            value1: values,
            ControlRuleld: ControlRuleld, //控制属性
            BaseCustomerList: this.$refs.addFormBaseCustomer.list, //客户档案集合
            SubstituteGoodLis: this.$refs.addFormWmsSubstituteGood.list, //替代品
            value5: {},
            value6: {},
          }
          WmsMaterialAdd(param)
            .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>