上海预案管理平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

170 lines
5.2 KiB

import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import Viewer from 'viewerjs';
class unitInfo {
id: string;
name: string; //单位信息名字
usci: string; //单位信用代码
contacts: string; //联系人
phone: string; //联系电话
address: string; //单位地址
imageUrl: string; //图片地址
location: string; //单位地理位置
modifiedTime: string; //信息修改时间
organizationId: string; //所属组织机构
organizationName: string; //组织机构名称
buildingTypes: [
{
id:string;
name:string;
}
]
}
@Component({
selector: 'app-basic-info',
templateUrl: './basic-info.component.html',
styleUrls: ['./basic-info.component.scss']
})
export class BasicInfoComponent implements OnInit {
constructor(private http: HttpClient) { }
unitId:string;//单位相关数据
unitInfo:unitInfo = {
id: '',
name: '', //单位信息名字
usci: '', //单位信用代码
contacts: '', //联系人
phone: '', //联系电话
address: '', //单位地址
imageUrl: '', //图片地址
location: '', //单位地理位置
modifiedTime: '', //信息修改时间
organizationId: '', //所属组织机构
organizationName: '', //组织机构名称
buildingTypes: [
{
id:'',
name:''
}
]
}
noImg:string = '../../../assets/images/noImg.png'
gallery:any //Viewer实例
ngOnInit(): void {
this.everyInin()
}
//每次初始化 加载 组件调用方法
everyInin () {
//this.unitId = sessionStorage.getItem('unitId')
this.unitId=sessionStorage.getItem('companyId')
if (this.unitId) {
this.getUnitInfo().then(()=>{
setTimeout(() => {
this.gallery = new Viewer(document.getElementById('viewerjs'),{ url: 'data-original' });
},0);
});
this.getAllBuildingsInfo()
}
}
//获得单位信息
async getUnitInfo(){
let result = await new Promise((resolve, reject) => {
this.http.get(`/api/Companies/${this.unitId}`).subscribe((data:any)=>{
resolve('获取单位信息成功')
this.unitInfo = data
})
})
}
buildingsData:any
//获得所有建筑信息
getAllBuildingsInfo(){
this.http.get("/api/Buildings",{
params:{
companyId:this.unitId
}
}).subscribe(async (data:any)=>{
this.buildingsData = data
for (let i = 0, length = data.length; i < length; i++){
const result = await new Promise((resolve) =>{
this.http.get("/api/BuildingBasicInfos",{ // 循环请求当前单位建筑每一个建筑的信息保存到数组中
params:{
companyId :this.unitId,
buildingId:data[i].id,
buildingType:data[i].buildingTypes[0].id
}
}).subscribe((buildingsData:any)=>{
//获得当前建筑自定义信息并且添加到item自定义属性上
let _data = buildingsData
_data[0].buildingCustomData = {}
_data[0].buildingCustomData.customProperties = []
this.http.get("/api/BuildingCustomData",{params:{
buildingId:data[i].id
}}).subscribe((data:any)=>{
_data[0].buildingCustomData = data
if(data && data.customProperties.length != 0){
_data[0].isCustomData = true
}else{
_data[0].isCustomData = false
_data[0].buildingCustomData ={
id: "",
customProperties: [
{
name: "",
value: ""
}
],
buildingId: _data[0].buildingId
}
}
})
//如果是表格类需要处理数据
// console.log(i,buildingsData)
buildingsData[0].buildingBasicGroups.forEach(element => {
if(element.type == 1){
var map = {},
dest:any = [];
for(var i = 0; i < element.propertyInfos.length; i++){
var ai = element.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)
})
})
element.tabledata = dest
}
});
this.buildingsData[i].details = buildingsData
resolve(i)
})
})
}
})
}
}