|
|
|
@ -5,6 +5,7 @@ import {IconService} from '../../../services/icon.service'; |
|
|
|
|
import {NzMessageService, NzModalService, NzUploadFile} from 'ng-zorro-antd'; |
|
|
|
|
import {ConfigService} from '../../../services/config.service'; |
|
|
|
|
import {Router} from '@angular/router'; |
|
|
|
|
import {CommonsService} from "../../../services/commons.service"; |
|
|
|
|
|
|
|
|
|
function getBase64(file: File): Promise<string | ArrayBuffer | null> { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
@ -37,7 +38,14 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
imgFile = []; |
|
|
|
|
previewImage: string | undefined = ''; |
|
|
|
|
previewVisible = false; |
|
|
|
|
|
|
|
|
|
businessTypeS; |
|
|
|
|
goodsTypeData; |
|
|
|
|
goodsTypeDataChild; |
|
|
|
|
parentIdIsShow = false; |
|
|
|
|
listModal = false; |
|
|
|
|
listModalLoading = false; |
|
|
|
|
editTitle = '编辑'; |
|
|
|
|
parentId; |
|
|
|
|
constructor( |
|
|
|
|
private form: FormBuilder, |
|
|
|
|
private config: ConfigService, |
|
|
|
@ -45,6 +53,7 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
private message: NzMessageService, |
|
|
|
|
private router: Router, |
|
|
|
|
private modalService: NzModalService, |
|
|
|
|
private commonsService: CommonsService, |
|
|
|
|
private fb: FormBuilder, |
|
|
|
|
) { |
|
|
|
|
} |
|
|
|
@ -56,12 +65,20 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
public init(): void { |
|
|
|
|
this.searchForm = this.form.group({ |
|
|
|
|
title: [null], |
|
|
|
|
businessType: [null], |
|
|
|
|
parentId: [null], |
|
|
|
|
}); |
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
title: [null, [Validators.required]], |
|
|
|
|
userService: [null], |
|
|
|
|
businessType: [null , [Validators.required]], |
|
|
|
|
parentId: [null], |
|
|
|
|
}); |
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
|
|
|
|
|
this.getListGoodsTypeByParentId(); |
|
|
|
|
this.commonsService.getDictionary('BUSINESS_TYPE', data => { |
|
|
|
|
this.businessTypeS = data['return_data']; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 图片查看
|
|
|
|
@ -74,6 +91,16 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
this.previewVisible = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public getListGoodsTypeByParentId(parentId?: number): void { |
|
|
|
|
this.config.getListGoodsTypeByParentId(parentId , data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
parentId == null ? this.goodsTypeData = data['return_data'] : this.goodsTypeDataChild = data['return_data']; |
|
|
|
|
} else { |
|
|
|
|
this.message.error(data['return_msg']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询列表
|
|
|
|
|
public getRequest(reset: boolean = false, whereObject: object) { |
|
|
|
|
|
|
|
|
@ -100,23 +127,20 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 修改
|
|
|
|
|
public getEdit(id?: number): void { |
|
|
|
|
public getEdit(id?: number , parentId?: number , title?: string): void { |
|
|
|
|
this.id = id; |
|
|
|
|
if (id != null) { |
|
|
|
|
this.parentId = parentId; |
|
|
|
|
if (title != null) { |
|
|
|
|
this.editTitle = title + '添加子类'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (id != null && parentId == null) { |
|
|
|
|
this.editFlag = true; |
|
|
|
|
this.config.getGoodsTypeById(id, data => { |
|
|
|
|
if (data['return_data']['img'] != null && data['return_data']['img'] !== '') { |
|
|
|
|
const img = String(data['return_data']['img']); |
|
|
|
|
const imgArray = []; |
|
|
|
|
imgArray.push( |
|
|
|
|
{ |
|
|
|
|
uid: 1, |
|
|
|
|
name: img, |
|
|
|
|
status: 'done', |
|
|
|
|
url: environment.imageUrl + img |
|
|
|
|
}); |
|
|
|
|
this.imgFile = imgArray; |
|
|
|
|
if (!this.commonsService.whetherStringIsNull(data['return_data']['img'])) { |
|
|
|
|
this.imgFile = this.commonsService.stitchImg(data['return_data']['img']); |
|
|
|
|
} |
|
|
|
|
data['return_data']['businessType'] = String(data['return_data']['businessType']); |
|
|
|
|
this.validateForm.patchValue(data['return_data']); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
@ -137,12 +161,10 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleOk(): void { |
|
|
|
|
// tslint:disable-next-line:forin
|
|
|
|
|
for (const i in this.validateForm.controls) { |
|
|
|
|
this.validateForm.controls[i].markAsDirty(); |
|
|
|
|
this.validateForm.controls[i].updateValueAndValidity(); |
|
|
|
|
if (this.validateForm.controls[i].errors != null) { |
|
|
|
|
this.message.error('必填项不能为空'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -154,13 +176,20 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
this.validateForm.value.img = this.imgFile[0].name; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.validateForm.value['parentId'] == null) { |
|
|
|
|
this.validateForm.value['parentId'] = this.parentId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.editFlag) { |
|
|
|
|
this.validateForm.value.id = this.id; |
|
|
|
|
|
|
|
|
|
this.config.updateGoodsType(this.validateForm.value, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.message.success('修改成功'); |
|
|
|
|
this.isVisible = false; |
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
this.getListGoodsTypeByParentId(this.validateForm.value['parentId']); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
} |
|
|
|
@ -171,39 +200,47 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
|
this.message.success('添加成功'); |
|
|
|
|
this.isVisible = false; |
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
this.getListGoodsTypeByParentId(this.validateForm.value['parentId']); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleCancel(): void { |
|
|
|
|
this.isVisible = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查看子类列表
|
|
|
|
|
public getGoodsTypesChild(parentId: number) { |
|
|
|
|
this.listModal = true; |
|
|
|
|
this.getListGoodsTypeByParentId(parentId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 對話框删除
|
|
|
|
|
showDeleteConfirm(id): void { |
|
|
|
|
this.modalService.confirm({ |
|
|
|
|
nzTitle: '确定删除', |
|
|
|
|
nzOkText: '是', |
|
|
|
|
nzOnOk: () => this.onDelete(id), |
|
|
|
|
nzCancelText: '否', |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onDelete(ids) { |
|
|
|
|
nzOnOk: () => { |
|
|
|
|
this.config.getGoodsTypeByDelete({ |
|
|
|
|
id: ids |
|
|
|
|
id: id |
|
|
|
|
}, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.message.create('success', `删除成功!`); |
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
this.getListGoodsTypeByParentId(this.parentId); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
nzCancelText: '否', |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|