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.
167 lines
5.8 KiB
167 lines
5.8 KiB
import { Component, OnInit, ViewContainerRef } from '@angular/core'; |
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
import { NzModalService } from 'ng-zorro-antd/modal'; |
|
import { NzMessageService } from 'ng-zorro-antd/message'; |
|
import { AddequipmentComponent } from './addequipment/addequipment.component'; |
|
import { HttpClient } from '@angular/common/http'; |
|
import { EditequipmentComponent } from './editequipment/editequipment.component'; |
|
import { Router, ActivatedRoute } from '@angular/router' |
|
import * as moment from 'moment'; |
|
@Component({ |
|
selector: 'app-equipment-info', |
|
templateUrl: './equipment-info.component.html', |
|
styleUrls: ['./equipment-info.component.scss'] |
|
}) |
|
export class EquipmentInfoComponent implements OnInit { |
|
validateForm!: FormGroup; |
|
constructor(private router: Router, private fb: FormBuilder, private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient) { } |
|
arr = [] |
|
ngOnInit(): void { |
|
this.validateForm = this.fb.group({ |
|
search: [null] |
|
}); |
|
this.getEquipment() |
|
// console.log(JSON.parse(sessionStorage.getItem('userdata'))) |
|
} |
|
|
|
//获取装备列表 |
|
equipmentList: any |
|
|
|
getEquipment() { |
|
this.http.get('/api/services/app/FireEquipment/GetAll', { |
|
params: { |
|
Name: this.validateForm.value.search ? this.validateForm.value.search : '', |
|
organizationUnitId: JSON.parse(sessionStorage.getItem('userdata')).organization.id, |
|
SkipCount: String(this.SkipCount), |
|
MaxResultCount: String(this.MaxResultCount) |
|
} |
|
}).subscribe((data: any) => { |
|
console.log('装备列表', data) |
|
this.equipmentList = data.result.items |
|
this.equipmentNum = data.result.totalCount |
|
}) |
|
} |
|
SkipCount: number = 0 //0 16 32 48 |
|
MaxResultCount: number = 16 |
|
equipmentNum: string |
|
pageChange($event) { |
|
this.SkipCount = ($event - 1) * this.MaxResultCount |
|
this.getEquipment() |
|
} |
|
|
|
|
|
submitForm() { |
|
this.getEquipment() |
|
} |
|
add() { |
|
const modal = this.modal.create({ |
|
nzContent: AddequipmentComponent, |
|
nzViewContainerRef: this.viewContainerRef, |
|
nzWidth: 380, |
|
nzBodyStyle: { |
|
'border': '1px solid #91CCFF', |
|
'border-radius': '0px', |
|
'padding': '7px', |
|
'box-shadow': '0 0 8px 0 #fff', |
|
'background-image': 'linear-gradient(#003665, #000f25)' |
|
}, |
|
nzComponentParams: {}, |
|
nzFooter: null, |
|
nzClosable: false, |
|
nzOnOk: async () => { |
|
if (instance.validateForm.valid) { |
|
await new Promise(resolve => { |
|
let body = { |
|
name: instance.validateForm.value.name, |
|
specification: instance.validateForm.value.specification, |
|
productionDate: moment(instance.validateForm.value.prodtime).format('yyyy-MM-DD'), |
|
purchaseDate: moment(instance.validateForm.value.buytime).format('yyyy-MM-DD'), |
|
validityEndTime: moment(instance.validateForm.value.validitytime).format('yyyy-MM-DD'), |
|
organizationUnitId: JSON.parse(sessionStorage.getItem('userdata')).organization.id |
|
} |
|
this.http.post('/api/services/app/FireEquipment/Create', body).subscribe(data => { |
|
resolve(data) |
|
this.message.create('success', '创建成功!'); |
|
return true |
|
}) |
|
}) |
|
} else { |
|
this.message.create('warning', '请填写完整!'); |
|
return false |
|
} |
|
}, |
|
}); |
|
modal.afterClose.subscribe(result => this.getEquipment()); |
|
const instance = modal.getContentComponent(); |
|
} |
|
edit(item) { |
|
console.log('xxxxx',item) |
|
const modal = this.modal.create({ |
|
nzContent: EditequipmentComponent, |
|
nzViewContainerRef: this.viewContainerRef, |
|
nzWidth: 380, |
|
nzBodyStyle: { |
|
'border': '1px solid #91CCFF', |
|
'border-radius': '0px', |
|
'padding': '7px', |
|
'box-shadow': '0 0 8px 0 #fff', |
|
'background-image': 'linear-gradient(#003665, #000f25)' |
|
}, |
|
nzComponentParams: { |
|
data: item |
|
}, |
|
nzFooter: null, |
|
nzClosable: false, |
|
nzOnOk: async () => { |
|
if (instance.validateForm.valid) { |
|
await new Promise(resolve => { |
|
let body = { |
|
id: item.id, |
|
name: instance.validateForm.value.name, |
|
specification: instance.validateForm.value.specification, |
|
productionDate: moment(instance.validateForm.value.prodtime).format('yyyy-MM-DD'), |
|
purchaseDate: moment(instance.validateForm.value.buytime).format('yyyy-MM-DD'), |
|
validityEndTime: moment(instance.validateForm.value.validitytime).format('yyyy-MM-DD'), |
|
organizationUnitId: item.organizationUnitId |
|
} |
|
this.http.put('/api/services/app/FireEquipment/Update', body).subscribe(data => { |
|
resolve(data) |
|
this.message.create('success', '修改成功!'); |
|
return true |
|
}) |
|
}) |
|
} else { |
|
this.message.create('warning', '请填写完整!'); |
|
return false |
|
} |
|
} |
|
}); |
|
const instance = modal.getContentComponent(); |
|
modal.afterClose.subscribe(result => this.getEquipment()); |
|
} |
|
delete(item) { |
|
this.modal.confirm({ |
|
nzTitle: `确定要删除${item.name}这个器材吗?`, |
|
nzOkText: '确定', |
|
nzOkType: 'danger', |
|
nzOnOk: () => { |
|
this.http.delete('/api/services/app/FireEquipment/Delete', { |
|
params: { |
|
Id: item.id |
|
} |
|
}).subscribe(data => { |
|
this.message.create('success', '删除成功!'); |
|
this.getEquipment() |
|
}) |
|
}, |
|
nzCancelText: '取消', |
|
nzOnCancel: () => { |
|
|
|
} |
|
}); |
|
} |
|
|
|
goback() { |
|
this.router.navigate(['/warning/petrolStation']) |
|
} |
|
}
|
|
|