mt-ck-wms-ui/src/views/basicData/Equipment/components/equipmentInfoAttr-add.vue

136 lines
4.2 KiB
Vue
Raw Normal View History

2021-09-13 14:56:28 +08:00
<!--
* @Author: zwq
* @Date: 2020-12-29 16:37:56
* @LastEditors: zwq
* @LastEditTime: 2021-03-25 16:31:46
* @Description:
-->
<template>
<el-drawer
:append-to-body="true"
:show-close="false"
:visible.sync="visible"
size="40%"
>
<div slot="title" style=" background-color:#02BCFF;font-size:1.5em;color:white;padding:5px 20px">
{{ !dataForm.id ? 'btn.add' : 'btn.edit' | i18nFilter }}
</div>
<el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-width="130px" @keyup.enter.native="dataFormSubmit()">
<el-form-item :label="$t('module.basicData.visual.AttributeName')" prop="attrName">
<el-input v-model="dataForm.attrName" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.visual.AttributeName')])" clearable />
</el-form-item>
<el-form-item :label="$t('module.basicData.visual.AttributeValue')" prop="attrValue">
<el-input v-model="dataForm.attrValue" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.visual.AttributeValue')])" clearable />
</el-form-item>
<el-form-item :label="$t('module.basicData.visual.Remarks')" prop="remark">
<el-input v-model="dataForm.remark" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.visual.Remarks')])" clearable />
</el-form-item>
</el-form>
<div class="drawer-footer">
<el-button @click="visible = false">{{ 'btn.cancel' | i18nFilter }}</el-button>
<el-button type="primary" :loading="btnLoading" @click="dataFormSubmit()">{{ 'btn.confirm' | i18nFilter }}</el-button>
</div>
</el-drawer>
</template>
<script>
import { equipmentInfoAttrDetail, equipmentInfoAttrUpdate, equipmentInfoAttrAdd } from '@/api/basicData/Equipment/equipmentInfoAttr'
export default {
props: {
equipmentId: {
type: String,
default: () => {
return ''
}
}
},
data() {
return {
visible: false,
btnLoading: false,
dataForm: {
id: 0,
attrName: '',
attrValue: '',
remark: ''
},
dataRule: {
attrName: [
{ required: true, message: this.$i18nForm(['placeholder.input', this.$t('module.basicData.visual.AttributeName')]), trigger: 'blur' }
],
attrValue: [
{ required: true, message: this.$i18nForm(['placeholder.input', this.$t('module.basicData.visual.AttributeValue')]), trigger: 'blur' }
]
}
}
},
methods: {
init(id) {
this.dataForm.id = id || ''
this.btnLoading = false
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
equipmentInfoAttrDetail(this.dataForm.id).then(res => {
this.dataForm = res.data
})
}
})
},
// 表单提交
dataFormSubmit() {
this.btnLoading = true
this.$refs['dataForm'].validate((valid) => {
if (valid) {
const data = {
'attrName': this.dataForm.attrName,
'attrValue': this.dataForm.attrValue,
'remark': this.dataForm.remark,
'equipmentId': this.equipmentId,
'id': this.dataForm.id
}
if (this.dataForm.id) {
equipmentInfoAttrUpdate(data).then(res => {
this.$message({
message: this.$t('module.basicData.visual.success'),
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
})
} else {
equipmentInfoAttrAdd(data).then(res => {
this.$message({
message: this.$t('module.basicData.visual.success'),
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
})
}
}
})
}
}
}
</script>
<style scoped>
.drawer-footer {
width: 100%;
margin-top: 50px;
border-top: 1px solid #e8e8e8;
padding: 10px 50px;
text-align: left;
background: #fff;
}
</style>