Fixiaobai
2023-10-25 ae87b881865d0b6812aba2a8928cadb9ef6dd62a
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      class="l-mes"
      label-width="85px"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="扫码获取箱号">
            <el-input
              v-model="barCodeValue"
              ref="seach_input"
              placeholder="扫码输入自动解析"
              @input="barCodeChange"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="箱号" prop="no">
            <el-input v-model="dataForm.no" placeholder="箱号"></el-input>
          </el-form-item>
          <el-form-item label="包装尺寸" prop="packSize">
            <el-select
              v-model="dataForm.packSize"
              filterable
              placeholder="请选择包装尺寸"
              style="width: 100%"
              @change="setPackWeight"
            >
              <el-option
                v-for="item in packSizeOptions"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="包装重量" prop="packWeight">
            <el-input
              v-model="dataForm.packWeight"
              placeholder="包装重量"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料编码" prop="cusMaterialCode">
            <el-input
              v-model="dataForm.cusMaterialCode"
              placeholder="物料编码"
            ></el-input>
          </el-form-item>
          <el-form-item label="包材" prop="packMaterial">
            <el-select
              v-model="dataForm.packMaterial"
              filterable
              placeholder="请选择包材"
              style="width: 100%"
            >
              <el-option
                v-for="item in packMaterialOptions"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
import { addObj, getObj, putObj } from '@/api/warehouse/packaging'
import { validateSixDecimalPositives } from '../../../util/validate'
import { remote } from '../../../api/admin/dict'
 
export default {
  data() {
    return {
      assortmentOptions: [],
      packSizeOptions: [],
      packMaterialOptions: [],
      showPart: false,
      visible: false,
      barCodeValue: '',
      timer: null,
      dataForm: {
        id: 0,
        no: '',
        theoreticalNumber: '',
        netWeight: '',
        grossWeight: '',
        createTime: '',
        updateTime: '',
        createUser: '',
        updateUser: '',
        realWeight: '',
        assortment: '',
        number: '',
        packSize: null,
        cusMaterialCode: null,
        packMaterial: null,
        packWeight: null
      },
      dataRule: {
        no: [{ required: true, message: '箱号不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getPackSizeDict()
    this.getPackMaterialDict()
  },
  methods: {
    init(id) {
      this.barCodeValue = ''
      this.dataForm.id = id || 0
      this.dataForm.theoreticalNumber = null
      this.dataForm.netWeight = null
      this.dataForm.grossWeight = null
      this.dataForm.createTime = null
      this.dataForm.updateTime = null
      this.dataForm.createUser = null
      this.dataForm.updateUser = null
      this.dataForm.realWeight = null
      this.dataForm.assortment = null
      this.dataForm.number = null
      this.dataForm.packSize = null
      this.dataForm.cusMaterialCode = null
      this.dataForm.packMaterial = null
      this.dataForm.packWeight = null
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        this.$refs.seach_input.focus()
        if (this.dataForm.id) {
          getObj(this.dataForm.id).then((response) => {
            this.dataForm = response.data.data
          })
        }
      })
    },
    barCodeChange(val) {
      if (this.timer) {
        clearTimeout(this.timer)
      }
      const c = val.trim()
      this.timer = setTimeout(() => {
        if (c) {
          const reg = /^{[\w\W]*}$/
          if (reg.test(c)) {
            this.dataForm.no = JSON.parse(c).package_code
          } else {
            this.dataForm.no = c
          }
          this.barCodeValue = ''
          this.dataFormSubmit()
        }
      }, 500)
    },
    // 获取包装尺寸的字典
    getPackSizeDict() {
      remote('pack_size_weight').then((response) => {
        if (response.data.code === 0) {
          this.packSizeOptions = response.data.data
        }
      })
    },
    // 获取包材的字典
    getPackMaterialDict() {
      remote('pack_material').then((response) => {
        if (response.data.code === 0) {
          this.packMaterialOptions = response.data.data
        }
      })
    },
    setPackWeight() {
      const currPackSize = this.packSizeOptions.find((item) => {
        return item.value == this.dataForm.packSize
      })
      if (currPackSize) {
        this.dataForm.packWeight = currPackSize.description
      }
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs.dataForm.validate((valid) => {
        if (this.dataForm.no.trim().length != 15) {
          this.$message.error('包装箱号的长度不正确,请重新扫码')
          return
        }
        if (this.dataForm.no != null) {
          this.dataForm.theoreticalNumber = this.dataForm.no.trim().substr(8, 2)
        }
        this.dataForm.no = this.dataForm.no.trim()
        if (valid) {
          if (this.dataForm.id) {
            putObj(this.dataForm).then((data) => {
              this.$message.success('修改成功')
              this.visible = false
              this.$emit('refreshDataList')
            })
          } else {
            addObj(this.dataForm).then((response) => {
              if (response.data.code === 0) {
                var data = response.data.data
                this.$message.success('添加成功')
                this.visible = false
                this.$emit('refreshDataList', data.id)
              } else {
                this.$message.error('添加失败')
              }
            })
          }
        }
      })
    }
  }
}
</script>