|
@@ -45,7 +45,7 @@ export class RiskItemFormComponent {
|
|
|
category: [] as Option[],
|
|
|
type: [] as Option[],
|
|
|
job: [] as Option[],
|
|
|
- unit: [] as Option[],
|
|
|
+ position: [] as Option[],
|
|
|
operation: [] as Option[],
|
|
|
equipment: [] as Option[],
|
|
|
};
|
|
@@ -110,21 +110,31 @@ export class RiskItemFormComponent {
|
|
|
label: item.value,
|
|
|
value: item.id,
|
|
|
}));
|
|
|
-
|
|
|
- this.options.job = this.basic.jobs.map(item => ({
|
|
|
- label: this.basic.getJobName(item.id),
|
|
|
- value: item.id,
|
|
|
- }));
|
|
|
- this.options.unit = this.getPositionOptions();
|
|
|
- this.options.operation = this.getOperationOptions();
|
|
|
- this.options.equipment = this.getEquipmentOptions();
|
|
|
+ this.options.operation = this.getTargetOptions('operation');
|
|
|
+ this.options.position = this.getTargetOptions('position');
|
|
|
+ this.options.equipment = this.getTargetOptions('equipment');
|
|
|
+ this.setJobOptions();
|
|
|
+ }
|
|
|
+ setJobOptions() {
|
|
|
+ this.currentCategory = this.getCurrentCategory();
|
|
|
+ if (!this.currentCategory) {
|
|
|
+ this.options.job = [];
|
|
|
+ this.currentDepartments = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.currentDepartments = this.getSelectedDepartments();
|
|
|
+ this.options.job = this.basic.jobs
|
|
|
+ .filter(j => this.currentCategory!.departments.includes(j.department))
|
|
|
+ .map(item => ({
|
|
|
+ label: this.basic.getJobName(item.id),
|
|
|
+ value: item.id,
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
- getOperationOptions() {
|
|
|
+ getOptions(rawList: (BasicData.Operation | BasicData.Operation | BasicData.Equipment)[]) {
|
|
|
const { type, category } = this.validateForm.value;
|
|
|
if (!type || !category) return [];
|
|
|
- const all = this.basic.operations;
|
|
|
- const filtered = all.filter(item => {
|
|
|
+ const filtered = rawList.filter(item => {
|
|
|
let isMatch = true;
|
|
|
|
|
|
if (isMatch && type) {
|
|
@@ -140,46 +150,17 @@ export class RiskItemFormComponent {
|
|
|
value: item.id,
|
|
|
}));
|
|
|
}
|
|
|
- getPositionOptions() {
|
|
|
- const { type, category } = this.validateForm.value;
|
|
|
- if (!type || !category) return [];
|
|
|
- const all = this.basic.positions;
|
|
|
- const filtered = all.filter(item => {
|
|
|
- let isMatch = true;
|
|
|
-
|
|
|
- if (isMatch && type) {
|
|
|
- isMatch = item.type === type;
|
|
|
- }
|
|
|
- if (isMatch && category) {
|
|
|
- isMatch = item.category === category;
|
|
|
- }
|
|
|
- return isMatch;
|
|
|
- });
|
|
|
- return filtered.map(item => ({
|
|
|
- label: item.name,
|
|
|
- value: item.id,
|
|
|
- }));
|
|
|
+ getTargetOptions(key: 'operation' | 'position' | 'equipment') {
|
|
|
+ switch (key) {
|
|
|
+ case 'position':
|
|
|
+ return this.getOptions(this.basic.positions);
|
|
|
+ case 'operation':
|
|
|
+ return this.getOptions(this.basic.operations);
|
|
|
+ case 'equipment':
|
|
|
+ return this.getOptions(this.basic.equipments);
|
|
|
+ }
|
|
|
}
|
|
|
- getEquipmentOptions() {
|
|
|
- const { type, category } = this.validateForm.value;
|
|
|
- if (!type || !category) return [];
|
|
|
- const all = this.basic.equipments;
|
|
|
- const filtered = all.filter(item => {
|
|
|
- let isMatch = true;
|
|
|
|
|
|
- if (isMatch && type) {
|
|
|
- isMatch = item.type === type;
|
|
|
- }
|
|
|
- if (isMatch && category) {
|
|
|
- isMatch = item.category === category;
|
|
|
- }
|
|
|
- return isMatch;
|
|
|
- });
|
|
|
- return filtered.map(item => ({
|
|
|
- label: item.name,
|
|
|
- value: item.id,
|
|
|
- }));
|
|
|
- }
|
|
|
changeType(value: number) {
|
|
|
this.options.category = this.knowledge.getCategoryOptionsByType(value);
|
|
|
this.validateForm.patchValue({
|
|
@@ -187,20 +168,25 @@ export class RiskItemFormComponent {
|
|
|
involvedOperations: [],
|
|
|
involvedEquipments: [],
|
|
|
involvedPositions: [],
|
|
|
+ responsiblePositions: [],
|
|
|
});
|
|
|
- this.options.operation = this.getOperationOptions();
|
|
|
- this.options.unit = this.getPositionOptions();
|
|
|
- this.options.equipment = this.getEquipmentOptions();
|
|
|
+ this.options.operation = this.getTargetOptions('operation');
|
|
|
+ this.options.position = this.getTargetOptions('position');
|
|
|
+ this.options.equipment = this.getTargetOptions('equipment');
|
|
|
}
|
|
|
changeCategory() {
|
|
|
this.validateForm.patchValue({
|
|
|
involvedOperations: [],
|
|
|
involvedEquipments: [],
|
|
|
involvedPositions: [],
|
|
|
+ responsiblePositions: [],
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ this.options.operation = this.getTargetOptions('operation');
|
|
|
+ this.options.position = this.getTargetOptions('position');
|
|
|
+ this.options.equipment = this.getTargetOptions('equipment');
|
|
|
+ this.setJobOptions();
|
|
|
});
|
|
|
- this.options.operation = this.getOperationOptions();
|
|
|
- this.options.unit = this.getPositionOptions();
|
|
|
- this.options.equipment = this.getEquipmentOptions();
|
|
|
}
|
|
|
closeInsideDrawer() {
|
|
|
this.insideDrawerVisible = false;
|
|
@@ -425,4 +411,18 @@ export class RiskItemFormComponent {
|
|
|
nzOnOk: () => this.onUpdate({ ...v, updateReason: this.updateReason }),
|
|
|
});
|
|
|
}
|
|
|
+ currentCategory?: Knowledge.RiskCategoryDto;
|
|
|
+ getCurrentCategory() {
|
|
|
+ const { category, type } = this.validateForm.value;
|
|
|
+ const currentType = this.knowledge.types().find(t => t.id === type);
|
|
|
+ if (!currentType) return undefined;
|
|
|
+ return currentType.categories.find(c => c.id === category);
|
|
|
+ }
|
|
|
+ currentDepartments: BasicData.Department[] = [];
|
|
|
+ getSelectedDepartments() {
|
|
|
+ if (!this.currentCategory) return [];
|
|
|
+ return (this.currentDepartments = this.basic.departments.filter(d =>
|
|
|
+ this.currentCategory!.departments.includes(d.id)
|
|
|
+ ));
|
|
|
+ }
|
|
|
}
|