1
lzhe
2024-06-05 dcf9c9e0410fe1186239e3f8d6f7bdc789c08010
src/views/notification/editbusiness.vue
@@ -1,37 +1,41 @@
<template>
   <el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
      <el-form :model="addDictForm" :rules="addDictRules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="center">
      <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="code">
                  <el-input v-model="addDictForm.code" placeholder="字典编号" clearable></el-input>
               <el-form-item label="模版名称" prop="notifyTemplateName">
                  <el-input v-model="addBusinessForm.notifyTemplateName" placeholder="模版名称" clearable></el-input>
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="字典名称" prop="dictValue">
                  <el-input v-model="addDictForm.dictValue" placeholder="字典名称" clearable></el-input>
            <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="12">
               <el-form-item label="字典排序" prop="sort">
                  <el-input v-model="addDictForm.sort" placeholder="字典排序" clearable></el-input>
            <!-- <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="12">
               <el-form-item label="封存">
                  <el-switch v-model="addDictForm.isSealed" />
            <el-col :span="24">
               <el-form-item label="内容">
                  <el-input v-model="addBusinessForm.message" placeholder="内容" clearable></el-input>
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="字典备注">
                  <el-input v-model="addDictForm.remark" placeholder="字典备注" clearable></el-input>
               </el-form-item>
            </el-col>
            </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="dictSubmit()">保 存</el-button>
         <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>
@@ -41,48 +45,40 @@
      emits: ['success', 'closed'],
      data() {
         return {
            value1: true,
            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: '修改',
               edit: '编辑模版',
               show: '查看'
            },
            visible: false,
            isSaveing: false,
            //表单数据
            addDictForm: {
               code: "",
               dictValue: "",
               sort: "",
               isSealed: false,
               remark: "",
               dictKey: "-1",
               $isSealed: "否"
            addBusinessForm: {
               notifyTemplateName: "",
               agentId: "",
               title: "",
               message: ""
            },
            //验证规则
            addDictRules: {
               code:[{required: true, message: '请输入字典编号'}],
               dictValue:[{required: true, message: '请输入字典名称'}],
               sort:[{required: true, message: '请输入字典排序'}]
            addBusinessRules: {
               notifyTemplateName:[{required: true, message: '请输入模版名称'}]
            },
            //所需数据选项
            groups: [],
            groupsProps: {
               value: "id",
               multiple: true,
               checkStrictly: true
            },
            depts: [],
            deptsProps: {
               value: "id",
               checkStrictly: true
            }
         }
      },
      mounted() {
         // this.getGroup()
         // this.getDept()
      },
      methods: {
         //显示
@@ -91,34 +87,29 @@
            this.visible = true;
            return this
         },
         //加载树数据
         async getGroup(){
            var res = await this.$API.system.role.list.get();
            this.groups = res.data.rows;
         },
         async getDept(){
            var res = await this.$API.system.dept.list.get();
            this.depts = res.data;
         },
         //表单提交方法
         dictSubmit(){
            var obj = Object.assign({},this.addDictForm);
            if(obj.isSealed === true) {
               obj.$isSealed = "是";
               obj.isSealed = "1";
            }else {
               obj.$isSealed = "否";
               obj.isSealed = "0";
         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.post("/api/blade-system/dict/submit",obj).then(res=> {
                  this.$HTTP.put("/api/blade-notify/business-notify/modify",obj).then(res=> {
                     this.isSaveing = false;
                     if(res.code == 200) {
                        this.$emit('success', this.addDictForm, this.mode);
                        this.$emit('success', this.addBusinessForm, this.mode);
                        this.visible = false;
                        this.$message.success("操作成功");
                        this.$message.success("编辑成功");
                     }else {
                        this.$alert(res.message, "提示", {type: 'error'});
                     }
@@ -130,18 +121,23 @@
         },
         //表单注入数据
         setData(data){
            console.log(data)
            var template = JSON.parse(data.template);
            Object.assign(data, template);
            //可以和上面一样单个注入,也可以像下面一样直接合并进去
            if(data.isSealed == "1") {
               data.isSealed = true;
            }else {
               data.isSealed = false;
            }
            Object.assign(this.addDictForm, data);
            Object.assign(this.addBusinessForm, data);
            console.log(this.addBusinessForm)
         }
      }
   }
</script>
<style>
<style scoped>
.modelTitle {
   padding-left: 45px;
    padding-bottom: 20px;
}
.modelTitle span {
   display: inline-block;
   width:30%;
}
</style>