<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="name">
|
<el-input v-model="dataForm.name" placeholder="姓名"></el-input>
|
</el-form-item>
|
<el-form-item label="性别" prop="sex">
|
<!--<el-input v-model="dataForm.sex" placeholder="性别"></el-input>-->
|
<el-select v-model="dataForm.sex" placeholder="性别">
|
<el-option value="男" label="男">男</el-option>
|
<el-option value="女" label="女">女</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="民族" prop="nation">
|
<el-input v-model="dataForm.nation" placeholder="民族"></el-input>
|
</el-form-item>
|
<el-form-item label="出生日期" prop="birthday">
|
<!--<el-input v-model="dataForm.birthday" placeholder="出生日期"></el-input>-->
|
<el-date-picker
|
v-model="dataForm.birthday"
|
type="date"
|
placeholder="选择日期">
|
</el-date-picker>
|
</el-form-item>
|
<el-form-item label="住址" prop="address">
|
<el-input v-model="dataForm.address" placeholder="地址"></el-input>
|
</el-form-item>
|
<el-form-item label="身份证号" prop="cardNo">
|
<el-input v-model="dataForm.cardNo" placeholder="身份证号"></el-input>
|
</el-form-item>
|
<el-form-item label="违法总数" prop="lawNum">
|
<el-input v-model="dataForm.lawNum" 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>
|
import {getObj, addObj, putObj} from '@/api/person'
|
|
export default {
|
data () {
|
return {
|
visible: false,
|
dataForm: {
|
id: 0,
|
name: '',
|
sex: '',
|
birthday: '',
|
cardNo: '',
|
address: '',
|
phone: '',
|
lawNum: '',
|
nation: ''
|
},
|
dataRule: {
|
name: [
|
{ required: true, message: '姓名不能为空', trigger: 'blur' }
|
],
|
sex: [
|
{ required: true, message: '性别不能为空', trigger: 'blur' }
|
],
|
nation: [
|
{ required: true, message: '民族不能为空', trigger: 'blur' }
|
],
|
birthday: [
|
{ required: true, message: '出生日期不能为空', trigger: 'blur' }
|
],
|
address: [
|
{ required: true, message: '住址不能为空', trigger: 'blur' }
|
],
|
cardNo: [
|
{ required: true, message: '身份证号不能为空', trigger: 'blur' }
|
],
|
lawNum: [
|
{ required: true, message: '违法总数不能为空', trigger: 'blur' }
|
]
|
}
|
}
|
},
|
methods: {
|
init (id) {
|
this.dataForm.id = id || 0
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs['dataForm'].resetFields()
|
if (this.dataForm.id) {
|
getObj(this.dataForm.id).then(response => {
|
this.dataForm = response.data.data
|
})
|
}
|
})
|
},
|
// 表单提交
|
dataFormSubmit () {
|
this.dataForm.birthday = this.moment(this.dataForm.birthday).format('YYYY-MM-DD')
|
this.$refs['dataForm'].validate((valid) => {
|
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(data => {
|
this.$message.success('添加成功')
|
this.visible = false
|
this.$emit('refreshDataList')
|
})
|
}
|
}
|
})
|
}
|
}
|
}
|
</script>
|