Newer
Older
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {TrackInfoComponent} from '../../../project-manager/modal/track-info/track-info.component';
import {WorkService} from '../../work.service';
import {OverAllService} from '../../../overAll/overAll.service';
import {NzMessageService} from 'ng-zorro-antd';
selector: 'smart-spare-parts',
templateUrl: './spare-parts.component.html',
styles: []
@ViewChild('smartTrackInfo') smartTrackInfo: TrackInfoComponent;
@Output() done = new EventEmitter<any>();
modal = {
isVisible: false,
title: '',
isOkLoading: false,
tabNum: 0,
id: null,
};
validateForm: FormGroup;
parentTypeList;
typeList;
inventoryParentId;
hostTypeList;
constructor(private fb: FormBuilder, private workSer: WorkService,
private overAllSer: OverAllService,
private message: NzMessageService) {
}
ngOnInit() {
this.initForm();
this.getParentType();
this.getTree();
}
initForm() {
this.validateForm = this.fb.group({
inventoryNo: [null], inventoryName: [null], secondlevelTypeId: [null],
secondlevelType: [null], inventoryTypeId: [null], inventoryType: [null],
amount: [null], contact: [null], name: [null],
brand: [null], model: [null], serialNo: [null],
versionNo: [null], price: [null], fundsSource: [null],
purchaseUser: [null], storageNum: [null], storeroom: [null],
storageLocation: [null], installLocation: [null], receiveUser: [null],
receiveNum: [null], operatUser: [null], relateFacility: [null],
buyDate: [null], warrantyDate: [null], price1: [null],
belongObject: [null],
});
}
//父级分类
getParentType() {
this.workSer.findByParentType().subscribe(
(res) => {
const data = res.data;
this.parentTypeList = data;
}
);
}
//通过父级分类查询子级分类
getTypeByParent(parentid) {
this.workSer.findByParentidCount(parentid).subscribe(
(res) => {
const data = res.data;
this.typeList = data;
}
);
}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//获取设备类型
getTree() {
this.overAllSer.findTree().subscribe(
(res) => {
if (res.errCode == 10000) {
this.hostTypeList = res.data;
}
}
);
}
showAddModal(title) {
this.modal.title = title;
this.modal.isVisible = true;
}
showEditModa(title, id) {
this.modal.title = title;
this.modal.id = id;
this.modal.isVisible = true;
this.getDetail();
}
//查询登记详情
getDetail(){
this.workSer.selectComponents({id:this.modal.id}).subscribe(
(res)=>{
if(res.errCode == 10000){
this.validateForm.patchValue(res.data);
}
}
)
}
handleCancel() {
this.modal.isVisible = false;
this.modal.isOkLoading = false;
this.initForm();
}
handleOk() {
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if (this.validateForm.invalid) {
return false;
}
this.modal.isOkLoading = true;
this.validateForm.value.secondlevelType = this.typeList.filter(e => e.id == this.validateForm.value.inventoryTypeId)[0].name;
this.validateForm.patchValue({
buyDate: new Date(this.validateForm.value.buyDate).getTime(),
warrantyDate: new Date(this.validateForm.value.warrantyDate).getTime()
});
if (this.modal.title.includes('入库登记')) this.create();
if (this.modal.title.includes('编辑信息')) this.update();
}
create() {
this.workSer.insertComponents(this.validateForm.value).subscribe(
(res) => {
this.modal.isOkLoading = false;
if (res.errCode == 10000) {
this.initForm();
this.done.emit();
this.modal.isVisible = false;
this.message.success('登记成功');
}
}
);
}
update() {
this.validateForm.patchValue(
{id: this.modal.id}
);
this.workSer.updateComponents(this.validateForm.value).subscribe(
(res) => {
this.modal.isOkLoading = false;
if (res.errCode == 10000) {
this.initForm();
this.done.emit();
this.modal.isVisible = false;
this.message.success('信息更新成功');
}
}
);
}
tabsChange(e) {
this.modal.tabNum = e;
}