diff --git a/src/app/examiner/create-test-score/create-test-score.component.html b/src/app/examiner/create-test-score/create-test-score.component.html index b5bf94a..65cbe03 100644 --- a/src/app/examiner/create-test-score/create-test-score.component.html +++ b/src/app/examiner/create-test-score/create-test-score.component.html @@ -287,7 +287,7 @@ - + 编辑 删除 diff --git a/src/app/examiner/create-test-score/create-test-score.component.ts b/src/app/examiner/create-test-score/create-test-score.component.ts index 20d332a..ba626b6 100644 --- a/src/app/examiner/create-test-score/create-test-score.component.ts +++ b/src/app/examiner/create-test-score/create-test-score.component.ts @@ -1,827 +1,981 @@ -import { SelectionModel } from '@angular/cdk/collections'; -import { HttpClient } from '@angular/common/http'; -import { Component, Inject, OnInit, ViewChild } from '@angular/core'; -import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatTableDataSource } from '@angular/material/table'; -import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; -import { NzDatePickerModule } from 'ng-zorro-antd/date-picker'; -import { DisabledTimeFn, DisabledTimePartial } from 'ng-zorro-antd/date-picker'; -import getISOWeek from 'date-fns/getISOWeek'; -import setHours from 'date-fns/setHours'; -import { NzFormatEmitEvent, NzTreeComponent } from 'ng-zorro-antd/tree'; -import { ActivatedRoute, Router } from '@angular/router'; -import { async } from '@angular/core/testing'; -import { functions } from 'firebase'; +import { SelectionModel } from "@angular/cdk/collections"; +import { HttpClient } from "@angular/common/http"; +import { Component, Inject, OnInit, ViewChild } from "@angular/core"; +import { + MatDialog, + MatDialogRef, + MAT_DIALOG_DATA, +} from "@angular/material/dialog"; +import { MatTableDataSource } from "@angular/material/table"; +import { MatSnackBar, MatSnackBarConfig } from "@angular/material/snack-bar"; +import { NzDatePickerModule } from "ng-zorro-antd/date-picker"; +import { DisabledTimeFn, DisabledTimePartial } from "ng-zorro-antd/date-picker"; +import getISOWeek from "date-fns/getISOWeek"; +import setHours from "date-fns/setHours"; +import { NzFormatEmitEvent, NzTreeComponent } from "ng-zorro-antd/tree"; +import { ActivatedRoute, Router } from "@angular/router"; +import { async } from "@angular/core/testing"; +import { functions } from "firebase"; @Component({ - selector: 'app-create-test-score', - templateUrl: './create-test-score.component.html', - styleUrls: ['./create-test-score.component.scss'] + selector: "app-create-test-score", + templateUrl: "./create-test-score.component.html", + styleUrls: ["./create-test-score.component.scss"], }) export class CreateTestScoreComponent implements OnInit { - - constructor(private router: Router, public dialog: MatDialog, private http: HttpClient, public snackBar: MatSnackBar, private route: ActivatedRoute) { } - selectedTab: number = 1 //选中的选项卡 + constructor( + private router: Router, + public dialog: MatDialog, + private http: HttpClient, + public snackBar: MatSnackBar, + private route: ActivatedRoute + ) {} + selectedTab: number = 1; //选中的选项卡 selectTab(index) { setTimeout(() => { - this.selectedTab = index + this.selectedTab = index; }, 0); - } - pattern: any = this.route.snapshot.queryParams.pattern || '' + pattern: any = this.route.snapshot.queryParams.pattern || ""; ngOnInit(): void { - if (this.route.snapshot.queryParams.status == 0 || this.route.snapshot.queryParams.status == 1) { + if ( + this.route.snapshot.queryParams.status == 0 || + this.route.snapshot.queryParams.status == 1 + ) { //已创建完成 未开考/开考中 - this.getSoloPaper() + this.getSoloPaper(); } else { //创建考题 - this.unitId = JSON.parse(sessionStorage.getItem(sessionStorage.getItem('paperId'))) - console.log('this.unitId', this.unitId) + this.unitId = JSON.parse( + sessionStorage.getItem(sessionStorage.getItem("paperId")) + ); + console.log("this.unitId", this.unitId); for (let y = 0, length = this.unitId.length; y < length; y++) { - let element = this.unitId[y] - element.score = 0 - element.basicInfoScore = 0 - element.basicInfoItemScore = 0 - element.basicInfoNodes = [] - element.aroundScore = 0 - element.aroundItemScore = 0 - element.aroundNodes = [] - element.keySiteScore = 0 - element.keySiteItemScore = 0 - element.keySiteNodes = [] - element.funDivScore = 0 - element.funDivItemScore = 0 - element.funDivNodes = [] - element.fireFacScore = 0 - element.fireFacItemScore = 0 - element.fireFacNodes = [] + let element = this.unitId[y]; + element.score = 0; + element.basicInfoScore = 0; + element.basicInfoItemScore = 0; + element.basicInfoNodes = []; + element.aroundScore = 0; + element.aroundItemScore = 0; + element.aroundNodes = []; + element.keySiteScore = 0; + element.keySiteItemScore = 0; + element.keySiteNodes = []; + element.funDivScore = 0; + element.funDivItemScore = 0; + element.funDivNodes = []; + element.fireFacScore = 0; + element.fireFacItemScore = 0; + element.fireFacNodes = []; } this.getUnitData().then(() => { this.getAround().then(() => { this.getKeySite().then(() => { this.getFunDiv().then(() => { - this.getFireFac() - }) - }) - }) - }) + this.getFireFac(); + }); + }); + }); + }); this.getPaperPlans().then(() => { - this.planItemScore() - }) + this.planItemScore(); + }); } if (this.route.snapshot.queryParams.pattern) { - } else { - } - - } //获得指定试卷信息。 - editdata + editdata; getSoloPaper() { - this.http.get(`/api/Papers/${sessionStorage.getItem('paperId')}`).subscribe((data: any) => { - this.editdata = data - console.log('试卷信息', this.editdata) - if (data.paperDataInfo) { - data.paperDataInfo.forEach(item => { - console.log('xxxx', JSON.parse(item.originalData)) - this.unitId.push(JSON.parse(item.originalData)) - }) - this.planItemScore() - } - }) + this.http + .get(`/api/Papers/${sessionStorage.getItem("paperId")}`) + .subscribe((data: any) => { + this.editdata = data; + console.log("试卷信息", this.editdata); + if (data.paperDataInfo) { + data.paperDataInfo.forEach((item) => { + console.log("xxxx", JSON.parse(item.originalData)); + this.unitId.push(JSON.parse(item.originalData)); + }); + this.planItemScore(); + } + }); } - //获取所有考试设定 async getPaperPlans() { - for (let y = 0, length = this.unitId.length; y < length; y++) { - let element = this.unitId[y] + let element = this.unitId[y]; await new Promise((resolve, reject) => { - this.http.get('/api/PaperPlans', { - params: { - paperId: sessionStorage.getItem('paperId'), - companyId: element.id - } - }).subscribe(data => { - console.log('当前试卷的预案列表', data) - element.planList = data - resolve(1) - }) - }) - + this.http + .get("/api/PaperPlans", { + params: { + paperId: sessionStorage.getItem("paperId"), + companyId: element.id, + }, + }) + .subscribe((data) => { + console.log("当前试卷的预案列表", data); + element.planList = data; + resolve(1); + }); + }); } - - } - //当前选中的单位 - selectedUnitIndex = 0 + selectedUnitIndex = 0; clickUnitName(key) { - this.selectedUnitIndex = key + this.selectedUnitIndex = key; } - unitId: any = [] + unitId: any = []; //获取单位基本信息 async getUnitData() { - let that = this + let that = this; for (let y = 0, length = this.unitId.length; y < length; y++) { - let element = this.unitId[y] + let element = this.unitId[y]; let result1 = await new Promise((resolve, reject) => { this.http.get(`/api/Companies/${element.id}`).subscribe((data: any) => { let unitData = { - name: '单位信息', - type: '基本信息', + name: "单位信息", + type: "基本信息", expanded: true, - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - children: [] - } - data.usci ? unitData.children.push({ - name: '统一社会信用代码', key: element.id + '统一社会信用代码', isLeaf: true, value: data.usci - }) : null - data.buildingTypes[0].name ? unitData.children.push({ - name: '单位类型', key: element.id + '单位类型', isLeaf: true, value: data.buildingTypes[0].name - }) : null - data.contacts ? unitData.children.push({ - name: '联系人', key: element.id + '联系人', isLeaf: true, value: data.contacts - }) : null - data.phone ? unitData.children.push({ - name: '联系电话', key: element.id + '联系电话', isLeaf: true, value: data.phone - }) : null - data.organizationName ? unitData.children.push({ - name: '消防救援站', key: element.id + '消防救援站', isLeaf: true, value: data.organizationName - }) : null - data.address ? unitData.children.push({ - name: '单位地址', key: element.id + '单位地址', isLeaf: true, value: data.address - }) : null - + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + children: [], + }; + data.usci + ? unitData.children.push({ + name: "统一社会信用代码", + key: element.id + "统一社会信用代码", + isLeaf: true, + value: data.usci, + }) + : null; + data.buildingTypes[0].name + ? unitData.children.push({ + name: "单位类型", + key: element.id + "单位类型", + isLeaf: true, + value: data.buildingTypes[0].name, + }) + : null; + data.contacts + ? unitData.children.push({ + name: "联系人", + key: element.id + "联系人", + isLeaf: true, + value: data.contacts, + }) + : null; + data.phone + ? unitData.children.push({ + name: "联系电话", + key: element.id + "联系电话", + isLeaf: true, + value: data.phone, + }) + : null; + data.organizationName + ? unitData.children.push({ + name: "消防救援站", + key: element.id + "消防救援站", + isLeaf: true, + value: data.organizationName, + }) + : null; + data.address + ? unitData.children.push({ + name: "单位地址", + key: element.id + "单位地址", + isLeaf: true, + value: data.address, + }) + : null; - element.basicInfoNodes.push(unitData) + element.basicInfoNodes.push(unitData); - resolve(1) - }) + resolve(1); + }); }).then(async () => { let result2 = await new Promise((resolve, reject) => { - var buildingsData: any - this.http.get("/api/Buildings", { - params: { - companyId: element.id - } - }).subscribe(async (data: any) => { - await getAllBuildingData(data) - resolve(2) - }) - }) - }) + var buildingsData: any; + this.http + .get("/api/Buildings", { + params: { + companyId: element.id, + }, + }) + .subscribe(async (data: any) => { + await getAllBuildingData(data); + resolve(2); + }); + }); + }); async function getAllBuildingData(data) { for (let i = 0, length = data.length; i < length; i++) { const result = await new Promise((resolve) => { - that.http.get("/api/BuildingBasicInfos", { // 循环请求当前单位建筑每一个建筑的信息保存到数组中 - params: { - companyId: element.id, - buildingId: data[i].id, - buildingType: data[i].buildingTypes[0].id - } - }).subscribe((buildingsData: any) => { - buildingsData.name = data[i].name - buildingsData.buildingType = data[i].buildingTypes[0].name - buildingsData[0].buildingBasicGroups.forEach((y, m) => { - - let propertyInfosArr = [] - let tabledata - if (y.type == 1) {//如果是表格类 - var map = {}, - dest: any = []; - for (var i = 0; i < y.propertyInfos.length; i++) { - var ai = y.propertyInfos[i]; - if (!map[ai.propertyName]) { - dest.push({ - propertyName: ai.propertyName, - data: [ai] - }); - map[ai.propertyName] = ai; - } else { - for (var j = 0; j < dest.length; j++) { - var dj = dest[j]; - if (dj.propertyName == ai.propertyName) { - dj.data.push(ai); - break; + that.http + .get("/api/BuildingBasicInfos", { + // 循环请求当前单位建筑每一个建筑的信息保存到数组中 + params: { + companyId: element.id, + buildingId: data[i].id, + buildingType: data[i].buildingTypes[0].id, + }, + }) + .subscribe((buildingsData: any) => { + buildingsData.name = data[i].name; + buildingsData.buildingType = data[i].buildingTypes[0].name; + buildingsData[0].buildingBasicGroups.forEach((y, m) => { + let propertyInfosArr = []; + let tabledata; + if (y.type == 1) { + //如果是表格类 + var map = {}, + dest: any = []; + for (var i = 0; i < y.propertyInfos.length; i++) { + var ai = y.propertyInfos[i]; + if (!map[ai.propertyName]) { + dest.push({ + propertyName: ai.propertyName, + data: [ai], + }); + map[ai.propertyName] = ai; + } else { + for (var j = 0; j < dest.length; j++) { + var dj = dest[j]; + if (dj.propertyName == ai.propertyName) { + dj.data.push(ai); + break; + } } } } - } - //根据行数确定在循环数组中的index - dest.forEach(item => { - item.data.sort(function (a, b) { - return Number(a.tag) - Number(b.tag) - }) - }) - y.tabledata = dest - tabledata = dest - if (y.tabledata[0].propertyName == '罐区') { + //根据行数确定在循环数组中的index + dest.forEach((item) => { + item.data.sort(function (a, b) { + return Number(a.tag) - Number(b.tag); + }); + }); + y.tabledata = dest; + tabledata = dest; + if (y.tabledata[0].propertyName == "罐区") { + if (y.tabledata[1].propertyName != "储罐编号") { + let index; + y.tabledata.forEach((element, key) => { + if (element.propertyName == "储罐编号") { + index = key; + } + }); + y.tabledata[1] = y.tabledata.splice( + index, + 1, + y.tabledata[1] + )[0]; + } - if (y.tabledata[1].propertyName != '储罐编号') { - let index - y.tabledata.forEach((element, key) => { - if (element.propertyName == '储罐编号') { - index = key + y.tabledata[0].data.forEach((x, key) => { + if (x.propertyValue) { + x.key = + (Math.random() * 10000000) + .toString(16) + .substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5); + x.isLeaf = true; + x.name = + x.propertyValue + + "-" + + y.tabledata[1].data[key].propertyValue; + propertyInfosArr.push(x); + } + }); + } else { + y.tabledata[0].data.forEach((x, key) => { + if (x.propertyValue) { + x.key = + (Math.random() * 10000000) + .toString(16) + .substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5); + x.isLeaf = true; + x.name = x.propertyValue; + propertyInfosArr.push(x); } - }) - y.tabledata[1] = y.tabledata.splice(index, 1, y.tabledata[1])[0]; + }); } - - y.tabledata[0].data.forEach((x, key) => { - - if (x.propertyValue) { - x.key = (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5) - x.isLeaf = true - x.name = x.propertyValue + '-' + y.tabledata[1].data[key].propertyValue - propertyInfosArr.push(x) - } - }) } else { - y.tabledata[0].data.forEach((x, key) => { + y.propertyInfos.forEach((x, key) => { if (x.propertyValue) { - x.key = (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5) - x.isLeaf = true - x.name = x.propertyValue - propertyInfosArr.push(x) + x.key = + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5); + x.isLeaf = true; + x.name = x.propertyName; + propertyInfosArr.push(x); } - }) + }); } - - } else { - y.propertyInfos.forEach((x, key) => { - if (x.propertyValue) { - x.key = (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5) - x.isLeaf = true - x.name = x.propertyName - propertyInfosArr.push(x) - } - }) - } - if (propertyInfosArr.length != 0) { - element.basicInfoNodes.push({ - name: y.name != '基本信息' ? buildingsData.name + '-' + y.name : buildingsData.name, - type: '基本信息', - expanded: true, - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - children: propertyInfosArr, - tabledata: tabledata ? tabledata : null - }) - element.basicInfoNodes = [...element.basicInfoNodes] - } - - }) - resolve(i) - }) - }) + if (propertyInfosArr.length != 0) { + element.basicInfoNodes.push({ + name: + y.name != "基本信息" + ? buildingsData.name + "-" + y.name + : buildingsData.name, + type: "基本信息", + expanded: true, + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + children: propertyInfosArr, + tabledata: tabledata ? tabledata : null, + }); + element.basicInfoNodes = [...element.basicInfoNodes]; + } + }); + resolve(i); + }); + }); } } - } } //获取四周毗邻数据 async getAround() { - let that = this + let that = this; for (let y = 0, length = this.unitId.length; y < length; y++) { - let element = this.unitId[y] + let element = this.unitId[y]; //获得当前单位的单位毗邻 - let id = { companyId: element.id } + let id = { companyId: element.id }; let result1 = await new Promise((resolve, reject) => { - this.http.get('/api/CompanyAdjoins', { params: id }).subscribe((data: any) => { - data.forEach(item => { - item.direction == 0 ? item.title = '东方向' : null - item.direction == 1 ? item.title = '西方向' : null - item.direction == 2 ? item.title = '南方向' : null - item.direction == 3 ? item.title = '北方向' : null - item.direction == 4 ? item.title = '东南方向' : null - item.direction == 5 ? item.title = '西南方向' : null - item.direction == 6 ? item.title = '东北方向' : null - item.direction == 7 ? item.title = '西北方向' : null - item.isLeaf = true, - item.key = item.id - }) - //如果存在单位毗邻 - if (data.length != 0) { - this.unitId[y].aroundNodes.push({ - name: '单位毗邻', - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - expanded: true, - type: '四周毗邻', - children: data - }) - element.aroundNodes = [...element.aroundNodes] - } - resolve(1) - }) + this.http + .get("/api/CompanyAdjoins", { params: id }) + .subscribe((data: any) => { + data.forEach((item) => { + item.direction == 0 ? (item.title = "东方向") : null; + item.direction == 1 ? (item.title = "西方向") : null; + item.direction == 2 ? (item.title = "南方向") : null; + item.direction == 3 ? (item.title = "北方向") : null; + item.direction == 4 ? (item.title = "东南方向") : null; + item.direction == 5 ? (item.title = "西南方向") : null; + item.direction == 6 ? (item.title = "东北方向") : null; + item.direction == 7 ? (item.title = "西北方向") : null; + (item.isLeaf = true), (item.key = item.id); + }); + //如果存在单位毗邻 + if (data.length != 0) { + this.unitId[y].aroundNodes.push({ + name: "单位毗邻", + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + expanded: true, + type: "四周毗邻", + children: data, + }); + element.aroundNodes = [...element.aroundNodes]; + } + resolve(1); + }); }).then(async () => { //获得当前单位的建筑毗邻 let result2 = await new Promise((resolve, reject) => { - this.http.get('/api/Buildings', { params: id }).subscribe(async (data: any) => { - if (data.length) { - await getAllArchitecture(data) - resolve(2) - } - }) - }) - }) + this.http + .get("/api/Buildings", { params: id }) + .subscribe(async (data: any) => { + if (data.length) { + await getAllArchitecture(data); + resolve(2); + } + }); + }); + }); async function getAllArchitecture(buildingsdata) { for (let i = 0, length = buildingsdata.length; i < length; i++) { - let id = { buildingId: buildingsdata[i].id } + let id = { buildingId: buildingsdata[i].id }; let result = await new Promise((resolve, reject) => { - that.http.get('/api/BuildingAdjoins', { params: id }).subscribe((data: any) => { - data.forEach(item => { - item.direction == 0 ? item.title = '东方向' : null - item.direction == 1 ? item.title = '西方向' : null - item.direction == 2 ? item.title = '南方向' : null - item.direction == 3 ? item.title = '北方向' : null - item.direction == 4 ? item.title = '东南方向' : null - item.direction == 5 ? item.title = '西南方向' : null - item.direction == 6 ? item.title = '东北方向' : null - item.direction == 7 ? item.title = '西北方向' : null - item.isLeaf = true - item.key = item.id - }) - if (data.length != 0) { - that.unitId[y].aroundNodes.push({ - name: buildingsdata[i].name, - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - expanded: true, - type: '四周毗邻', - children: data - }) - element.aroundNodes = [...element.aroundNodes] - } - resolve(1) - }) - }) + that.http + .get("/api/BuildingAdjoins", { params: id }) + .subscribe((data: any) => { + data.forEach((item) => { + item.direction == 0 ? (item.title = "东方向") : null; + item.direction == 1 ? (item.title = "西方向") : null; + item.direction == 2 ? (item.title = "南方向") : null; + item.direction == 3 ? (item.title = "北方向") : null; + item.direction == 4 ? (item.title = "东南方向") : null; + item.direction == 5 ? (item.title = "西南方向") : null; + item.direction == 6 ? (item.title = "东北方向") : null; + item.direction == 7 ? (item.title = "西北方向") : null; + item.isLeaf = true; + item.key = item.id; + }); + if (data.length != 0) { + that.unitId[y].aroundNodes.push({ + name: buildingsdata[i].name, + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + expanded: true, + type: "四周毗邻", + children: data, + }); + element.aroundNodes = [...element.aroundNodes]; + } + resolve(1); + }); + }); } - } } } //获取重点部位 async getKeySite() { - let that = this + let that = this; for (let y = 0, length = this.unitId.length; y < length; y++) { - let element = this.unitId[y] + let element = this.unitId[y]; //获得单位重点部位 - let id = { companyId: element.id } + let id = { companyId: element.id }; let result1 = await new Promise((resolve, reject) => { - this.http.get('/api/CompanyImportantLocations', { params: id }).subscribe((data: any) => { - //如果存在单位重点部位 - let newData = [] - data.forEach(item => { - item.isLeaf = true - item.key = item.id - item.name ? newData.push(item) : null - }) - if (newData.length != 0) { - this.unitId[y].keySiteNodes.push({ - name: '单位重点部位', - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - expanded: true, - type: '重点部位', - children: newData - }) - element.keySiteNodes = [...element.keySiteNodes] - } - resolve(1) - }) + this.http + .get("/api/CompanyImportantLocations", { params: id }) + .subscribe((data: any) => { + //如果存在单位重点部位 + let newData = []; + data.forEach((item) => { + item.isLeaf = true; + item.key = item.id; + item.name ? newData.push(item) : null; + }); + if (newData.length != 0) { + this.unitId[y].keySiteNodes.push({ + name: "单位重点部位", + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + expanded: true, + type: "重点部位", + children: newData, + }); + element.keySiteNodes = [...element.keySiteNodes]; + } + resolve(1); + }); }).then(async () => { //获得建筑重点部位 let result2 = await new Promise((resolve, reject) => { - this.http.get('/api/Buildings', { params: id }).subscribe(async (data: any) => { - if (data.length) { - await getAllBuildingPositon(data) - resolve(2) - } - }) - }) - - }) - - - console.log(element) + this.http + .get("/api/Buildings", { params: id }) + .subscribe(async (data: any) => { + if (data.length) { + await getAllBuildingPositon(data); + resolve(2); + } + }); + }); + }); + console.log(element); //获取当前单位所有建筑重点部位 async function getAllBuildingPositon(buildingsdata) { for (let i = 0, length = buildingsdata.length; i < length; i++) { - let id = { buildingId: buildingsdata[i].id } + let id = { buildingId: buildingsdata[i].id }; let result = await new Promise((resolve, reject) => { - that.http.get('/api/BuildingImportantLocations', { params: id }).subscribe((data: any) => { - let newData = [] - data.forEach(item => { - item.isLeaf = true - item.key = item.id - item.name ? newData.push(item) : null - }) - if (newData.length != 0) { - that.unitId[y].keySiteNodes.push({ - name: buildingsdata[i].name, - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - expanded: true, - type: '重点部位', - children: newData - }) - element.keySiteNodes = [...element.keySiteNodes] - } - resolve('2') - }) - }) - + that.http + .get("/api/BuildingImportantLocations", { params: id }) + .subscribe((data: any) => { + let newData = []; + data.forEach((item) => { + item.isLeaf = true; + item.key = item.id; + item.name ? newData.push(item) : null; + }); + if (newData.length != 0) { + that.unitId[y].keySiteNodes.push({ + name: buildingsdata[i].name, + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + expanded: true, + type: "重点部位", + children: newData, + }); + element.keySiteNodes = [...element.keySiteNodes]; + } + resolve("2"); + }); + }); } } } } //获取功能分区 async getFunDiv() { - let that = this + let that = this; for (let y = 0, length = this.unitId.length; y < length; y++) { - let element = this.unitId[y] + let element = this.unitId[y]; - let id = { companyId: element.id } + let id = { companyId: element.id }; //单位功能分区 let result1 = await new Promise((resolve, reject) => { - this.http.get('/api/CompanyFunctionalDivisions', { params: id }).subscribe((data: any) => { - //如果存在单位的单位功能分区 - let newData = [] - data.forEach(item => { - item.isLeaf = true - item.key = item.id - item.region ? newData.push(item) : null - }) - if (data.length != 0) { - this.unitId[y].funDivNodes.push({ - name: '单位功能分区', - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - expanded: true, - type: '功能分区', - children: newData - }) - element.funDivNodes = [...element.funDivNodes] - } - resolve(1) - }) + this.http + .get("/api/CompanyFunctionalDivisions", { params: id }) + .subscribe((data: any) => { + //如果存在单位的单位功能分区 + let newData = []; + data.forEach((item) => { + item.isLeaf = true; + item.key = item.id; + item.region ? newData.push(item) : null; + }); + if (data.length != 0) { + this.unitId[y].funDivNodes.push({ + name: "单位功能分区", + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + expanded: true, + type: "功能分区", + children: newData, + }); + element.funDivNodes = [...element.funDivNodes]; + } + resolve(1); + }); }).then(async () => { //建筑功能分区 let result2 = await new Promise((resolve, reject) => { - this.http.get('/api/Buildings', { params: id }).subscribe(async (data: any) => { - if (data.length) { - await getAllBuildingFunDiv(data) - resolve(2) - } - }) - }) - }) - - - + this.http + .get("/api/Buildings", { params: id }) + .subscribe(async (data: any) => { + if (data.length) { + await getAllBuildingFunDiv(data); + resolve(2); + } + }); + }); + }); //获取当前单位所有建筑功能分区 async function getAllBuildingFunDiv(buildingsdata) { for (let i = 0, length = buildingsdata.length; i < length; i++) { - let id = { buildingId: buildingsdata[i].id } + let id = { buildingId: buildingsdata[i].id }; let result = await new Promise((resolve, reject) => { - that.http.get('/api/BuildingFunctionalDivisions', { params: id }).subscribe((data: any) => { - let newData = [] - data.forEach(item => { - - item.isLeaf = true - item.key = item.id - item.region ? newData.push(item) : null - - }) - if (newData.length != 0) { - that.unitId[y].funDivNodes.push({ - name: buildingsdata[i].name, - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - expanded: true, - type: '功能分区', - children: newData - }) - element.funDivNodes = [...element.funDivNodes] - } - resolve('2') - }) - }) - + that.http + .get("/api/BuildingFunctionalDivisions", { params: id }) + .subscribe((data: any) => { + let newData = []; + data.forEach((item) => { + item.isLeaf = true; + item.key = item.id; + item.region ? newData.push(item) : null; + }); + if (newData.length != 0) { + that.unitId[y].funDivNodes.push({ + name: buildingsdata[i].name, + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + expanded: true, + type: "功能分区", + children: newData, + }); + element.funDivNodes = [...element.funDivNodes]; + } + resolve("2"); + }); + }); } } - } } //获取消防设施 getFireFac() { - let that = this + let that = this; this.unitId.forEach((element, index) => { - - let companyId = element.id + let companyId = element.id; //获取单位级别消防设施 this.http.get(`/api/Companies/${companyId}`).subscribe((data: any) => { if (data.buildingTypes.length) { - let newData = { buildingType: data.buildingTypes[0].id, companyId: companyId } - this.http.get('/api/CompanyFacilities', { params: newData }).subscribe((data: any) => { //获得单位的消防设施 - - data[0].summary.companyFacilityGroups.forEach(element => { //循环单位内置分组项 - element.facilityItems.forEach((elements, index) => { - elements.total = element.facilityCount[index] + let newData = { + buildingType: data.buildingTypes[0].id, + companyId: companyId, + }; + this.http + .get("/api/CompanyFacilities", { params: newData }) + .subscribe((data: any) => { + //获得单位的消防设施 + + data[0].summary.companyFacilityGroups.forEach((element) => { + //循环单位内置分组项 + element.facilityItems.forEach((elements, index) => { + elements.total = element.facilityCount[index]; + }); }); + let newData = []; + data[0].summary.companyFacilityGroups.forEach((item) => { + item.facilityItems.forEach((i) => { + i.isLeaf = true; + (i.key = + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5)), + i.total && i.total != "总数:0" && i.total != "总数:0" + ? newData.push(i) + : null; + }); + }); + if (newData.length != 0) { + this.unitId[index].fireFacNodes.push({ + name: "单位消防设施", + key: + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5), + expanded: true, + type: "消防设施", + children: newData, + }); + element.fireFacNodes = [...element.fireFacNodes]; + } }); - let newData = [] - data[0].summary.companyFacilityGroups.forEach(item => { - item.facilityItems.forEach(i => { - i.isLeaf = true - i.key = (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - (i.total && (i.total != '总数:0' && i.total != '总数:0')) ? newData.push(i) : null - }) - }) - if (newData.length != 0) { - this.unitId[index].fireFacNodes.push({ - name: '单位消防设施', - key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - expanded: true, - type: '消防设施', - children: newData - }) - element.fireFacNodes = [...element.fireFacNodes] - } - }) } - }) + }); //获取各建筑消防设施 - this.http.get('/api/Buildings', { - params: { - companyId: companyId - } - }).subscribe((data: any) => { - if (data.length != 0) { getAllBuildingFireFac(data) } - }) + this.http + .get("/api/Buildings", { + params: { + companyId: companyId, + }, + }) + .subscribe((data: any) => { + if (data.length != 0) { + getAllBuildingFireFac(data); + } + }); async function getAllBuildingFireFac(buildingsdata) { // console.log('建筑'+index,buildingsdata) for (let i = 0, length = buildingsdata.length; i < length; i++) { - let header = { buildingId: buildingsdata[i].id, buildingType: buildingsdata[i].buildingTypes[0].id, companyId: buildingsdata[i].companyId } + let header = { + buildingId: buildingsdata[i].id, + buildingType: buildingsdata[i].buildingTypes[0].id, + companyId: buildingsdata[i].companyId, + }; let result = await new Promise((resolve, reject) => { - that.http.get('/api/BuildingFacilities', { params: header }).subscribe((data: any) => { - // console.log(index+'消防设施'+ i,data) - - data[0].summary.buildingFacilityGroups.forEach(element => { //循环单位内置分组项 - element.facilityItems.forEach((elements, index) => { - elements.total = element.facilityCount[index] + that.http + .get("/api/BuildingFacilities", { params: header }) + .subscribe((data: any) => { + // console.log(index+'消防设施'+ i,data) + + data[0].summary.buildingFacilityGroups.forEach((element) => { + //循环单位内置分组项 + element.facilityItems.forEach((elements, index) => { + elements.total = element.facilityCount[index]; + }); }); + let newData = []; + data[0].summary.buildingFacilityGroups.forEach((item) => { + item.facilityItems.forEach((i) => { + i.isLeaf = true; + (i.key = + (Math.random() * 10000000).toString(16).substr(0, 4) + + new Date().getTime() + + Math.random().toString().substr(2, 5)), + i.total && i.total != "总数:0" && i.total != "总数:0" + ? newData.push(i) + : null; + }); + }); + if (newData.length != 0) { + that.unitId[index].fireFacNodes.push({ + name: buildingsdata[i].name, + key: buildingsdata[i].id, + expanded: true, + type: "消防设施", + children: newData, + }); + element.fireFacNodes = [...element.fireFacNodes]; + } + resolve("消防设施"); }); - let newData = [] - data[0].summary.buildingFacilityGroups.forEach(item => { - item.facilityItems.forEach(i => { - i.isLeaf = true - i.key = (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), - (i.total && (i.total != '总数:0' && i.total != '总数:0')) ? newData.push(i) : null - }) - }) - if (newData.length != 0) { - that.unitId[index].fireFacNodes.push({ - name: buildingsdata[i].name, - key: buildingsdata[i].id, - expanded: true, - type: '消防设施', - children: newData - }) - element.fireFacNodes = [...element.fireFacNodes] - } - resolve('消防设施') - }) - }) - + }); } } - }) + }); } //查看树节点 lookTreeNode(node) { const dialogRef = this.dialog.open(LookTreeNodeDialog, { - id: 'lookTreeNode', - data: node.origin + id: "lookTreeNode", + data: node.origin, }); - dialogRef.afterClosed().subscribe(result => { - console.log('The dialog was closed'); + dialogRef.afterClosed().subscribe((result) => { + console.log("The dialog was closed"); }); } //阻止input事件冒泡 stopPropagation($event) { - $event.stopPropagation() + $event.stopPropagation(); } defaultCheckedKeys = []; //指定选中复选框的树节点 key值 defaultExpandedKeys = []; //展开指定的树节点 key值 defaultSelectedKeys = []; //指定选中的树节点 key值 - examScore: any = 0//整个试卷的总分 + examScore: any = 0; //整个试卷的总分 //计算分数 calculateScore(key) { //key代表第几个建筑 //计算整个单位的总分 - this.unitId[key].score = this.unitId[key].basicInfoScore + this.unitId[key].aroundScore + this.unitId[key].keySiteScore + this.unitId[key].funDivScore + this.unitId[key].fireFacScore + this.unitId[key].score = + this.unitId[key].basicInfoScore + + this.unitId[key].aroundScore + + this.unitId[key].keySiteScore + + this.unitId[key].funDivScore + + this.unitId[key].fireFacScore; //计算整个试卷的总分 - let examScore = 0 - this.unitId.forEach(element => { - examScore += element.score - }) - let examScore2 = 0 - this.unitId.forEach(element => { - let x = 0 + let examScore = 0; + this.unitId.forEach((element) => { + examScore += element.score; + }); + let examScore2 = 0; + this.unitId.forEach((element) => { + let x = 0; if (element.planList) { - element.planList.forEach(i => { - x += i.score - }) + element.planList.forEach((i) => { + x += i.score; + }); } - element.planScore = x - examScore2 += Number(x) - }) - this.examScore = examScore + examScore2 + element.planScore = x; + examScore2 += Number(x); + }); + this.examScore = examScore + examScore2; } //tree的选择事件 nzEvent(event: NzFormatEmitEvent, key): void { - - if (event.node.origin.type == '基本信息' || (event.node.parentNode && event.node.parentNode.origin.type == '基本信息')) { - - let selectedNum = [] - this.unitId[key].basicInfoNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum.push(i) : '' - }) - }) + if ( + event.node.origin.type == "基本信息" || + (event.node.parentNode && event.node.parentNode.origin.type == "基本信息") + ) { + let selectedNum = []; + this.unitId[key].basicInfoNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum.push(i) : ""; + }); + }); if (selectedNum.length != 0) { - this.unitId[key].basicInfoScore ? this.unitId[key].basicInfoItemScore = this.unitId[key].basicInfoScore / selectedNum.length : null + this.unitId[key].basicInfoScore + ? (this.unitId[key].basicInfoItemScore = + this.unitId[key].basicInfoScore / selectedNum.length) + : null; } else { - this.unitId[key].basicInfoItemScore = 0 + this.unitId[key].basicInfoItemScore = 0; } - this.unitId[key].basicInfoSelectedNum = selectedNum.length + this.unitId[key].basicInfoSelectedNum = selectedNum.length; } - if (event.node.origin.type == '四周毗邻' || (event.node.parentNode && event.node.parentNode.origin.type == '四周毗邻')) { - let selectedNum = [] - this.unitId[key].aroundNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum.push(i) : '' - }) - }) + if ( + event.node.origin.type == "四周毗邻" || + (event.node.parentNode && event.node.parentNode.origin.type == "四周毗邻") + ) { + let selectedNum = []; + this.unitId[key].aroundNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum.push(i) : ""; + }); + }); if (selectedNum.length != 0) { - this.unitId[key].aroundScore ? this.unitId[key].aroundItemScore = this.unitId[key].aroundScore / selectedNum.length : null + this.unitId[key].aroundScore + ? (this.unitId[key].aroundItemScore = + this.unitId[key].aroundScore / selectedNum.length) + : null; } else { - this.unitId[key].aroundItemScore = 0 + this.unitId[key].aroundItemScore = 0; } - this.unitId[key].aroundSelectedNum = selectedNum.length + this.unitId[key].aroundSelectedNum = selectedNum.length; } - if (event.node.origin.type == '重点部位' || (event.node.parentNode && event.node.parentNode.origin.type == '重点部位')) { - let selectedNum = [] - this.unitId[key].keySiteNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum.push(i) : '' - }) - }) + if ( + event.node.origin.type == "重点部位" || + (event.node.parentNode && event.node.parentNode.origin.type == "重点部位") + ) { + let selectedNum = []; + this.unitId[key].keySiteNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum.push(i) : ""; + }); + }); if (selectedNum.length != 0) { - this.unitId[key].keySiteScore ? this.unitId[key].keySiteItemScore = this.unitId[key].keySiteScore / selectedNum.length : null + this.unitId[key].keySiteScore + ? (this.unitId[key].keySiteItemScore = + this.unitId[key].keySiteScore / selectedNum.length) + : null; } else { - this.unitId[key].keySiteItemScore = 0 + this.unitId[key].keySiteItemScore = 0; } - this.unitId[key].keySiteSelectedNum = selectedNum.length + this.unitId[key].keySiteSelectedNum = selectedNum.length; } - if (event.node.origin.type == '功能分区' || (event.node.parentNode && event.node.parentNode.origin.type == '功能分区')) { - let selectedNum = [] - this.unitId[key].funDivNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum.push(i) : '' - }) - }) + if ( + event.node.origin.type == "功能分区" || + (event.node.parentNode && event.node.parentNode.origin.type == "功能分区") + ) { + let selectedNum = []; + this.unitId[key].funDivNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum.push(i) : ""; + }); + }); if (selectedNum.length != 0) { - this.unitId[key].funDivScore ? this.unitId[key].funDivItemScore = this.unitId[key].funDivScore / selectedNum.length : null + this.unitId[key].funDivScore + ? (this.unitId[key].funDivItemScore = + this.unitId[key].funDivScore / selectedNum.length) + : null; } else { - this.unitId[key].funDivItemScore = 0 + this.unitId[key].funDivItemScore = 0; } - this.unitId[key].funDivSelectedNum = selectedNum.length + this.unitId[key].funDivSelectedNum = selectedNum.length; } - if (event.node.origin.type == '消防设施' || (event.node.parentNode && event.node.parentNode.origin.type == '消防设施')) { - let selectedNum = [] - this.unitId[key].fireFacNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum.push(i) : '' - }) - }) + if ( + event.node.origin.type == "消防设施" || + (event.node.parentNode && event.node.parentNode.origin.type == "消防设施") + ) { + let selectedNum = []; + this.unitId[key].fireFacNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum.push(i) : ""; + }); + }); if (selectedNum.length != 0) { - this.unitId[key].fireFacScore ? this.unitId[key].fireFacItemScore = this.unitId[key].fireFacScore / selectedNum.length : null + this.unitId[key].fireFacScore + ? (this.unitId[key].fireFacItemScore = + this.unitId[key].fireFacScore / selectedNum.length) + : null; } else { - this.unitId[key].fireFacItemScore = 0 + this.unitId[key].fireFacItemScore = 0; } - this.unitId[key].fireFacSelectedNum = selectedNum.length + this.unitId[key].fireFacSelectedNum = selectedNum.length; } } //单位各项总分数动态计算 sumScore(type, key) { //key代表第几个建筑 type代表哪个部分 - if (type == '基本信息') { - let selectedNum = 0 - this.unitId[key].basicInfoNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum++ : '' - }) - }) + if (type == "基本信息") { + let selectedNum = 0; + this.unitId[key].basicInfoNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum++ : ""; + }); + }); if (selectedNum != 0) { - this.unitId[key].basicInfoItemScore = this.unitId[key].basicInfoScore / selectedNum + this.unitId[key].basicInfoItemScore = + this.unitId[key].basicInfoScore / selectedNum; } else { - this.unitId[key].basicInfoItemScore = 0 + this.unitId[key].basicInfoItemScore = 0; } } - if (type == '四周毗邻') { - let selectedNum = 0 - this.unitId[key].aroundNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum++ : '' - }) - }) + if (type == "四周毗邻") { + let selectedNum = 0; + this.unitId[key].aroundNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum++ : ""; + }); + }); if (selectedNum != 0) { - this.unitId[key].aroundItemScore = this.unitId[key].aroundScore / selectedNum + this.unitId[key].aroundItemScore = + this.unitId[key].aroundScore / selectedNum; } else { - this.unitId[key].aroundItemScore = 0 + this.unitId[key].aroundItemScore = 0; } } - if (type == '重点部位') { - console.log('重点部位') - let selectedNum = 0 - this.unitId[key].keySiteNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum++ : '' - }) - }) + if (type == "重点部位") { + console.log("重点部位"); + let selectedNum = 0; + this.unitId[key].keySiteNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum++ : ""; + }); + }); if (selectedNum != 0) { - this.unitId[key].keySiteItemScore = this.unitId[key].keySiteScore / selectedNum + this.unitId[key].keySiteItemScore = + this.unitId[key].keySiteScore / selectedNum; } else { - this.unitId[key].keySiteItemScore = 0 + this.unitId[key].keySiteItemScore = 0; } } - if (type == '功能分区') { - let selectedNum = 0 - this.unitId[key].funDivNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum++ : '' - }) - }) + if (type == "功能分区") { + let selectedNum = 0; + this.unitId[key].funDivNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum++ : ""; + }); + }); if (selectedNum != 0) { - this.unitId[key].funDivItemScore = this.unitId[key].funDivScore / selectedNum + this.unitId[key].funDivItemScore = + this.unitId[key].funDivScore / selectedNum; } else { - this.unitId[key].funDivItemScore = 0 + this.unitId[key].funDivItemScore = 0; } } - if (type == '数据核验') { - let selectedNum = 0 - this.unitId[key].fireFacNodes.forEach(item => { - item.children.forEach(i => { - i.checked ? selectedNum++ : '' - }) - }) + if (type == "数据核验") { + let selectedNum = 0; + this.unitId[key].fireFacNodes.forEach((item) => { + item.children.forEach((i) => { + i.checked ? selectedNum++ : ""; + }); + }); if (selectedNum != 0) { - this.unitId[key].fireFacItemScore = this.unitId[key].fireFacScore / selectedNum + this.unitId[key].fireFacItemScore = + this.unitId[key].fireFacScore / selectedNum; } else { - this.unitId[key].fireFacItemScore = 0 + this.unitId[key].fireFacItemScore = 0; } } - this.calculateScore(key)//更新标题栏分数 - + this.calculateScore(key); //更新标题栏分数 } //添加预案 addPlan() { let companyData = { - companyData: this.unitId[this.selectedUnitIndex] - } + companyData: this.unitId[this.selectedUnitIndex], + }; const dialogRef = this.dialog.open(AddPlanDialog, { - width: '380px', - height: '136px', - data: companyData + width: "380px", + height: "136px", + data: companyData, }); - dialogRef.afterClosed().subscribe(result => { + dialogRef.afterClosed().subscribe((result) => { if (result) { if (this.unitId[this.selectedUnitIndex].planList) { - this.unitId[this.selectedUnitIndex].planList.push(result) + this.unitId[this.selectedUnitIndex].planList.push(result); } else { - this.unitId[this.selectedUnitIndex].planList = [] - this.unitId[this.selectedUnitIndex].planList.push(result) + this.unitId[this.selectedUnitIndex].planList = []; + this.unitId[this.selectedUnitIndex].planList.push(result); } } }); @@ -830,492 +984,544 @@ export class CreateTestScoreComponent implements OnInit { //每条预案分数增加在试卷分数 planItemScore() { //计算整个试卷的总分 - let examScore = 0 - this.unitId.forEach(element => { - examScore += element.score - }) - let examScore2 = 0 - this.unitId.forEach(element => { - let x = 0 + let examScore = 0; + this.unitId.forEach((element) => { + examScore += element.score; + }); + let examScore2 = 0; + this.unitId.forEach((element) => { + let x = 0; if (element.planList) { - element.planList.forEach(i => { - x += i.score - }) + element.planList.forEach((i) => { + x += i.score; + }); } - element.planScore = x - examScore2 += Number(x) - }) - this.examScore = examScore + examScore2 + element.planScore = x; + examScore2 += Number(x); + }); + this.examScore = examScore + examScore2; } //编辑每条预案试卷 edit(item) { - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('暂不能编辑', '确定', config); + console.log('这张试卷中这个预案的信息', item); + if (item.planLevel === 0) { + //自定义预案 + sessionStorage.setItem("planId", item.planComponentId); + sessionStorage.setItem("companyId", item.companyId); + sessionStorage.setItem( + "buildingTypeId", + this.unitId[this.selectedUnitIndex].buildingTypes[0].id + ); + sessionStorage.setItem("editable", "1"); + window.open( + `/canvasTool?openType=2&planName=${item.title}&paperplanId=${item.id}&paperId=${item.paperId}` + ); + } else { + //已存在预案 + sessionStorage.setItem( + "companyName", + this.unitId[this.selectedUnitIndex].companyData.name + ); + sessionStorage.setItem("planId", item.planComponentId); + sessionStorage.setItem( + "buildingTypeId", + this.unitId[this.selectedUnitIndex].companyData.buildingTypes[0].id + ); + sessionStorage.setItem( + "companyId", + this.unitId[this.selectedUnitIndex].companyData.id + ); + window.open( + `/canvasTool?openType=1&planName=${item.title}&paperplanId=${item.id}&paperId=${item.paperId}` + ); + } } //删除每条预案试卷 deletePlan(item) { - if (window.confirm('你确定要删除该预案设定吗?')) { - this.http.delete(`/api/PaperPlans/${item.id}`).subscribe(data => { + if (window.confirm("你确定要删除该预案设定吗?")) { + this.http.delete(`/api/PaperPlans/${item.id}`).subscribe((data) => { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('删除成功', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("删除成功", "确定", config); this.unitId[this.selectedUnitIndex].planList.forEach((element, key) => { if (item == element) { - this.unitId[this.selectedUnitIndex].planList.splice(key, 1) + this.unitId[this.selectedUnitIndex].planList.splice(key, 1); } - }) - this.planItemScore() - }) + }); + this.planItemScore(); + }); } else { - - } - console.log(item) - + console.log(item); } //保存 save() { - this.unitId.forEach(item => { + this.unitId.forEach((item) => { //建筑的基本信息选中key集合 - item.basicInfoNodesKey = [] + item.basicInfoNodesKey = []; item.basicInfoNodes.forEach((i, key) => { if (i.checked) { - item.basicInfoNodesKey.push(i.key) + item.basicInfoNodesKey.push(i.key); } else { - i.children.forEach(ele => { - ele.checked ? item.basicInfoNodesKey.push(ele.key) : null - }) + i.children.forEach((ele) => { + ele.checked ? item.basicInfoNodesKey.push(ele.key) : null; + }); } - }) + }); //四周毗邻选中key集合 - item.aroundNodesKey = [] + item.aroundNodesKey = []; item.aroundNodes.forEach((i, key) => { if (i.checked) { - item.aroundNodesKey.push(i.key) + item.aroundNodesKey.push(i.key); } else { - i.children.forEach(ele => { - ele.checked ? item.aroundNodesKey.push(ele.key) : null - }) + i.children.forEach((ele) => { + ele.checked ? item.aroundNodesKey.push(ele.key) : null; + }); } - }) + }); //重点部位选中key集合 - item.keySiteNodesKey = [] + item.keySiteNodesKey = []; item.keySiteNodes.forEach((i, key) => { if (i.checked) { - item.keySiteNodesKey.push(i.key) + item.keySiteNodesKey.push(i.key); } else { - i.children.forEach(ele => { - ele.checked ? item.keySiteNodesKey.push(ele.key) : null - }) + i.children.forEach((ele) => { + ele.checked ? item.keySiteNodesKey.push(ele.key) : null; + }); } - }) + }); //功能分区选中key集合 - item.funDivNodesKey = [] + item.funDivNodesKey = []; item.funDivNodes.forEach((i, key) => { if (i.checked) { - item.funDivNodesKey.push(i.key) + item.funDivNodesKey.push(i.key); } else { - i.children.forEach(ele => { - ele.checked ? item.funDivNodesKey.push(ele.key) : null - }) + i.children.forEach((ele) => { + ele.checked ? item.funDivNodesKey.push(ele.key) : null; + }); } - }) + }); //数据核验选中key集合 - item.fireFacNodesKey = [] + item.fireFacNodesKey = []; item.fireFacNodes.forEach((i, key) => { if (i.checked) { - item.fireFacNodesKey.push(i.key) + item.fireFacNodesKey.push(i.key); } else { - i.children.forEach(ele => { - ele.checked ? item.fireFacNodesKey.push(ele.key) : null - }) + i.children.forEach((ele) => { + ele.checked ? item.fireFacNodesKey.push(ele.key) : null; + }); } - }) - }) + }); + }); - let copyDatas = JSON.parse(JSON.stringify(this.unitId)) + let copyDatas = JSON.parse(JSON.stringify(this.unitId)); //循环每个建筑处理数据筛选出选中数据 - copyDatas.forEach(item => { + copyDatas.forEach((item) => { //建筑的基本信息模块处理 item.basicInfoNodes.forEach((i, key) => { //如果顶级节点未选中则需要筛除没有选中的数据 if (!i.checked) { // console.log(i) - let newArr = [] - i.children.forEach(element => { - element.checked ? newArr.push(element) : null - }) - let discard = []//即将废弃的数组 + let newArr = []; + i.children.forEach((element) => { + element.checked ? newArr.push(element) : null; + }); + let discard = []; //即将废弃的数组 // newArr.length == 0 ? item.basicInfoNodes.splice(key,1) : i.children = newArr - newArr.length == 0 ? discard.push(i) : i.children = newArr - item.basicInfoNodes = item.basicInfoNodes.filter(items => { + newArr.length == 0 ? discard.push(i) : (i.children = newArr); + item.basicInfoNodes = item.basicInfoNodes.filter((items) => { if (!discard.includes(items)) return items; - }) + }); } //将children处理成指定形式 - if (i.name == '单位信息') { - let newChildren = [] + if (i.name == "单位信息") { + let newChildren = []; i.children.forEach((element, index) => { - let newChildrenItem: any = {} - newChildrenItem.name = element.name//题目名称 - newChildrenItem.result = element.value//题目答案 - newChildrenItem.physicalUnit = element.physicalUnit || ''//计量单位 - newChildrenItem.propertyType = 0//输入框类型 - newChildren.push(newChildrenItem) - }) - i.children = newChildren + let newChildrenItem: any = {}; + newChildrenItem.name = element.name; //题目名称 + newChildrenItem.result = element.value; //题目答案 + newChildrenItem.physicalUnit = element.physicalUnit || ""; //计量单位 + newChildrenItem.propertyType = 0; //输入框类型 + newChildren.push(newChildrenItem); + }); + i.children = newChildren; } else if (!i.tabledata) { - let newChildren = [] + let newChildren = []; i.children.forEach((element, index) => { - let newChildrenItem: any = {} - newChildrenItem.name = element.propertyName//题目名称 - newChildrenItem.result = element.propertyValue//题目答案 - newChildrenItem.physicalUnit = element.physicalUnit || ''//计量单位 - newChildrenItem.propertyType = element.propertyType//输入框类型 - newChildren.push(newChildrenItem) - }) - i.children = newChildren - } else if (i.tabledata) {//如果是表格类 - let newChildren = [] + let newChildrenItem: any = {}; + newChildrenItem.name = element.propertyName; //题目名称 + newChildrenItem.result = element.propertyValue; //题目答案 + newChildrenItem.physicalUnit = element.physicalUnit || ""; //计量单位 + newChildrenItem.propertyType = element.propertyType; //输入框类型 + newChildren.push(newChildrenItem); + }); + i.children = newChildren; + } else if (i.tabledata) { + //如果是表格类 + let newChildren = []; i.children.forEach((element, index) => { - let newChildrenItem: any = {} - newChildrenItem.name = element.propertyValue//题目名称 - newChildrenItem.result = element.tag//代表第几行 - newChildrenItem.physicalUnit = ''//计量单位 - newChildrenItem.propertyType = ''//输入框类型 - newChildren.push(newChildrenItem) - }) - i.children = newChildren - i.tabledata.forEach(element => { - let newData = [] - element.data.forEach(ele => { - let newObj: any = {} - newObj.name = ele.propertyName//题目名称 - newObj.result = ele.propertyValue//代表第几行 - newObj.physicalUnit = ele.physicalUnit//计量单位 - newObj.propertyType = ele.propertyType//输入框类型 - newObj.tag = ele.tag//第几行 - newData.push(newObj) - }) - element.data = newData - }) + let newChildrenItem: any = {}; + newChildrenItem.name = element.propertyValue; //题目名称 + newChildrenItem.result = element.tag; //代表第几行 + newChildrenItem.physicalUnit = ""; //计量单位 + newChildrenItem.propertyType = ""; //输入框类型 + newChildren.push(newChildrenItem); + }); + i.children = newChildren; + i.tabledata.forEach((element) => { + let newData = []; + element.data.forEach((ele) => { + let newObj: any = {}; + newObj.name = ele.propertyName; //题目名称 + newObj.result = ele.propertyValue; //代表第几行 + newObj.physicalUnit = ele.physicalUnit; //计量单位 + newObj.propertyType = ele.propertyType; //输入框类型 + newObj.tag = ele.tag; //第几行 + newData.push(newObj); + }); + element.data = newData; + }); } - delete i.selected - - }) + delete i.selected; + }); //建筑的四周毗邻模块处理 item.aroundNodes.forEach((i, key) => { //如果顶级节点未选中则需要筛除没有选中的数据 if (!i.checked) { - let newArr = [] - i.children.forEach(element => { - element.checked ? newArr.push(element) : null - }) - let discard = []//即将废弃的数组 - newArr.length == 0 ? discard.push(i) : i.children = newArr - item.aroundNodes = item.aroundNodes.filter(items => { + let newArr = []; + i.children.forEach((element) => { + element.checked ? newArr.push(element) : null; + }); + let discard = []; //即将废弃的数组 + newArr.length == 0 ? discard.push(i) : (i.children = newArr); + item.aroundNodes = item.aroundNodes.filter((items) => { if (!discard.includes(items)) return items; - }) + }); } - let newChildren = [] + let newChildren = []; i.children.forEach((element, index) => { - let newChildrenItem: any = {} - newChildrenItem.name = element.title//题目名称 - newChildrenItem.result = element.name//题目答案 - newChildrenItem.physicalUnit = ''//计量单位 - newChildrenItem.propertyType = 0//输入框类型 - newChildren.push(newChildrenItem) - }) - i.children = newChildren - delete i.selected - }) + let newChildrenItem: any = {}; + newChildrenItem.name = element.title; //题目名称 + newChildrenItem.result = element.name; //题目答案 + newChildrenItem.physicalUnit = ""; //计量单位 + newChildrenItem.propertyType = 0; //输入框类型 + newChildren.push(newChildrenItem); + }); + i.children = newChildren; + delete i.selected; + }); // console.log(111,item) //建筑的重点部位模块处理 - item.keySiteNodes ? item.keySiteNodes.forEach((i, key) => { - i.selected ? i.selected = null : null - //如果顶级节点未选中则需要筛除没有选中的数据 - if (!i.checked) { - let newArr = [] - i.children.forEach(element => { - element.checked ? newArr.push(element) : null - }) - let discard = []//即将废弃的数组 - newArr.length == 0 ? discard.push(i) : i.children = newArr - item.keySiteNodes = item.keySiteNodes.filter(items => { - if (!discard.includes(items)) return items; - }) - } - i.tabledata = [{ propertyName: "重点部位名称", data: [] }, - { propertyName: "重点部位所在位置", data: [] }, - { propertyName: "建筑结构", data: [] }, - { propertyName: "使用性质", data: [] }, - { propertyName: "主要危险性", data: [] }] - i.children.forEach(element => { - i.tabledata[0].data.push({ - name: "重点部位名称", - physicalUnit: '', - propertyType: 0, - result: element.name, - tag: "" - }) - i.tabledata[1].data.push({ - name: "重点部位所在位置", - physicalUnit: '', - propertyType: 0, - result: element.position, - tag: "" - }) - i.tabledata[2].data.push({ - name: "建筑结构", - physicalUnit: '', - propertyType: 0, - result: element.structure, - tag: "" - }) - i.tabledata[3].data.push({ - name: "使用性质", - physicalUnit: '', - propertyType: 0, - result: element.nature, - tag: "" - }) - i.tabledata[4].data.push({ - name: "主要危险性", - physicalUnit: '', - propertyType: 0, - result: element.hazards, - tag: "" + item.keySiteNodes + ? item.keySiteNodes.forEach((i, key) => { + i.selected ? (i.selected = null) : null; + //如果顶级节点未选中则需要筛除没有选中的数据 + if (!i.checked) { + let newArr = []; + i.children.forEach((element) => { + element.checked ? newArr.push(element) : null; + }); + let discard = []; //即将废弃的数组 + newArr.length == 0 ? discard.push(i) : (i.children = newArr); + item.keySiteNodes = item.keySiteNodes.filter((items) => { + if (!discard.includes(items)) return items; + }); + } + i.tabledata = [ + { propertyName: "重点部位名称", data: [] }, + { propertyName: "重点部位所在位置", data: [] }, + { propertyName: "建筑结构", data: [] }, + { propertyName: "使用性质", data: [] }, + { propertyName: "主要危险性", data: [] }, + ]; + i.children.forEach((element) => { + i.tabledata[0].data.push({ + name: "重点部位名称", + physicalUnit: "", + propertyType: 0, + result: element.name, + tag: "", + }); + i.tabledata[1].data.push({ + name: "重点部位所在位置", + physicalUnit: "", + propertyType: 0, + result: element.position, + tag: "", + }); + i.tabledata[2].data.push({ + name: "建筑结构", + physicalUnit: "", + propertyType: 0, + result: element.structure, + tag: "", + }); + i.tabledata[3].data.push({ + name: "使用性质", + physicalUnit: "", + propertyType: 0, + result: element.nature, + tag: "", + }); + i.tabledata[4].data.push({ + name: "主要危险性", + physicalUnit: "", + propertyType: 0, + result: element.hazards, + tag: "", + }); + }); + let newChildren = []; + i.children.forEach((element, index) => { + let newChildrenItem: any = {}; + // newChildrenItem.name = element.name//重点部位题目名称 + // newChildrenItem.position = element.position//重点部位所在位置 + // newChildrenItem.structure = element.structure//重点部位建筑结构 + // newChildrenItem.nature = element.nature//重点部位使用性质 + // newChildrenItem.hazards = element.hazards//重点部位主要危险性 + newChildrenItem.name = element.name; //题目名称 + newChildrenItem.result = + element.position + + element.structure + + element.nature + + element.hazards; //题目答案 + newChildrenItem.physicalUnit = element.physicalUnit || ""; //计量单位 + newChildrenItem.propertyType = 0; //输入框类型 + newChildren.push(newChildrenItem); + }); + i.children = newChildren; + delete i.selected; }) - }) - let newChildren = [] - i.children.forEach((element, index) => { - let newChildrenItem: any = {} - // newChildrenItem.name = element.name//重点部位题目名称 - // newChildrenItem.position = element.position//重点部位所在位置 - // newChildrenItem.structure = element.structure//重点部位建筑结构 - // newChildrenItem.nature = element.nature//重点部位使用性质 - // newChildrenItem.hazards = element.hazards//重点部位主要危险性 - newChildrenItem.name = element.name//题目名称 - newChildrenItem.result = element.position + element.structure + element.nature + element.hazards//题目答案 - newChildrenItem.physicalUnit = element.physicalUnit || ''//计量单位 - newChildrenItem.propertyType = 0//输入框类型 - newChildren.push(newChildrenItem) - }) - i.children = newChildren - delete i.selected - - - }) : null + : null; //建筑的功能分区模块处理 - item.funDivNodes ? item.funDivNodes.forEach((i, key) => { - - //如果顶级节点未选中则需要筛除没有选中的数据 - if (!i.checked) { - let newArr = [] - i.children.forEach(element => { - element.checked ? newArr.push(element) : null - }) - let discard = []//即将废弃的数组 - newArr.length == 0 ? discard.push(i) : i.children = newArr - item.funDivNodes = item.funDivNodes.filter(items => { - if (!discard.includes(items)) return items; - }) - } + item.funDivNodes + ? item.funDivNodes.forEach((i, key) => { + //如果顶级节点未选中则需要筛除没有选中的数据 + if (!i.checked) { + let newArr = []; + i.children.forEach((element) => { + element.checked ? newArr.push(element) : null; + }); + let discard = []; //即将废弃的数组 + newArr.length == 0 ? discard.push(i) : (i.children = newArr); + item.funDivNodes = item.funDivNodes.filter((items) => { + if (!discard.includes(items)) return items; + }); + } - i.tabledata = [{ propertyName: "区域", data: [] }, - { propertyName: "面积", data: [] }, - { propertyName: "基本情况", data: [] }] - i.children.forEach(element => { - i.tabledata[0].data.push({ - name: "区域", - physicalUnit: '', - propertyType: 0, - result: element.region, - tag: "" - }) - i.tabledata[1].data.push({ - name: "面积", - physicalUnit: '', - propertyType: 0, - result: element.area, - tag: "" - }) - i.tabledata[2].data.push({ - name: "基本情况", - physicalUnit: '', - propertyType: 0, - result: element.details, - tag: "" + i.tabledata = [ + { propertyName: "区域", data: [] }, + { propertyName: "面积", data: [] }, + { propertyName: "基本情况", data: [] }, + ]; + i.children.forEach((element) => { + i.tabledata[0].data.push({ + name: "区域", + physicalUnit: "", + propertyType: 0, + result: element.region, + tag: "", + }); + i.tabledata[1].data.push({ + name: "面积", + physicalUnit: "", + propertyType: 0, + result: element.area, + tag: "", + }); + i.tabledata[2].data.push({ + name: "基本情况", + physicalUnit: "", + propertyType: 0, + result: element.details, + tag: "", + }); + }); + let newChildren = []; + i.children.forEach((element, index) => { + let newChildrenItem: any = {}; + // newChildrenItem.name = element.region//功能分区题目名称 + // newChildrenItem.area = element.area//功能分区面积 + // newChildrenItem.details = element.details//功能分区基本情况 + newChildrenItem.name = element.region; //题目名称 + newChildrenItem.result = element.area + element.details; //题目答案 + newChildrenItem.physicalUnit = element.physicalUnit || ""; //计量单位 + newChildrenItem.propertyType = 0; //输入框类型 + newChildren.push(newChildrenItem); + }); + i.children = newChildren; + delete i.selected; }) - }) - let newChildren = [] - i.children.forEach((element, index) => { - let newChildrenItem: any = {} - // newChildrenItem.name = element.region//功能分区题目名称 - // newChildrenItem.area = element.area//功能分区面积 - // newChildrenItem.details = element.details//功能分区基本情况 - newChildrenItem.name = element.region//题目名称 - newChildrenItem.result = element.area + element.details//题目答案 - newChildrenItem.physicalUnit = element.physicalUnit || ''//计量单位 - newChildrenItem.propertyType = 0//输入框类型 - newChildren.push(newChildrenItem) - }) - i.children = newChildren - delete i.selected - }) : null + : null; //建筑的数据核验模块处理 - item.fireFacNodes ? item.fireFacNodes.forEach((i, key) => { - i.selected ? i.selected = null : null - //如果顶级节点未选中则需要筛除没有选中的数据 - if (!i.checked) { - let newArr = [] - i.children.forEach(element => { - element.checked ? newArr.push(element) : null - }) - let discard = []//即将废弃的数组 - newArr.length == 0 ? discard.push(i) : i.children = newArr - item.fireFacNodes = item.fireFacNodes.filter(items => { - if (!discard.includes(items)) return items; + item.fireFacNodes + ? item.fireFacNodes.forEach((i, key) => { + i.selected ? (i.selected = null) : null; + //如果顶级节点未选中则需要筛除没有选中的数据 + if (!i.checked) { + let newArr = []; + i.children.forEach((element) => { + element.checked ? newArr.push(element) : null; + }); + let discard = []; //即将废弃的数组 + newArr.length == 0 ? discard.push(i) : (i.children = newArr); + item.fireFacNodes = item.fireFacNodes.filter((items) => { + if (!discard.includes(items)) return items; + }); + } + let newChildren = []; + i.children.forEach((element, index) => { + let newChildrenItem: any = {}; + newChildrenItem.name = element.name; //题目名称 + newChildrenItem.result = element.total; //题目答案 + newChildrenItem.physicalUnit = ""; //计量单位 + newChildrenItem.propertyType = 0; //输入框类型 + newChildren.push(newChildrenItem); + }); + i.children = newChildren; + delete i.selected; }) - } - let newChildren = [] - i.children.forEach((element, index) => { - let newChildrenItem: any = {} - newChildrenItem.name = element.name//题目名称 - newChildrenItem.result = element.total//题目答案 - newChildrenItem.physicalUnit = ''//计量单位 - newChildrenItem.propertyType = 0//输入框类型 - newChildren.push(newChildrenItem) - }) - i.children = newChildren - delete i.selected - }) : null - }) + : null; + }); //将筛选出来的数据变为服务器提交数据 - let paperDataInfo = [] + let paperDataInfo = []; copyDatas.forEach((item, key) => { - paperDataInfo[key] = {} - paperDataInfo[key].id = null - paperDataInfo[key].paperId = sessionStorage.getItem('paperId') - paperDataInfo[key].companyId = item.id - paperDataInfo[key].basicInfoData = item.basicInfoNodes ? JSON.stringify(item.basicInfoNodes) : '[]' - paperDataInfo[key].basicInfoScore = item.basicInfoScore - paperDataInfo[key].adjoinData = item.aroundNodes ? JSON.stringify(item.aroundNodes) : '[]' - paperDataInfo[key].adjoinScore = item.aroundScore - paperDataInfo[key].importLocationData = item.keySiteNodes ? JSON.stringify(item.keySiteNodes) : '[]' - paperDataInfo[key].importLocationScore = item.keySiteScore - paperDataInfo[key].functionalDivisionData = item.funDivNodes ? JSON.stringify(item.funDivNodes) : '[]' - paperDataInfo[key].functionalDivisionScore = item.funDivScore - paperDataInfo[key].facilityData = item.fireFacNodes ? JSON.stringify(item.fireFacNodes) : '[]' - paperDataInfo[key].facilityScore = item.fireFacScore, - paperDataInfo[key].originalData = JSON.stringify(this.unitId[key]) + paperDataInfo[key] = {}; + paperDataInfo[key].id = null; + paperDataInfo[key].paperId = sessionStorage.getItem("paperId"); + paperDataInfo[key].companyId = item.id; + paperDataInfo[key].basicInfoData = item.basicInfoNodes + ? JSON.stringify(item.basicInfoNodes) + : "[]"; + paperDataInfo[key].basicInfoScore = item.basicInfoScore; + paperDataInfo[key].adjoinData = item.aroundNodes + ? JSON.stringify(item.aroundNodes) + : "[]"; + paperDataInfo[key].adjoinScore = item.aroundScore; + paperDataInfo[key].importLocationData = item.keySiteNodes + ? JSON.stringify(item.keySiteNodes) + : "[]"; + paperDataInfo[key].importLocationScore = item.keySiteScore; + paperDataInfo[key].functionalDivisionData = item.funDivNodes + ? JSON.stringify(item.funDivNodes) + : "[]"; + paperDataInfo[key].functionalDivisionScore = item.funDivScore; + paperDataInfo[key].facilityData = item.fireFacNodes + ? JSON.stringify(item.fireFacNodes) + : "[]"; + (paperDataInfo[key].facilityScore = item.fireFacScore), + (paperDataInfo[key].originalData = JSON.stringify(this.unitId[key])); //赋值单项分 - paperDataInfo[key].basicInfoItemScore = item.basicInfoItemScore - paperDataInfo[key].adjoinItemScore = item.aroundItemScore - paperDataInfo[key].importLocationItemScore = item.keySiteItemScore - paperDataInfo[key].functionalDivisionItemSocre = item.funDivItemScore - paperDataInfo[key].facilityItemScore = item.fireFacItemScore - }) + paperDataInfo[key].basicInfoItemScore = item.basicInfoItemScore; + paperDataInfo[key].adjoinItemScore = item.aroundItemScore; + paperDataInfo[key].importLocationItemScore = item.keySiteItemScore; + paperDataInfo[key].functionalDivisionItemSocre = item.funDivItemScore; + paperDataInfo[key].facilityItemScore = item.fireFacItemScore; + }); //判断是否存在总分填写后没有勾选 或者勾选了没有填写总分的情况 for (let index = 0; index < this.unitId.length; index++) { const element = this.unitId[index]; - element.isPlanScore = true - element.planList.length != 0 ? - element.isPlanScore = element.planList.some(item => { - if (!item.score || item.score == 0) { - return false - } else { - return true - } - }) : null + element.isPlanScore = true; + element.planList.length != 0 + ? (element.isPlanScore = element.planList.some((item) => { + if (!item.score || item.score == 0) { + return false; + } else { + return true; + } + })) + : null; //判断存在总分填写后没有勾选题目 - if ((element.basicInfoScore != 0 && element.basicInfoNodesKey.length == 0) || + if ( + (element.basicInfoScore != 0 && + element.basicInfoNodesKey.length == 0) || (element.aroundScore != 0 && element.aroundNodesKey.length == 0) || (element.keySiteScore != 0 && element.keySiteNodesKey.length == 0) || (element.funDivScore != 0 && element.funDivNodesKey.length == 0) || - (element.fireFacScore != 0 && element.fireFacNodesKey.length == 0)) { + (element.fireFacScore != 0 && element.fireFacNodesKey.length == 0) + ) { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('存在填写过总分,但未勾选题目的分组', '确定', config); - return - } else - //勾选了题目存在没有填写总分 - if ( - (element.basicInfoScore == 0 && element.basicInfoNodesKey.length != 0) || - (element.aroundScore == 0 && element.aroundNodesKey.length != 0) || - (element.keySiteScore == 0 && element.keySiteNodesKey.length != 0) || - (element.funDivScore == 0 && element.funDivNodesKey.length != 0) || - (element.fireFacScore == 0 && element.fireFacNodesKey.length != 0)) { - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('存在勾选过题目,但未填写总分的分组', '确定', config); - return - } else - //存在预案没有填写总分 - if (element.isPlanScore == false) { - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('存在预案未填写总分的分组', '确定', config); - return - } + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("存在填写过总分,但未勾选题目的分组", "确定", config); + return; + } + //勾选了题目存在没有填写总分 + else if ( + (element.basicInfoScore == 0 && + element.basicInfoNodesKey.length != 0) || + (element.aroundScore == 0 && element.aroundNodesKey.length != 0) || + (element.keySiteScore == 0 && element.keySiteNodesKey.length != 0) || + (element.funDivScore == 0 && element.funDivNodesKey.length != 0) || + (element.fireFacScore == 0 && element.fireFacNodesKey.length != 0) + ) { + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("存在勾选过题目,但未填写总分的分组", "确定", config); + return; + } + //存在预案没有填写总分 + else if (element.isPlanScore == false) { + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("存在预案未填写总分的分组", "确定", config); + return; + } } - let _this = this + let _this = this; async function setPlansScore() { for (let index = 0; index < _this.unitId.length; index++) { const element = _this.unitId[index]; for (let i = 0; i < element.planList.length; i++) { await new Promise((resolve, reject) => { const item = element.planList[i]; - _this.http.put(`/api/PaperPlans/ModifyScore/${item.id}`, '', { - params: { - score: item.score - } - }).subscribe(((data) => { - resolve(i) - console.log('修改分数成功' + i, item.score) - })) - }) + _this.http + .put(`/api/PaperPlans/ModifyScore/${item.id}`, "", { + params: { + score: item.score, + }, + }) + .subscribe((data) => { + resolve(i); + console.log("修改分数成功" + i, item.score); + }); + }); } - } - } setPlansScore().then(() => { let body = { - id: sessionStorage.getItem('paperId'), + id: sessionStorage.getItem("paperId"), valid: true, - paperDataInfo: paperDataInfo - } - this.http.put(`/api/Papers/UpdatePaperData/${sessionStorage.getItem('paperId')}`, body).subscribe(data => { - // const dialogRef = this.dialog.open(editorsDia, { - // width: '650px', - // data: this.editdata - // }); - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('创建试卷成功,页面将于一秒后退出', '确定', config); - setTimeout(() => { - this.router.navigateByUrl('/home/createexam-index') - }, 1000); - }) - }) - - - - - + paperDataInfo: paperDataInfo, + }; + this.http + .put( + `/api/Papers/UpdatePaperData/${sessionStorage.getItem("paperId")}`, + body + ) + .subscribe((data) => { + // const dialogRef = this.dialog.open(editorsDia, { + // width: '650px', + // data: this.editdata + // }); + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("创建试卷成功,页面将于一秒后退出", "确定", config); + setTimeout(() => { + this.router.navigateByUrl("/home/createexam-index"); + }, 1000); + }); + }); } //上一步 goBack() { @@ -1325,13 +1531,16 @@ export class CreateTestScoreComponent implements OnInit { //添加预案1 @Component({ - selector: 'addplan-dialog', - templateUrl: 'addPlan.html', - styleUrls: ['addPlan.scss'] + selector: "addplan-dialog", + templateUrl: "addPlan.html", + styleUrls: ["addPlan.scss"], }) export class AddPlanDialog { - - constructor(public dialog: MatDialog, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any) { } + constructor( + public dialog: MatDialog, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any + ) {} onNoClick(): void { this.dialogRef.close(); @@ -1345,63 +1554,70 @@ export class AddPlanDialog { selectType(type) { let obj = { type: type, - companyData: this.data - } + companyData: this.data, + }; const dialogRef = this.dialog.open(AddPlanTwoDialog, { - id: 'addPlanTwo', - data: obj + id: "addPlanTwo", + data: obj, }); - dialogRef.afterClosed().subscribe(result => { + dialogRef.afterClosed().subscribe((result) => { if (result) { - console.log(1111111, result) + console.log(1111111, result); this.dialogRef.close(result); } else { this.dialogRef.close(); } - }); } } - //添加预案2 @Component({ - selector: 'addplantwo-dialog', - templateUrl: 'addPlanTwo.html', - styleUrls: ['addPlanTwo.scss'] + selector: "addplantwo-dialog", + templateUrl: "addPlanTwo.html", + styleUrls: ["addPlanTwo.scss"], }) export class AddPlanTwoDialog { - - constructor(public snackBar: MatSnackBar, private http: HttpClient, public dialog: MatDialog, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any) { } - - planType: any = this.data.type == 1 ? true : false//显示的预案类型 - displayedColumns: string[] = ['select', 'name', 'people', 'time', 'level']; - dataSource: any //列表数据 - selectedRadioData: any//当前选择的二维预案 - customPlanName: any//自定义预案名称 + constructor( + public snackBar: MatSnackBar, + private http: HttpClient, + public dialog: MatDialog, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any + ) {} + + planType: any = this.data.type == 1 ? true : false; //显示的预案类型 + displayedColumns: string[] = ["select", "name", "people", "time", "level"]; + dataSource: any; //列表数据 + selectedRadioData: any; //当前选择的二维预案 + customPlanName: any; //自定义预案名称 radioChange(e) { - this.selectedRadioData = e + this.selectedRadioData = e; } ngOnInit(): void { - this.get2DPlan() - console.log(1, this.data.companyData.companyData.id) + this.get2DPlan(); + console.log(1, this.data.companyData.companyData.id); } //获取当前公司的二维预案 get2DPlan() { - let planArr = [] - this.http.get('/api/PlanComponents', { - params: { - companyId: this.data.companyData.companyData.id - } - }).subscribe((data: any) => { - data.items.forEach(item => { - //二维预案并且审核通过 - (item.planType == 1 && item.auditStatus == 2) ? planArr.push(item) : null + let planArr = []; + this.http + .get("/api/PlanComponents", { + params: { + companyId: this.data.companyData.companyData.id, + }, }) - this.dataSource = planArr - }) + .subscribe((data: any) => { + data.items.forEach((item) => { + //二维预案并且审核通过 + item.planType == 1 && item.auditStatus == 2 + ? planArr.push(item) + : null; + }); + this.dataSource = planArr; + }); } onNoClick(): void { @@ -1409,15 +1625,16 @@ export class AddPlanTwoDialog { } //确定 confirm() { - if (this.planType) {//如果选择的是已存在预案 + if (this.planType) { + //如果选择的是已存在预案 if (this.selectedRadioData) { - console.log(this.selectedRadioData) + console.log(this.selectedRadioData); let paperPlansBody = { id: null, - paperId: sessionStorage.getItem('paperId'), + paperId: sessionStorage.getItem("paperId"), planComponentId: this.selectedRadioData.id, examPlanType: 0, - creatorId: JSON.parse(sessionStorage.getItem('creatorData')).id, + creatorId: JSON.parse(sessionStorage.getItem("creatorData")).id, modifiedTime: new Date(), isPublic: this.selectedRadioData.openRange == "未公开" ? false : true, title: this.selectedRadioData.name, @@ -1427,42 +1644,46 @@ export class AddPlanTwoDialog { examDisposalNodesData: null, companyId: this.data.companyData.companyData.id, creatorName: this.selectedRadioData.creatorName, - planLevel: Number(this.selectedRadioData.planLevel) - } + planLevel: Number(this.selectedRadioData.planLevel), + }; let paperPlansParams: any = { - paperId: sessionStorage.getItem('paperId'), - } - this.http.post('/api/PaperPlans', paperPlansBody, { params: paperPlansParams }).subscribe((data2: any) => { - this.dialogRef.close(data2); - sessionStorage.setItem('companyName', this.data.companyData.companyData.name) - sessionStorage.setItem('planId', this.selectedRadioData.id) - sessionStorage.setItem('buildingTypeId', this.data.companyData.companyData.buildingTypes[0].id) - sessionStorage.setItem('companyId', this.data.companyData.companyData.id) - window.open(`/canvasTool?openType=1&planName=${this.selectedRadioData.name}&paperplanId=${data2.id}`) - }) - - + paperId: sessionStorage.getItem("paperId"), + }; + this.http + .post("/api/PaperPlans", paperPlansBody, { params: paperPlansParams }) + .subscribe((data2: any) => { + this.dialogRef.close(data2); + sessionStorage.setItem( + "companyName", + this.data.companyData.companyData.name + ); + sessionStorage.setItem("planId", this.selectedRadioData.id); + sessionStorage.setItem( + "buildingTypeId", + this.data.companyData.companyData.buildingTypes[0].id + ); + sessionStorage.setItem( + "companyId", + this.data.companyData.companyData.id + ); + window.open( + `/canvasTool?openType=1&planName=${this.selectedRadioData.name}&paperplanId=${data2.id}` + ); + }); } else { if (this.dataSource.length == 0) { this.dialogRef.close(); } else { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('请选择要添加的预案', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("请选择要添加的预案", "确定", config); } - } - } else {//如果选择的是自定义预案 - - - - - - - + } else { + //如果选择的是自定义预案 - let level = sessionStorage.getItem('level') + let level = sessionStorage.getItem("level"); let body = { id: null, name: this.customPlanName, @@ -1470,76 +1691,90 @@ export class AddPlanTwoDialog { planMode: 2, planLevel: Number(level), url: null, - attachmentUrls: null - } - this.http.post("/api/ExamPlanComponents2D", body, { - params: { - companyId: this.data.companyData.companyData.id - } - }).subscribe((data: any) => { - console.log("创建自定义二维成功") - - let paperPlansBody = { - id: null, - paperId: sessionStorage.getItem('paperId'), - planComponentId: data.id, - examPlanType: 1, - creatorId: JSON.parse(sessionStorage.getItem('creatorData')).id, - modifiedTime: new Date(), - isPublic: true, - title: this.customPlanName, - mainPoint: null, - score: 0, - examFacilityAssetsData: null, - examDisposalNodesData: null, - companyId: this.data.companyData.companyData.id, - creatorName: sessionStorage.getItem('realName'), - planLevel: Number(sessionStorage.getItem('level')) - } - let paperPlansParams: any = { - paperId: sessionStorage.getItem('paperId') - } - console.log(this) - this.http.post('/api/PaperPlans', paperPlansBody, { params: paperPlansParams }).subscribe((data2: any) => { - this.dialogRef.close(data2); - sessionStorage.setItem("planId", data.id); - sessionStorage.setItem("companyId", this.data.companyData.companyData.id) - sessionStorage.setItem("buildingTypeId", this.data.companyData.companyData.buildingTypes[0].id) - sessionStorage.setItem("editable", "1") - window.open(`/canvasTool?openType=2&planName=${this.customPlanName}&paperplanId=${data2.id}`) + attachmentUrls: null, + }; + this.http + .post("/api/ExamPlanComponents2D", body, { + params: { + companyId: this.data.companyData.companyData.id, + }, }) - }) + .subscribe((data: any) => { + console.log("创建自定义二维成功"); + + let paperPlansBody = { + id: null, + paperId: sessionStorage.getItem("paperId"), + planComponentId: data.id, + examPlanType: 1, + creatorId: JSON.parse(sessionStorage.getItem("creatorData")).id, + modifiedTime: new Date(), + isPublic: true, + title: this.customPlanName, + mainPoint: null, + score: 0, + examFacilityAssetsData: null, + examDisposalNodesData: null, + companyId: this.data.companyData.companyData.id, + creatorName: sessionStorage.getItem("realName"), + planLevel: Number(sessionStorage.getItem("level")), + }; + let paperPlansParams: any = { + paperId: sessionStorage.getItem("paperId"), + }; + console.log(this); + this.http + .post("/api/PaperPlans", paperPlansBody, { + params: paperPlansParams, + }) + .subscribe((data2: any) => { + this.dialogRef.close(data2); + sessionStorage.setItem("planId", data.id); + sessionStorage.setItem( + "companyId", + this.data.companyData.companyData.id + ); + sessionStorage.setItem( + "buildingTypeId", + this.data.companyData.companyData.buildingTypes[0].id + ); + sessionStorage.setItem("editable", "1"); + window.open( + `/canvasTool?openType=2&planName=${this.customPlanName}&paperplanId=${data2.id}` + ); + }); + }); } } //取消 close() { this.dialogRef.close(); } - } //完成弹窗 @Component({ - selector: 'finish-dialog', - templateUrl: 'finishDialog.html', - styleUrls: ['finishDialog.scss'] + selector: "finish-dialog", + templateUrl: "finishDialog.html", + styleUrls: ["finishDialog.scss"], }) export class FinishDialog { - - constructor(private router: Router, private http: HttpClient, public dialog: MatDialog, public snackBar: MatSnackBar, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any) { } - ngOnInit(): void { - - } - + constructor( + private router: Router, + private http: HttpClient, + public dialog: MatDialog, + public snackBar: MatSnackBar, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any + ) {} + ngOnInit(): void {} //弹窗确定点击事件 onNoClick(): void { - if (window.confirm('你确定要创建该试卷吗?')) { + if (window.confirm("你确定要创建该试卷吗?")) { alert("确定"); - } else { alert("取消"); - } } @@ -1550,17 +1785,19 @@ export class FinishDialog { //查看答案 @Component({ - selector: 'lookTreeNode-dialog', - templateUrl: 'lookTreeNode.html', - styleUrls: ['lookTreeNode.scss'] + selector: "lookTreeNode-dialog", + templateUrl: "lookTreeNode.html", + styleUrls: ["lookTreeNode.scss"], }) export class LookTreeNodeDialog { - - constructor(public dialog: MatDialog, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any) { } - + constructor( + public dialog: MatDialog, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any + ) {} ngOnInit(): void { - console.log(this.data) + console.log(this.data); } onNoClick(): void { @@ -1571,57 +1808,62 @@ export class LookTreeNodeDialog { close() { this.dialogRef.close(); } - } //编辑试题弹窗 @Component({ - selector: 'finish-dialog', - templateUrl: 'editors.html', - styleUrls: ['finishDia.scss'] + selector: "finish-dialog", + templateUrl: "editors.html", + styleUrls: ["finishDia.scss"], }) export class editorsDia { - constructor(private router: Router, private http: HttpClient, public dialog: MatDialog, public snackBar: MatSnackBar, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public datas: any) { } + constructor( + private router: Router, + private http: HttpClient, + public dialog: MatDialog, + public snackBar: MatSnackBar, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public datas: any + ) {} ngOnInit(): void { /* this.startTime=this.datas.startTime this.endTime=this.datas.endTime */ - this.startTime = this.datas.startTime.split("+")[0] - this.endTime = this.datas.endTime.split("+")[0] - this.examName = this.datas.title - console.log(this.datas) + this.startTime = this.datas.startTime.split("+")[0]; + this.endTime = this.datas.endTime.split("+")[0]; + this.examName = this.datas.title; + console.log(this.datas); } //获取登录账号的个人资料 - Profiles: any + Profiles: any; getProfiles() { - this.http.get('/api/ExamAccounts/Profiles').subscribe((data: any) => { - console.log(data) - this.Profiles = data - sessionStorage.setItem('creatorData', JSON.stringify(data)) - }) + this.http.get("/api/ExamAccounts/Profiles").subscribe((data: any) => { + console.log(data); + this.Profiles = data; + sessionStorage.setItem("creatorData", JSON.stringify(data)); + }); } - - startTime: string//考试开始时间 - endTime: string//考试结束时间 - examName: string//考试名称 - indexid: string//创建考试的id - tabledate + startTime: string; //考试开始时间 + endTime: string; //考试结束时间 + examName: string; //考试名称 + indexid: string; //创建考试的id + tabledate; //弹窗确定点击事件 onNoClick(): void { //console.log( this.startTime,this.endTime) if (this.startTime > this.endTime) { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('开始时间不能早于结束时间', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("开始时间不能早于结束时间", "确定", config); } else { let body = { id: this.datas.id, startTime: this.startTime, endTime: this.endTime, - title: this.examName - } + title: this.examName, + }; let params = { id: null, title: this.examName, @@ -1632,14 +1874,14 @@ export class editorsDia { endTime: this.endTime, organizationId: this.datas.organizationId, creatorId: this.datas.creatorId, - paperDataInfo: null - } - this.http.put(`/api/Papers/${this.datas.id}`, body).subscribe(data => { + paperDataInfo: null, + }; + this.http.put(`/api/Papers/${this.datas.id}`, body).subscribe((data) => { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('修改试卷成功', '确定', config); - this.router.navigateByUrl('/home/createexam-index') + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("修改试卷成功", "确定", config); + this.router.navigateByUrl("/home/createexam-index"); this.dialogRef.close(); /* setTimeout(() => { this.http.get(`/api/Papers/${this.datas.id}`).subscribe((data:any) => { @@ -1661,13 +1903,10 @@ export class editorsDia { this.dialogRef.close(); }, 1000); */ - }) + }); } - - } - close() { this.dialogRef.close(); } diff --git a/src/app/ui/collection-tools/collection-tools.component.ts b/src/app/ui/collection-tools/collection-tools.component.ts index 19a7a11..e9162b1 100644 --- a/src/app/ui/collection-tools/collection-tools.component.ts +++ b/src/app/ui/collection-tools/collection-tools.component.ts @@ -1,38 +1,77 @@ -import { Component, OnInit, Inject, ViewChild, ElementRef, Renderer2, ViewContainerRef } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; -import { leftFunctionalDomainComponent, editPlaneFigureComponent, editDisposalNodeComponent, addDisposalNodeComponent } from './leftFunctionalDomain' -import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree'; -import { FlatTreeControl } from '@angular/cdk/tree'; -import { WorkingAreaComponent } from '../../working-area/working-area.component' -import { CanvasShareDataService, DisposalNodeData } from '../../canvas-share-data.service' //引入服务 -import Viewer from 'viewerjs'; -import Swiper from 'swiper'; -import { saveOneDialog } from './save'; -import { NzFormatBeforeDropEvent, NzFormatEmitEvent, NzTreeComponent } from 'ng-zorro-antd/tree'; -import { Observable, of } from 'rxjs'; -import { delay } from 'rxjs/operators'; -import { windows } from 'src/app/interface'; -import { GameMode } from 'src/app/working-area/model/gameMode'; -import { ActivatedRoute, Router } from '@angular/router'; -import { examinationQuestions, uploadDisposalNodes, uploadQuestions } from './examinationQuestions' -import { AxMessageSystem } from 'src/app/working-area/model/axMessageSystem'; - +import { + Component, + OnInit, + Inject, + ViewChild, + ElementRef, + Renderer2, + ViewContainerRef, +} from "@angular/core"; +import { HttpClient, HttpHeaders } from "@angular/common/http"; +import { + MatDialog, + MatDialogRef, + MAT_DIALOG_DATA, +} from "@angular/material/dialog"; +import { MatSnackBar, MatSnackBarConfig } from "@angular/material/snack-bar"; +import { + leftFunctionalDomainComponent, + editPlaneFigureComponent, + editDisposalNodeComponent, + addDisposalNodeComponent, +} from "./leftFunctionalDomain"; +import { + MatTreeFlatDataSource, + MatTreeFlattener, +} from "@angular/material/tree"; +import { FlatTreeControl } from "@angular/cdk/tree"; +import { WorkingAreaComponent } from "../../working-area/working-area.component"; +import { + CanvasShareDataService, + DisposalNodeData, +} from "../../canvas-share-data.service"; //引入服务 +import Viewer from "viewerjs"; +import Swiper from "swiper"; +import { saveOneDialog } from "./save"; +import { + NzFormatBeforeDropEvent, + NzFormatEmitEvent, + NzTreeComponent, +} from "ng-zorro-antd/tree"; +import { Observable, of } from "rxjs"; +import { delay } from "rxjs/operators"; +import { windows } from "src/app/interface"; +import { GameMode } from "src/app/working-area/model/gameMode"; +import { ActivatedRoute, Router } from "@angular/router"; +import { + examinationQuestions, + uploadDisposalNodes, + uploadQuestions, +} from "./examinationQuestions"; +import { AxMessageSystem } from "src/app/working-area/model/axMessageSystem"; @Component({ - selector: 'app-collection-tools', - templateUrl: './collection-tools.component.html', - styleUrls: ['./collection-tools.component.scss'] + selector: "app-collection-tools", + templateUrl: "./collection-tools.component.html", + styleUrls: ["./collection-tools.component.scss"], }) export class CollectionToolsComponent implements OnInit { - - @ViewChild('canvas', { static: true }) canvas: WorkingAreaComponent; //父组件中获得子组件的引用 - - constructor(private http: HttpClient, public dialog: MatDialog, public snackBar: MatSnackBar, private element: ElementRef, public canvasData: CanvasShareDataService, private router: Router, private route: ActivatedRoute) { } - @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; + @ViewChild("canvas", { static: true }) canvas: WorkingAreaComponent; //父组件中获得子组件的引用 + + constructor( + private http: HttpClient, + public dialog: MatDialog, + public snackBar: MatSnackBar, + private element: ElementRef, + public canvasData: CanvasShareDataService, + private router: Router, + private route: ActivatedRoute + ) {} + @ViewChild("nzTreeComponent", { static: false }) + nzTreeComponent!: NzTreeComponent; // tree配置 - private _transformer = (node, level: number) => {//要给渲染节点传那些属性参数 + private _transformer = (node, level: number) => { + //要给渲染节点传那些属性参数 return { expandable: !!node.children && node.children.length > 0, name: node.name || node.Name, @@ -42,725 +81,853 @@ export class CollectionToolsComponent implements OnInit { isTemplate: node.isTemplate, isNewElement: node.isNewElement, isLook: node.isLook, - isLookPattern: node.isLookPattern || null + isLookPattern: node.isLookPattern || null, }; - } - treeControl = new FlatTreeControl(node => node.level, node => node.expandable); - - treeFlattener = new MatTreeFlattener(this._transformer, node => node.level, node => node.expandable, node => 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; - colors = ['#076eec', '#4dd0e1', '#00ee76', '#ffff00', '#eeb422', - '#FF6A6A', '#ff0000', '#ff6eb4', '#00bfff', '#54ff9f', - '#009688', '#836fff', '#ff8c00', '#ee00ee', '#ffa07a', - '#00C500', '#00ffff', '#6495ed', '#ffdAb9', '#AA00FF'] - selected = "1" //图标大小选择框 - - allBuildings //该单位所有建筑 + colors = [ + "#076eec", + "#4dd0e1", + "#00ee76", + "#ffff00", + "#eeb422", + "#FF6A6A", + "#ff0000", + "#ff6eb4", + "#00bfff", + "#54ff9f", + "#009688", + "#836fff", + "#ff8c00", + "#ee00ee", + "#ffa07a", + "#00C500", + "#00ffff", + "#6495ed", + "#ffdAb9", + "#AA00FF", + ]; + selected = "1"; //图标大小选择框 + + allBuildings; //该单位所有建筑 beforeOneCheckedBuilding: any = { name: "总平面图" }; //当前点击选择的建筑 beforeOneCheckedBuildingIsShow: boolean = false; //建筑是否显示 - togglebeforeOneCheckedBuilding() { this.beforeOneCheckedBuildingIsShow = !this.beforeOneCheckedBuildingIsShow } - checkedBuildingIndex: number = -1 //当前点击选择的建筑index - isEditPat: boolean = true //当前是否是编辑模式 - - assetName: String//素材名称 - assetWidth: number//素材宽度 - assetHeight: number//素材高度 - sliderValue: number = 0//角度滑竿的值 - sliderValueThickness: number = 0//厚度滑竿的值 - isHighLight: boolean = false//是否高亮选择框 - PropertyInfos = [] //去除图片链接真正用于循环的内容 - imagesArrNum //素材属性图片数量上限 - imagesArr = [] //属性中的图片链接集合 - clickedIndex //点击图片时的索引值 + togglebeforeOneCheckedBuilding() { + this.beforeOneCheckedBuildingIsShow = !this.beforeOneCheckedBuildingIsShow; + } + checkedBuildingIndex: number = -1; //当前点击选择的建筑index + isEditPat: boolean = true; //当前是否是编辑模式 + + assetName: String; //素材名称 + assetWidth: number; //素材宽度 + assetHeight: number; //素材高度 + sliderValue: number = 0; //角度滑竿的值 + sliderValueThickness: number = 0; //厚度滑竿的值 + isHighLight: boolean = false; //是否高亮选择框 + PropertyInfos = []; //去除图片链接真正用于循环的内容 + imagesArrNum; //素材属性图片数量上限 + imagesArr = []; //属性中的图片链接集合 + clickedIndex; //点击图片时的索引值 //传入素材对象,设置右侧属性栏内容 - canvasAssetObj //传入的素材属性对象 - isImgNumCss = false //控制上传文件input显隐 - mySwiper: any //轮播图实例 + canvasAssetObj; //传入的素材属性对象 + isImgNumCss = false; //控制上传文件input显隐 + mySwiper: any; //轮播图实例 - gallery//viewerJs实例 + gallery; //viewerJs实例 //设置属性框 setAssetsProperty(obj) { //初始化viewerJs实例 setTimeout(() => { - obj.PropertyInfos.forEach(item => { + obj.PropertyInfos.forEach((item) => { if (item.PropertyType == 4) { - this.gallery = new Viewer(document.getElementById('viewerjs'), { - url: 'data-original' + this.gallery = new Viewer(document.getElementById("viewerjs"), { + url: "data-original", }); } - }) + }); }, 0); //从颜色中取出透明度 - let color = obj.Color - let strh = color.substring(color.length - 2, color.length) - let opacity = Math.round(parseInt(strh, 16) / 255 * 100) - this.colorDivSliderValue = opacity - - this.isShowProperty = true - this.isShowAttribute = false - let _this = this - this.imagesArr = [] - this.imagesArrNum = "" - - this.canvasAssetObj = obj //将选中素材对象存到本地变量 - - this.assetName = obj.Name - this.assetWidth = obj.Width - this.assetHeight = obj.Height - this.sliderValue = obj.Angle - this.selectedcolor = obj.Color - this.PropertyInfos = obj.PropertyInfos - this.sliderValueThickness = obj.Thickness - this.PropertyInfos.forEach(item => { - if (item.PropertyType == 3) { //如果是图片链接类型 - this.imagesArr.push(item) + let color = obj.Color; + let strh = color.substring(color.length - 2, color.length); + let opacity = Math.round((parseInt(strh, 16) / 255) * 100); + this.colorDivSliderValue = opacity; + + this.isShowProperty = true; + this.isShowAttribute = false; + let _this = this; + this.imagesArr = []; + this.imagesArrNum = ""; + + this.canvasAssetObj = obj; //将选中素材对象存到本地变量 + + this.assetName = obj.Name; + this.assetWidth = obj.Width; + this.assetHeight = obj.Height; + this.sliderValue = obj.Angle; + this.selectedcolor = obj.Color; + this.PropertyInfos = obj.PropertyInfos; + this.sliderValueThickness = obj.Thickness; + this.PropertyInfos.forEach((item) => { + if (item.PropertyType == 3) { + //如果是图片链接类型 + this.imagesArr.push(item); } - if (item.PropertyType == 4) {//图片数值上线 - this.imagesArrNum = item.PropertyValue + if (item.PropertyType == 4) { + //图片数值上线 + this.imagesArrNum = item.PropertyValue; } - }) + }); //如果存在图片则加载轮播图 if (this.imagesArr.length) { setTimeout(() => { - this.mySwiper = new Swiper('.swiper-container', { + this.mySwiper = new Swiper(".swiper-container", { loop: false, // grabCursor: true, // 如果需要前进后退按钮 navigation: { - nextEl: '.swiper-button-next', - prevEl: '.swiper-button-prev', + nextEl: ".swiper-button-next", + prevEl: ".swiper-button-prev", }, on: { click: function () { - _this.clickedIndex = this.clickedIndex + _this.clickedIndex = this.clickedIndex; }, - } + }, }); }, 0); } //判断此时图片数量是否达到上限 - if (this.imagesArr.length < this.imagesArrNum) {//如果不超出 - this.isImgNumCss = true + if (this.imagesArr.length < this.imagesArrNum) { + //如果不超出 + this.isImgNumCss = true; } else { - this.isImgNumCss = false + this.isImgNumCss = false; } } - pattern: boolean = false//默认为基本信息编辑 + pattern: boolean = false; //默认为基本信息编辑 //ngzorro tree 拖拽 nzEvent(event: NzFormatEmitEvent): void { if (this.isDrag) { - let parentId + let parentId; if (this.pos == 0) { - parentId = event.node.key + parentId = event.node.key; } else { if (event.node.level == 0) { - parentId = null + parentId = null; } else { - parentId = event.node.origin.parentId + parentId = event.node.origin.parentId; } } - - let orders = {} - let originalData = JSON.parse(JSON.stringify(this.canvasData.allDisposalNode || [])) //tree原始数据 - let targetNodeData = []//拖动移入节点的数据,用于遍历求出放在该数组的第几位 + let orders = {}; + let originalData = JSON.parse( + JSON.stringify(this.canvasData.allDisposalNode || []) + ); //tree原始数据 + let targetNodeData = []; //拖动移入节点的数据,用于遍历求出放在该数组的第几位 //找到需要重新排序的数组 if (this.pos == 0) { - originalData.forEach(item => { + originalData.forEach((item) => { if (item.parentId == event.node.key) { - targetNodeData.push(item) + targetNodeData.push(item); } - }) + }); } else { - if (event.node.origin.parentId) {//如果拖动目标为非一级节点 - originalData.forEach(item => { + if (event.node.origin.parentId) { + //如果拖动目标为非一级节点 + originalData.forEach((item) => { if (item.parentId == event.node.origin.parentId) { - targetNodeData.push(item) + targetNodeData.push(item); } - }) - } else {//如果拖动目标为一级节点 - originalData.forEach(item => { + }); + } else { + //如果拖动目标为一级节点 + originalData.forEach((item) => { if (!item.parentId) { - targetNodeData.push(item) + targetNodeData.push(item); } - }) + }); } } - - let idArr = [] - targetNodeData.forEach(i => { - idArr.push(i.id) - }) + let idArr = []; + targetNodeData.forEach((i) => { + idArr.push(i.id); + }); // console.log(6666666666666,event); if (this.pos == 0 && event.node.origin.children.length == 1) { - console.log("移入,没有兄弟") - let key = event.dragNode.key - orders[key] = 0 - parentId = event.node.key + console.log("移入,没有兄弟"); + let key = event.dragNode.key; + orders[key] = 0; + parentId = event.node.key; } else { - console.log("移入,多个兄弟") - let array = [] - targetNodeData.forEach(item => { - if (item.id != event.dragNode.key) { //将拖动项先移除掉 - array.push(item) + console.log("移入,多个兄弟"); + let array = []; + targetNodeData.forEach((item) => { + if (item.id != event.dragNode.key) { + //将拖动项先移除掉 + array.push(item); } - }) - if (event.dragNode.isEnd[event.dragNode.isEnd.length - 1]) { //如果移入到最后一个 - console.log("最后") - array.push(event.dragNode.origin) - } else if (event.dragNode.isStart[event.dragNode.isStart.length - 1]) {//如果移入到第一个 - console.log("第一") - array.unshift(event.dragNode.origin) - } else {//如果移入中间位置 - console.log("中间") - array.splice(event.node.origin.order, 0, event.dragNode.origin) + }); + if (event.dragNode.isEnd[event.dragNode.isEnd.length - 1]) { + //如果移入到最后一个 + console.log("最后"); + array.push(event.dragNode.origin); + } else if (event.dragNode.isStart[event.dragNode.isStart.length - 1]) { + //如果移入到第一个 + console.log("第一"); + array.unshift(event.dragNode.origin); + } else { + //如果移入中间位置 + console.log("中间"); + array.splice(event.node.origin.order, 0, event.dragNode.origin); } array.forEach((item, key) => { - orders[item.id] = key - }) + orders[item.id] = key; + }); } let obj = { id: event.dragNode.origin.id, parentId: parentId, - orders: orders - } + orders: orders, + }; - this.http.put("/api/DisposalNodes/Sort", obj).subscribe(data => { + this.http.put("/api/DisposalNodes/Sort", obj).subscribe((data) => { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('排序成功', '确定', config) - this.refurbishTreeData() - }) + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("排序成功", "确定", config); + this.refurbishTreeData(); + }); } } - isDrag //是否可以拖动 - pos//放置位置 + isDrag; //是否可以拖动 + pos; //放置位置 beforeDrop = (arg: NzFormatBeforeDropEvent) => { - if (arg.dragNode.origin.isDataNode && arg.node.level === 0) {//如果为数据节点则不允许拖到一级节点 + if (arg.dragNode.origin.isDataNode && arg.node.level === 0) { + //如果为数据节点则不允许拖到一级节点 const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('数据节点不允许拖拽到一级节点', '确定', config) - this.isDrag = false + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("数据节点不允许拖拽到一级节点", "确定", config); + this.isDrag = false; return of(false); } else if (!arg.dragNode.origin.isDataNode && arg.node.level === 2) { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('处置节点不允许拖拽到三级节点', '确定', config) - this.isDrag = false + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("处置节点不允许拖拽到三级节点", "确定", config); + this.isDrag = false; return of(false); } else { - this.isDrag = true - this.pos = arg.pos - return of(true) + this.isDrag = true; + this.pos = arg.pos; + return of(true); } - } + }; //ngzorro tree 拖拽 //天气栏目 - weatherBtn = true + weatherBtn = true; weatherBtnShow() { - this.weatherBtn = !this.weatherBtn + this.weatherBtn = !this.weatherBtn; } weatherBtnHidden() { - this.weatherBtn = !this.weatherBtn + this.weatherBtn = !this.weatherBtn; } //底部切换按钮div - detailsAndattentBtn = true + detailsAndattentBtn = true; //节点详情 details() { - this.detailsAndattentBtn = true + this.detailsAndattentBtn = true; } //注意事项 attent() { - this.detailsAndattentBtn = false + this.detailsAndattentBtn = false; } //消防要素div边框高度调节 firecategoriesDivMouseDown(e) { document.onmousemove = (ev) => { - let bodyHeight = document.body.clientHeight //网页宽度 - let maxHeight = this.element.nativeElement.querySelector('#rightDiv').clientHeight - 35 //最大宽度 + let bodyHeight = document.body.clientHeight; //网页宽度 + let maxHeight = + this.element.nativeElement.querySelector("#rightDiv").clientHeight - 35; //最大宽度 if (bodyHeight - ev.clientY >= maxHeight) { - this.element.nativeElement.querySelector('#firecategories').style.height = maxHeight + 'px' - this.element.nativeElement.querySelector('#property').style.height = 35 + 'px' + this.element.nativeElement.querySelector( + "#firecategories" + ).style.height = maxHeight + "px"; + this.element.nativeElement.querySelector("#property").style.height = + 35 + "px"; } else { - this.element.nativeElement.querySelector('#firecategories').style.height = (bodyHeight - ev.clientY) + 'px'; - this.element.nativeElement.querySelector('#property').style.height = (this.element.nativeElement.querySelector('#rightDiv').clientHeight - this.element.nativeElement.querySelector('#firecategories').clientHeight) + 'px' + this.element.nativeElement.querySelector( + "#firecategories" + ).style.height = bodyHeight - ev.clientY + "px"; + this.element.nativeElement.querySelector("#property").style.height = + this.element.nativeElement.querySelector("#rightDiv").clientHeight - + this.element.nativeElement.querySelector("#firecategories") + .clientHeight + + "px"; } - } + }; document.onmouseup = () => { document.onmousemove = null; document.onmouseup = null; - } + }; } //左侧div边框宽度调节 leftDivMouseDown(e) { document.onmousemove = (ev) => { - let bodyWidth = document.body.clientWidth //网页宽度 - let maxWidth = bodyWidth - 260 - this.element.nativeElement.querySelector('#rightDiv').clientWidth //最大宽度 + let bodyWidth = document.body.clientWidth; //网页宽度 + let maxWidth = + bodyWidth - + 260 - + this.element.nativeElement.querySelector("#rightDiv").clientWidth; //最大宽度 if (ev.clientX - 240 >= maxWidth) { - this.element.nativeElement.querySelector('#leftDiv').style.width = maxWidth + 'px' + this.element.nativeElement.querySelector("#leftDiv").style.width = + maxWidth + "px"; } else { - this.element.nativeElement.querySelector('#leftDiv').style.width = ev.clientX - 260 + 'px'; + this.element.nativeElement.querySelector("#leftDiv").style.width = + ev.clientX - 260 + "px"; } - } + }; document.onmouseup = () => { document.onmousemove = null; document.onmouseup = null; - } + }; } //底部div高度调节 bottomDivMouseDown(e) { document.onmousemove = (ev) => { - let bodyHeight = document.body.clientHeight //网页高度 - let maxHeight = this.element.nativeElement.querySelector('#rightDiv').clientHeight //最大高度 + let bodyHeight = document.body.clientHeight; //网页高度 + let maxHeight = + this.element.nativeElement.querySelector("#rightDiv").clientHeight; //最大高度 if (bodyHeight - ev.clientY >= maxHeight) { - this.element.nativeElement.querySelector('#bottomDiv').style.height = maxHeight + 'px' + this.element.nativeElement.querySelector("#bottomDiv").style.height = + maxHeight + "px"; } else { - this.element.nativeElement.querySelector('#bottomDiv').style.height = (bodyHeight - ev.clientY) + 'px'; + this.element.nativeElement.querySelector("#bottomDiv").style.height = + bodyHeight - ev.clientY + "px"; } - } + }; document.onmouseup = () => { document.onmousemove = null; document.onmouseup = null; - } + }; } //右侧div边框宽度调节 rightDivMouseDown(e) { document.onmousemove = (ev) => { - let bodyWidth = document.body.clientWidth //网页宽度 - let maxWidth = bodyWidth - 240 - this.element.nativeElement.querySelector('#leftDiv').clientWidth //最大宽度 + let bodyWidth = document.body.clientWidth; //网页宽度 + let maxWidth = + bodyWidth - + 240 - + this.element.nativeElement.querySelector("#leftDiv").clientWidth; //最大宽度 if (bodyWidth - ev.clientX >= maxWidth) { - this.element.nativeElement.querySelector('#rightDiv').style.width = maxWidth + 'px' + this.element.nativeElement.querySelector("#rightDiv").style.width = + maxWidth + "px"; } else { - this.element.nativeElement.querySelector('#rightDiv').style.width = bodyWidth - ev.clientX + 'px'; + this.element.nativeElement.querySelector("#rightDiv").style.width = + bodyWidth - ev.clientX + "px"; } - } + }; document.onmouseup = () => { document.onmousemove = null; document.onmouseup = null; - } + }; } //放大图标 iconScale() { - let number = Number(this.selected) - this.canvas.setIconScale(number) + let number = Number(this.selected); + this.canvas.setIconScale(number); } //素材宽度输入框改变 assetWidthIunput() { - this.canvasAssetObj.Width = this.assetWidth - this.canvasData.isChange = true - this.canvas.refreshIcon(this.canvasAssetObj.Id) + this.canvasAssetObj.Width = this.assetWidth; + this.canvasData.isChange = true; + this.canvas.refreshIcon(this.canvasAssetObj.Id); } //素材高度输入框改变 assetHeightIunput() { - this.canvasAssetObj.Height = this.assetHeight - this.canvasData.isChange = true - this.canvas.refreshIcon(this.canvasAssetObj.Id) + this.canvasAssetObj.Height = this.assetHeight; + this.canvasData.isChange = true; + this.canvas.refreshIcon(this.canvasAssetObj.Id); } //素材角度输入框改变 assetAngleIunput() { - this.canvasAssetObj.Angle = this.sliderValue - this.canvasData.isChange = true - this.canvas.refreshIcon(this.canvasAssetObj.Id) + this.canvasAssetObj.Angle = this.sliderValue; + this.canvasData.isChange = true; + this.canvas.refreshIcon(this.canvasAssetObj.Id); } //素材厚度输入框改变 assetThicknessIunput() { - this.canvasAssetObj.Thickness = this.sliderValueThickness - this.canvasData.isChange = true - this.canvas.refreshIcon(this.canvasAssetObj.Id) + this.canvasAssetObj.Thickness = this.sliderValueThickness; + this.canvasData.isChange = true; + this.canvas.refreshIcon(this.canvasAssetObj.Id); } //素材是否高亮改变----->本地操作行为 - assetHighLightIunput() { - - } + assetHighLightIunput() {} //动态属性素材input框值改变 assetInputChange(i, e) { let index = this.canvasAssetObj.PropertyInfos.findIndex((item) => { - return i.PropertyName == item.PropertyName - }) - this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value - this.canvasData.isChange = true - this.canvas.refreshIcon(this.canvasAssetObj.Id) + return i.PropertyName == item.PropertyName; + }); + this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value; + this.canvasData.isChange = true; + this.canvas.refreshIcon(this.canvasAssetObj.Id); } //动态属性素材布尔值框改变radio assetRadioChange(i, boolean) { let index = this.canvasAssetObj.PropertyInfos.findIndex((item) => { - return i.PropertyName == item.PropertyName - }) - this.canvasAssetObj.PropertyInfos[index].PropertyValue = boolean - this.canvasData.isChange = true + return i.PropertyName == item.PropertyName; + }); + this.canvasAssetObj.PropertyInfos[index].PropertyValue = boolean; + this.canvasData.isChange = true; } - colorIndex//默认素材颜色 - selectedcolor//点击选择的颜色 + colorIndex; //默认素材颜色 + selectedcolor; //点击选择的颜色 //选择素材颜色 selectcolor(item, key) { //在当前透明度基础上改变颜色 - this.selectedcolor = item + this.selectedcolor.substring(this.selectedcolor.length - 2) - this.canvasAssetObj.Color = this.selectedcolor - this.canvasData.isChange = true - this.canvas.refreshIcon(this.canvasAssetObj.Id) + this.selectedcolor = + item + this.selectedcolor.substring(this.selectedcolor.length - 2); + this.canvasAssetObj.Color = this.selectedcolor; + this.canvasData.isChange = true; + this.canvas.refreshIcon(this.canvasAssetObj.Id); } //颜色选择滑竿的值 - colorDivSliderValue + colorDivSliderValue; colorDivSliderChange() { - let colorOpacity = Math.round(255 * this.colorDivSliderValue * 0.01) + let colorOpacity = Math.round(255 * this.colorDivSliderValue * 0.01); //根据滑竿值改变16进制颜色后两位 function replacepos(text, start, stop, replacetext) { - let mystr = text.substring(0, stop - 1) + replacetext + text.substring(stop + 1); + let mystr = + text.substring(0, stop - 1) + replacetext + text.substring(stop + 1); return mystr; } - this.selectedcolor = replacepos(this.selectedcolor, 7, 8, colorOpacity.toString(16)) - this.canvasAssetObj.Color = this.selectedcolor - this.canvasData.isChange = true - this.canvas.refreshIcon(this.canvasAssetObj.Id) + this.selectedcolor = replacepos( + this.selectedcolor, + 7, + 8, + colorOpacity.toString(16) + ); + this.canvasAssetObj.Color = this.selectedcolor; + this.canvasData.isChange = true; + this.canvas.refreshIcon(this.canvasAssetObj.Id); } //查看图片详情 lookImg() { - const dialogRef = this.dialog.open(ViewDetailss, {//调用open方法打开对话框并且携带参数过去 - data: { imagesArr: this.imagesArr, index: this.clickedIndex } + const dialogRef = this.dialog.open(ViewDetailss, { + //调用open方法打开对话框并且携带参数过去 + data: { imagesArr: this.imagesArr, index: this.clickedIndex }, }); - dialogRef.afterClosed().subscribe(data => { }); + dialogRef.afterClosed().subscribe((data) => {}); } //上传素材图片 selectFile(e) { - let imgFile = e.target.files[0] || null //上传的文件 - this.startUploading(imgFile) + let imgFile = e.target.files[0] || null; //上传的文件 + this.startUploading(imgFile); } - objectName: any //上传对象名 + objectName: any; //上传对象名 startUploading(imgFile) { - let _this = this - let file = imgFile || null //获取上传的文件 - let fileSize = file.size || null //上传文件的总大小 - let shardSize = 5 * 1024 * 1024 //5MB一个分片 - let companyId = sessionStorage.getItem("companyId") - if (file && fileSize <= shardSize) { //上传文件<=5MB时 - let formData = new FormData() - formData.append("file", file) - this.http.post(`api/Objects/WebPlan2D/${companyId}`, formData).subscribe((data: any) => { - this.objectName = data.objectName - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('上传成功', '确定', config) - - //在原始素材对象和需要循环图片的对象中分别push最新上传的图片 - let imgObj = { - "Tag": null, - "Order": 0, - "Enabled": false, - "Visible": false, - "Required": false, - "RuleName": null, - "RuleValue": null, - "PhysicalUnit": null, - "PropertyName": "图片", - "PropertyType": 3, - "PropertyValue": "/api/Objects/WebPlan2D/" + this.objectName - } - - this.imagesArr.push(imgObj) - this.canvasAssetObj.PropertyInfos.push(imgObj) - - setTimeout(() => { - this.mySwiper = new Swiper('.swiper-container', { - loop: false, - // grabCursor: true, - // 如果需要前进后退按钮 - navigation: { - nextEl: '.swiper-button-next', - prevEl: '.swiper-button-prev', - }, - on: { - click: function () { - _this.clickedIndex = this.clickedIndex + let _this = this; + let file = imgFile || null; //获取上传的文件 + let fileSize = file.size || null; //上传文件的总大小 + let shardSize = 5 * 1024 * 1024; //5MB一个分片 + let companyId = sessionStorage.getItem("companyId"); + if (file && fileSize <= shardSize) { + //上传文件<=5MB时 + let formData = new FormData(); + formData.append("file", file); + this.http + .post(`api/Objects/WebPlan2D/${companyId}`, formData) + .subscribe((data: any) => { + this.objectName = data.objectName; + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("上传成功", "确定", config); + + //在原始素材对象和需要循环图片的对象中分别push最新上传的图片 + let imgObj = { + Tag: null, + Order: 0, + Enabled: false, + Visible: false, + Required: false, + RuleName: null, + RuleValue: null, + PhysicalUnit: null, + PropertyName: "图片", + PropertyType: 3, + PropertyValue: "/api/Objects/WebPlan2D/" + this.objectName, + }; + + this.imagesArr.push(imgObj); + this.canvasAssetObj.PropertyInfos.push(imgObj); + + setTimeout(() => { + this.mySwiper = new Swiper(".swiper-container", { + loop: false, + // grabCursor: true, + // 如果需要前进后退按钮 + navigation: { + nextEl: ".swiper-button-next", + prevEl: ".swiper-button-prev", }, - } - }); - - this.mySwiper.slideTo(this.imagesArr.length - 1) - this.gallery.update() - }, 0); - - //判断上传素材属性图片是否超出数量 超出数量则隐藏input框 - if (this.imagesArr.length < this.imagesArrNum) {//不超出input才会显示 - this.isImgNumCss = true - } else { - this.isImgNumCss = false - } + on: { + click: function () { + _this.clickedIndex = this.clickedIndex; + }, + }, + }); + + this.mySwiper.slideTo(this.imagesArr.length - 1); + this.gallery.update(); + }, 0); + + //判断上传素材属性图片是否超出数量 超出数量则隐藏input框 + if (this.imagesArr.length < this.imagesArrNum) { + //不超出input才会显示 + this.isImgNumCss = true; + } else { + this.isImgNumCss = false; + } - this.canvasData.isChange = true - }) - } else if (file && fileSize > shardSize) { //上传文件>5MB时,分块上传 + this.canvasData.isChange = true; + }); + } else if (file && fileSize > shardSize) { + //上传文件>5MB时,分块上传 let config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('上传图片文件不允许大于5mb', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("上传图片文件不允许大于5mb", "确定", config); } - } //不能上传图片提示 imgNumBeyond() { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('图片数量已达上限', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("图片数量已达上限", "确定", config); } //删除素材属性图片 deleteImg() { if (this.imagesArr.length == 0) { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('没有可删除的图片,请先上传', '确定', config) + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("没有可删除的图片,请先上传", "确定", config); } else { // 在素材原始对象中将删除的图片去掉 - this.canvasAssetObj.PropertyInfos = [...this.canvasAssetObj.PropertyInfos.filter((item) => { - return item.PropertyValue != this.imagesArr[this.mySwiper.activeIndex].PropertyValue - })] + this.canvasAssetObj.PropertyInfos = [ + ...this.canvasAssetObj.PropertyInfos.filter((item) => { + return ( + item.PropertyValue != + this.imagesArr[this.mySwiper.activeIndex].PropertyValue + ); + }), + ]; //在图片循环数组中将图片去掉 this.imagesArr.splice(this.mySwiper.activeIndex, 1); //更新swiper视图 setTimeout(() => { this.mySwiper.update(); - this.gallery.update() + this.gallery.update(); }, 0); //将上传的input框显示出来 this.isImgNumCss = true; //清除图片缓存 - if ((document.getElementById('inputimg'))) { - (document.getElementById('inputimg')).value = null //清空input框缓存 + if (document.getElementById("inputimg")) { + (document.getElementById("inputimg")).value = null; //清空input框缓存 } - this.canvasData.isChange = true + this.canvasData.isChange = true; } } //动态属性方向select选择框 direction(i, e) { let index = this.canvasAssetObj.PropertyInfos.findIndex((item) => { - return i.PropertyName == item.PropertyName - }) - this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value - this.canvasData.isChange = true + return i.PropertyName == item.PropertyName; + }); + this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value; + this.canvasData.isChange = true; } //动态属性供给区域select选择框 supplyArea(i, e) { let index = this.canvasAssetObj.PropertyInfos.findIndex((item) => { - return i.PropertyName == item.PropertyName - }) - this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value - this.canvasData.isChange = true + return i.PropertyName == item.PropertyName; + }); + this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value; + this.canvasData.isChange = true; } //动态属性供给类型select选择框 supplyType(i, e) { let index = this.canvasAssetObj.PropertyInfos.findIndex((item) => { - return i.PropertyName == item.PropertyName - }) - this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value - this.canvasData.isChange = true + return i.PropertyName == item.PropertyName; + }); + this.canvasAssetObj.PropertyInfos[index].PropertyValue = e.target.value; + this.canvasData.isChange = true; } - isSixShow = true - isSixbtn = true //控制想定作业编辑按钮 - isxxx = true //控制查看编辑模式的编辑模式按钮 - examMsg = { //单位,考试信息 - conpanyName: sessionStorage.getItem('companyName') || '暂无数据', //单位名称 - keynote: '', //考试要点 - } + isSixShow = true; + isSixbtn = true; //控制想定作业编辑按钮 + isxxx = true; //控制查看编辑模式的编辑模式按钮 + examMsg = { + //单位,考试信息 + conpanyName: sessionStorage.getItem("companyName") || "暂无数据", //单位名称 + keynote: "", //考试要点 + }; ngOnInit(): void { - this.canvasData.gameMode = GameMode.Examinee - this.getAllLibrary('plan') //获取素材库 - this.getAllBuildings() //获取所有建筑 - this.getAllFirePlan() //获取当前单位灾情 - - let that = this - AxMessageSystem.addListener('selectionChanged', () => { - if (this.canvas.selection.size() == 1) {//如果是单选 - console.log('单选', this.canvas.selection.first().assetData) - this.setAssetsProperty(this.canvas.selection.first().assetData) - } else if (this.canvas.selection.size() == 0) { - this.isShowProperty = false - } - }, this) - AxMessageSystem.addListener('imageResize', (eventName, args1) => { - this.assetWidth = args1.Width - this.assetHeight = args1.Height - }, this) + this.canvasData.gameMode = GameMode.Examinee; + this.getAllLibrary("plan"); //获取素材库 + this.getAllBuildings(); //获取所有建筑 + this.getAllFirePlan(); //获取当前单位灾情 + + this.getPaperPlanData(); + let that = this; + AxMessageSystem.addListener( + "selectionChanged", + () => { + if (this.canvas.selection.size() == 1) { + //如果是单选 + console.log("单选", this.canvas.selection.first().assetData); + this.setAssetsProperty(this.canvas.selection.first().assetData); + } else if (this.canvas.selection.size() == 0) { + this.isShowProperty = false; + } + }, + this + ); + AxMessageSystem.addListener( + "imageResize", + (eventName, args1) => { + this.assetWidth = args1.Width; + this.assetHeight = args1.Height; + }, + this + ); window.setTimeout(() => { - document.getElementById("functionalDomainContent").oncontextmenu = function (event) { - // that.canvas.cancelPaint() - that.selectImageIndex = -1 - event.preventDefault(); - }; - }) + document.getElementById("functionalDomainContent").oncontextmenu = + function (event) { + // that.canvas.cancelPaint() + that.selectImageIndex = -1; + event.preventDefault(); + }; + }); this.canvasData.getMessage().subscribe((message: any) => { if (message == "send a message") { - this.refurbishTreeData() + this.refurbishTreeData(); } - }) + }); + } + async getPaperPlanData() { + let params = { + paperId: this.route.snapshot.queryParams.paperId, + }; + await new Promise((resolve, reject) => { + this.http + .get(`/api/PaperPlans`, { params: params }) + .subscribe((data: any) => { + if (data && data.length !== 0) { + let planData; + data.forEach((item) => { + item.id == this.route.snapshot.queryParams.paperplanId + ? (planData = item) + : null; + }); + console.log("当前预案数据信息", planData); + // let questions = JSON.parse(planData.examDisposalNodesData); + sessionStorage.setItem( + "examNodeList", + planData.examDisposalNodesData + ); + // let Facilities = JSON.parse(planData.examFacilityAssetsData); + sessionStorage.setItem( + "消防设施" + this.route.snapshot.queryParams.paperId, + planData.examFacilityAssetsData + ); + + this.examMsg.keynote = planData.mainPoint; + + let weatherData = JSON.parse(planData.weather); + weatherData ? (this.weatherData = weatherData) : null; + } + }); + }); } ngAfterViewInit(): void { - - this.getSitePlan() //获取总平面图/楼层 + this.getSitePlan(); //获取总平面图/楼层 // 监听canvas组件选中素材事件 - this.canvas.on("select", obj => { + this.canvas.on("select", (obj) => { //选中素材属性注入函数 - console.log(1111) - this.setAssetsProperty(obj.assetData) - }) + console.log(1111); + this.setAssetsProperty(obj.assetData); + }); // 监听canvas组件取消选中素材事件 - this.canvas.on("deselect", obj => { - this.isShowProperty = false - }) + this.canvas.on("deselect", (obj) => { + this.isShowProperty = false; + }); // 监听canvas组件新增素材事件 - this.canvas.on("createIcon", obj => { - console.log(2222, this.canvasData.selectPanelPoint.Data) - this.renovateTreeData(false) - }) + this.canvas.on("createIcon", (obj) => { + console.log(2222, this.canvasData.selectPanelPoint.Data); + this.renovateTreeData(false); + }); // 监听canvas组件删除素材事件 - this.canvas.on("deleteIcon", obj => { - this.renovateTreeData(false) - }) - + this.canvas.on("deleteIcon", (obj) => { + this.renovateTreeData(false); + }); } - copyAssetData: any //存储用于复制的素材 + copyAssetData: any; //存储用于复制的素材 //复制素材 copyAsset() { - this.canvas.copy() + this.canvas.copy(); } //粘贴素材 pasteAsset() { - let companyId = sessionStorage.getItem("companyId") - let buildingId = this.beforeOneCheckedBuilding.id - let floorId = this.selectingSitePlan.id - this.canvas.paste(companyId, buildingId, floorId) + let companyId = sessionStorage.getItem("companyId"); + let buildingId = this.beforeOneCheckedBuilding.id; + let floorId = this.selectingSitePlan.id; + this.canvas.paste(companyId, buildingId, floorId); } - basicInfo: boolean = true //基本信息名称显隐 - wantToWork: boolean = true //想定作业名称显隐 + basicInfo: boolean = true; //基本信息名称显隐 + wantToWork: boolean = true; //想定作业名称显隐 //点击基本信息名称 basicInfoClick() { - this.basicInfo = !this.basicInfo - this.canvas.setNameVisible(this.basicInfo, 0) + this.basicInfo = !this.basicInfo; + this.canvas.setNameVisible(this.basicInfo, 0); } //点击想定作业名称 wantToWorkClick() { - this.wantToWork = !this.wantToWork - this.canvas.setNameVisible(this.wantToWork, 1) + this.wantToWork = !this.wantToWork; + this.canvas.setNameVisible(this.wantToWork, 1); } - //保存平面图 - saveNum: any = [] + saveNum: any = []; saveSite() { if (this.selectingSitePlan && this.selectingSitePlan.id) { - this.saveNum = [] - let SitePlanData = JSON.parse(JSON.stringify(this.canvasData.originaleveryStoreyData)); - SitePlanData.data = JSON.stringify(SitePlanData.data) - let CompanyData = JSON.parse(JSON.stringify(this.canvasData.originalcompanyBuildingData)); - CompanyData.data = JSON.stringify(CompanyData.data) - - let object = this.canvasData.originalcompanyBuildingData.data - let adjoinArr = [] //毗邻数组 - - if (this.pattern) {//如果是基本信息编辑模式 - return true - } else {//如果是想定作业编辑模式 + this.saveNum = []; + let SitePlanData = JSON.parse( + JSON.stringify(this.canvasData.originaleveryStoreyData) + ); + SitePlanData.data = JSON.stringify(SitePlanData.data); + let CompanyData = JSON.parse( + JSON.stringify(this.canvasData.originalcompanyBuildingData) + ); + CompanyData.data = JSON.stringify(CompanyData.data); + + let object = this.canvasData.originalcompanyBuildingData.data; + let adjoinArr = []; //毗邻数组 + + if (this.pattern) { + //如果是基本信息编辑模式 + return true; + } else { + //如果是想定作业编辑模式 const dialogRef = this.dialog.open(saveOneDialog, { data: { allDisposalNode: this.canvasData.allDisposalNode, selectedBuildingData: this.beforeOneCheckedBuilding, selectedSiteData: this.selectingSitePlan, siteOrbuilding: this.checkedBuildingIndex, - disasterId: this.allFirePlan[0].id || '' - } + disasterId: this.allFirePlan[0].id || "", + }, }); - dialogRef.afterClosed().subscribe(result => { - console.log('The dialog was closed'); + dialogRef.afterClosed().subscribe((result) => { + console.log("The dialog was closed"); }); } - - } else { //if + } else { + //if const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('暂无楼层数据', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("暂无楼层数据", "确定", config); } } //获得所有的建筑物 getAllBuildings() { - this.http.get("/api/Buildings", { - params: { - companyId: this.params.companyId - } - }).subscribe(data => { - this.allBuildings = data - }) + this.http + .get("/api/Buildings", { + params: { + companyId: this.params.companyId, + }, + }) + .subscribe((data) => { + this.allBuildings = data; + }); } //创建建筑 createBuilding() { let data = { allBuildings: this.allBuildings, - companyId: this.params.companyId - } + companyId: this.params.companyId, + }; let dialogRef = this.dialog.open(CreateBuilding, { data }); - dialogRef.afterClosed().subscribe(data => { + dialogRef.afterClosed().subscribe((data) => { if (data == "创建成功") { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('创建成功', '确定', config); - this.getAllBuildings() + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("创建成功", "确定", config); + this.getAllBuildings(); } else if (data == "创建失败") { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('创建失败', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("创建失败", "确定", config); } }); } @@ -768,7 +935,6 @@ export class CollectionToolsComponent implements OnInit { //选择建筑 checkedBuilding(item, index) { if (this.checkedBuildingIndex != index) { - // if (this.canvasData.isChange) { //true 数据被改动 // let isTrue = confirm('是否保存当前编辑数据') // if (isTrue) { //先保存数据 在切换 @@ -794,12 +960,14 @@ export class CollectionToolsComponent implements OnInit { // } else { //flase 数据未被改动 // } //if - this.beforeOneCheckedBuilding = item - this.checkedBuildingIndex = index - if (index == -1) { //总平面图数据 - this.getSitePlan() - } else { //建筑楼层/区域数据 - this.getBuildingSitePlan(item) + this.beforeOneCheckedBuilding = item; + this.checkedBuildingIndex = index; + if (index == -1) { + //总平面图数据 + this.getSitePlan(); + } else { + //建筑楼层/区域数据 + this.getBuildingSitePlan(item); } } //if } @@ -808,18 +976,18 @@ export class CollectionToolsComponent implements OnInit { editBuilding(e, item) { e.stopPropagation(); let dialogRef = this.dialog.open(EditBuilding, { data: { item: item } }); - dialogRef.afterClosed().subscribe(data => { + dialogRef.afterClosed().subscribe((data) => { if (data == "修改成功") { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('修改成功', '确定', config); - this.getAllBuildings() + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("修改成功", "确定", config); + this.getAllBuildings(); } else if (data == "修改失败") { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('修改失败', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("修改失败", "确定", config); } }); } @@ -828,80 +996,94 @@ export class CollectionToolsComponent implements OnInit { deleteBuilding(e, item) { e.stopPropagation(); if (confirm("是否删除该建筑") == true) { - let isHave = this.canvasData.allDisposalNode.find(items => { return items.buildingId === item.id }) + let isHave = this.canvasData.allDisposalNode.find((items) => { + return items.buildingId === item.id; + }); if (isHave == undefined) { - this.http.delete(`/api/Buildings/${item.id}`).subscribe(data => { - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('删除成功', '确定', config); - this.http.get("/api/Buildings", { - params: { - companyId: this.params.companyId - } - }).subscribe(data => { - this.allBuildings = data - this.beforeOneCheckedBuilding = { name: "总平面图" } - this.checkedBuildingIndex = -1 - this.getSitePlan() - }) - }, err => { - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('删除失败', '确定', config); - this.getAllBuildings() - }) - } else { //建筑 含有数据节点时 + this.http.delete(`/api/Buildings/${item.id}`).subscribe( + (data) => { + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("删除成功", "确定", config); + this.http + .get("/api/Buildings", { + params: { + companyId: this.params.companyId, + }, + }) + .subscribe((data) => { + this.allBuildings = data; + this.beforeOneCheckedBuilding = { name: "总平面图" }; + this.checkedBuildingIndex = -1; + this.getSitePlan(); + }); + }, + (err) => { + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("删除失败", "确定", config); + this.getAllBuildings(); + } + ); + } else { + //建筑 含有数据节点时 const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('含有数据节点的建筑不允许删除', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("含有数据节点的建筑不允许删除", "确定", config); } } } - storeyData //将建筑素材和当前楼层素材合二为一 + storeyData; //将建筑素材和当前楼层素材合二为一 //处理 tree 数据结构 handleTreeData(storeyData) { //storeyData为当前楼层拥有的消防设施 - this.storeyData = storeyData - let data = JSON.parse(JSON.stringify(this.allFireElements)) //所有消防要素模板 + this.storeyData = storeyData; + let data = JSON.parse(JSON.stringify(this.allFireElements)); //所有消防要素模板 // console.log(889,this.storeyData) - let treeData = [] //tree型 处理完成后的数据 - this.allFireElements.forEach(element => { - element.key = element.id - element.isTemplate = true //添加模板标识 - element.isLook = true //添加是否可见标识 - element.name != '其他' ? element.children = [] : null + let treeData = []; //tree型 处理完成后的数据 + this.allFireElements.forEach((element) => { + element.key = element.id; + element.isTemplate = true; //添加模板标识 + element.isLook = true; //添加是否可见标识 + element.name != "其他" ? (element.children = []) : null; if (storeyData) { for (let key in storeyData.data) { - storeyData.data[key].isLookPattern = true + storeyData.data[key].isLookPattern = true; if (element.id == storeyData.data[key].FireElementId) { - storeyData.data[key].isTemplate = false - storeyData.data[key].isLook = true + storeyData.data[key].isTemplate = false; + storeyData.data[key].isLook = true; - element.isNewElement = true //该节点children是否存在新添加的真实素材 标识 + element.isNewElement = true; //该节点children是否存在新添加的真实素材 标识 //定义查看模式下能看到的元素 - element.isLookPattern = true + element.isLookPattern = true; if (element.parentId) { - this.allFireElements.forEach(i => { + this.allFireElements.forEach((i) => { if (i.id == element.parentId) { - i.isLookPattern = true + i.isLookPattern = true; } - }) + }); } - element.children.push(storeyData.data[key]) + element.children.push(storeyData.data[key]); } } } - this.allFireElements.forEach(item => { if (item.parentId == element.id) { element.children.push(item) } }); + this.allFireElements.forEach((item) => { + if (item.parentId == element.id) { + element.children.push(item); + } + }); }); - this.allFireElements.forEach(element => { - if (!element.parentId) { treeData.push(element) } + this.allFireElements.forEach((element) => { + if (!element.parentId) { + treeData.push(element); + } }); function recursionFilterEmpty(originalList, result) { @@ -919,7 +1101,7 @@ export class CollectionToolsComponent implements OnInit { item.children = newChildren; // 子项有真实的数据,就保留这一项 result.push(item); - } // 如果没有这一项就会被删除 + } // 如果没有这一项就会被删除 } } } @@ -930,82 +1112,83 @@ export class CollectionToolsComponent implements OnInit { return result; } - this.dataSource.data = filterEmpty(treeData) - - this.treeControl.expandAll() + this.dataSource.data = filterEmpty(treeData); + this.treeControl.expandAll(); } //点击树节点 clickTreeNode(node) { - if (this.canvasData.originalcompanyBuildingData.data[node.id]) { - this.setAssetsProperty(this.canvasData.originalcompanyBuildingData.data[node.id]) + this.setAssetsProperty( + this.canvasData.originalcompanyBuildingData.data[node.id] + ); } else if (this.canvasData.originaleveryStoreyData.data[node.id]) { - this.setAssetsProperty(this.canvasData.originaleveryStoreyData.data[node.id]) + this.setAssetsProperty( + this.canvasData.originaleveryStoreyData.data[node.id] + ); } // console.log(node) // canvas上的素材高亮 - let iconHighLightArr: any = [] - if (node.isTemplate) {//如果是模板,则开始向下找 - node.children.forEach(item => { - if (item.isTemplate) {//如果子节点依旧是模板,则继续开始向下找 - item.children.forEach(i => { - iconHighLightArr.push(i.Id) - }) + let iconHighLightArr: any = []; + if (node.isTemplate) { + //如果是模板,则开始向下找 + node.children.forEach((item) => { + if (item.isTemplate) { + //如果子节点依旧是模板,则继续开始向下找 + item.children.forEach((i) => { + iconHighLightArr.push(i.Id); + }); } else { - iconHighLightArr.push(item.Id) + iconHighLightArr.push(item.Id); } - }) + }); } else { - iconHighLightArr.push(node.id) + iconHighLightArr.push(node.id); } // console.log(456,iconHighLightArr) - this.canvas.setHighlight(iconHighLightArr) + this.canvas.setHighlight(iconHighLightArr); } //点击树节点的显示隐藏icon clickLookItem(node) { - //修改真实素材islook属性 for (let key in this.storeyData.data) { if (key == node.id) { - this.storeyData.data[key].isLook = !this.storeyData.data[key].isLook + this.storeyData.data[key].isLook = !this.storeyData.data[key].isLook; } } //所有消防要素模板变化islook值 if (node.isTemplate && node.name == "其他") { - this.allFireElements.forEach(item => { + this.allFireElements.forEach((item) => { if (item.name == "其他") { - item.isLook = !item.isLook + item.isLook = !item.isLook; } - }) + }); } if (node.isTemplate) { - this.allFireElements.forEach(item => { + this.allFireElements.forEach((item) => { if (item.id == node.id) { - item.isLook = !item.isLook + item.isLook = !item.isLook; } - }) + }); } - //子节点跟随父节点的islook变化 if (node.children && node.children.length != 0) { - node.children.forEach(item => { - item.isLook = !node.isLook + node.children.forEach((item) => { + item.isLook = !node.isLook; if (item.children && item.children.length != 0) { - item.children.forEach(i => { - i.isLook = !node.isLook - }) + item.children.forEach((i) => { + i.isLook = !node.isLook; + }); } - }) + }); } - const nodes = this.treeControl.dataNodes; const expandNodes = []; nodes.forEach((item) => { @@ -1014,45 +1197,50 @@ export class CollectionToolsComponent implements OnInit { } }); - this.dataSource.data = [...this.dataSource.data] + this.dataSource.data = [...this.dataSource.data]; let newNodes = this.treeControl.dataNodes; - newNodes = newNodes.filter(n => { + newNodes = newNodes.filter((n) => { return expandNodes.indexOf(n.id) >= 0; }); - newNodes.forEach(item => { + newNodes.forEach((item) => { this.treeControl.expand(item); }); //canvas上的素材显隐 - let iconVisibleArr: any = [] - if (node.isTemplate) {//如果是模板,则开始向下找 - node.children.forEach(item => { - if (item.isTemplate) {//如果子节点依旧是模板,则继续开始向下找 - item.children.forEach(i => { - iconVisibleArr.push(i.Id) - }) + let iconVisibleArr: any = []; + if (node.isTemplate) { + //如果是模板,则开始向下找 + node.children.forEach((item) => { + if (item.isTemplate) { + //如果子节点依旧是模板,则继续开始向下找 + item.children.forEach((i) => { + iconVisibleArr.push(i.Id); + }); } else { - iconVisibleArr.push(item.Id) + iconVisibleArr.push(item.Id); } - }) + }); } else { - iconVisibleArr.push(node.id) + iconVisibleArr.push(node.id); } - console.log(1, iconVisibleArr) - console.log(2, node.isLook) - this.canvas.setIconVisible(iconVisibleArr, !node.isLook) - + console.log(1, iconVisibleArr); + console.log(2, node.isLook); + this.canvas.setIconVisible(iconVisibleArr, !node.isLook); } //打开消防设施考题设定 openFireExamination() { - let treeData = JSON.parse(JSON.stringify(this.dataSource.data)) + let treeData = JSON.parse(JSON.stringify(this.dataSource.data)); let buildFloorData = { buildingData: this.beforeOneCheckedBuilding, - floorData: this.selectingSitePlan - } - let data = { treeData: treeData, oldRealData: this.storeyData, buildFloorData: buildFloorData } + floorData: this.selectingSitePlan, + }; + let data = { + treeData: treeData, + oldRealData: this.storeyData, + buildFloorData: buildFloorData, + }; let dialogRef = this.dialog.open(examinationQuestions, { data }); } @@ -1061,56 +1249,70 @@ export class CollectionToolsComponent implements OnInit { weather: null, airTemperature: null, windScale: null, - windDirection: null - } + windDirection: null, + }; openUploadQuestions() { - let treeData = JSON.parse(JSON.stringify(this.dataSource.data)) - let nodes = JSON.parse(JSON.stringify(JSON.parse(sessionStorage.getItem('examNodeList')))) + let treeData = JSON.parse(JSON.stringify(this.dataSource.data)); + let nodes = JSON.parse( + JSON.stringify(JSON.parse(sessionStorage.getItem("examNodeList"))) + ); if (nodes) { - let data = { treeData: treeData, question: JSON.parse(JSON.stringify(this.examMsg)), node: nodes, allFireElements: this.allFireElements, weatherData: this.weatherData } + let data = { + treeData: treeData, + question: JSON.parse(JSON.stringify(this.examMsg)), + node: nodes, + allFireElements: this.allFireElements, + weatherData: this.weatherData, + }; let dialogRef = this.dialog.open(uploadQuestions, { data }); } else { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('未选择考核处置节点', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("未选择考核处置节点", "确定", config); } } //封装 刷新 tree 数据 async renovateTreeData(isRefresh: boolean = true) { - - this.allFireElements[this.allFireElements.length - 1].children = [] - this.beforeOneCheckedBuildingIsShow = false - isRefresh ? this.canvasData.isChange = false : null //服务中 数据是否改动 改为false - isRefresh ? this.isShowProperty = true : null - isRefresh ? this.isShowAttribute = true : null - - let beforeOneId = this.selectingSitePlan.id || '' //当前 选中 平面图 楼层/区域 id - let companyBuildingData = JSON.parse(JSON.stringify(this.canvasData.originalcompanyBuildingData || {})) // 当前 单位/建筑 数据 - let storeyData = JSON.parse(JSON.stringify(this.canvasData.originaleveryStoreyData || {})) //当前 楼层 数据 - - for (let key in storeyData.data) { //筛选数据 - storeyData.data[key].key = storeyData.data[key].Id - let noMatch = this.allFireElements.find(every => every.id === storeyData.data[key].FireElementId) + this.allFireElements[this.allFireElements.length - 1].children = []; + this.beforeOneCheckedBuildingIsShow = false; + isRefresh ? (this.canvasData.isChange = false) : null; //服务中 数据是否改动 改为false + isRefresh ? (this.isShowProperty = true) : null; + isRefresh ? (this.isShowAttribute = true) : null; + + let beforeOneId = this.selectingSitePlan.id || ""; //当前 选中 平面图 楼层/区域 id + let companyBuildingData = JSON.parse( + JSON.stringify(this.canvasData.originalcompanyBuildingData || {}) + ); // 当前 单位/建筑 数据 + let storeyData = JSON.parse( + JSON.stringify(this.canvasData.originaleveryStoreyData || {}) + ); //当前 楼层 数据 + + for (let key in storeyData.data) { + //筛选数据 + storeyData.data[key].key = storeyData.data[key].Id; + let noMatch = this.allFireElements.find( + (every) => every.id === storeyData.data[key].FireElementId + ); //没有匹配全部放入到 其他 数组 if (!noMatch) { - this.allFireElements[this.allFireElements.length - 1].children.push(storeyData.data[key]) + this.allFireElements[this.allFireElements.length - 1].children.push( + storeyData.data[key] + ); } } - this.handleTreeData(storeyData) //处理tree数据结构 + this.handleTreeData(storeyData); //处理tree数据结构 } - - //陈鹏飞↓↓↓ //陈鹏飞↓↓↓ //陈鹏飞↓↓↓ - params = { companyId: sessionStorage.getItem('companyId') } + params = { companyId: sessionStorage.getItem("companyId") }; allFireElements: any = []; //当前 单位/建筑 下的消防要素 isShowAttribute: boolean = true; //属性栏 是否显示 默认数据 - isShowProperty: boolean = false //属性栏 是否有东西 + isShowProperty: boolean = false; //属性栏 是否有东西 toggleExpandPanel: boolean = false; //左侧可展开面板展开或关闭 toggleExpandPanelRight: boolean = false; //右侧可展开面板展开或关闭 @@ -1119,23 +1321,23 @@ export class CollectionToolsComponent implements OnInit { toggleHandlePlans: boolean = true; //可展开面板处置预案 显隐 //可展开面板展开或关闭 toggle() { - this.toggleExpandPanel = !this.toggleExpandPanel + this.toggleExpandPanel = !this.toggleExpandPanel; } //可展开面板展开或关闭 toggle2() { - this.toggleExpandPanelRight = !this.toggleExpandPanelRight + this.toggleExpandPanelRight = !this.toggleExpandPanelRight; } //可展开面板 平面图 展开或关闭 togglePlanarGraph() { - this.togglePlane = !this.togglePlane + this.togglePlane = !this.togglePlane; } //可展开面板 素材库 展开或关闭 toggleMaterial() { - this.toggleMaterialBank = !this.toggleMaterialBank + this.toggleMaterialBank = !this.toggleMaterialBank; } //可展开面板 处置预案 展开或关闭 toggleHandlePlan() { - this.toggleHandlePlans = !this.toggleHandlePlans + this.toggleHandlePlans = !this.toggleHandlePlans; } sitePlanData: any = []; //总平面图 楼层/区域 数据 @@ -1144,118 +1346,161 @@ export class CollectionToolsComponent implements OnInit { //获取总平面图 getSitePlan() { - let fireData = this.getFireElements(sessionStorage.getItem('buildingTypeId')) //获取单位下 消防要素 - let planData = this.getSitePlanCompanyData() //获取 单位 数据 - this.http.get('/api/SitePlans', { params: this.params }).subscribe(data => { - this.sitePlanData = data - this.selectingSitePlan = this.sitePlanData[0] || {} - this.canvasData.selectStorey = this.sitePlanData[0] || {} //服务中 存一份数据 - this.selectSitePlanIndex = 0 + let fireData = this.getFireElements( + sessionStorage.getItem("buildingTypeId") + ); //获取单位下 消防要素 + let planData = this.getSitePlanCompanyData(); //获取 单位 数据 + this.http + .get("/api/SitePlans", { params: this.params }) + .subscribe((data) => { + this.sitePlanData = data; + this.selectingSitePlan = this.sitePlanData[0] || {}; + this.canvasData.selectStorey = this.sitePlanData[0] || {}; //服务中 存一份数据 + this.selectSitePlanIndex = 0; - Promise.all([fireData, planData]).then((res) => { - this.getSitePlanStorey(this.selectingSitePlan) //获取 平面图 楼层数据 - }) - - }) + Promise.all([fireData, planData]).then((res) => { + this.getSitePlanStorey(this.selectingSitePlan); //获取 平面图 楼层数据 + }); + }); } //获取建筑 楼层/区域 getBuildingSitePlan(item) { - let params = { buildingId: item.id } - let fireData = this.getFireElements(item.buildingTypes[0].id || '') //获取建筑下 消防要素 - let planData = this.getBuildingData(params) //获取 建筑 数据 - this.http.get('/api/BuildingAreas', { params }).subscribe(data => { - this.sitePlanData = data - this.selectingSitePlan = this.sitePlanData[0] || {} - this.canvasData.selectStorey = this.sitePlanData[0] || {} //服务中 存一份数据 - this.selectSitePlanIndex = 0 + let params = { buildingId: item.id }; + let fireData = this.getFireElements(item.buildingTypes[0].id || ""); //获取建筑下 消防要素 + let planData = this.getBuildingData(params); //获取 建筑 数据 + this.http.get("/api/BuildingAreas", { params }).subscribe((data) => { + this.sitePlanData = data; + this.selectingSitePlan = this.sitePlanData[0] || {}; + this.canvasData.selectStorey = this.sitePlanData[0] || {}; //服务中 存一份数据 + this.selectSitePlanIndex = 0; Promise.all([fireData, planData]).then((res) => { - this.getBuildingStorey(this.selectingSitePlan) //获取 建筑 楼层数据 - }) - - }) + this.getBuildingStorey(this.selectingSitePlan); //获取 建筑 楼层数据 + }); + }); } //根据单位类型获得所有的消防要素 getFireElements(e) { - let params = { ids: e } + let params = { ids: e }; return new Promise((resolve, reject) => { - this.http.get('/api/Companies/FireElements', { params }).subscribe((data: any) => { - this.allFireElements = data //所有消防要素 - let other = { - children: [], - computed: true, - id: '', - name: '其他', - order: 999, - parentId: null, - tag: "INPUT", - isLookPattern: true - } - this.allFireElements.push(other) - resolve('success') - }) - }) + this.http + .get("/api/Companies/FireElements", { params }) + .subscribe((data: any) => { + this.allFireElements = data; //所有消防要素 + let other = { + children: [], + computed: true, + id: "", + name: "其他", + order: 999, + parentId: null, + tag: "INPUT", + isLookPattern: true, + }; + this.allFireElements.push(other); + resolve("success"); + }); + }); } //获取 单位 数据 getSitePlanCompanyData() { return new Promise((resolve, reject) => { - this.http.get('/api/CompanyData', { params: this.params }).subscribe((data: any) => { - - this.canvasData.originalcompanyBuildingData = data || {} // 单位原数据 - this.canvasData.originalcompanyBuildingData.data ? this.canvasData.originalcompanyBuildingData.data = JSON.parse(this.canvasData.originalcompanyBuildingData.data) : this.canvasData.originalcompanyBuildingData.data = {} - this.canvasData.originalcompanyBuildingData.version ? null : this.canvasData.originalcompanyBuildingData.version = "2.0" - this.canvasData.originalcompanyBuildingData.companyId ? null : this.canvasData.originalcompanyBuildingData.companyId = sessionStorage.getItem('companyId') - resolve('success') - }) - }) + this.http + .get("/api/CompanyData", { params: this.params }) + .subscribe((data: any) => { + this.canvasData.originalcompanyBuildingData = data || {}; // 单位原数据 + this.canvasData.originalcompanyBuildingData.data + ? (this.canvasData.originalcompanyBuildingData.data = JSON.parse( + this.canvasData.originalcompanyBuildingData.data + )) + : (this.canvasData.originalcompanyBuildingData.data = {}); + this.canvasData.originalcompanyBuildingData.version + ? null + : (this.canvasData.originalcompanyBuildingData.version = "2.0"); + this.canvasData.originalcompanyBuildingData.companyId + ? null + : (this.canvasData.originalcompanyBuildingData.companyId = + sessionStorage.getItem("companyId")); + resolve("success"); + }); + }); } //获取 平面图 楼层数据 getSitePlanStorey(e) { - let params = { sitePlanId: e.id } + let params = { sitePlanId: e.id }; this.http.get(`/api/SitePlanData`, { params }).subscribe((data: any) => { - console.log(12345, data) - this.canvasData.originaleveryStoreyData = data || {} // 楼层原数据 - this.canvasData.originaleveryStoreyData.data ? this.canvasData.originaleveryStoreyData.data = JSON.parse(this.canvasData.originaleveryStoreyData.data) : this.canvasData.originaleveryStoreyData.data = {} - this.canvasData.originaleveryStoreyData.version ? null : this.canvasData.originaleveryStoreyData.version = "2.0" - this.canvasData.originaleveryStoreyData.sitePlanId ? null : this.canvasData.originaleveryStoreyData.sitePlanId = e.id || null - this.renovateTreeData() - this.canvas.onExaminerClickFloor_CreateTestpaper() - }) + console.log(12345, data); + this.canvasData.originaleveryStoreyData = data || {}; // 楼层原数据 + this.canvasData.originaleveryStoreyData.data + ? (this.canvasData.originaleveryStoreyData.data = JSON.parse( + this.canvasData.originaleveryStoreyData.data + )) + : (this.canvasData.originaleveryStoreyData.data = {}); + this.canvasData.originaleveryStoreyData.version + ? null + : (this.canvasData.originaleveryStoreyData.version = "2.0"); + this.canvasData.originaleveryStoreyData.sitePlanId + ? null + : (this.canvasData.originaleveryStoreyData.sitePlanId = e.id || null); + this.renovateTreeData(); + this.canvas.onExaminerClickFloor_CreateTestpaper(); + }); } //获取 建筑 数据 getBuildingData(e) { return new Promise((resolve, reject) => { - this.http.get(`/api/BuildingData`, { params: e }).subscribe((data: any) => { - this.canvasData.originalcompanyBuildingData = data || {} // 建筑原数据 - this.canvasData.originalcompanyBuildingData.data ? this.canvasData.originalcompanyBuildingData.data = JSON.parse(this.canvasData.originalcompanyBuildingData.data) : this.canvasData.originalcompanyBuildingData.data = {} - this.canvasData.originalcompanyBuildingData.version ? null : this.canvasData.originalcompanyBuildingData.version = "2.0" - this.canvasData.originalcompanyBuildingData.buildingId ? null : this.canvasData.originalcompanyBuildingData.buildingId = e.buildingId - resolve('success') - }) - }) + this.http + .get(`/api/BuildingData`, { params: e }) + .subscribe((data: any) => { + this.canvasData.originalcompanyBuildingData = data || {}; // 建筑原数据 + this.canvasData.originalcompanyBuildingData.data + ? (this.canvasData.originalcompanyBuildingData.data = JSON.parse( + this.canvasData.originalcompanyBuildingData.data + )) + : (this.canvasData.originalcompanyBuildingData.data = {}); + this.canvasData.originalcompanyBuildingData.version + ? null + : (this.canvasData.originalcompanyBuildingData.version = "2.0"); + this.canvasData.originalcompanyBuildingData.buildingId + ? null + : (this.canvasData.originalcompanyBuildingData.buildingId = + e.buildingId); + resolve("success"); + }); + }); } //获取 建筑 楼层数据 async getBuildingStorey(e) { - let params = { buildingAreaId: e.id } - this.http.get(`/api/BuildingAreaData`, { params }).subscribe((data: any) => { - this.canvasData.originaleveryStoreyData = data || {} // 楼层原数据 - this.canvasData.originaleveryStoreyData.data ? this.canvasData.originaleveryStoreyData.data = JSON.parse(this.canvasData.originaleveryStoreyData.data) : this.canvasData.originaleveryStoreyData.data = {} - this.canvasData.originaleveryStoreyData.version ? null : this.canvasData.originaleveryStoreyData.version = "2.0" - this.canvasData.originaleveryStoreyData.buildingAreaId ? null : this.canvasData.originaleveryStoreyData.buildingAreaId = e.id || null - this.renovateTreeData() - this.canvas.onExaminerClickFloor_CreateTestpaper() - }) + let params = { buildingAreaId: e.id }; + this.http + .get(`/api/BuildingAreaData`, { params }) + .subscribe((data: any) => { + this.canvasData.originaleveryStoreyData = data || {}; // 楼层原数据 + this.canvasData.originaleveryStoreyData.data + ? (this.canvasData.originaleveryStoreyData.data = JSON.parse( + this.canvasData.originaleveryStoreyData.data + )) + : (this.canvasData.originaleveryStoreyData.data = {}); + this.canvasData.originaleveryStoreyData.version + ? null + : (this.canvasData.originaleveryStoreyData.version = "2.0"); + this.canvasData.originaleveryStoreyData.buildingAreaId + ? null + : (this.canvasData.originaleveryStoreyData.buildingAreaId = + e.id || null); + this.renovateTreeData(); + this.canvas.onExaminerClickFloor_CreateTestpaper(); + }); } //点击选中 平面图 楼层/区域 时 selectSitePlan(item, index) { - if (this.selectSitePlanIndex != index) { this.canvasData.selectPanelPoint = new DisposalNodeData(); // if (this.canvasData.isChange) { //true 数据被改动 @@ -1289,33 +1534,37 @@ export class CollectionToolsComponent implements OnInit { // } else { //false 数据没被改动 // } //if - this.selectingSitePlan = item - this.selectSitePlanIndex = index - this.canvasData.selectStorey = item //服务中 存一份数据 - if (this.checkedBuildingIndex == -1) { //总平面图时 - this.getSitePlanStorey(item) //获取 平面图 楼层数据 - } else { //楼层/区域时 - this.getBuildingStorey(item) //获取 建筑 楼层数据 + this.selectingSitePlan = item; + this.selectSitePlanIndex = index; + this.canvasData.selectStorey = item; //服务中 存一份数据 + if (this.checkedBuildingIndex == -1) { + //总平面图时 + this.getSitePlanStorey(item); //获取 平面图 楼层数据 + } else { + //楼层/区域时 + this.getBuildingStorey(item); //获取 建筑 楼层数据 } } } //新增平面图 楼层/区域 foundPanel(e) { - e.stopPropagation() + e.stopPropagation(); let data = { isBuilding: this.checkedBuildingIndex == -1 ? false : true, Panel: this.beforeOneCheckedBuilding, - order: this.sitePlanData.length ? this.sitePlanData[this.sitePlanData.length - 1].order + 1 : 0, - } + order: this.sitePlanData.length + ? this.sitePlanData[this.sitePlanData.length - 1].order + 1 + : 0, + }; let dialogRef = this.dialog.open(leftFunctionalDomainComponent, { data }); - dialogRef.afterClosed().subscribe(data => { - if (data == '总平面图') { - this.renovateSitePlan() - } else if (data == '建筑') { - this.renovateBuilding() + dialogRef.afterClosed().subscribe((data) => { + if (data == "总平面图") { + this.renovateSitePlan(); + } else if (data == "建筑") { + this.renovateBuilding(); } - }) + }); } //编辑平面图 楼层/区域 @@ -1324,115 +1573,174 @@ export class CollectionToolsComponent implements OnInit { isBuilding: this.checkedBuildingIndex == -1 ? false : true, Panel: this.beforeOneCheckedBuilding, buildingData: e, - } + }; let dialogRef = this.dialog.open(editPlaneFigureComponent, { data }); - dialogRef.afterClosed().subscribe(data => { - if (data == '总平面图') { - this.renovateSitePlan() - } else if (data == '建筑') { - this.renovateBuilding() + dialogRef.afterClosed().subscribe((data) => { + if (data == "总平面图") { + this.renovateSitePlan(); + } else if (data == "建筑") { + this.renovateBuilding(); } - }) + }); } //平面图 楼层/区域 上移 moveUp(item, index) { if (index != 0) { - let replaceIndex = this.sitePlanData[index].order - this.sitePlanData[index].order = this.sitePlanData[index - 1].order - this.sitePlanData[index - 1].order = replaceIndex - if (this.checkedBuildingIndex == -1) { //总平面图 - this.http.put(`/api/SitePlans/${this.sitePlanData[index - 1].id}`, this.sitePlanData[index - 1]).subscribe(data => { - this.http.put(`/api/SitePlans/${this.sitePlanData[index].id}`, this.sitePlanData[index]).subscribe(data => { - this.selectSitePlanIndex = this.selectSitePlanIndex - 1 - this.renovateSitePlan() - }) - }) - } else { //楼层/区域 - this.http.put(`/api/BuildingAreas/${this.sitePlanData[index - 1].id}`, this.sitePlanData[index - 1], { params: this.params }).subscribe(data => { - this.http.put(`/api/BuildingAreas/${this.sitePlanData[index].id}`, this.sitePlanData[index], { params: this.params }).subscribe(data => { - this.selectSitePlanIndex = this.selectSitePlanIndex - 1 - this.renovateBuilding() - }) - }) + let replaceIndex = this.sitePlanData[index].order; + this.sitePlanData[index].order = this.sitePlanData[index - 1].order; + this.sitePlanData[index - 1].order = replaceIndex; + if (this.checkedBuildingIndex == -1) { + //总平面图 + this.http + .put( + `/api/SitePlans/${this.sitePlanData[index - 1].id}`, + this.sitePlanData[index - 1] + ) + .subscribe((data) => { + this.http + .put( + `/api/SitePlans/${this.sitePlanData[index].id}`, + this.sitePlanData[index] + ) + .subscribe((data) => { + this.selectSitePlanIndex = this.selectSitePlanIndex - 1; + this.renovateSitePlan(); + }); + }); + } else { + //楼层/区域 + this.http + .put( + `/api/BuildingAreas/${this.sitePlanData[index - 1].id}`, + this.sitePlanData[index - 1], + { params: this.params } + ) + .subscribe((data) => { + this.http + .put( + `/api/BuildingAreas/${this.sitePlanData[index].id}`, + this.sitePlanData[index], + { params: this.params } + ) + .subscribe((data) => { + this.selectSitePlanIndex = this.selectSitePlanIndex - 1; + this.renovateBuilding(); + }); + }); } - } //if index } //平面图 楼层/区域 下移 moveDown(item, index) { if (index != this.sitePlanData.length - 1) { - let replaceIndex = this.sitePlanData[index].order - this.sitePlanData[index].order = this.sitePlanData[index + 1].order - this.sitePlanData[index + 1].order = replaceIndex - if (this.checkedBuildingIndex == -1) { //总平面图 - this.http.put(`/api/SitePlans/${this.sitePlanData[index + 1].id}`, this.sitePlanData[index + 1]).subscribe(data => { - this.http.put(`/api/SitePlans/${this.sitePlanData[index].id}`, this.sitePlanData[index]).subscribe(data => { - this.selectSitePlanIndex = this.selectSitePlanIndex + 1 - this.renovateSitePlan() - }) - }) - } else { //楼层/区域 - this.http.put(`/api/BuildingAreas/${this.sitePlanData[index + 1].id}`, this.sitePlanData[index + 1], { params: this.params }).subscribe(data => { - this.http.put(`/api/BuildingAreas/${this.sitePlanData[index].id}`, this.sitePlanData[index], { params: this.params }).subscribe(data => { - this.selectSitePlanIndex = this.selectSitePlanIndex + 1 - this.renovateBuilding() - }) - }) + let replaceIndex = this.sitePlanData[index].order; + this.sitePlanData[index].order = this.sitePlanData[index + 1].order; + this.sitePlanData[index + 1].order = replaceIndex; + if (this.checkedBuildingIndex == -1) { + //总平面图 + this.http + .put( + `/api/SitePlans/${this.sitePlanData[index + 1].id}`, + this.sitePlanData[index + 1] + ) + .subscribe((data) => { + this.http + .put( + `/api/SitePlans/${this.sitePlanData[index].id}`, + this.sitePlanData[index] + ) + .subscribe((data) => { + this.selectSitePlanIndex = this.selectSitePlanIndex + 1; + this.renovateSitePlan(); + }); + }); + } else { + //楼层/区域 + this.http + .put( + `/api/BuildingAreas/${this.sitePlanData[index + 1].id}`, + this.sitePlanData[index + 1], + { params: this.params } + ) + .subscribe((data) => { + this.http + .put( + `/api/BuildingAreas/${this.sitePlanData[index].id}`, + this.sitePlanData[index], + { params: this.params } + ) + .subscribe((data) => { + this.selectSitePlanIndex = this.selectSitePlanIndex + 1; + this.renovateBuilding(); + }); + }); } - } //if index } //旋转底图 revolveImg(item) { - item.imageAngle == 270 ? item.imageAngle = 0 : item.imageAngle = item.imageAngle + 90 - if (this.checkedBuildingIndex == -1) { //总平面图 - this.http.put(`/api/SitePlans/${item.id}`, item).subscribe(data => { - let isSuccess = this.renovateSitePlan() - isSuccess.then(res => { - this.canvas.refreshBackgroundImage() - }) - }) - } else { //楼层/区域 - this.http.put(`/api/BuildingAreas/${item.id}`, item, { params: this.params }).subscribe(data => { - let isSuccess = this.renovateBuilding() - isSuccess.then(res => { - this.canvas.refreshBackgroundImage() - }) - }) + item.imageAngle == 270 + ? (item.imageAngle = 0) + : (item.imageAngle = item.imageAngle + 90); + if (this.checkedBuildingIndex == -1) { + //总平面图 + this.http.put(`/api/SitePlans/${item.id}`, item).subscribe((data) => { + let isSuccess = this.renovateSitePlan(); + isSuccess.then((res) => { + this.canvas.refreshBackgroundImage(); + }); + }); + } else { + //楼层/区域 + this.http + .put(`/api/BuildingAreas/${item.id}`, item, { params: this.params }) + .subscribe((data) => { + let isSuccess = this.renovateBuilding(); + isSuccess.then((res) => { + this.canvas.refreshBackgroundImage(); + }); + }); } - } //删除 平面图 楼层/区域 deletePlaneData(item) { - const isDelete = confirm('您确定要删除吗'); + const isDelete = confirm("您确定要删除吗"); if (isDelete) { - if (this.checkedBuildingIndex == -1) { //总平面图 - let isHave = this.canvasData.allDisposalNode.find(items => { return items.sitePlanId === item.id }) + if (this.checkedBuildingIndex == -1) { + //总平面图 + let isHave = this.canvasData.allDisposalNode.find((items) => { + return items.sitePlanId === item.id; + }); if (isHave == undefined) { - this.http.delete(`/api/SitePlans/${item.id}`).subscribe(data => { - this.deleteShareData(item, -1) - }) + this.http.delete(`/api/SitePlans/${item.id}`).subscribe((data) => { + this.deleteShareData(item, -1); + }); } else { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('含有数据节点的楼层不允许删除', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("含有数据节点的楼层不允许删除", "确定", config); } - } else { //楼层/区域 - let isHave = this.canvasData.allDisposalNode.find(items => { return items.buildingAreaId === item.id }) + } else { + //楼层/区域 + let isHave = this.canvasData.allDisposalNode.find((items) => { + return items.buildingAreaId === item.id; + }); if (isHave == undefined) { - this.http.delete(`/api/BuildingAreas/${item.id}`).subscribe(data => { - this.deleteShareData(item, 1) - }) + this.http + .delete(`/api/BuildingAreas/${item.id}`) + .subscribe((data) => { + this.deleteShareData(item, 1); + }); } else { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('含有数据节点的楼层不允许删除', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("含有数据节点的楼层不允许删除", "确定", config); } } } @@ -1442,154 +1750,195 @@ export class CollectionToolsComponent implements OnInit { deleteShareData(e, isCompany) { this.sitePlanData.forEach((element, index) => { if (element.id === e.id) { - this.sitePlanData.splice(index, 1) - return + this.sitePlanData.splice(index, 1); + return; } }); let data = this.canvasData.originalcompanyBuildingData; for (let key in data.data) { - if (data.data[key].FloorId === e.id) { //处理 单位/建筑 数据是否归于当前楼层下 - delete data.data[key] + if (data.data[key].FloorId === e.id) { + //处理 单位/建筑 数据是否归于当前楼层下 + delete data.data[key]; } } - let newData = JSON.parse(JSON.stringify(this.canvasData.originalcompanyBuildingData)); - newData.data = JSON.stringify(newData.data) // 转换JSON 数据格式 - this.selectingSitePlan = this.sitePlanData[0] || {} - this.canvasData.selectStorey = this.sitePlanData[0] || {} //服务中 存一份数据 - this.selectSitePlanIndex = 0 - this.canvasData.isChange = false + let newData = JSON.parse( + JSON.stringify(this.canvasData.originalcompanyBuildingData) + ); + newData.data = JSON.stringify(newData.data); // 转换JSON 数据格式 + this.selectingSitePlan = this.sitePlanData[0] || {}; + this.canvasData.selectStorey = this.sitePlanData[0] || {}; //服务中 存一份数据 + this.selectSitePlanIndex = 0; + this.canvasData.isChange = false; if (isCompany === -1) { - this.http.post("/api/CompanyData", newData).subscribe(data => { }) - this.getSitePlanStorey(this.selectingSitePlan) //获取 平面图 楼层数据 + this.http.post("/api/CompanyData", newData).subscribe((data) => {}); + this.getSitePlanStorey(this.selectingSitePlan); //获取 平面图 楼层数据 } else { - this.http.post("/api/BuildingData", newData, { params: this.params }).subscribe(data => { }) - this.getBuildingStorey(this.selectingSitePlan) //获取 建筑 楼层数据 + this.http + .post("/api/BuildingData", newData, { params: this.params }) + .subscribe((data) => {}); + this.getBuildingStorey(this.selectingSitePlan); //获取 建筑 楼层数据 } } //复制图层 平面图 楼层/区域 duplicateLayer(item) { - if (this.checkedBuildingIndex == -1) { //总平面图 - item.id = "" - item.modifiedTime = new Date() - item.name = item.name + '(副本)' - item.order = this.sitePlanData[this.sitePlanData.length - 1].order + 1 - this.http.post('/api/SitePlans', item).subscribe((data: any) => { + if (this.checkedBuildingIndex == -1) { + //总平面图 + item.id = ""; + item.modifiedTime = new Date(); + item.name = item.name + "(副本)"; + item.order = this.sitePlanData[this.sitePlanData.length - 1].order + 1; + this.http.post("/api/SitePlans", item).subscribe((data: any) => { let newData = { version: this.canvasData.originaleveryStoreyData.version || "2.0", id: "", - data: JSON.stringify(JSON.parse(JSON.stringify(this.canvasData.originaleveryStoreyData.data))) || null, - sitePlanId: data.id - } - this.http.post('/api/SitePlanData', newData, { params: this.params }).subscribe(data => { - this.renovateSitePlan() - }) - - }) - } else { //楼层/区域 - item.id = "" - item.modifiedTime = new Date() - item.name = item.name + '(副本)' - item.order = this.sitePlanData[this.sitePlanData.length - 1].order + 1 - this.http.post('/api/BuildingAreas', item, { params: this.params }).subscribe((data: any) => { - let newData = { - version: this.canvasData.originaleveryStoreyData.version || "2.0", - id: "", - data: JSON.stringify(JSON.parse(JSON.stringify(this.canvasData.originaleveryStoreyData.data))) || null, - buildingAreaId: data.id - } - this.http.post('/api/BuildingAreaData', newData, { params: this.params }).subscribe(data => { - this.renovateBuilding() - }) - - }) + data: + JSON.stringify( + JSON.parse( + JSON.stringify(this.canvasData.originaleveryStoreyData.data) + ) + ) || null, + sitePlanId: data.id, + }; + this.http + .post("/api/SitePlanData", newData, { params: this.params }) + .subscribe((data) => { + this.renovateSitePlan(); + }); + }); + } else { + //楼层/区域 + item.id = ""; + item.modifiedTime = new Date(); + item.name = item.name + "(副本)"; + item.order = this.sitePlanData[this.sitePlanData.length - 1].order + 1; + this.http + .post("/api/BuildingAreas", item, { params: this.params }) + .subscribe((data: any) => { + let newData = { + version: this.canvasData.originaleveryStoreyData.version || "2.0", + id: "", + data: + JSON.stringify( + JSON.parse( + JSON.stringify(this.canvasData.originaleveryStoreyData.data) + ) + ) || null, + buildingAreaId: data.id, + }; + this.http + .post("/api/BuildingAreaData", newData, { params: this.params }) + .subscribe((data) => { + this.renovateBuilding(); + }); + }); } } //平面图 楼层/区域 替换底图 replaceBaseMap(e, item) { e.stopPropagation(); - let file = e.target.files[0] || null //获取上传的文件 - let fileSize = file.size || null //上传文件的总大小 - let maxSize = 5 * 1024 * 1024 //5MB一个分片 - - if (file && fileSize <= maxSize) { //上传文件<=5MB时 - let formData = new FormData() - formData.append("file", file) - this.http.post(`/api/Objects/WebPlan2D/${sessionStorage.getItem('companyId')}`, formData).subscribe((data: any) => { - this.renovateBaseMap(data.objectName, item) - }) + let file = e.target.files[0] || null; //获取上传的文件 + let fileSize = file.size || null; //上传文件的总大小 + let maxSize = 5 * 1024 * 1024; //5MB一个分片 + + if (file && fileSize <= maxSize) { + //上传文件<=5MB时 + let formData = new FormData(); + formData.append("file", file); + this.http + .post( + `/api/Objects/WebPlan2D/${sessionStorage.getItem("companyId")}`, + formData + ) + .subscribe((data: any) => { + this.renovateBaseMap(data.objectName, item); + }); } else { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('上传底图需小于5MB', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("上传底图需小于5MB", "确定", config); } } //封装 替换底图 function renovateBaseMap(e, item) { - item.imageUrl = '/api/Objects/WebPlan2D/' + e - if (this.checkedBuildingIndex == -1) { //总平面图 - this.http.put(`/api/SitePlans/${item.id}`, item).subscribe(data => { - let isSuccess = this.renovateSitePlan() - isSuccess.then(res => { - this.canvas.refreshBackgroundImage() - }) - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('上传底图成功', '确定', config); - }) - } else { //楼层/区域 - this.http.put(`/api/BuildingAreas/${item.id}`, item, { params: this.params }).subscribe(data => { - let isSuccess = this.renovateBuilding() - isSuccess.then(res => { - this.canvas.refreshBackgroundImage() - }) + item.imageUrl = "/api/Objects/WebPlan2D/" + e; + if (this.checkedBuildingIndex == -1) { + //总平面图 + this.http.put(`/api/SitePlans/${item.id}`, item).subscribe((data) => { + let isSuccess = this.renovateSitePlan(); + isSuccess.then((res) => { + this.canvas.refreshBackgroundImage(); + }); const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('上传底图成功', '确定', config); - }) + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("上传底图成功", "确定", config); + }); + } else { + //楼层/区域 + this.http + .put(`/api/BuildingAreas/${item.id}`, item, { params: this.params }) + .subscribe((data) => { + let isSuccess = this.renovateBuilding(); + isSuccess.then((res) => { + this.canvas.refreshBackgroundImage(); + }); + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("上传底图成功", "确定", config); + }); } } //封装 刷新总平面图 数据 renovateSitePlan() { return new Promise((resolve, reject) => { - this.http.get('/api/SitePlans', { params: this.params }).subscribe(data => { - this.sitePlanData = data - this.selectingSitePlan = this.sitePlanData[this.selectSitePlanIndex] - this.canvasData.selectStorey = this.sitePlanData[this.selectSitePlanIndex] //服务中 存一份数据 - this.canvasData.originaleveryStoreyData.sitePlanId ? null : this.canvasData.originaleveryStoreyData.sitePlanId = this.selectingSitePlan.id || null - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('数据更新成功', '确定', config); - resolve('success') - }) - }) + this.http + .get("/api/SitePlans", { params: this.params }) + .subscribe((data) => { + this.sitePlanData = data; + this.selectingSitePlan = this.sitePlanData[this.selectSitePlanIndex]; + this.canvasData.selectStorey = + this.sitePlanData[this.selectSitePlanIndex]; //服务中 存一份数据 + this.canvasData.originaleveryStoreyData.sitePlanId + ? null + : (this.canvasData.originaleveryStoreyData.sitePlanId = + this.selectingSitePlan.id || null); + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("数据更新成功", "确定", config); + resolve("success"); + }); + }); } //封装 刷新 楼层/区域 数据 renovateBuilding() { let params = { - buildingId: this.beforeOneCheckedBuilding.id - } + buildingId: this.beforeOneCheckedBuilding.id, + }; return new Promise((resolve, reject) => { - this.http.get('/api/BuildingAreas', { params }).subscribe(data => { - this.sitePlanData = data - this.selectingSitePlan = this.sitePlanData[this.selectSitePlanIndex] - this.canvasData.selectStorey = this.sitePlanData[this.selectSitePlanIndex] //服务中 存一份数据 - this.canvasData.originaleveryStoreyData.buildingAreaId ? null : this.canvasData.originaleveryStoreyData.buildingAreaId = this.selectingSitePlan.id || null + this.http.get("/api/BuildingAreas", { params }).subscribe((data) => { + this.sitePlanData = data; + this.selectingSitePlan = this.sitePlanData[this.selectSitePlanIndex]; + this.canvasData.selectStorey = + this.sitePlanData[this.selectSitePlanIndex]; //服务中 存一份数据 + this.canvasData.originaleveryStoreyData.buildingAreaId + ? null + : (this.canvasData.originaleveryStoreyData.buildingAreaId = + this.selectingSitePlan.id || null); const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('数据更新成功', '确定', config); - resolve('success') - }) - }) + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("数据更新成功", "确定", config); + resolve("success"); + }); + }); } allLibrary: any = []; //所有素材库 + 素材 @@ -1598,189 +1947,233 @@ export class CollectionToolsComponent implements OnInit { selectImageIndex: number; //选中的素材库图片index //获取素材库 - getAllLibrary(type: string = 'input') { + getAllLibrary(type: string = "input") { this.http.get(`/api/AssetLibraries?tag=${type}`).subscribe((data: any) => { - data.forEach(element => { - element.images = [] + data.forEach((element) => { + element.images = []; }); - this.allLibrary = data - this.selectImageIndex = -1 + this.allLibrary = data; + this.selectImageIndex = -1; // this.canvas.cancelPaint() - }) + }); } //素材库展开面板展开时 opened(e) { - if (!e.images.length) { //当前素材库没加载素材时 + if (!e.images.length) { + //当前素材库没加载素材时 this.http.get(`/api/Assets?libraryId=${e.id}`).subscribe((data: any) => { - e.images = data - }) + e.images = data; + }); } } //点击选中素材库图片时 selectImg(item, items, index) { - this.selectLibrary = item.name - this.selectImage = items - this.selectImageIndex = index - this.canvasData.selectTemplateData = items - this.canvas.beginPaint() + this.selectLibrary = item.name; + this.selectImage = items; + this.selectImageIndex = index; + this.canvasData.selectTemplateData = items; + this.canvas.beginPaint(); } - - //处置预案 - examType = this.route.snapshot.queryParams.openType // 预案类型 1=已存在/2=自定义 + examType = this.route.snapshot.queryParams.openType; // 预案类型 1=已存在/2=自定义 allFirePlan: any = []; //所有灾情 - selectDisposalNode: string = ''; //当前点击tree节点 css选中样式 + selectDisposalNode: string = ""; //当前点击tree节点 css选中样式 //获取所有灾情 getAllFirePlan() { - let api - this.examType == 1 ? api = '/api/Disasters' : api = '/api/ExamDisasters' - let params = { componentId: sessionStorage.getItem('planId') } + let api; + this.examType == 1 + ? (api = "/api/Disasters") + : (api = "/api/ExamDisasters"); + let params = { componentId: sessionStorage.getItem("planId") }; this.http.get(api, { params: params }).subscribe((data: any) => { - if (!data.length) { //该 单位没有灾情时 + if (!data.length) { + //该 单位没有灾情时 let msg = { - name: '灾情', + name: "灾情", modifiedTime: new Date(), - examPlanComponentId: sessionStorage.getItem('planId') - } - this.http.post('/api/ExamDisasters', msg).subscribe(data => { - this.allFirePlan.push(data) - this.getDisposalNode() - }) - } else { //单位 有灾情时 - this.allFirePlan = data - this.getDisposalNode() + examPlanComponentId: sessionStorage.getItem("planId"), + }; + this.http.post("/api/ExamDisasters", msg).subscribe((data) => { + this.allFirePlan.push(data); + this.getDisposalNode(); + }); + } else { + //单位 有灾情时 + this.allFirePlan = data; + this.getDisposalNode(); } - }) + }); } //获取所有处置节点 getDisposalNode() { - let api - this.examType == 1 ? api = '/api/DisposalNodes' : api = '/api/ExamDisposalNodes' - this.selectDisposalNode = '' - let params - this.examType == 1 ? params = { disasterId: this.allFirePlan[0].id || '' } : params = { examDisasterId: this.allFirePlan[0].id || '' } - this.http.get(api, { params: params }).subscribe(data => { //处置节点 - this.canvasData.allDisposalNode = data - this.handleHybridTree() - }) + let api; + this.examType == 1 + ? (api = "/api/DisposalNodes") + : (api = "/api/ExamDisposalNodes"); + this.selectDisposalNode = ""; + let params; + this.examType == 1 + ? (params = { disasterId: this.allFirePlan[0].id || "" }) + : (params = { examDisasterId: this.allFirePlan[0].id || "" }); + this.http.get(api, { params: params }).subscribe((data) => { + //处置节点 + this.canvasData.allDisposalNode = data; + this.handleHybridTree(); + }); } treeData: any = []; //渲染tree处理完成数据 defaultExpandedKeys: any = []; //首次渲染 tree展开状态 //处理 节点 Tree数据 handleHybridTree() { - this.defaultExpandedKeys = [] - let treeData = [] - let data = JSON.parse(JSON.stringify(this.canvasData.allDisposalNode || [])) - data.forEach(element => { - this.defaultExpandedKeys.push(element.id) - element.title = element.name //name - element.key = element.id //id - element.children = [] //children - if (element.sitePlanId || element.buildingAreaId) { //是数据节点 - element.isLeaf = true - element.isDataNode = true - } else { //不是数据节点 - element.isLeaf = false - element.isDataNode = false + this.defaultExpandedKeys = []; + let treeData = []; + let data = JSON.parse( + JSON.stringify(this.canvasData.allDisposalNode || []) + ); + data.forEach((element) => { + console.log("走这里了吗"); + this.defaultExpandedKeys.push(element.id); + element.title = element.name; //name + element.key = element.id; //id + element.children = []; //children + if (element.sitePlanId || element.buildingAreaId) { + //是数据节点 + element.isLeaf = true; + element.isDataNode = true; + } else { + //不是数据节点 + element.isLeaf = false; + element.isDataNode = false; } - data.forEach(item => { - item.parentId === element.id ? element.children.push(item) : null - }) + data.forEach((item) => { + item.parentId === element.id ? element.children.push(item) : null; + }); + }); + data.forEach((element) => { + !element.parentId ? treeData.push(element) : null; }); - data.forEach(element => { - !element.parentId ? treeData.push(element) : null - }) - this.treeData = [...treeData] - this.defaultExpandedKeys = [...this.defaultExpandedKeys] + this.treeData = [...treeData]; + this.defaultExpandedKeys = [...this.defaultExpandedKeys]; } //刷新 treeData 保存已展开节点 refurbishTreeData() { - let api - this.examType == 1 ? api = '/api/DisposalNodes' : api = '/api/ExamDisposalNodes' - this.defaultExpandedKeys = [] - let params - this.examType == 1 ? params = { disasterId: this.allFirePlan[0].id || '' } : params = { examDisasterId: this.allFirePlan[0].id || '' } - this.http.get(api, { params: params }).subscribe(nodeData => { //处置节点 - this.canvasData.allDisposalNode = nodeData - let oldTreeData = this.nzTreeComponent.getExpandedNodeList() - oldTreeData.forEach(item => { - this.defaultExpandedKeys.push(item.key) - }) - let treeData = [] - let data = JSON.parse(JSON.stringify(this.canvasData.allDisposalNode || [])) - data.forEach(element => { - element.title = element.name //name - element.key = element.id //id - element.children = [] //children - if (element.sitePlanId || element.buildingAreaId) { //是数据节点 - element.isLeaf = true - element.isDataNode = true - } else { //不是数据节点 - element.isLeaf = false - element.isDataNode = false + let api; + this.examType == 1 + ? (api = "/api/DisposalNodes") + : (api = "/api/ExamDisposalNodes"); + this.defaultExpandedKeys = []; + let params; + this.examType == 1 + ? (params = { disasterId: this.allFirePlan[0].id || "" }) + : (params = { examDisasterId: this.allFirePlan[0].id || "" }); + this.http.get(api, { params: params }).subscribe((nodeData) => { + //处置节点 + this.canvasData.allDisposalNode = nodeData; + let oldTreeData = this.nzTreeComponent.getExpandedNodeList(); + oldTreeData.forEach((item) => { + this.defaultExpandedKeys.push(item.key); + }); + let treeData = []; + let data = JSON.parse( + JSON.stringify(this.canvasData.allDisposalNode || []) + ); + data.forEach((element) => { + element.title = element.name; //name + element.key = element.id; //id + element.children = []; //children + if (element.sitePlanId || element.buildingAreaId) { + //是数据节点 + element.isLeaf = true; + element.isDataNode = true; + } else { + //不是数据节点 + element.isLeaf = false; + element.isDataNode = false; } - data.forEach(item => { - item.parentId === element.id ? element.children.push(item) : null - }) + data.forEach((item) => { + item.parentId === element.id ? element.children.push(item) : null; + }); }); - data.forEach(element => { - !element.parentId ? treeData.push(element) : null - }) - this.treeData = [...treeData] - this.defaultExpandedKeys = [...this.defaultExpandedKeys] - }) + data.forEach((element) => { + !element.parentId ? treeData.push(element) : null; + }); + this.treeData = [...treeData]; + this.defaultExpandedKeys = [...this.defaultExpandedKeys]; + }); } - sitePlanIcon = { fire: 0, force: 0 } // 总平面图 火源/力量 图标 是否展示 + sitePlanIcon = { fire: 0, force: 0 }; // 总平面图 火源/力量 图标 是否展示 //刷新 建筑楼层 匹配 火源/力量 图标 mateFireForce() { - let data = this.canvasData.allNodeMarkers.markers || {} - for (let key in data) { //遍历 火/力量 图标 - this.sitePlanData.forEach(element => { //楼层 - if (element.id == key) { // 相匹配时 - data[key].fireCount != 0 ? element.fire = 1 : element.fire = 0 - data[key].forceCount != 0 ? element.force = 1 : element.force = 0 + let data = this.canvasData.allNodeMarkers.markers || {}; + for (let key in data) { + //遍历 火/力量 图标 + this.sitePlanData.forEach((element) => { + //楼层 + if (element.id == key) { + // 相匹配时 + data[key].fireCount != 0 ? (element.fire = 1) : (element.fire = 0); + data[key].forceCount != 0 ? (element.force = 1) : (element.force = 0); } }); - this.allBuildings.forEach(element => { //建筑 - if (element.id == key) { // 相匹配时 - data[key].fireCount != 0 ? element.fire = 1 : element.fire = 0 - data[key].forceCount != 0 ? element.force = 1 : element.force = 0 + this.allBuildings.forEach((element) => { + //建筑 + if (element.id == key) { + // 相匹配时 + data[key].fireCount != 0 ? (element.fire = 1) : (element.fire = 0); + data[key].forceCount != 0 ? (element.force = 1) : (element.force = 0); } }); - if (this.params.companyId == key) { //总平面图时 - data[key].fireCount != 0 ? this.sitePlanIcon.fire = 1 : this.sitePlanIcon.fire = 0 - data[key].forceCount != 0 ? this.sitePlanIcon.force = 1 : this.sitePlanIcon.force = 0 + if (this.params.companyId == key) { + //总平面图时 + data[key].fireCount != 0 + ? (this.sitePlanIcon.fire = 1) + : (this.sitePlanIcon.fire = 0); + data[key].forceCount != 0 + ? (this.sitePlanIcon.force = 1) + : (this.sitePlanIcon.force = 0); } } - let buildingMSG = this.canvasData.allNodeMarkers.highlightMarkers || {} + let buildingMSG = this.canvasData.allNodeMarkers.highlightMarkers || {}; for (let key in buildingMSG) { if (key === this.canvasData.selectPanelPoint.DisposalNodeId) { for (let keys in buildingMSG[key]) { - this.sitePlanData.forEach(element => { //楼层 + this.sitePlanData.forEach((element) => { + //楼层 if (element.id === keys) { - buildingMSG[key][keys].fireCount != 0 ? element.fire = 2 : null - buildingMSG[key][keys].forceCount != 0 ? element.force = 2 : null + buildingMSG[key][keys].fireCount != 0 ? (element.fire = 2) : null; + buildingMSG[key][keys].forceCount != 0 + ? (element.force = 2) + : null; } }); - this.allBuildings.forEach(element => { //建筑 - if (element.id === keys) { // 相匹配时 - buildingMSG[key][keys].fireCount != 0 ? element.fire = 2 : null - buildingMSG[key][keys].forceCount != 0 ? element.force = 2 : null + this.allBuildings.forEach((element) => { + //建筑 + if (element.id === keys) { + // 相匹配时 + buildingMSG[key][keys].fireCount != 0 ? (element.fire = 2) : null; + buildingMSG[key][keys].forceCount != 0 + ? (element.force = 2) + : null; } }); - if (this.params.companyId === keys) { //总平面图时 - buildingMSG[key][keys].fireCount != 0 ? this.sitePlanIcon.fire = 2 : null - buildingMSG[key][keys].forceCount != 0 ? this.sitePlanIcon.force = 2 : null + if (this.params.companyId === keys) { + //总平面图时 + buildingMSG[key][keys].fireCount != 0 + ? (this.sitePlanIcon.fire = 2) + : null; + buildingMSG[key][keys].forceCount != 0 + ? (this.sitePlanIcon.force = 2) + : null; } } } @@ -1789,217 +2182,268 @@ export class CollectionToolsComponent implements OnInit { // 切换 基本信息时 刷新 删除 建筑楼层 自定义属性 mateDeleteCustomize() { - this.defaultExpandedKeys = [] - this.sitePlanIcon = { fire: 0, force: 0 } - this.sitePlanData.forEach(element => { //楼层 - delete element.fire - delete element.force + this.defaultExpandedKeys = []; + this.sitePlanIcon = { fire: 0, force: 0 }; + this.sitePlanData.forEach((element) => { + //楼层 + delete element.fire; + delete element.force; }); - this.allBuildings.forEach(element => { //建筑 - delete element.fire - delete element.force + this.allBuildings.forEach((element) => { + //建筑 + delete element.fire; + delete element.force; }); } //选择 考试节点 countValue(e) { - e.stopPropagation() + e.stopPropagation(); if (this.canvasData.allDisposalNode.length) { - let data = { treeData: JSON.parse(JSON.stringify(this.treeData)), oldTreeData: JSON.parse(JSON.stringify(this.canvasData.allDisposalNode)) } + let data = { + treeData: JSON.parse(JSON.stringify(this.treeData)), + oldTreeData: JSON.parse( + JSON.stringify(this.canvasData.allDisposalNode) + ), + }; let dialogRef = this.dialog.open(uploadDisposalNodes, { data }); - dialogRef.afterClosed().subscribe(data => { + dialogRef.afterClosed().subscribe((data) => { if (data) { - sessionStorage.setItem('examNodeList', JSON.stringify(data)) + sessionStorage.setItem("examNodeList", JSON.stringify(data)); const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('节点保存成功', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("节点保存成功", "确定", config); } - }) + }); } else { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('暂无处置节点', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("暂无处置节点", "确定", config); } } //新建 处置预案 节点 addPanelPoint(e, item, treeData) { - e.stopPropagation() - let order + e.stopPropagation(); + let order; if (item) { - item.children.length ? order = item.children[item.children.length - 1].order + 1 : order = 0 + item.children.length + ? (order = item.children[item.children.length - 1].order + 1) + : (order = 0); } else { - treeData.length ? order = treeData[treeData.length - 1].order + 1 : order = 0 + treeData.length + ? (order = treeData[treeData.length - 1].order + 1) + : (order = 0); } let data = { - name: '', + name: "", level: item ? 1 : 0, order: order, - description: '', - disasterId: this.allFirePlan[0].id || '', + description: "", + disasterId: this.allFirePlan[0].id || "", parentId: item ? item.id : null, - planComponentId: sessionStorage.getItem('planId') || '', - } + planComponentId: sessionStorage.getItem("planId") || "", + }; let dialogRef = this.dialog.open(addDisposalNodeComponent, { data }); - dialogRef.afterClosed().subscribe(data => { - if (data) { this.refurbishTreeData() } - }) + dialogRef.afterClosed().subscribe((data) => { + if (data) { + this.refurbishTreeData(); + } + }); } //编辑 处置预案 节点 editPanelPoint(e, item) { - e.stopPropagation() - let data = item.origin + e.stopPropagation(); + let data = item.origin; let dialogRef = this.dialog.open(editDisposalNodeComponent, { data }); - dialogRef.afterClosed().subscribe(data => { + dialogRef.afterClosed().subscribe((data) => { if (data) { - item.title = data - this.canvasData.allDisposalNode.forEach(element => { element.id === item.key ? element.name = data : null }); + item.title = data; + this.canvasData.allDisposalNode.forEach((element) => { + element.id === item.key ? (element.name = data) : null; + }); } - }) + }); } //复制 处置预案 节点 copyPanelPoint(e, item, treeData) { - e.stopPropagation() + e.stopPropagation(); if (confirm(`确定要复制 ${item.title} ?`)) { - let params = { id: item.origin.id } - let order + let params = { id: item.origin.id }; + let order; if (item.level == 0) { - treeData.length ? order = treeData[treeData.length - 1].order + 1 : order = 0 + treeData.length + ? (order = treeData[treeData.length - 1].order + 1) + : (order = 0); } else { - let parent = item.getParentNode() //获取父节点 - parent.origin.children.length ? order = parent.origin.children[parent.origin.children.length - 1].order + 1 : order = 0 + let parent = item.getParentNode(); //获取父节点 + parent.origin.children.length + ? (order = + parent.origin.children[parent.origin.children.length - 1].order + + 1) + : (order = 0); } let data = { - name: item.title + '(副本)', + name: item.title + "(副本)", level: item.level, order: order, - description: '', - disasterId: item.origin.disasterId || '', + description: "", + disasterId: item.origin.disasterId || "", parentId: item.origin.parentId || null, - planComponentId: item.origin.planComponentId || '', - } - this.http.post('/api/DisposalNodes/Clone', data, { params: params }).subscribe(data => { - this.refurbishTreeData() - }) + planComponentId: item.origin.planComponentId || "", + }; + this.http + .post("/api/DisposalNodes/Clone", data, { params: params }) + .subscribe((data) => { + this.refurbishTreeData(); + }); } //isTrue } //删除 处置预案 节点 deletePanelPoint(e, item) { - e.stopPropagation() + e.stopPropagation(); if (confirm(`确定要删除 ${item.name} ?`)) { - this.http.delete(`/api/DisposalNodes/${item.id}`).subscribe(data => { - this.refurbishTreeData() - }) + this.http.delete(`/api/DisposalNodes/${item.id}`).subscribe((data) => { + this.refurbishTreeData(); + }); } } //点击 处置Tree节点 selectanelPoint(e) { - if (!e.buildingAreaId && !e.sitePlanId) { //当前节点 不是 数据节点 时 - let msg = this.canvasData.findDisposalNode(e.id) - this.canvasData.selectPanelPointBaseData = msg - this.selectDisposalNode == msg.id ? this.selectDisposalNode = '' : this.selectDisposalNode = msg.id //选中 节点 - - } else if (e.buildingAreaId || e.sitePlanId) { //当前节点 是 数据节点 时 - let msg = this.canvasData.findDisposalNode(e.parentId) - this.canvasData.selectPanelPointBaseData = msg - this.selectDisposalNode = e.parentId //选中 节点 - - if (this.canvasData.selectPanelPoint.DisposalNodeId != e.id) { //选择节点 不是当前节点时 - let api - this.examType == 1 ? api = '/api/DisposalNodeData' : api = '/api/ExamDisposalNodeData' - let params = { nodeId: e.id } - let parameter = { //查询 节点 对应 建筑/楼层 index,id - buildingIndex: e.sitePlanId ? -1 : this.allBuildings.findIndex(item => { return item.id === e.buildingId }), //总平面图/建筑 index + if (!e.buildingAreaId && !e.sitePlanId) { + //当前节点 不是 数据节点 时 + let msg = this.canvasData.findDisposalNode(e.id); + this.canvasData.selectPanelPointBaseData = msg; + this.selectDisposalNode == msg.id + ? (this.selectDisposalNode = "") + : (this.selectDisposalNode = msg.id); //选中 节点 + } else if (e.buildingAreaId || e.sitePlanId) { + //当前节点 是 数据节点 时 + let msg = this.canvasData.findDisposalNode(e.parentId); + this.canvasData.selectPanelPointBaseData = msg; + this.selectDisposalNode = e.parentId; //选中 节点 + + if (this.canvasData.selectPanelPoint.DisposalNodeId != e.id) { + //选择节点 不是当前节点时 + let api; + this.examType == 1 + ? (api = "/api/DisposalNodeData") + : (api = "/api/ExamDisposalNodeData"); + let params = { nodeId: e.id }; + let parameter = { + //查询 节点 对应 建筑/楼层 index,id + buildingIndex: e.sitePlanId + ? -1 + : this.allBuildings.findIndex((item) => { + return item.id === e.buildingId; + }), //总平面图/建筑 index storeyId: e.sitePlanId ? e.sitePlanId : e.buildingAreaId, //楼层id - } - this.http.get(api, { params: params }).subscribe(data => { - this.canvasData.selectPanelPoint = this.canvasData.deserialize(JSON.stringify(data || new DisposalNodeData())) //选择 当前 节点 - this.canvasData.selectPanelPoint.Data = this.canvasData.deserialize(this.canvasData.selectPanelPoint.Data) - this.seekPanelPoint(parameter) - }) + }; + this.http.get(api, { params: params }).subscribe((data) => { + this.canvasData.selectPanelPoint = this.canvasData.deserialize( + JSON.stringify(data || new DisposalNodeData()) + ); //选择 当前 节点 + this.canvasData.selectPanelPoint.Data = this.canvasData.deserialize( + this.canvasData.selectPanelPoint.Data + ); + this.seekPanelPoint(parameter); + }); } //if - } //else if } //查找 数据节点 对应 建筑/楼层 seekPanelPoint(paramsData) { - this.checkedBuildingIndex = paramsData.buildingIndex - if (paramsData.buildingIndex == -1) { //总平面图时 - this.beforeOneCheckedBuilding = { name: "总平面图" } - let fireData = this.getFireElements(sessionStorage.getItem('buildingTypeId')) //获取单位下 消防要素 - let planData = this.getSitePlanCompanyData() //获取 单位 数据 - this.http.get('/api/SitePlans', { params: this.params }).subscribe(data => { - this.sitePlanData = data - let index = this.sitePlanData.findIndex(item => { return item.id === paramsData.storeyId }) - this.selectingSitePlan = this.sitePlanData[index] || {} - this.canvasData.selectStorey = this.sitePlanData[index] || {} //服务中 存一份数据 - this.selectSitePlanIndex = index + this.checkedBuildingIndex = paramsData.buildingIndex; + if (paramsData.buildingIndex == -1) { + //总平面图时 + this.beforeOneCheckedBuilding = { name: "总平面图" }; + let fireData = this.getFireElements( + sessionStorage.getItem("buildingTypeId") + ); //获取单位下 消防要素 + let planData = this.getSitePlanCompanyData(); //获取 单位 数据 + this.http + .get("/api/SitePlans", { params: this.params }) + .subscribe((data) => { + this.sitePlanData = data; + let index = this.sitePlanData.findIndex((item) => { + return item.id === paramsData.storeyId; + }); + this.selectingSitePlan = this.sitePlanData[index] || {}; + this.canvasData.selectStorey = this.sitePlanData[index] || {}; //服务中 存一份数据 + this.selectSitePlanIndex = index; - Promise.all([fireData, planData]).then((res) => { - this.getSitePlanStorey(this.selectingSitePlan) //获取 平面图 楼层数据 - }) - }) //get - } else { //建筑时 - this.beforeOneCheckedBuilding = this.allBuildings[paramsData.buildingIndex] - let params = { buildingId: this.beforeOneCheckedBuilding.id } - let fireData = this.getFireElements(this.beforeOneCheckedBuilding.buildingTypes[0].id || '') //获取建筑下 消防要素 - let planData = this.getBuildingData(params) //获取 建筑 数据 - this.http.get('/api/BuildingAreas', { params }).subscribe(data => { - this.sitePlanData = data - let index = this.sitePlanData.findIndex(item => { return item.id === paramsData.storeyId }) - this.selectingSitePlan = this.sitePlanData[index] || {} - this.canvasData.selectStorey = this.sitePlanData[index] || {} //服务中 存一份数据 - this.selectSitePlanIndex = index + Promise.all([fireData, planData]).then((res) => { + this.getSitePlanStorey(this.selectingSitePlan); //获取 平面图 楼层数据 + }); + }); //get + } else { + //建筑时 + this.beforeOneCheckedBuilding = + this.allBuildings[paramsData.buildingIndex]; + let params = { buildingId: this.beforeOneCheckedBuilding.id }; + let fireData = this.getFireElements( + this.beforeOneCheckedBuilding.buildingTypes[0].id || "" + ); //获取建筑下 消防要素 + let planData = this.getBuildingData(params); //获取 建筑 数据 + this.http.get("/api/BuildingAreas", { params }).subscribe((data) => { + this.sitePlanData = data; + let index = this.sitePlanData.findIndex((item) => { + return item.id === paramsData.storeyId; + }); + this.selectingSitePlan = this.sitePlanData[index] || {}; + this.canvasData.selectStorey = this.sitePlanData[index] || {}; //服务中 存一份数据 + this.selectSitePlanIndex = index; Promise.all([fireData, planData]).then((res) => { - this.getBuildingStorey(this.selectingSitePlan) //获取 建筑 楼层数据 - }) - }) //get + this.getBuildingStorey(this.selectingSitePlan); //获取 建筑 楼层数据 + }); + }); //get } } - - - } - - //创建建筑 @Component({ - selector: 'app-createBuilding', - templateUrl: './createBuilding.html', - styleUrls: ['./collection-tools.component.scss'] + selector: "app-createBuilding", + templateUrl: "./createBuilding.html", + styleUrls: ["./collection-tools.component.scss"], }) export class CreateBuilding { - - constructor(private http: HttpClient, public dialog: MatDialog, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data) { } - - allBuildingType: any//所有的建筑类型 + constructor( + private http: HttpClient, + public dialog: MatDialog, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data + ) {} + + allBuildingType: any; //所有的建筑类型 selected: any; //选中的建筑 ngOnInit(): void { - this.getAllBuildingType() + this.getAllBuildingType(); } //获得所有单位类型 getAllBuildingType() { - this.http.get("/api/BuildingTypes/Simple").subscribe(data => { - this.allBuildingType = data - }) + this.http.get("/api/BuildingTypes/Simple").subscribe((data) => { + this.allBuildingType = data; + }); } //创建建筑功能分区 onSubmit(e) { - let companyId = sessionStorage.getItem("companyId") - let lastBuildingOrder = this.data.allBuildings.length != 0 ? this.data.allBuildings[this.data.allBuildings.length - 1].order + 1 : 0 - let data = - { + let companyId = sessionStorage.getItem("companyId"); + let lastBuildingOrder = + this.data.allBuildings.length != 0 + ? this.data.allBuildings[this.data.allBuildings.length - 1].order + 1 + : 0; + let data = { id: "", name: e.propertyName, order: lastBuildingOrder, @@ -2008,51 +2452,59 @@ export class CreateBuilding { buildingTypes: [ { id: e.buildingId, - name: "" + name: "", + }, + ], + }; + this.http + .post("/api/Buildings", data, { + params: { + companyId: this.data.companyId, + }, + }) + .subscribe( + (data) => { + this.dialogRef.close("创建成功"); + }, + (err) => { + this.dialogRef.close("创建失败"); } - ] - } - this.http.post("/api/Buildings", data, { - params: { - companyId: this.data.companyId - } - }).subscribe(data => { - this.dialogRef.close("创建成功"); - }, err => { - this.dialogRef.close("创建失败"); - }) + ); } } //编辑建筑 @Component({ - selector: 'app-editBuilding', - templateUrl: './editBuilding.html', - styleUrls: ['./collection-tools.component.scss'] + selector: "app-editBuilding", + templateUrl: "./editBuilding.html", + styleUrls: ["./collection-tools.component.scss"], }) export class EditBuilding { + constructor( + private http: HttpClient, + public dialog: MatDialog, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data + ) {} - constructor(private http: HttpClient, public dialog: MatDialog, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data) { } - - defaultName: String = this.data.item.name//默认建筑名称 - defaultBuildingType: String = this.data.item.buildingTypes[0].id//默认建筑类型 - allBuildingType: any//所有的建筑类型 + defaultName: String = this.data.item.name; //默认建筑名称 + defaultBuildingType: String = this.data.item.buildingTypes[0].id; //默认建筑类型 + allBuildingType: any; //所有的建筑类型 ngOnInit(): void { - this.getAllBuildingType() + this.getAllBuildingType(); } getAllBuildingType() { - this.http.get("/api/BuildingTypes/Simple").subscribe(data => { - this.allBuildingType = data - }) + this.http.get("/api/BuildingTypes/Simple").subscribe((data) => { + this.allBuildingType = data; + }); } //编辑建筑信息 onSubmit(e) { - let companyId = sessionStorage.getItem("companyId") - let data = - { + let companyId = sessionStorage.getItem("companyId"); + let data = { id: this.data.item.id, name: e.propertyName, order: this.data.item.order, @@ -2061,48 +2513,58 @@ export class EditBuilding { buildingTypes: [ { id: e.buildingId, - name: "" + name: "", + }, + ], + }; + this.http + .put(`/api/Buildings/${this.data.item.id}`, data, { + params: { + id: this.data.item.id, + companyId: companyId, + }, + }) + .subscribe( + (data) => { + this.dialogRef.close("修改成功"); + }, + (err) => { + this.dialogRef.close("修改失败"); } - ] - } - this.http.put(`/api/Buildings/${this.data.item.id}`, data, { - params: { - id: this.data.item.id, - companyId: companyId - } - }).subscribe(data => { - this.dialogRef.close("修改成功"); - }, err => { - this.dialogRef.close("修改失败"); - }) + ); } } //查看图片大图 @Component({ - selector: 'viewdetails', - templateUrl: './viewdetails.html', - styleUrls: ['./collection-tools.component.scss'] + selector: "viewdetails", + templateUrl: "./viewdetails.html", + styleUrls: ["./collection-tools.component.scss"], }) export class ViewDetailss { // myControl = new FormControl(); //注入MatDialogRef,可以用来关闭对话框 //要访问对话框组件中的数据,必须使用MAT_DIALOG_DATA注入令牌 - constructor(private http: HttpClient, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data, private element: ElementRef) { } - imagesArr = this.data.imagesArr + constructor( + private http: HttpClient, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data, + private element: ElementRef + ) {} + imagesArr = this.data.imagesArr; onNoClick(): void { this.dialogRef.close(); } ngOnInit(): void { setTimeout(() => { - var mySwiper = new Swiper('.swiper-container', { + var mySwiper = new Swiper(".swiper-container", { loop: false, - initialSlide: this.data.index,//默认索引 + initialSlide: this.data.index, //默认索引 // 如果需要前进后退按钮 navigation: { - nextEl: '.swiper-button-next', - prevEl: '.swiper-button-prev', - } + nextEl: ".swiper-button-next", + prevEl: ".swiper-button-prev", + }, //其他设置 }); }, 0); @@ -2110,18 +2572,17 @@ export class ViewDetailss { closeDialog() { this.dialogRef.close(); } - count = 10 + count = 10; zoomimg(e) { if (this.count != 1 || e.wheelDelta >= 120) { if (e.wheelDelta >= 120) { - this.count++ + this.count++; } else { - this.count-- + this.count--; } } - e.srcElement.style.zoom = this.count + '0%' - e.srcElement.style.maxWidth = null - e.srcElement.style.maxHeight = null + e.srcElement.style.zoom = this.count + "0%"; + e.srcElement.style.maxWidth = null; + e.srcElement.style.maxHeight = null; } - } diff --git a/src/app/ui/collection-tools/examinationQuestions.ts b/src/app/ui/collection-tools/examinationQuestions.ts index f9390cc..17c0ffc 100644 --- a/src/app/ui/collection-tools/examinationQuestions.ts +++ b/src/app/ui/collection-tools/examinationQuestions.ts @@ -1,217 +1,263 @@ -import { Component, OnInit, Inject, ViewChild } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; -import { CanvasShareDataService, DisposalNodeData } from '../../canvas-share-data.service' //引入服务 -import { FlatTreeControl } from '@angular/cdk/tree'; -import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree'; -import { NzFormatBeforeDropEvent, NzFormatEmitEvent, NzTreeComponent } from 'ng-zorro-antd/tree'; -import { ActivatedRoute } from '@angular/router'; +import { Component, OnInit, Inject, ViewChild } from "@angular/core"; +import { HttpClient, HttpHeaders } from "@angular/common/http"; +import { + MatDialog, + MatDialogRef, + MAT_DIALOG_DATA, +} from "@angular/material/dialog"; +import { MatSnackBar, MatSnackBarConfig } from "@angular/material/snack-bar"; +import { + CanvasShareDataService, + DisposalNodeData, +} from "../../canvas-share-data.service"; //引入服务 +import { FlatTreeControl } from "@angular/cdk/tree"; +import { + MatTreeFlatDataSource, + MatTreeFlattener, +} from "@angular/material/tree"; +import { + NzFormatBeforeDropEvent, + NzFormatEmitEvent, + NzTreeComponent, +} from "ng-zorro-antd/tree"; +import { ActivatedRoute } from "@angular/router"; @Component({ - selector: 'dialog-examination-questions', - templateUrl: './examinationQuestions.html', - styleUrls: ['./collection-tools.component.scss',] + selector: "dialog-examination-questions", + templateUrl: "./examinationQuestions.html", + styleUrls: ["./collection-tools.component.scss"], }) export class examinationQuestions { + constructor( + private http: HttpClient, + public dialog: MatDialog, + public snackBar: MatSnackBar, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data + ) {} - constructor(private http: HttpClient, public dialog: MatDialog, public snackBar: MatSnackBar, public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data) { } - - @ViewChild('nzTreeComponent3', { static: false }) nzTreeComponent!: NzTreeComponent; + @ViewChild("nzTreeComponent3", { static: false }) + nzTreeComponent!: NzTreeComponent; defaultCheckedKeys = []; //指定选中复选框的树节点 key值 defaultExpandedKeys = []; //展开指定的树节点 key值 defaultSelectedKeys = []; //指定选中的树节点 key值 - renderData: any + renderData: any; ngOnInit(): void { - this.renderData = this.data.treeData - if (JSON.parse(sessionStorage.getItem('tree型数据')) && JSON.parse(sessionStorage.getItem('tree型数据'))[this.data.buildFloorData.floorData.id]) { - this.defaultCheckedKeys = JSON.parse(sessionStorage.getItem('tree型数据'))[this.data.buildFloorData.floorData.id] + this.renderData = this.data.treeData; + if ( + JSON.parse(sessionStorage.getItem("tree型数据")) && + JSON.parse(sessionStorage.getItem("tree型数据"))[ + this.data.buildFloorData.floorData.id + ] + ) { + this.defaultCheckedKeys = JSON.parse( + sessionStorage.getItem("tree型数据") + )[this.data.buildFloorData.floorData.id]; } - this.data.treeData.forEach(element => { + this.data.treeData.forEach((element) => { if (element.isTemplate) { - element.isLeaf = false + element.isLeaf = false; } else { - element.isLeaf = true + element.isLeaf = true; } if (element.children && element.children.length != 0) { - element.children.forEach(ele => { + element.children.forEach((ele) => { if (ele.isTemplate) { - ele.isLeaf = false + ele.isLeaf = false; } else { - ele.isLeaf = true + ele.isLeaf = true; } if (ele.children && ele.children.length != 0) { - ele.children.forEach(item => { + ele.children.forEach((item) => { if (item.isTemplate) { - item.isLeaf = false + item.isLeaf = false; } else { - item.isLeaf = true + item.isLeaf = true; } - }); } - }) + }); } - }) + }); //阻止 滚轮滚动事件穿透 - window.setTimeout(()=>{ - (document.getElementById('nodeTree') as any).onmousewheel = (e)=>{ + window.setTimeout(() => { + (document.getElementById("nodeTree") as any).onmousewheel = (e) => { e.stopPropagation(); - } - }, 0) + }; + }, 0); } - nzEvent($event) { - console.log($event) + console.log($event); } - - //提交 submit() { + let oldTreeData = this.nzTreeComponent.getCheckedNodeList(); - let oldTreeData = this.nzTreeComponent.getCheckedNodeList() - - - // console.log(oldTreeData) - let alltreedata = JSON.parse(sessionStorage.getItem("tree型数据")) - let keyArr = [] - oldTreeData.forEach(element => { - keyArr.push(element.origin.key) - }) + let alltreedata = JSON.parse(sessionStorage.getItem("tree型数据")); + let keyArr = []; + oldTreeData.forEach((element) => { + keyArr.push(element.origin.key); + }); if (alltreedata) { //如果已经保存过当前楼层则替换 - alltreedata[this.data.buildFloorData.floorData.id] = keyArr - sessionStorage.setItem('tree型数据', JSON.stringify(alltreedata)) + alltreedata[this.data.buildFloorData.floorData.id] = keyArr; + sessionStorage.setItem("tree型数据", JSON.stringify(alltreedata)); } else { - alltreedata = {} - alltreedata[this.data.buildFloorData.floorData.id] = keyArr - sessionStorage.setItem('tree型数据', JSON.stringify(alltreedata)) + alltreedata = {}; + alltreedata[this.data.buildFloorData.floorData.id] = keyArr; + sessionStorage.setItem("tree型数据", JSON.stringify(alltreedata)); } - - let checkList = [] //只存真实素材 + let checkList = []; //只存真实素材 for (const key in this.data.oldRealData.data) { - let element = this.data.oldRealData.data[key] - let isChecked = (this.nzTreeComponent.getTreeNodeByKey(key)).isChecked - isChecked ? checkList.push(element) : null + let element = this.data.oldRealData.data[key]; + let isChecked = this.nzTreeComponent.getTreeNodeByKey(key).isChecked; + isChecked ? checkList.push(element) : null; } //存储真实素材数据 - let basicAssetsId = [] + let basicAssetsId = []; if (checkList && checkList.length != 0) { - checkList.forEach(item => { - basicAssetsId.push(item.TemplateId) - }) + checkList.forEach((item) => { + basicAssetsId.push(item.TemplateId); + }); } - basicAssetsId = Array.from(new Set(basicAssetsId)) - console.log(123, this.data.buildFloorData) + basicAssetsId = Array.from(new Set(basicAssetsId)); + console.log(123, this.data.buildFloorData); let obj = { - name: this.data.buildFloorData.buildingData.name + '-' + this.data.buildFloorData.floorData.name, + name: + this.data.buildFloorData.buildingData.name + + "-" + + this.data.buildFloorData.floorData.name, key: this.data.buildFloorData.floorData.id, buildingId: this.data.buildFloorData.buildingData.id, children: checkList, - basicAssetsId: basicAssetsId - } + basicAssetsId: basicAssetsId, + }; - let data = JSON.parse(sessionStorage.getItem("消防设施" + sessionStorage.getItem('paperId'))) + let data = JSON.parse( + sessionStorage.getItem("消防设施" + sessionStorage.getItem("paperId")) + ); if (data && data.length != 0) { - console.log(1) - let ind = null + console.log(1); + let ind = null; data.forEach((item, index) => { if (item.key == obj.key) { - ind = index + 1 + ind = index + 1; } - }) + }); if (ind) { if (checkList.length != 0) { - data[ind - 1].children = checkList + data[ind - 1].children = checkList; } else { - data.splice(ind - 1, 1) + data.splice(ind - 1, 1); } - } else { - data.push(obj) + data.push(obj); } - sessionStorage.setItem("消防设施" + sessionStorage.getItem('paperId'), JSON.stringify(data)) - + sessionStorage.setItem( + "消防设施" + sessionStorage.getItem("paperId"), + JSON.stringify(data) + ); } else { - console.log(2) - data = [] - data[0] = obj - sessionStorage.setItem("消防设施" + sessionStorage.getItem('paperId'), JSON.stringify(data)) + console.log(2); + data = []; + data[0] = obj; + sessionStorage.setItem( + "消防设施" + sessionStorage.getItem("paperId"), + JSON.stringify(data) + ); } - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('当层消防设施考题设置完成', '确定', config); - this.dialogRef.close() + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("当层消防设施考题设置完成", "确定", config); + this.dialogRef.close(); } - } - //上传按钮 @Component({ - selector: 'dialog-upload-questions', - templateUrl: './uploadQuestions.html', - styleUrls: ['./collection-tools.component.scss',] + selector: "dialog-upload-questions", + templateUrl: "./uploadQuestions.html", + styleUrls: ["./collection-tools.component.scss"], }) export class uploadQuestions { - - constructor(private http: HttpClient, public dialog: MatDialog, public snackBar: MatSnackBar, public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data, private route: ActivatedRoute) { } + constructor( + private http: HttpClient, + public dialog: MatDialog, + public snackBar: MatSnackBar, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data, + private route: ActivatedRoute + ) {} defaultCheckedKeys = []; //指定选中复选框的树节点 key值 defaultExpandedKeys = []; //展开指定的树节点 key值 defaultSelectedKeys = []; //指定选中的树节点 key值 - renderData: any + renderData: any; ngOnInit(): void { - let data = JSON.parse(sessionStorage.getItem("消防设施" + sessionStorage.getItem('paperId'))) - data ? data.forEach(item => { - let realData = item.children - let allFireElements = JSON.parse(JSON.stringify(this.data.allFireElements)) - item.children = this.processingData(allFireElements, realData) - }) : null - this.renderData = data - this.getProfiles() - this.nodeInit() + let data = JSON.parse( + sessionStorage.getItem("消防设施" + sessionStorage.getItem("paperId")) + ); + + console.log(888, data); + + data + ? data.forEach((item) => { + let realData = item.children; + let allFireElements = JSON.parse( + JSON.stringify(this.data.allFireElements) + ); + item.children = this.processingData(allFireElements, realData); + }) + : null; + this.renderData = data; + this.getProfiles(); + this.nodeInit(); - console.log('天气信息', this.data.weatherData) + console.log("天气信息", this.data.weatherData); } //处理数据 将消防要素模板与真实素材结合 processingData(allFireElements, realData) { - allFireElements[allFireElements.length - 1].children = [] - realData.forEach(item => { - item.isLeaf = true - let noMatch = allFireElements.find(every => every.id === item.FireElementId) + allFireElements[allFireElements.length - 1].children = []; + realData.forEach((item) => { + item.isLeaf = true; + let noMatch = allFireElements.find( + (every) => every.id === item.FireElementId + ); if (!noMatch) { - allFireElements[allFireElements.length - 1].children.push(item) + allFireElements[allFireElements.length - 1].children.push(item); } - }) - let treeData = [] //tree型 处理完成后的数据 - allFireElements.forEach(element => { - element.key = element.id - element.name != '其他' ? element.children = [] : null + }); + let treeData = []; //tree型 处理完成后的数据 + allFireElements.forEach((element) => { + element.key = element.id; + element.name != "其他" ? (element.children = []) : null; if (realData) { - realData.forEach(item => { + realData.forEach((item) => { if (element.id == item.FireElementId) { - element.children.push(item) + element.children.push(item); } - }) + }); } - allFireElements.forEach(item => { if (item.parentId == element.id) { element.children.push(item) } }); + allFireElements.forEach((item) => { + if (item.parentId == element.id) { + element.children.push(item); + } + }); }); - allFireElements.forEach(element => { - if (!element.parentId) { treeData.push(element) } + allFireElements.forEach((element) => { + if (!element.parentId) { + treeData.push(element); + } }); function recursionFilterEmpty(originalList, result) { for (let i = 0, length = originalList.length; i < length; i++) { @@ -228,7 +274,7 @@ export class uploadQuestions { item.children = newChildren; // 子项有真实的数据,就保留这一项 result.push(item); - } // 如果没有这一项就会被删除 + } // 如果没有这一项就会被删除 } } } @@ -237,53 +283,55 @@ export class uploadQuestions { recursionFilterEmpty(listData, result); return result; } - return filterEmpty(treeData) + return filterEmpty(treeData); } - //获取登录账号的个人资料 - Profiles: any + Profiles: any; getProfiles() { - this.http.get('/api/ExamAccounts/Profiles').subscribe(data => { - this.Profiles = data - }) + this.http.get("/api/ExamAccounts/Profiles").subscribe((data) => { + this.Profiles = data; + }); } nodeTreeData: any = []; //处置节点tree //节点初始化 nodeInit() { - let treeData = [] - this.data.node.forEach(element => { - element.title = element.name //name - element.key = element.id //id - element.children = [] //children - if (element.sitePlanId || element.buildingAreaId) { //是数据节点 - element.isLeaf = true - element.isDataNode = true - } else { //不是数据节点 - element.isLeaf = false - element.isDataNode = false + let treeData = []; + console.log(9999, this.data.node); + this.data.node.forEach((element) => { + element.title = element.name; //name + element.key = element.id; //id + element.children = []; //children + if (element.sitePlanId || element.buildingAreaId) { + //是数据节点 + element.isLeaf = true; + element.isDataNode = true; + } else { + //不是数据节点 + element.isLeaf = false; + element.isDataNode = false; } - this.data.node.forEach(item => { - item.parentId === element.id ? element.children.push(item) : null - }) + this.data.node.forEach((item) => { + item.parentId === element.id ? element.children.push(item) : null; + }); + }); + this.data.node.forEach((element) => { + !element.parentId ? treeData.push(element) : null; }); - this.data.node.forEach(element => { - !element.parentId ? treeData.push(element) : null - }) - this.nodeTreeData = [...treeData] + this.nodeTreeData = [...treeData]; } nzEvent($event) { - console.log($event) + console.log($event); } //上传 submit() { - console.log(this.data.question) + console.log(this.data.question); let body: any = { id: this.route.snapshot.queryParams.paperplanId, - paperId: sessionStorage.getItem('paperId'), - planComponentId: sessionStorage.getItem('planId'), + paperId: sessionStorage.getItem("paperId"), + planComponentId: sessionStorage.getItem("planId"), examPlanType: this.route.snapshot.queryParams.openType == 1 ? 0 : 1, creatorId: this.Profiles.id, modifiedTime: new Date(), @@ -291,70 +339,87 @@ export class uploadQuestions { title: this.route.snapshot.queryParams.planName, mainPoint: this.data.question.keynote, score: 0, - examFacilityAssetsData: sessionStorage.getItem('消防设施' + sessionStorage.getItem('paperId')) ? sessionStorage.getItem('消防设施' + sessionStorage.getItem('paperId')) : null, - examDisposalNodesData: sessionStorage.getItem('examNodeList') ? sessionStorage.getItem('examNodeList') : null, - companyId: sessionStorage.getItem('companyId'), - weather: JSON.stringify(this.data.weatherData) - } - - - this.http.put(`/api/PaperPlans/${this.route.snapshot.queryParams.paperplanId}`, body).subscribe(data => { - - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('设置完成,页面将于一秒后关闭', '确定', config); - setTimeout(() => { - window.close() - }, 1000); - - }) - - + examFacilityAssetsData: sessionStorage.getItem( + "消防设施" + sessionStorage.getItem("paperId") + ) + ? sessionStorage.getItem("消防设施" + sessionStorage.getItem("paperId")) + : null, + examDisposalNodesData: sessionStorage.getItem("examNodeList") + ? sessionStorage.getItem("examNodeList") + : null, + companyId: sessionStorage.getItem("companyId"), + weather: JSON.stringify(this.data.weatherData), + }; + + this.http + .put( + `/api/PaperPlans/${this.route.snapshot.queryParams.paperplanId}`, + body + ) + .subscribe( + (data) => { + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("设置完成,页面将于一秒后关闭", "确定", config); + setTimeout(() => { + window.close(); + }, 1000); + }, + (err) => { + const config = new MatSnackBarConfig(); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("保存失败", "确定", config); + } + ); } - } - - //保存考的节点 @Component({ - selector: 'dialog-disposal-nodes', - templateUrl: './uploadDisposalNodes.html', - styleUrls: ['./collection-tools.component.scss',] + selector: "dialog-disposal-nodes", + templateUrl: "./uploadDisposalNodes.html", + styleUrls: ["./collection-tools.component.scss"], }) export class uploadDisposalNodes { - - constructor(private http: HttpClient, public dialog: MatDialog, public snackBar: MatSnackBar, public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data) { } - @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; + constructor( + private http: HttpClient, + public dialog: MatDialog, + public snackBar: MatSnackBar, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data + ) {} + @ViewChild("nzTreeComponent", { static: false }) + nzTreeComponent!: NzTreeComponent; ngOnInit(): void { - this.treeData = [...this.data.treeData] + this.treeData = [...this.data.treeData]; } treeData: any = []; //tree //提交 保存考试节点 submit() { - let checkList = [] - this.data.oldTreeData.forEach(element => { - let isChecked = (this.nzTreeComponent.getTreeNodeByKey(element.id)).isChecked - isChecked ? checkList.push(element) : null + let checkList = []; + this.data.oldTreeData.forEach((element) => { + let isChecked = this.nzTreeComponent.getTreeNodeByKey( + element.id + ).isChecked; + isChecked ? checkList.push(element) : null; }); - let galfList = this.nzTreeComponent.getHalfCheckedNodeList() - this.data.oldTreeData.forEach(element => { - galfList.forEach(elements => { - element.id == elements.origin.id ? checkList.push(element) : null + let galfList = this.nzTreeComponent.getHalfCheckedNodeList(); + this.data.oldTreeData.forEach((element) => { + galfList.forEach((elements) => { + element.id == elements.origin.id ? checkList.push(element) : null; }); }); if (checkList.length) { this.dialogRef.close(checkList); } else { const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('请选择节点', '确定', config); + config.verticalPosition = "top"; + config.duration = 3000; + this.snackBar.open("请选择节点", "确定", config); } } - -} \ No newline at end of file +}