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 async ngOnInit(): Promise { this.validateForm = this.fb.group({ search: [null] }); await this.getPutRoles() await this.getHandleRoles() 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) } }); }); }); this.list = data.result console.log('预警类型', this.list) }) } //获取推送的角色列表 pushRoleIds async getPutRoles() { await new Promise((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((resolve, reject) => { this.http.get('/api/services/app/Violation/GetHandleRoles').subscribe((data: any) => { this.handleRoleIds = data.result resolve(data) console.log('处置角色', data) }) }) } edititem(item) { const modal = this.modal.create({ nzTitle: '编辑推送设置', nzContent: EditPushItemComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 300, nzComponentParams: { data: item, pushRoleIds: this.pushRoleIds, handleRoleIds: this.handleRoleIds }, nzOnOk: async () => { if (instance.validateForm.valid) { await new Promise(resolve => { console.log('表单信息', instance.validateForm) let body = { id: item.id, pushRoleIds: instance.validateForm.value.push, handleRoleIds: instance.validateForm.value.handle, } this.http.put('/api/services/app/Violation/UpdateRoles', body).subscribe(data => { resolve(data) this.message.create('success', '修改成功!'); this.getViolation() return true }) }) } 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() } } }