中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

209 lines
6.2 KiB

import { HttpClient } from "@angular/common/http";
import { Component, OnInit, ViewContainerRef } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { NzModalService } from "ng-zorro-antd/modal";
import { NzMessageService } from "ng-zorro-antd/message";
import { EditPushItemComponent } from "./edit-push-item/edit-push-item.component";
@Component({
selector: "app-push",
templateUrl: "./push.component.html",
styleUrls: ["./push.component.scss"],
})
export class PushComponent implements OnInit {
validateForm!: FormGroup;
constructor(
private modal: NzModalService,
private viewContainerRef: ViewContainerRef,
private fb: FormBuilder,
private http: HttpClient,
private message: NzMessageService
) {}
checked;
level: number; //当前登录账号的组织机构等级
async ngOnInit(): Promise<void> {
this.level = JSON.parse(
sessionStorage.getItem("userdata")
).organization.level;
this.validateForm = this.fb.group({
search: [null],
});
await this.getPutRoles();
// await this.getHandleRoles()
await this.getNoteRoles();
this.getViolation();
this.getSetting();
}
//获取短信推送状态
getSetting() {
let params = {
settingName: "ViolationSmsSwitch",
};
this.http
.get("/api/services/app/Configuration/GetSetting", { params: params })
.subscribe((data: any) => {
// console.log('获取短信推送状态', data)
data.result == "true" ? (this.checked = true) : (this.checked = false);
});
}
changeNotePush(e) {
console.log(e);
let params = {
settingName: "ViolationSmsSwitch",
value: e,
};
this.http
.post("/api/services/app/Configuration/SetSetting", "", {
params: params,
})
.subscribe((data: any) => {
// console.log('设置短信推送状态成功', data)
if (e) {
this.message.create("success", "开启成功!");
} else {
this.message.create("success", "关闭成功!");
}
});
}
//获取预警类型
list: any;
getViolation() {
this.http
.get("/api/services/app/Violation/GetAllList")
.subscribe((data: any) => {
data.result.forEach((element) => {
element.pushRoleNames = [];
element.pushRoleIds.forEach((item) => {
this.pushRoleIds.forEach((i) => {
if (i.id == item) {
element.pushRoleNames.push(i.displayName);
}
});
});
// element.handleRoleNames = []
// element.handleRoleIds.forEach(item => {
// this.handleRoleIds.forEach(i => {
// if (i.id == item) {
// element.handleRoleNames.push(i.displayName)
// }
// });
// });
element.noteRoleNames = [];
element.smsPushRoleIds.forEach((item) => {
this.noteRoleIds.forEach((i) => {
if (i.id == item) {
element.noteRoleNames.push(i.displayName);
}
});
});
});
this.list = data.result;
console.log("预警类型", this.list);
});
}
//获取推送的角色列表
pushRoleIds;
async getPutRoles() {
await new Promise<void>((resolve, reject) => {
this.http
.get("/api/services/app/Violation/GetPutRoles")
.subscribe((data: any) => {
this.pushRoleIds = data.result;
resolve(data);
console.log("推送角色", data);
});
});
}
// handleRoleIds
// //获取处置的角色列表
// async getHandleRoles() {
// await new Promise<void>((resolve, reject) => {
// this.http.get('/api/services/app/Violation/GetHandleRoles').subscribe((data: any) => {
// this.handleRoleIds = data.result
// resolve(data)
// console.log('处置角色', data)
// })
// })
// }
noteRoleIds;
//获取处置的角色列表
async getNoteRoles() {
await new Promise<void>((resolve, reject) => {
this.http
.get("/api/services/app/Violation/GetSmsPutRoles")
.subscribe((data: any) => {
this.noteRoleIds = data.result;
resolve(data);
console.log("短信角色", data);
});
});
}
edititem(item) {
console.log(item);
const modal = this.modal.create({
nzTitle: "编辑推送设置",
nzContent: EditPushItemComponent,
nzViewContainerRef: this.viewContainerRef,
nzWidth: 400,
nzComponentParams: {
data: item,
pushRoleIds: this.pushRoleIds,
noteRoleIds: this.noteRoleIds,
// handleRoleIds: this.handleRoleIds
},
nzOnOk: async () => {
if (instance.validateForm.valid) {
await new Promise((resolve, reject) => {
console.log("表单信息", instance.validateForm);
let body = {
id: item.id,
pushRoleIds: instance.validateForm.value.push,
// handleRoleIds: instance.validateForm.value.handle,
smsPushRoleIds: instance.validateForm.value.note,
};
this.http
.put("/api/services/app/Violation/UpdateRoles", body)
.subscribe({
next: (data) => {
resolve(data);
this.message.create("success", "修改成功!");
this.getViolation();
return true;
},
error: (err) => {
this.message.create("success", "修改失败!");
reject(err);
},
});
});
} else {
this.message.create("warning", "请填写完整!");
return false;
}
},
});
const instance = modal.getContentComponent();
}
//搜索框提交
submitForm(): void {
for (const i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if (this.validateForm.value.search) {
this.list = this.list.filter((item) => {
return item.violationType.indexOf(this.validateForm.value.search) != -1;
});
} else {
this.getViolation();
}
}
}