<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>
|