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 eb420da..ecd59ea 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 @@ -267,7 +267,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 6e95f16..d77722a 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 @@ -19,25 +19,23 @@ import { functions } from 'firebase'; }) export class CreateTestScoreComponent implements OnInit { - constructor(private router:Router,public dialog: MatDialog,private http: HttpClient,public snackBar: MatSnackBar,private route:ActivatedRoute) { } - selectedTab:number = 1 //选中的选项卡 - selectTab(index){ + 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 }, 0); - + } - pattern:any = this.route.snapshot.queryParams.pattern || '' + pattern: any = this.route.snapshot.queryParams.pattern || '' ngOnInit(): void { - - - - - if(this.route.snapshot.queryParams.pattern){ + if (this.route.snapshot.queryParams.status == 0) { + //已创建完成未开考 this.getSoloPaper() - }else{ - this.unitId = JSON.parse(sessionStorage.getItem(sessionStorage.getItem('paperId'))) - for (let y = 0, length = this.unitId.length; y < length; y++){ + } else { + console.log('this.unitId',this.unitId) + this.unitId = JSON.parse(sessionStorage.getItem(sessionStorage.getItem('paperId'))) + for (let y = 0, length = this.unitId.length; y < length; y++) { let element = this.unitId[y] element.score = 0 element.basicInfoScore = 0 @@ -56,219 +54,230 @@ export class CreateTestScoreComponent implements OnInit { element.fireFacItemScore = 0 element.fireFacNodes = [] } - - this.getUnitData().then(()=>{ - this.getAround().then(()=>{ - this.getKeySite().then(()=>{ - this.getFunDiv().then(()=>{ + + this.getUnitData().then(() => { + this.getAround().then(() => { + this.getKeySite().then(() => { + this.getFunDiv().then(() => { this.getFireFac() }) }) }) }) - this.getPaperPlans().then(()=>{ + this.getPaperPlans().then(() => { this.planItemScore() }) } + if (this.route.snapshot.queryParams.pattern) { + + } else { + + } + - } //获得指定试卷信息。 editdata - getSoloPaper(){ - this.http.get(`/api/Papers/${sessionStorage.getItem('paperId')}`).subscribe((data:any) => { - this.editdata=data - console.log('试卷信息',this.editdata) - data.paperDataInfo.forEach(item => { - this.unitId.push(JSON.parse(item.originalData)) - }) - // console.log('试卷信息',this.unitId) - this.planItemScore() + 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 => { + this.unitId.push(JSON.parse(item.originalData)) + }) + // console.log('试卷信息',this.unitId) + this.planItemScore() + } else { + } + }) } //获取所有考试设定 - async getPaperPlans(){ + async getPaperPlans() { - for (let y = 0, length = this.unitId.length; y < length; y++){ + for (let y = 0, length = this.unitId.length; y < length; 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) + 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) }) }) - + } - + } //当前选中的单位 selectedUnitIndex = 0 - clickUnitName(key){ + clickUnitName(key) { this.selectedUnitIndex = key } - unitId:any = [] + unitId: any = [] //获取单位基本信息 - async getUnitData(){ + async getUnitData() { let that = this - for (let y = 0, length = this.unitId.length; y < length; y++){ + for (let y = 0, length = this.unitId.length; y < length; y++) { let element = this.unitId[y] - + let result1 = await new Promise((resolve, reject) => { - this.http.get(`/api/Companies/${element.id}`).subscribe((data:any)=>{ + this.http.get(`/api/Companies/${element.id}`).subscribe((data: any) => { let unitData = { name: '单位信息', - type:'基本信息', + type: '基本信息', expanded: true, - key:(Math.random()*10000000).toString(16).substr(0,4)+(new Date()).getTime()+Math.random().toString().substr(2,5), - children:[] + 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 + 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 + 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 + name: '联系人', key: element.id + '联系人', isLeaf: true, value: data.contacts }) : null data.phone ? unitData.children.push({ - name: '联系电话',key: element.id+'联系电话',isLeaf:true,value:data.phone + name: '联系电话', key: element.id + '联系电话', isLeaf: true, value: data.phone }) : null data.organizationName ? unitData.children.push({ - name: '辖区中队',key: element.id+'辖区中队',isLeaf:true,value:data.organizationName + name: '辖区中队', key: element.id + '辖区中队', isLeaf: true, value: data.organizationName }) : null data.address ? unitData.children.push({ - name: '单位地址',key: element.id+'单位地址',isLeaf:true,value:data.address + name: '单位地址', key: element.id + '单位地址', isLeaf: true, value: data.address }) : null - - + + element.basicInfoNodes.push(unitData) resolve(1) - }) - }).then(async ()=>{ + }) + }).then(async () => { let result2 = await new Promise((resolve, reject) => { - var buildingsData:any - this.http.get("/api/Buildings",{ - params:{ - companyId:element.id + var buildingsData: any + this.http.get("/api/Buildings", { + params: { + companyId: element.id } - }).subscribe(async (data:any)=>{ + }).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 + 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)=>{ + }).subscribe((buildingsData: any) => { buildingsData.name = data[i].name buildingsData.buildingType = data[i].buildingTypes[0].name - buildingsData[0].buildingBasicGroups.forEach((y,m) => { - + buildingsData[0].buildingBasicGroups.forEach((y, m) => { + let propertyInfosArr = [] let tabledata - if(y.type == 1){//如果是表格类 + 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; - } - } + 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) + 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 == '储罐编号'){ + 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]; } - - 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) + 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) + } 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) } }) } - - }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) + + } 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){ + if (propertyInfosArr.length != 0) { element.basicInfoNodes.push({ - name:y.name != '基本信息' ? buildingsData.name + '-' + y.name : buildingsData.name , - type:'基本信息', + 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 + 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) }) @@ -279,15 +288,15 @@ export class CreateTestScoreComponent implements OnInit { } } //获取四周毗邻数据 - async getAround(){ + async getAround() { let that = this - for (let y = 0, length = this.unitId.length; y < length; y++){ + for (let y = 0, length = this.unitId.length; y < length; 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)=>{ + 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 @@ -298,37 +307,37 @@ export class CreateTestScoreComponent implements OnInit { item.direction == 6 ? item.title = '东北方向' : null item.direction == 7 ? item.title = '西北方向' : null item.isLeaf = true, - item.key = item.id + item.key = item.id }) //如果存在单位毗邻 - if(data.length != 0){ + 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), + key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), expanded: true, - type:'四周毗邻', + type: '四周毗邻', children: data }) element.aroundNodes = [...element.aroundNodes] } resolve(1) }) - }).then(async ()=>{ + }).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} + async function getAllArchitecture(buildingsdata) { + for (let i = 0, length = buildingsdata.length; i < length; i++) { + let id = { buildingId: buildingsdata[i].id } let result = await new Promise((resolve, reject) => { - that.http.get('/api/BuildingAdjoins',{params:id}).subscribe((data:any)=>{ + 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 @@ -341,35 +350,35 @@ export class CreateTestScoreComponent implements OnInit { item.isLeaf = true item.key = item.id }) - if(data.length != 0){ + 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), + key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), expanded: true, - type:'四周毗邻', + type: '四周毗邻', children: data }) element.aroundNodes = [...element.aroundNodes] } resolve(1) }) - }) + }) } } } } //获取重点部位 - async getKeySite(){ + async getKeySite() { let that = this - for (let y = 0, length = this.unitId.length; y < length; y++){ + for (let y = 0, length = this.unitId.length; y < length; 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)=>{ + this.http.get('/api/CompanyImportantLocations', { params: id }).subscribe((data: any) => { //如果存在单位重点部位 let newData = [] data.forEach(item => { @@ -377,53 +386,53 @@ export class CreateTestScoreComponent implements OnInit { item.key = item.id item.name ? newData.push(item) : null }) - if(newData.length != 0){ + 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), + key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), expanded: true, - type:'重点部位', + type: '重点部位', children: newData }) element.keySiteNodes = [...element.keySiteNodes] } resolve(1) }) - }).then(async ()=>{ + }).then(async () => { //获得建筑重点部位 let result2 = await new Promise((resolve, reject) => { - this.http.get('/api/Buildings',{params:id}).subscribe(async (data:any)=>{ - if (data.length) { + 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 result = await new Promise((resolve, reject) =>{ - that.http.get('/api/BuildingImportantLocations',{params:id}).subscribe((data:any)=>{ + async function getAllBuildingPositon(buildingsdata) { + for (let i = 0, length = buildingsdata.length; i < length; i++) { + 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){ + 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), + key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), expanded: true, - type:'重点部位', + type: '重点部位', children: newData }) element.keySiteNodes = [...element.keySiteNodes] @@ -431,21 +440,21 @@ export class CreateTestScoreComponent implements OnInit { resolve('2') }) }) - + } } - } + } } //获取功能分区 - async getFunDiv(){ + async getFunDiv() { let that = this - for (let y = 0, length = this.unitId.length; y < length; y++){ + for (let y = 0, length = this.unitId.length; y < length; 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)=>{ + this.http.get('/api/CompanyFunctionalDivisions', { params: id }).subscribe((data: any) => { //如果存在单位的单位功能分区 let newData = [] data.forEach(item => { @@ -453,39 +462,39 @@ export class CreateTestScoreComponent implements OnInit { item.key = item.id item.region ? newData.push(item) : null }) - if(data.length != 0){ + 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), + key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), expanded: true, - type:'功能分区', + type: '功能分区', children: newData }) element.funDivNodes = [...element.funDivNodes] - } + } resolve(1) }) - }).then(async ()=>{ + }).then(async () => { //建筑功能分区 let result2 = await new Promise((resolve, reject) => { - this.http.get('/api/Buildings',{params:id}).subscribe(async (data:any)=>{ - if (data.length) { + 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 result = await new Promise((resolve, reject) =>{ - that.http.get('/api/BuildingFunctionalDivisions',{params:id}).subscribe((data:any)=>{ + async function getAllBuildingFunDiv(buildingsdata) { + for (let i = 0, length = buildingsdata.length; i < length; i++) { + 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 => { @@ -494,12 +503,12 @@ export class CreateTestScoreComponent implements OnInit { item.region ? newData.push(item) : null }) - if(newData.length != 0){ + 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), + key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), expanded: true, - type:'功能分区', + type: '功能分区', children: newData }) element.funDivNodes = [...element.funDivNodes] @@ -507,26 +516,26 @@ export class CreateTestScoreComponent implements OnInit { resolve('2') }) }) - + } } } } //获取消防设施 - getFireFac(){ + getFireFac() { let that = this - this.unitId.forEach((element,index) =>{ - - let companyId = element.id + this.unitId.forEach((element, index) => { + + let companyId = element.id //获取单位级别消防设施 - this.http.get(`/api/Companies/${companyId}`).subscribe((data:any)=>{ + 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)=>{ //获得单位的消防设施 - + 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) => { + element.facilityItems.forEach((elements, index) => { elements.total = element.facilityCount[index] }); }); @@ -534,41 +543,43 @@ export class CreateTestScoreComponent implements OnInit { 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 + 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){ + 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), + key: (Math.random() * 10000000).toString(16).substr(0, 4) + (new Date()).getTime() + Math.random().toString().substr(2, 5), expanded: true, - type:'消防设施', + type: '消防设施', children: newData }) element.fireFacNodes = [...element.fireFacNodes] } - }) - } + }) + } }) //获取各建筑消防设施 - this.http.get('/api/Buildings',{params:{ - companyId:companyId - }}).subscribe((data:any)=>{ + this.http.get('/api/Buildings', { + params: { + companyId: companyId + } + }).subscribe((data: any) => { if (data.length != 0) { getAllBuildingFireFac(data) } }) - async function getAllBuildingFireFac (buildingsdata) { + 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 result = await new Promise((resolve, reject) =>{ - that.http.get('/api/BuildingFacilities',{params:header}).subscribe((data:any)=>{ + 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 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) => { + element.facilityItems.forEach((elements, index) => { elements.total = element.facilityCount[index] }); }); @@ -576,16 +587,16 @@ export class CreateTestScoreComponent implements OnInit { 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 + 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){ + if (newData.length != 0) { that.unitId[index].fireFacNodes.push({ name: buildingsdata[i].name, key: buildingsdata[i].id, expanded: true, - type:'消防设施', + type: '消防设施', children: newData }) element.fireFacNodes = [...element.fireFacNodes] @@ -593,16 +604,16 @@ export class CreateTestScoreComponent implements OnInit { resolve('消防设施') }) }) - + } } }) } //查看树节点 - lookTreeNode(node){ + lookTreeNode(node) { const dialogRef = this.dialog.open(LookTreeNodeDialog, { - id:'lookTreeNode', + id: 'lookTreeNode', data: node.origin }); dialogRef.afterClosed().subscribe(result => { @@ -611,22 +622,22 @@ export class CreateTestScoreComponent implements OnInit { } //阻止input事件冒泡 - stopPropagation($event){ + stopPropagation($event) { $event.stopPropagation() } defaultCheckedKeys = []; //指定选中复选框的树节点 key值 defaultExpandedKeys = []; //展开指定的树节点 key值 defaultSelectedKeys = []; //指定选中的树节点 key值 - examScore:any = 0//整个试卷的总分 - + examScore: any = 0//整个试卷的总分 + //计算分数 - calculateScore(key){ + 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 @@ -634,123 +645,123 @@ export class CreateTestScoreComponent implements OnInit { let examScore2 = 0 this.unitId.forEach(element => { let x = 0 - if(element.planList){ + if (element.planList) { element.planList.forEach(i => { x += i.score }) } element.planScore = x - examScore2 += Number(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) : '' - }) + 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(selectedNum.length != 0 ){ - this.unitId[key].basicInfoScore ? this.unitId[key].basicInfoItemScore = this.unitId[key].basicInfoScore / selectedNum.length : null - }else{ - this.unitId[key].basicInfoItemScore = 0 - } - this.unitId[key].basicInfoSelectedNum = selectedNum.length + }) + if (selectedNum.length != 0) { + this.unitId[key].basicInfoScore ? this.unitId[key].basicInfoItemScore = this.unitId[key].basicInfoScore / selectedNum.length : null + } else { + this.unitId[key].basicInfoItemScore = 0 } - 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) : '' - }) + 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(selectedNum.length != 0 ){ - this.unitId[key].aroundScore ? this.unitId[key].aroundItemScore = this.unitId[key].aroundScore / selectedNum.length : null - }else{ - this.unitId[key].aroundItemScore = 0 - } - this.unitId[key].aroundSelectedNum = selectedNum.length + }) + if (selectedNum.length != 0) { + this.unitId[key].aroundScore ? this.unitId[key].aroundItemScore = this.unitId[key].aroundScore / selectedNum.length : null + } else { + this.unitId[key].aroundItemScore = 0 } - 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) : '' - }) + 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(selectedNum.length != 0 ){ - this.unitId[key].keySiteScore ? this.unitId[key].keySiteItemScore = this.unitId[key].keySiteScore / selectedNum.length : null - }else{ - this.unitId[key].keySiteItemScore = 0 - } - this.unitId[key].keySiteSelectedNum = selectedNum.length + }) + if (selectedNum.length != 0) { + this.unitId[key].keySiteScore ? this.unitId[key].keySiteItemScore = this.unitId[key].keySiteScore / selectedNum.length : null + } else { + this.unitId[key].keySiteItemScore = 0 } - 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) : '' - }) + 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(selectedNum.length != 0 ){ - this.unitId[key].funDivScore ? this.unitId[key].funDivItemScore = this.unitId[key].funDivScore / selectedNum.length : null - }else{ - this.unitId[key].funDivItemScore = 0 - } - this.unitId[key].funDivSelectedNum = selectedNum.length + }) + if (selectedNum.length != 0) { + this.unitId[key].funDivScore ? this.unitId[key].funDivItemScore = this.unitId[key].funDivScore / selectedNum.length : null + } else { + this.unitId[key].funDivItemScore = 0 } - 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) : '' - }) + 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(selectedNum.length != 0 ){ - this.unitId[key].fireFacScore ? this.unitId[key].fireFacItemScore = this.unitId[key].fireFacScore / selectedNum.length : null - }else{ - this.unitId[key].fireFacItemScore = 0 - } - this.unitId[key].fireFacSelectedNum = selectedNum.length + }) + if (selectedNum.length != 0) { + this.unitId[key].fireFacScore ? this.unitId[key].fireFacItemScore = this.unitId[key].fireFacScore / selectedNum.length : null + } else { + this.unitId[key].fireFacItemScore = 0 } + this.unitId[key].fireFacSelectedNum = selectedNum.length + } } //单位各项总分数动态计算 - sumScore(type,key){ + sumScore(type, key) { //key代表第几个建筑 type代表哪个部分 - if(type == '基本信息'){ + if (type == '基本信息') { let selectedNum = 0 this.unitId[key].basicInfoNodes.forEach(item => { item.children.forEach(i => { i.checked ? selectedNum++ : '' }) }) - if(selectedNum != 0){ + if (selectedNum != 0) { this.unitId[key].basicInfoItemScore = this.unitId[key].basicInfoScore / selectedNum - }else{ + } else { this.unitId[key].basicInfoItemScore = 0 } } - if(type == '四周毗邻'){ + if (type == '四周毗邻') { let selectedNum = 0 this.unitId[key].aroundNodes.forEach(item => { item.children.forEach(i => { i.checked ? selectedNum++ : '' }) }) - if(selectedNum != 0){ + if (selectedNum != 0) { this.unitId[key].aroundItemScore = this.unitId[key].aroundScore / selectedNum - }else{ + } else { this.unitId[key].aroundItemScore = 0 } } - if(type == '重点部位'){ + if (type == '重点部位') { console.log('重点部位') let selectedNum = 0 this.unitId[key].keySiteNodes.forEach(item => { @@ -758,46 +769,46 @@ export class CreateTestScoreComponent implements OnInit { i.checked ? selectedNum++ : '' }) }) - if(selectedNum != 0){ + if (selectedNum != 0) { this.unitId[key].keySiteItemScore = this.unitId[key].keySiteScore / selectedNum - }else{ + } else { this.unitId[key].keySiteItemScore = 0 } } - if(type == '功能分区'){ + if (type == '功能分区') { let selectedNum = 0 this.unitId[key].funDivNodes.forEach(item => { item.children.forEach(i => { i.checked ? selectedNum++ : '' }) }) - if(selectedNum != 0){ + if (selectedNum != 0) { this.unitId[key].funDivItemScore = this.unitId[key].funDivScore / selectedNum - }else{ + } else { this.unitId[key].funDivItemScore = 0 } } - if(type == '数据核验'){ + 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 - }else{ + if (selectedNum != 0) { + this.unitId[key].fireFacItemScore = this.unitId[key].fireFacScore / selectedNum + } else { this.unitId[key].fireFacItemScore = 0 } } this.calculateScore(key)//更新标题栏分数 - + } //添加预案 - addPlan(){ + addPlan() { let companyData = { - companyData : this.unitId[this.selectedUnitIndex] + companyData: this.unitId[this.selectedUnitIndex] } const dialogRef = this.dialog.open(AddPlanDialog, { width: '380px', @@ -806,11 +817,11 @@ export class CreateTestScoreComponent implements OnInit { }); dialogRef.afterClosed().subscribe(result => { - if(result){ - if(this.unitId[this.selectedUnitIndex].planList){ + if (result) { + if (this.unitId[this.selectedUnitIndex].planList) { this.unitId[this.selectedUnitIndex].planList.push(result) - }else{ - this.unitId[this.selectedUnitIndex].planList = [] + } else { + this.unitId[this.selectedUnitIndex].planList = [] this.unitId[this.selectedUnitIndex].planList.push(result) } } @@ -818,7 +829,7 @@ export class CreateTestScoreComponent implements OnInit { } //每条预案分数增加在试卷分数 - planItemScore(){ + planItemScore() { //计算整个试卷的总分 let examScore = 0 this.unitId.forEach(element => { @@ -827,57 +838,57 @@ export class CreateTestScoreComponent implements OnInit { let examScore2 = 0 this.unitId.forEach(element => { let x = 0 - if(element.planList){ + if (element.planList) { element.planList.forEach(i => { x += i.score }) } element.planScore = x - examScore2 += Number(x) + examScore2 += Number(x) }) this.examScore = examScore + examScore2 } //编辑每条预案试卷 - edit(item){ + edit(item) { const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 - this.snackBar.open('暂不能编辑','确定',config); + this.snackBar.open('暂不能编辑', '确定', config); } //删除每条预案试卷 - deletePlan(item){ - if(window.confirm('你确定要删除该预案设定吗?')){ + deletePlan(item) { + 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); - this.unitId[this.selectedUnitIndex].planList.forEach((element,key)=>{ - if(item == element){ - this.unitId[this.selectedUnitIndex].planList.splice(key,1) + this.snackBar.open('删除成功', '确定', config); + this.unitId[this.selectedUnitIndex].planList.forEach((element, key) => { + if (item == element) { + this.unitId[this.selectedUnitIndex].planList.splice(key, 1) } }) this.planItemScore() }) - }else{ + } else { + - } - + console.log(item) - + } //保存 - save(){ + save() { this.unitId.forEach(item => { //建筑的基本信息选中key集合 item.basicInfoNodesKey = [] - item.basicInfoNodes.forEach((i,key) => { - if(i.checked){ + item.basicInfoNodes.forEach((i, key) => { + if (i.checked) { item.basicInfoNodesKey.push(i.key) - }else{ + } else { i.children.forEach(ele => { ele.checked ? item.basicInfoNodesKey.push(ele.key) : null }) @@ -885,10 +896,10 @@ export class CreateTestScoreComponent implements OnInit { }) //四周毗邻选中key集合 item.aroundNodesKey = [] - item.aroundNodes.forEach((i,key) => { - if(i.checked){ + item.aroundNodes.forEach((i, key) => { + if (i.checked) { item.aroundNodesKey.push(i.key) - }else{ + } else { i.children.forEach(ele => { ele.checked ? item.aroundNodesKey.push(ele.key) : null }) @@ -896,10 +907,10 @@ export class CreateTestScoreComponent implements OnInit { }) //重点部位选中key集合 item.keySiteNodesKey = [] - item.keySiteNodes.forEach((i,key) => { - if(i.checked){ + item.keySiteNodes.forEach((i, key) => { + if (i.checked) { item.keySiteNodesKey.push(i.key) - }else{ + } else { i.children.forEach(ele => { ele.checked ? item.keySiteNodesKey.push(ele.key) : null }) @@ -907,10 +918,10 @@ export class CreateTestScoreComponent implements OnInit { }) //功能分区选中key集合 item.funDivNodesKey = [] - item.funDivNodes.forEach((i,key) => { - if(i.checked){ + item.funDivNodes.forEach((i, key) => { + if (i.checked) { item.funDivNodesKey.push(i.key) - }else{ + } else { i.children.forEach(ele => { ele.checked ? item.funDivNodesKey.push(ele.key) : null }) @@ -918,10 +929,10 @@ export class CreateTestScoreComponent implements OnInit { }) //数据核验选中key集合 item.fireFacNodesKey = [] - item.fireFacNodes.forEach((i,key) => { - if(i.checked){ + item.fireFacNodes.forEach((i, key) => { + if (i.checked) { item.fireFacNodesKey.push(i.key) - }else{ + } else { i.children.forEach(ele => { ele.checked ? item.fireFacNodesKey.push(ele.key) : null }) @@ -933,9 +944,9 @@ export class CreateTestScoreComponent implements OnInit { //循环每个建筑处理数据筛选出选中数据 copyDatas.forEach(item => { //建筑的基本信息模块处理 - item.basicInfoNodes.forEach((i,key) => { + item.basicInfoNodes.forEach((i, key) => { //如果顶级节点未选中则需要筛除没有选中的数据 - if(!i.checked){ + if (!i.checked) { // console.log(i) let newArr = [] i.children.forEach(element => { @@ -947,12 +958,12 @@ export class CreateTestScoreComponent implements OnInit { item.basicInfoNodes = item.basicInfoNodes.filter(items => { if (!discard.includes(items)) return items; }) - } + } //将children处理成指定形式 - if(i.name =='单位信息'){ + if (i.name == '单位信息') { let newChildren = [] - i.children.forEach((element,index) => { - let newChildrenItem:any= {} + i.children.forEach((element, index) => { + let newChildrenItem: any = {} newChildrenItem.name = element.name//题目名称 newChildrenItem.result = element.value//题目答案 newChildrenItem.physicalUnit = element.physicalUnit || ''//计量单位 @@ -960,10 +971,10 @@ export class CreateTestScoreComponent implements OnInit { newChildren.push(newChildrenItem) }) i.children = newChildren - }else if(!i.tabledata){ + } else if (!i.tabledata) { let newChildren = [] - i.children.forEach((element,index) => { - let newChildrenItem:any= {} + i.children.forEach((element, index) => { + let newChildrenItem: any = {} newChildrenItem.name = element.propertyName//题目名称 newChildrenItem.result = element.propertyValue//题目答案 newChildrenItem.physicalUnit = element.physicalUnit || ''//计量单位 @@ -971,10 +982,10 @@ export class CreateTestScoreComponent implements OnInit { newChildren.push(newChildrenItem) }) i.children = newChildren - }else if(i.tabledata){//如果是表格类 + } else if (i.tabledata) {//如果是表格类 let newChildren = [] - i.children.forEach((element,index) => { - let newChildrenItem:any= {} + i.children.forEach((element, index) => { + let newChildrenItem: any = {} newChildrenItem.name = element.propertyValue//题目名称 newChildrenItem.result = element.tag//代表第几行 newChildrenItem.physicalUnit = ''//计量单位 @@ -985,7 +996,7 @@ export class CreateTestScoreComponent implements OnInit { i.tabledata.forEach(element => { let newData = [] element.data.forEach(ele => { - let newObj:any = {} + let newObj: any = {} newObj.name = ele.propertyName//题目名称 newObj.result = ele.propertyValue//代表第几行 newObj.physicalUnit = ele.physicalUnit//计量单位 @@ -1000,9 +1011,9 @@ export class CreateTestScoreComponent implements OnInit { }) //建筑的四周毗邻模块处理 - item.aroundNodes.forEach((i,key) => { + item.aroundNodes.forEach((i, key) => { //如果顶级节点未选中则需要筛除没有选中的数据 - if(!i.checked){ + if (!i.checked) { let newArr = [] i.children.forEach(element => { element.checked ? newArr.push(element) : null @@ -1014,8 +1025,8 @@ export class CreateTestScoreComponent implements OnInit { }) } let newChildren = [] - i.children.forEach((element,index) => { - let newChildrenItem:any= {} + i.children.forEach((element, index) => { + let newChildrenItem: any = {} newChildrenItem.name = element.title//题目名称 newChildrenItem.result = element.name//题目答案 newChildrenItem.physicalUnit = ''//计量单位 @@ -1027,10 +1038,10 @@ export class CreateTestScoreComponent implements OnInit { }) // console.log(111,item) //建筑的重点部位模块处理 - item.keySiteNodes ? item.keySiteNodes.forEach((i,key) => { - i.selected ? i.selected = null : null + item.keySiteNodes ? item.keySiteNodes.forEach((i, key) => { + i.selected ? i.selected = null : null //如果顶级节点未选中则需要筛除没有选中的数据 - if(!i.checked){ + if (!i.checked) { let newArr = [] i.children.forEach(element => { element.checked ? newArr.push(element) : null @@ -1041,11 +1052,11 @@ export class CreateTestScoreComponent implements OnInit { if (!discard.includes(items)) return items; }) } - i.tabledata = [{propertyName: "重点部位名称",data:[]}, - {propertyName: "重点部位所在位置",data:[]}, - {propertyName: "建筑结构",data:[]}, - {propertyName: "使用性质",data:[]}, - {propertyName: "主要危险性",data:[]}] + i.tabledata = [{ propertyName: "重点部位名称", data: [] }, + { propertyName: "重点部位所在位置", data: [] }, + { propertyName: "建筑结构", data: [] }, + { propertyName: "使用性质", data: [] }, + { propertyName: "主要危险性", data: [] }] i.children.forEach(element => { i.tabledata[0].data.push({ name: "重点部位名称", @@ -1084,8 +1095,8 @@ export class CreateTestScoreComponent implements OnInit { }) }) let newChildren = [] - i.children.forEach((element,index) => { - let newChildrenItem:any= {} + i.children.forEach((element, index) => { + let newChildrenItem: any = {} // newChildrenItem.name = element.name//重点部位题目名称 // newChildrenItem.position = element.position//重点部位所在位置 // newChildrenItem.structure = element.structure//重点部位建筑结构 @@ -1099,14 +1110,14 @@ export class CreateTestScoreComponent implements OnInit { }) i.children = newChildren delete i.selected - + }) : null //建筑的功能分区模块处理 - item.funDivNodes ? item.funDivNodes.forEach((i,key) => { - + item.funDivNodes ? item.funDivNodes.forEach((i, key) => { + //如果顶级节点未选中则需要筛除没有选中的数据 - if(!i.checked){ + if (!i.checked) { let newArr = [] i.children.forEach(element => { element.checked ? newArr.push(element) : null @@ -1118,9 +1129,9 @@ export class CreateTestScoreComponent implements OnInit { }) } - i.tabledata = [{propertyName: "区域",data:[]}, - {propertyName: "面积",data:[]}, - {propertyName: "基本情况",data:[]}] + i.tabledata = [{ propertyName: "区域", data: [] }, + { propertyName: "面积", data: [] }, + { propertyName: "基本情况", data: [] }] i.children.forEach(element => { i.tabledata[0].data.push({ name: "区域", @@ -1145,8 +1156,8 @@ export class CreateTestScoreComponent implements OnInit { }) }) let newChildren = [] - i.children.forEach((element,index) => { - let newChildrenItem:any= {} + i.children.forEach((element, index) => { + let newChildrenItem: any = {} // newChildrenItem.name = element.region//功能分区题目名称 // newChildrenItem.area = element.area//功能分区面积 // newChildrenItem.details = element.details//功能分区基本情况 @@ -1160,10 +1171,10 @@ export class CreateTestScoreComponent implements OnInit { delete i.selected }) : null //建筑的数据核验模块处理 - item.fireFacNodes ? item.fireFacNodes.forEach((i,key) => { - i.selected ? i.selected = null : null + item.fireFacNodes ? item.fireFacNodes.forEach((i, key) => { + i.selected ? i.selected = null : null //如果顶级节点未选中则需要筛除没有选中的数据 - if(!i.checked){ + if (!i.checked) { let newArr = [] i.children.forEach(element => { element.checked ? newArr.push(element) : null @@ -1175,8 +1186,8 @@ export class CreateTestScoreComponent implements OnInit { }) } let newChildren = [] - i.children.forEach((element,index) => { - let newChildrenItem:any= {} + i.children.forEach((element, index) => { + let newChildrenItem: any = {} newChildrenItem.name = element.name//题目名称 newChildrenItem.result = element.total//题目答案 newChildrenItem.physicalUnit = ''//计量单位 @@ -1187,10 +1198,10 @@ export class CreateTestScoreComponent implements OnInit { delete i.selected }) : null }) - + //将筛选出来的数据变为服务器提交数据 let paperDataInfo = [] - copyDatas.forEach((item,key) =>{ + copyDatas.forEach((item, key) => { paperDataInfo[key] = {} paperDataInfo[key].id = null paperDataInfo[key].paperId = sessionStorage.getItem('paperId') @@ -1205,7 +1216,7 @@ export class CreateTestScoreComponent implements OnInit { 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].originalData = JSON.stringify(this.unitId[key]) //赋值单项分 paperDataInfo[key].basicInfoItemScore = item.basicInfoItemScore paperDataInfo[key].adjoinItemScore = item.aroundItemScore @@ -1219,73 +1230,75 @@ export class CreateTestScoreComponent implements OnInit { 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 = element.planList.some(item => { + if (!item.score || item.score == 0) { + return false + } else { + return true + } + }) : null //判断存在总分填写后没有勾选题目 - 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) ){ + 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( + 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 - } + (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 - async function setPlansScore(){ + 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) - })) - }) + 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) + })) + }) } - + } } - setPlansScore().then(()=>{ - let body = { - id:sessionStorage.getItem('paperId'), + setPlansScore().then(() => { + let body = { + id: sessionStorage.getItem('paperId'), valid: true, - paperDataInfo:paperDataInfo + paperDataInfo: paperDataInfo } - this.http.put(`/api/Papers/UpdatePaperData/${sessionStorage.getItem('paperId')}`,body).subscribe(data => { + this.http.put(`/api/Papers/UpdatePaperData/${sessionStorage.getItem('paperId')}`, body).subscribe(data => { // const dialogRef = this.dialog.open(editorsDia, { // width: '650px', // data: this.editdata @@ -1293,21 +1306,21 @@ export class CreateTestScoreComponent implements OnInit { const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 - this.snackBar.open('创建试卷成功,页面将于一秒后退出','确定',config); + this.snackBar.open('创建试卷成功,页面将于一秒后退出', '确定', config); setTimeout(() => { this.router.navigateByUrl('/home/createexam-index') - }, 1000); + }, 1000); }) }) - - + + } //上一步 - goBack(){ - window.history.back(); + goBack() { + window.history.back(); } } @@ -1319,35 +1332,35 @@ export class CreateTestScoreComponent implements OnInit { }) export class AddPlanDialog { - constructor(public dialog: MatDialog,public dialogRef: MatDialogRef