pad端六熟悉
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.
 
 
 
 

114 lines
4.1 KiB

import { Component, OnInit, Inject } from '@angular/core';
import {MatTreeFlatDataSource, MatTreeFlattener} from '@angular/material/tree';
import {FlatTreeControl} from '@angular/cdk/tree';
import { HttpClient } from '@angular/common/http';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
import {FormControl} from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import format from 'date-fns/format';
@Component({
selector: 'addgroups',
templateUrl: './addgroups.component.html',
styleUrls: ['./unit-information.component.scss']
})
export class AddGroups {
myControl = new FormControl();
templatestatus = "0"//创建模板时的默认状态
constructor(private http: HttpClient,public dialogRef: MatDialogRef<AddGroups>,@Inject(MAT_DIALOG_DATA) public data) {}
ngOnInit(): void {}
onNoClick(): void {
this.dialogRef.close();
}
grouporder = null; //没有'/'情况的order值
//提交表单新增分组
onSubmit(value){
if(this.data.allGrouping.length == 0){ //分组为空时
this.http.post("/api/BasicGroups",{
id: "",
name: value.groupname,
type: Number(value.propertyType),
addMode:Number(value.databehavior),
isOptional:true,
order: 0,
enabled: true,
propertyInfos: [],
basicCategoryId: this.data.unitInformation.id
}).subscribe(data=>{
this.dialogRef.close('yes');
})
}
if (value.groupname.indexOf('/') == -1 && this.data.allGrouping.length != 0) { //分组name中没有'/'情况时
this.grouporder = this.data.allGrouping[this.data.allGrouping.length - 1].order + 1
this.http.post("/api/BasicGroups",{
id: "",
name: value.groupname,
type: Number(value.propertyType),
addMode:Number(value.databehavior),
isOptional:true,
order: this.grouporder,
enabled: true,
propertyInfos: [],
basicCategoryId: this.data.unitInformation.id
}).subscribe(data=>{
this.dialogRef.close('yes');
})
}
else if (value.groupname.indexOf('/') != -1 && this.data.allGrouping.length != 0) { //分组name中有'/'情况时
let str = value.groupname.substring(0,value.groupname.lastIndexOf('/')) //截取'/'之前字符串
for (let i=this.data.allGrouping.length;i--;i>=0) {
if (str.indexOf(this.data.allGrouping[i].name)!=-1) {//分组name中含有新建分组'/'之前文字时
this.grouporder = this.data.allGrouping[this.data.allGrouping.length - 1].order + 1
this.http.post("/api/BasicGroups",{
id: "",
name: value.groupname,
type: Number(value.propertyType),
addMode:Number(value.databehavior),
isOptional:true,
order: this.grouporder,
enabled: true,
propertyInfos: [],
basicCategoryId: this.data.unitInformation.id
}).subscribe(data=>{
let id = {categoryId:this.data.unitInformation.id}
this.http.get('/api/BasicGroups',{params:id}).subscribe((data:any)=>{
let newitem = data.pop()
data.splice(i+1,0,newitem)
this.dialogRef.close(data);
})
});break}
else if (str.indexOf(this.data.allGrouping[i].name)==-1 && i<1) {//分组name中没有新建分组'/'之前文字时
this.grouporder = this.data.allGrouping[this.data.allGrouping.length - 1].order + 1
this.http.post("/api/BasicGroups",{
id: "",
name: value.groupname,
type: Number(value.propertyType),
addMode:Number(value.databehavior),
isOptional:true,
order: this.grouporder,
enabled: true,
propertyInfos: [],
basicCategoryId: this.data.unitInformation.id
}).subscribe(data=>{
this.dialogRef.close('yes');
});break}
} //for循环
} //else if
} //onSubmit
}