1
lzhe
2024-06-21 9c094a1fe3e1ae3dadef6433f8401818fe2b8304
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
        <div class="modelTitle">
            <span>所属业务 {{addBusinessForm.businessName}}</span>
            <span>通知类型 {{addBusinessForm.notifyName}}</span>
            <span>服务商 {{addBusinessForm.providerName}}</span>
        </div>
        <el-form :model="addBusinessForm" :rules="addBusinessRules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="center">
            <el-row>
                <el-col :span="24">
                    <el-form-item label="模版名称" prop="notifyTemplateName">
                        <el-input v-model="addBusinessForm.notifyTemplateName" placeholder="模版名称" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-for="item in addBusinessForm.properties">
                    <el-form-item :label="item.name" v-if="(addBusinessForm.notifyName != '站内信' && addBusinessForm.notifyName != '邮件') || (item.property != 'content' && item.property != 'attachments')">
                        <el-input v-model="addBusinessForm[item.property]" :placeholder="item.name" clearable></el-input>
                    </el-form-item>
 
                    <el-form-item :label="item.name" v-if="(addBusinessForm.notifyName == '站内信' || addBusinessForm.notifyName == '邮件') && item.property == 'content'">
                        <avue-ueditor v-model="addBusinessForm.content" v-bind="options"></avue-ueditor>
                    </el-form-item>
                </el-col>
                <!-- <el-col :span="24">
                    <el-form-item label="标题">
                        <el-input v-model="addBusinessForm.title" placeholder="标题" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="内容">
                        <el-input v-model="addBusinessForm.message" placeholder="内容" clearable></el-input>
                    </el-form-item>
                </el-col> -->
            </el-row>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取消</el-button>
            <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="businessSubmit">确定</el-button>
        </template>
    </el-dialog>
</template>
 
<script>
    export default {
        emits: ['success', 'closed'],
        data() {
            return {
                options: {
                    //普通上传地址
                    action: "/api/blade-resource/oss/endpoint/put-file",
                    customConfig: {},//wangEditor编辑的配置
                    headers:{Authorization: "Basic c2FiZXI6c2FiZXJfc2VjcmV0"},
                    data:{},
                    propsHttp: {
                      home:'',
                      url:'url',
                      res: 'data'
                    },
                },
                mode: "add",
                titleMap: {
                    add: '新增',
                    edit: '编辑模版',
                    show: '查看'
                },
                visible: false,
                isSaveing: false,
                //表单数据
                addBusinessForm: {
                    notifyTemplateName: "",
                    agentId: "",
                    title: "",
                    message: ""
                },
                //验证规则
                addBusinessRules: {
                    notifyTemplateName:[{required: true, message: '请输入模版名称'}]
                },
            }
        },
        mounted() {
        },
        methods: {
            //显示
            open(mode='add'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            //表单提交方法
            businessSubmit(){
                var obj = Object.assign({},this.addBusinessForm);
                obj.notifyType = obj.notifyType;
                obj.id = obj.notifyTemplateId;
                obj.business = obj.businessKey;
                obj.name = obj.notifyTemplateName;
                obj.provider = obj.providerType;
                obj.type = obj.notifyType;
                var template = JSON.parse(obj.template);
                for(var key in template) {
                    template[key] = obj[key];
                }
                obj.template = JSON.stringify(template);
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        this.$HTTP.put("/api/blade-notify/business-notify/modify",obj).then(res=> {
                            this.isSaveing = false;
                            if(res.code == 200) {
                                this.$emit('success', this.addBusinessForm, this.mode);
                                this.visible = false;
                                this.$message.success("编辑成功");
                            }else {
                                this.$alert(res.message, "提示", {type: 'error'});
                            }
                        })
                    }else{
                        return false;
                    }
                })
            },
            //表单注入数据
            setData(data){
                var template = JSON.parse(data.template);
                Object.assign(data, template);
                //可以和上面一样单个注入,也可以像下面一样直接合并进去
                Object.assign(this.addBusinessForm, data);
                console.log(this.addBusinessForm)
            }
        }
    }
</script>
 
<style scoped>
.modelTitle {
    padding-left: 45px;
    padding-bottom: 20px;
}
.modelTitle span {
    display: inline-block;
    width:30%;
}
</style>