'init'
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
<!--
|
||||
* @Author: zwq
|
||||
* @Date: 2020-12-29 16:37:56
|
||||
* @LastEditors: lb
|
||||
* @LastEditTime: 2022-04-19 15:20:00
|
||||
* @enName:
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:title="!dataForm.id ? 'btn.add' : 'btn.edit' | i18nFilter"
|
||||
width="40%"
|
||||
:visible.sync="visible"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form
|
||||
ref="dataForm"
|
||||
class="data-form"
|
||||
:model="dataForm"
|
||||
:rules="dataRule"
|
||||
@keyup.enter.native="dataFormSubmit()"
|
||||
>
|
||||
<!-- label-width="80px" -->
|
||||
<!-- <el-row :gutter="20">
|
||||
<el-col :span="12"></el-col>
|
||||
<el-col :span="12"></el-col>
|
||||
</el-row> -->
|
||||
<el-form-item :label="$t('module.basicData.equipment.maintenancePeriod')" prop="maintenancePeriod">
|
||||
<el-input
|
||||
v-model="dataForm.maintenancePeriod"
|
||||
:placeholder="$i18nForm(['placeholder.input', $t('module.basicData.equipment.maintenancePeriod')])"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('module.basicData.equipment.PeriodCode')" prop="code">
|
||||
<el-input
|
||||
v-model="dataForm.code"
|
||||
:placeholder="$i18nForm(['placeholder.input', $t('module.basicData.equipment.PeriodCode')])"
|
||||
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>
|
||||
|
||||
<el-row style="text-align: right">
|
||||
<el-button @click="visible = false">{{ 'btn.cancel' | i18nFilter }}</el-button>
|
||||
<el-button type="primary" @click="dataFormSubmit()">{{ 'btn.confirm' | i18nFilter }}</el-button>
|
||||
</el-row>
|
||||
<!-- <span slot="footer" class="dialog-footer">
|
||||
<el-button @click="visible = false">{{ 'btn.cancel' | i18nFilter }}</el-button>
|
||||
<el-button type="primary" @click="dataFormSubmit()">{{ 'btn.confirm' | i18nFilter }}</el-button>
|
||||
</span> -->
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { detail, update, add, getCode } from '@/api/basicData/Equipment/maintenanceCycle'
|
||||
import { refineData } from '@/utils/helpers'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
dataForm: {
|
||||
id: 0,
|
||||
maintenancePeriod: '',
|
||||
code: '',
|
||||
remark: ''
|
||||
},
|
||||
dataRule: {
|
||||
maintenancePeriod: [
|
||||
{
|
||||
required: true,
|
||||
message: this.$i18nForm(['placeholder.input', this.$t('module.basicData.equipment.maintenancePeriod')]),
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
code: [
|
||||
{
|
||||
required: true,
|
||||
message: this.$i18nForm(['placeholder.input', this.$t('module.basicData.equipment.PeriodCode')]),
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init(id) {
|
||||
this.dataForm.id = id || ''
|
||||
this.visible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].resetFields()
|
||||
if (this.dataForm.id) {
|
||||
detail(this.dataForm.id).then(res => {
|
||||
this.dataForm = refineData(res.data, ['id', 'maintenancePeriod', 'code', 'remark'])
|
||||
})
|
||||
} else {
|
||||
getCode().then(res => {
|
||||
this.dataForm.code = res.data
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 表单提交
|
||||
dataFormSubmit() {
|
||||
this.$refs['dataForm'].validate(valid => {
|
||||
if (valid) {
|
||||
const ajaxAction = this.dataForm.id ? update : add
|
||||
ajaxAction(this.dataForm).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>
|
||||
.data-form >>> .el-form-item__label {
|
||||
word-break: break-word;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user