/* * @Descripttion: * @version: * @Author: sueRimn * @Date: 2020-12-11 09:06:03 * @LastEditors: sueRimn * @LastEditTime: 2020-12-20 10:31:09 */ import { Component, OnInit, ViewChild, Inject,Input } from '@angular/core'; import {HttpClient} from '@angular/common/http' import { MatDialogRef, MatDialog, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatPaginator } from '@angular/material/paginator'; import { MatTableDataSource } from '@angular/material/table'; import { PageEvent } from '@angular/material/paginator'; import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; import {FormControl} from '@angular/forms'; import { Router,ActivatedRoute } from '@angular/router'; import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree'; import { FlatTreeControl } from '@angular/cdk/tree'; import { TreeService } from '../../http-interceptors/tree.service' @Component({ selector: 'app-examiner-index', templateUrl: './examiner-index.component.html', styleUrls: ['./examiner-index.component.scss'] }) export class ExaminerIndexComponent implements OnInit { constructor(private router: Router,private activatedRoute: ActivatedRoute,public http: HttpClient,public dialog: MatDialog,public snackBar: MatSnackBar,private tree: TreeService) { } //displayedColumns: string[] = ['name', 'organization', 'startTime', 'overTime', 'testState', 'operation']; ngOnInit(): void { this.getunitdata(); this.getOrganizations(); this.getUnittype(); this.getAlltabledate() setInterval(()=>this.getAlltabledate(),60000) //this.getHelp() } displayedColumns: string[] = ['name','startTime','endTime', 'examzhong','scc']; tabledataSource:any accound helpName//消防救援对名称 optionId @ViewChild('son') son; //分页 @ViewChild(MatPaginator, {static: true}) pageEvent: PageEvent; paginator: MatPaginator; length:any; //共多少条数据 pageSize:any; //每页条数 pageSizeOptions: number[] = [10] //设置每页条数 PageNumber:any //第几页 startTime:[] endTime:[] allorganizations:any allunittype:any //获取所有的单位类型 jscheck:any //辖区中队包含下级 private _transformer = (node, level: number) => { //初始化tree return { expandable: !!node.children && node.children.length > 0, name: node.name, level: level, id: node.id, parentId: node.parentId, children: node.children }; } treeControl = new FlatTreeControl(node => node.level, node => node.expandable); treeFlattener = new MatTreeFlattener(this._transformer, node => node.level, node => node.expandable, node => node.children); dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener); hasChild = (_: number, node: any) => node.expandable; //得到当前单位信息 getunitdata(){ this.http.get("/api/ExamAccounts/Profiles").subscribe( (data:any)=>{ this.organizationName = data.organizationName } ) } organizationName:any //当前单位组织机构名称 treedata:any //组织机构树型数据 newArr:any = [] newallorganizations:any //用于存储在原始数据基础上的每个机构增加children字段 newallorganizations2:any //得到当前单位所在组织机构的tree型数据 getpresentOrganization(){ this.newallorganizations = this.allorganizations this.newallorganizations.forEach(item => { item.children = [] this.newallorganizations.forEach(element => { if(element.parentId == item.id){ item.children.push(element) } }); }); this.http.get("/api/ExamAccounts/Profiles").subscribe( (data:any)=>{ this.organizationName = data.organizationName if(this.organizationName){ this.newallorganizations.forEach(item => { if(item.name == this.organizationName){ this.dataSource.data = [item] this.newallorganizations2 = [item] } }); }else{ this.newallorganizations2 = this.treedata this.dataSource.data = this.treedata } } ) } //获得所有组织机构 getOrganizations(){ this.http.get('/api/Organizations').subscribe( (data:any)=>{ this.allorganizations = data this.treedata = this.tree.toTree(data); this.getpresentOrganization(); } ) } //获得所有单位类型 getUnittype(){ this.http.get('/api/BuildingTypes/Simple').subscribe( data=>{ this.allunittype = data } ) } //获得查询支队信息 help(){ let paramsdata:any = { PageNumber: this.PageNumber || '1', PageSize: this.pageSizeOptions[0], Sort: null, SortType: null, } //console.log(paramsdata) this.http.get("/api/Papers",{params:paramsdata}).subscribe((data:any)=>{ this.tabledataSource=data console.log(this.tabledataSource) }) } //分页事件 chagePage(e){ this.PageNumber = e.pageIndex+1 this.getAlltabledate() } //获取表格信息 getAlltabledate(){ let paramsdata:any = { PageNumber: this.PageNumber || '1', PageSize: this.pageSizeOptions[0], OrganizationId: this.jsId || '', HasChildren:this.jscheck || '', Sort: null, SortType: null, } this.http.get("/api/Papers",{params:paramsdata}).subscribe((data:any)=>{ this.tabledataSource=data.items this.length=data.totalCount }) } //获取消防救援对信息 getHelp(){ let paramsdata:any={ Name:'', IdentityCard:'', Phone:'', RealName:'', OrganizationId:'', PageNumber:'', PageSize:'', Sort:'', RoleType:'1', SortType:'' } this.http.get("/api/ExamUsers",{params:paramsdata}).subscribe((data:any)=>{ this.helpName=data.items }) } //获取optionid getoption(){ var selectIndex =document.getElementById("cars"); console.log(selectIndex) //var activeName_value =document.getElementById("usertype").options[selectIndex].id; } //查询按钮 findClick(){ /* const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 if(this.accound==undefined){ this.snackBar.open('请输入消防救援队名称','确定',config); } else{ this.http.get(`/api/Papers/${this.accound}`).subscribe((data:any)=>{ console.log(data) }) } console.log(this.accound) */ console.log(this.jscheck,this.jsId) this.PageNumber = 1 this.pageEvent.pageIndex = 0 this.getAlltabledate() } //重置按钮 Reset(){ //this.accound=undefined this.jsId='' this.js='' this.jscheck='' } //删除一套考题 deleteExam(examid){ let isTrue = confirm('您确定要删除吗') if(isTrue){ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.http.delete(`/api/Papers/${examid}`).subscribe((data:any)=>{ this.snackBar.open('删除试卷成功','确定',config); this.getAlltabledate() }) } } //新增考题跳转 newExamination(){ this.router.navigate(['/home/createexam-index/examiner-new-one']) } //辖区中队div是否显示 isorganizationbox:boolean = false js:any //辖区中队输入框 jsId:any //辖区中队选择的id stopclose(e){ e.stopPropagation(); } //点击辖区中队树,将选择的辖区中队添加到变量 add(node) { this.isorganizationbox = false this.js = node.name this.jsId = node.id } //关闭辖区中队隐藏框 closeorganizationbox() { this.isorganizationbox = false } //打开辖区中队隐藏框 openorganizationbox() { this.isorganizationbox = true } //关闭出现的组织机构div closediv(){ this.isorganizationbox = false } }