<template>
|
<el-dialog :visible.sync="visible" append-to-body :title="!dataForm.id ? $t('add') : $t('update')"
|
:close-on-click-modal="false" :close-on-press-escape="false">
|
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()"
|
label-width="120px">
|
<el-row>
|
<el-col :span="12">
|
<el-form-item prop="mcName" label="煤仓名称">
|
<el-input v-model="dataForm.mcName" placeholder="煤仓名称"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item prop="mc" label="煤仓编号">
|
<el-input v-model="dataForm.mc" placeholder="煤仓编号"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item prop="unit" label="单位">
|
<el-input v-model="dataForm.unit" placeholder="单位"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item prop="capacity" label="容量">
|
<el-input v-model="dataForm.capacity" placeholder="容量"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template slot="footer">
|
<el-button size="mini" :loading="loading" @click="visible = false">{{ $t('cancel') }}</el-button>
|
<el-button size="mini" :loading="loading" type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}
|
</el-button>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script>
|
import debounce from 'lodash/debounce'
|
import DictSelectTag from "@/components/dict/dict-select-tag";
|
|
export default {
|
components: {DictSelectTag},
|
data() {
|
return {
|
visible: false,
|
loading: false,
|
dictCodeMz: '',
|
dataForm: {
|
mclx:'',
|
mc:'',
|
mcName: '',
|
unit: '',
|
capacity: ''
|
}
|
}
|
},
|
computed: {
|
dataRule() {
|
return {
|
mcName: [
|
{required: true, message: this.$t('validate.required'), trigger: 'blur'}
|
],
|
mc: [
|
{required: true, message: this.$t('validate.required'), trigger: 'blur'}
|
],
|
unit: [
|
{required: true, message: this.$t('validate.required'), trigger: 'blur'}
|
],
|
capacity: [
|
{required: true, message: this.$t('validate.required'), trigger: 'blur'}
|
]
|
}
|
}
|
},
|
methods: {
|
init(id,dictCode) {
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs['dataForm'].resetFields()
|
this.dataForm.mclx = dictCode
|
this.dataForm.id = id
|
if ('ymc' === dictCode) {
|
this.dictCodeMz = 'ymmz'
|
} else if ('cpc' === dictCode) {
|
this.dictCodeMz = 'cpmz'
|
}
|
if (this.dataForm.id) {
|
this.getInfo()
|
}
|
})
|
},
|
// 获取信息
|
getInfo() {
|
this.$http.get(`/iailab-iems-coal-proddisp/warehouse/item/info/${this.dataForm.id}`).then(({data: res}) => {
|
if (res.code !== 0) {
|
return this.$message.error(res.msg)
|
}
|
this.dataForm = {
|
...this.dataForm,
|
...res.info
|
}
|
}).catch(() => {
|
})
|
},
|
// 表单提交
|
dataFormSubmitHandle: debounce(function () {
|
this.$refs['dataForm'].validate((valid) => {
|
if (!valid) {
|
return false
|
}
|
this.loading = true
|
this.$http.post(`/iailab-iems-coal-proddisp/warehouse/item/${!this.dataForm.id ? 'add' : 'update'}`, this.dataForm).then(({data: res}) => {
|
if (res.code !== 0) {
|
return this.$message.error(res.msg)
|
}
|
this.$message({
|
message: this.$t('prompt.success'),
|
type: 'success',
|
duration: 500,
|
onClose: () => {
|
this.visible = false
|
this.$emit('refreshDataList')
|
}
|
})
|
this.loading = false
|
}).catch(() => {
|
})
|
})
|
}, 1000, {'leading': true, 'trailing': false})
|
}
|
}
|
</script>
|