<template>
|
<el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
|
<el-form :model="sendForm" :rules="sendRules" :disabled="mode=='show'" ref="dialogForm" label-width="140px" label-position="center">
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="通知方式">
|
<el-select style="width: 100%" v-model="sendForm.provider">
|
<el-option v-for="item in providerList" :key="item.id" :label="item.name" :value="item.id"/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="服务商">
|
<el-select style="width: 100%" v-model="sendForm.type">
|
<el-option v-for="item in providerInfos" :key="item.id" :label="item.name" :value="item.id"/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="接收人">
|
<el-input v-model="sendForm.pname" placeholder="接收人" clearable></el-input>
|
</el-form-item>
|
</el-col>
|
<!-- <el-col :span="24" v-for="(item,index) in sendForm.configuration">
|
<el-form-item :label="item.pname" v-if="item.name != 'properties'">
|
<el-input v-model="item.value" :placeholder="item.name" clearable></el-input>
|
</el-form-item>
|
<el-form-item :label="item.pname" v-if="item.name == 'properties'">
|
<div class="array-content">
|
<el-row v-for="(item1,index1) in item.value">
|
<el-col v-for="(item2,index2) in item1" :span="7">
|
<el-input v-model="item2.value" placeholder ="请输入" style="width: 76%;margin-right: 10px;"></el-input>
|
<el-icon style="vertical-align: -3px;"><ArrowRightBold /></el-icon>
|
</el-col>
|
<el-col :span="3" class="otherBtn">
|
<el-button type="primary" size="small" plain @click="addpro(index,index1)" v-show="index1 == (item.value.length-1)">添加</el-button>
|
<el-button type="danger" size="small" style="margin-left:0;" plain @click="delData(index,index1)" v-show="index1 != (item.value.length-1)">删除</el-button>
|
</el-col>
|
</el-row>
|
</div>
|
</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="sendSubmit">确定</el-button>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script>
|
export default {
|
emits: ['success', 'closed'],
|
data() {
|
return {
|
providerInfos: [],
|
providerList: [],
|
serviceproviders: "",
|
mode: "add",
|
titleMap: {
|
add: '配置调试',
|
edit: '编辑配置',
|
show: '查看'
|
},
|
visible: false,
|
isSaveing: false,
|
//表单数据
|
sendForm: {
|
provider: ""
|
},
|
//验证规则
|
sendRules: {
|
pname:[{required: true, message: '请输入接收人'}]
|
},
|
}
|
},
|
mounted() {
|
},
|
methods: {
|
addpro(index,index1) {
|
this.sendForm.configuration[index].value.push([
|
{name: 'name', value: ''},
|
{name: 'value', value: ''},
|
{name: 'description', value: ''},
|
])
|
},
|
delData(index,index1) {
|
this.sendForm.configuration[index].value.splice(index1,1);
|
},
|
//显示
|
open(tableData,mode='add'){
|
this.providerInfos = tableData[0].providerInfos; //服务商
|
this.getMetadata(); //内容
|
var providerList = [];
|
tableData.forEach(item=> {
|
if(item.isBindBusiness) {
|
providerList.push(item);
|
}
|
})
|
this.providerList = providerList;
|
this.$nextTick(()=> {
|
this.sendForm.provider = this.providerList[0].id;
|
this.sendForm.type = this.providerInfos[0].id;
|
|
console.log(this.providerList,this.sendForm.provider)
|
})
|
this.mode = mode;
|
this.visible = true;
|
return this
|
},
|
getMetadata() {
|
this.$HTTP.get(`/api/blade-notify/notifier/template/dingTalk/dingTalkMessage/config/metadata`).then(res=> {
|
if(res.code == 200) {
|
|
}else {
|
this.$message.error(res.msg);
|
}
|
})
|
},
|
//表单提交方法
|
sendSubmit(){
|
var configuration = {};
|
this.sendForm.configuration.forEach(item=> {
|
configuration[item.name] = item.value;
|
})
|
var obj = {
|
configuration: configuration,
|
}
|
if(this.mode == 'edit') {
|
obj.id = this.sendForm.configEntity.id;
|
obj.name = this.sendForm.configEntity.name;
|
obj.provider = this.sendForm.configEntity.provider;
|
obj.type = this.sendForm.configEntity.type;
|
if(this.sendForm.configEntity.type == "email") { //邮件
|
var newArr = [];
|
configuration.properties.forEach(item=> {
|
var formattedObject = {};
|
item.forEach(item => {
|
formattedObject[item.name] = item.value;
|
});
|
newArr.push(formattedObject);
|
})
|
configuration.properties = newArr;
|
}
|
}
|
if(this.mode == 'add') { //新增
|
obj.name = this.sendForm.pname;
|
obj.provider = this.serviceproviders;
|
obj.type = this.sendForm.id;
|
}
|
this.$refs.dialogForm.validate(async (valid) => {
|
if (valid) {
|
this.isSaveing = true;
|
this.$HTTP.put("/api/blade-notify/notifier/config",obj).then(res=> {
|
this.isSaveing = false;
|
if(res.code == 200) {
|
this.$emit('success', this.sendForm, this.mode);
|
this.visible = false;
|
this.$message.success("编辑成功");
|
}else {
|
this.$alert(res.message, "提示", {type: 'error'});
|
}
|
})
|
}else{
|
return false;
|
}
|
})
|
},
|
//表单注入数据
|
setData(data){
|
|
}
|
},
|
components: {},
|
}
|
</script>
|
|
<style scoped>
|
.modelTitle {
|
padding-left: 45px;
|
padding-bottom: 20px;
|
}
|
.modelTitle span {
|
display: inline-block;
|
width:50%;
|
}
|
.array-content {
|
border: 1px solid #d8d8d8;
|
border-radius: 2px;
|
min-height: 200px;
|
width: 100%;
|
padding: 12px;
|
}
|
.otherBtn {
|
margin-bottom: 12px;
|
}
|
</style>
|