<template>
    <div>
        <el-dialog title="新增模板" :visible="uploadVisable" v-if="uploadVisable" @close="cancel" width="600px" center>
            <el-form :model="ruleForm" label-position="left" :rules="rules" ref="ruleForm" label-width="90px"
                class="demo-ruleForm">
                <el-form-item label="模板名称" prop="name">
                    <el-input v-model="ruleForm.name"></el-input>
                </el-form-item>
                <el-form-item label="模板类型" prop="type">
                    <el-select v-model="ruleForm.type" placeholder="请选择">
                        <el-option v-for="dict in dict.type.manager_type" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="模板内容" prop="content">
                    <el-input type="textarea" placeholder="请输入内容" v-model="ruleForm.content">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel" class="endbutton"><span>取 消</span></el-button>
                <el-button type="primary" @click="submitUpload" class="endbutton"><span>确认</span></el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { getToken } from "@/utils/auth";
import {
    insertManager,
} from "@/api/officialSeal/officialSeal.js";
export default {
    props: ["uploadVisable", "uploadData", "queryParams"],
    dicts: ["manager_type"],
    data() {
        return {
            fileList: [],
            data: [],
            tempList: [],
            isImg: false,
            headers: {
                Authorization: "Bearer " + getToken(),
            },
            filedata: {},
            flagBtn: false,
            ruleForm: {},
            rules: {
                name: [
                    { required: true, message: '请输入模板名称', trigger: 'blur' },
                ],
                type: [
                    { required: true, message: '请输入模板名称', trigger: 'blur' },
                ],
                content: [
                    { required: true, message: '请输入模板名称', trigger: 'blur' },
                ]
            }
        };
    },
    watch: {
        uploadVisable(val) {
            if (val) {
                this.ruleForm = {};
            }
        }
    },
    created() {

    },
    methods: {
        cancel() {
            this.$emit("cancelUpload");
        },
        // 新增模板
        insertManagerFn(data) {
            insertManager(data).then(res => {
                this.$message.success('新增成功');
                this.$emit("cancelUpload");
                this.$emit('getList', this.queryParams);
            })
        },
        submitUpload() {
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    console.log(this.ruleForm, "LLLLLLLLLLLLLLLLLLLLLLL");
                    this.insertManagerFn(this.ruleForm)
                }
            });
        },
    },
};
</script>
  
<style lang="scss" scoped></style>