Skip to content
attendDialog.vue 3.08 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
<!--添加代码-->
<template>
    <div class="code">
        <el-dialog :title="title" :visible.sync="dialogFormVisible">
wangqinghua's avatar
wangqinghua committed
            <el-form :model="form" :rules="rulesForm" ref="form" :before-close="initForm">
                <el-form-item label="名称" prop="name" :label-width="formLabelWidth">
wangqinghua's avatar
wangqinghua committed
                    <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
wangqinghua's avatar
wangqinghua committed
                <el-button size="small" @click="initForm">取 消</el-button>
                <el-button size="small" type="primary" @click="submitForm('form')">确 定</el-button>
wangqinghua's avatar
wangqinghua committed
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {addAttendInfo,updateAttendInfo} from "../api/api"
    export default {
        name: "attend-dialog",
        data() {
            return {
                id:"",
                form:{
                  name:"",
                },
wangqinghua's avatar
wangqinghua committed
                rulesForm:{
                    name:[{required:true,message:"请输入名称",trigger:'blur'},{min:1,max:20,message:'长度在1到20个字符之间',trigger:'blur'}]
                },
wangqinghua's avatar
wangqinghua committed
                title: "",
                dialogFormVisible: false,
                formLabelWidth: "100px"
            }
        },
        methods: {
            showAddDialog(title) {
                this.dialogFormVisible = true
                this.title = title;
            },
            showEditDialog(title,item){
                this.dialogFormVisible = true
                this.title = title;
                this.id = item.id;
                this.form.name = item.name
            },
wangqinghua's avatar
wangqinghua committed
            initForm(){
                this.dialogFormVisible = false;
                this.$refs['form'].resetFields();
            },
            submitForm(formName){
                this.$refs[formName].validate((valid)=>{
                    console.log(valid)
                    if(valid){
                        if(this.title == "添加列席"){
                            addAttendInfo(this.form).then(
                                (res)=>{
                                    this.$message.success('添加成功')
                                    this.$emit('update',res.data)
                                    this.initForm()
                                }
                            )
                        }else{
                            const data = {
                                id:this.id,
                                name:this.form.name,
                            }
                            updateAttendInfo(data).then(
                                (res)=>{
                                    this.$emit('update',res.data)
                                    this.$message.success('编辑成功')
                                    this.initForm()
                                }
                            )
wangqinghua's avatar
wangqinghua committed
                        }
wangqinghua's avatar
wangqinghua committed
                    }else{
                        return false
wangqinghua's avatar
wangqinghua committed
                    }
wangqinghua's avatar
wangqinghua committed
                })
wangqinghua's avatar
wangqinghua committed
            }

        }
    }
</script>

<style scoped>

</style>