<template>
    <div v-loading="loading" elemeur-loading-text="正在读取数据...">
        <el-form :model="noticeData" ref="form" :rules="rules" label-position='top'>
            <el-row>
                <el-col :span='24'>
                    <el-form-item label="通知名称" prop="noticeName">
                        <el-select v-model="noticeData.noticeName" placeholder="通知名称" @change="handleChange">
                            <el-option
                                    v-for="item in noticenames"
                                    :key="item.noticename"
                                    :label="item.noticename"
                                    :value="item.noticeclass">
                                <span style="float: left">{{ item.noticename }}</span>
                                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.noticeclass }}</span>
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span='24'>
                    <el-form-item label="通知实现类路径" prop="noticeClass">
                        <el-input  placeholder="通知实现类路径" v-model="noticeData.noticeClass" :disabled="true"/>
                    </el-form-item>
                </el-col>
                <el-col :span='24'>
                    <el-form-item label="通知描述" prop="noticeDesc">
                        <el-input placeholder="通知描述" type="textarea" :autosize="{ minRows: 4, maxRows: 8}" v-model="noticeData.noticeDesc"/>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<script>
    import NoticeApi from "@/api/base/sysm/NoticeApi";

    let defaultData = {
        noticeName: null,
        noticeCode: null,
        noticeType: null,
        noticeDesc: null,
    };

    export default {
        name: "NoticeMgrEdit",
        components: {NoticeApi},
        props: {
            data: {},
            uuid:"",
        },
        data() {
            return {
                table: {
                    data: []
                },
                noticeData:{},
                loading: false,
                noticeTypes:[{
                    value: '0',
                    label: '默认'
                },{
                    value: '1',
                    label: '邮件'
                },{
                    value: '2',
                    label: '短信'
                },{
                    value: '3',
                    label: '电话'
                }],
                rules: {
                    noticeName: [
                        {required: true, message: "请输入通知名称"}
                    ],
                    noticeCode: [
                        {required: true, message: "请输入通知代码"}
                    ],
                    noticeDesc: [
                        {required: true, message: "请输入通知描述"}
                    ],
                },
                noticeClass:"",
                noticenames:[]
            };
        },
        mounted() {
            if(this.uuid){
                // uuid 不是空 查找指定的通知信息
                this.getNotice();
            }
            this.getNoticeCodes();
        },
        watch: {},
        methods: {
            // 验证
            async validate() {
                return this.$refs.form.validate().then(() => this.data);
            },
            // 获取系统通知主题集合
            async getNoticeCodes(){
                await NoticeApi.getNoticeCodes().then(resp=>{
                    this.noticenames = resp.noticeNameList;
                });
            },
            // 查询单个通知
            getNotice(){
                NoticeApi.doGet(this.uuid).then(resp=>{
                    // 赋值
                    this.noticeData = resp;
                })
            },
            // 保存表单
            async submitForm() {
                await this.validate();
                // for (let i=0; i<this.noticenames.length; i++){
                //     if(this.noticenames[i].noticeclass===this.noticeData.noticeClass){
                //         this.noticeData.noticeName = this.noticenames[i].noticeclass;
                //     }
                // }
                await NoticeApi.doSave(this.noticeData);
            },
            handleChange(noticeclass){
                this.noticeData.noticeClass = noticeclass;
            }
        }
    };
</script>
<style lang="scss">
</style>

