mt-qj-wms-ui/src/views/basic/components/location-add.vue

126 lines
4.0 KiB
Vue

<!--
* @Author: zwq
* @Date: 2021-11-18 14:16:25
* @LastEditors: zwq
* @LastEditTime: 2021-12-08 14:11:44
* @Description:
-->
<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()" label-width="80px">
<el-form-item label="库位名称" prop="locationName">
<el-input v-model="dataForm.locationName" placeholder="库位名称"></el-input>
</el-form-item>
<el-form-item label="库位编码" prop="code">
<el-input v-model="dataForm.code" placeholder="库位编码"></el-input>
</el-form-item>
<el-form-item label="当前状态" prop="alarmInfo"
><el-switch
v-model="dataForm.alarmInfo"
active-color="#13ce66"
inactive-color="#ff4949"
active-value="1"
inactive-value="0"
>
</el-switch>
</el-form-item>
<el-form-item label="库位别名" prop="locationNameAlias">
<el-input v-model="dataForm.locationNameAlias" placeholder="库位别名"></el-input>
</el-form-item>
<el-form-item label="英文名称" prop="alarmInfo">
<el-input v-model="dataForm.alarmInfo" placeholder="英文名称"></el-input>
</el-form-item>
</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>
export default {
data () {
return {
visible: false,
dataForm: {
id: '',
code: '',
locationName: '',
locationNameAlias: '',
warehouseId: ''
},
dataRule: {
code: [
{ required: true, message: '编码不能为空', trigger: 'blur' }
]
}
}
},
methods: {
init (id, warehouseId) {
this.dataForm.id = id || ''
this.dataForm.warehouseId = warehouseId
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
this.$http({
url: this.$http.adornUrl(`locationInfo/get`),
method: 'post',
data: this.$http.adornData({id})
}).then(({data}) => {
if (data && data.code === 0) {
this.dataForm = data.data
}
})
} else {
this.$http({
url: this.$http.adornUrl(`locationInfo/codeGenerator`),
method: 'post',
data: this.$http.adornData()
}).then((data) => {
this.dataForm.code = data.data
})
}
})
},
// 表单提交
dataFormSubmit () {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.$http({
url: this.$http.adornUrl(`locationInfo/${!this.dataForm.id ? 'add' : 'update'}`),
method: 'post',
data: this.$http.adornData({
'id': this.dataForm.id || undefined,
'code': this.dataForm.code,
'locationName': this.dataForm.locationName,
'warehouseId': this.dataForm.warehouseId,
'locationNameAlias': this.dataForm.locationNameAlias
})
}).then(({data}) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
} else {
this.$message.error(data.msg)
}
})
}
})
}
}
}
</script>