<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form ref="dialogForm" :model="formData" :rules="rules" label-width="100px" label-position="top">
            <el-form-item label="回复内容" prop="content">
                <el-input type="textarea" rows="10" v-model="formData.content" clearable placeholder="请输入"></el-input>
                <div class="el-form-item-msg"></div>
            </el-form-item>
        </el-form>
		<template #footer>
            <el-button @click="visible=false" size="large">取 消</el-button>
            <el-button v-if="mode!='show'" size="large" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
    </el-dialog>
    
</template>

<script>
export default {
    data(){
        return {
            loading: false,
            isSaveing: false,
            mode:"add",
            titleMap:{
                add:"新增个人快捷回复",
                edit:"编辑个人快捷回复"
            },
            visible:false,
            formData:{},
            rules:{
                content: [
                    {required: true, message: '请输入'}
                ]
            }
        }
    },
    methods:{
        open(mode = 'add'){
            this.mode = mode;
            this.visible = true;
            return this
        },
        //表单注入数据
        setData(data){
            this.formData = JSON.parse(JSON.stringify(data));
        },
        async submit(){
            var validate = await this.$refs.dialogForm.validate().catch(()=>{});
            if(!validate){ return false }
            this.isSaveing = true;
            let submitData = JSON.parse(JSON.stringify(this.formData));
            var resp = await this.$API.merQuick.save.post(submitData);
            this.isSaveing = false;
            if (resp.code == 0) {
                return this.$message.error(resp.msg);
            }
            this.$message.success(resp.msg);
            this.visible = false;
            this.formData = {};
            this.submitState = false;
            this.$emit("success");
        }
    }
}
</script>

<style>
.text-center{text-align: center;}
</style>