diff --git a/src/app/data/goods/goods.namespace.ts b/src/app/data/goods/goods.namespace.ts index 8b6e8c8..c7853d8 100644 --- a/src/app/data/goods/goods.namespace.ts +++ b/src/app/data/goods/goods.namespace.ts @@ -1,5 +1,3 @@ -export const goodsTypeSearch = [ - {title: "标题" , formControlName: "title"}, - {title: "业务类型" , formControlName: "businessType"} , -]; + +export const fallbackImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3PTWBSGcbGzM6GCKqlIBRV0dHRJFarQ0eUT8LH4BnRU0NHR0UEFVdIlFRV7TzRksomPY8uykTk/zewQfKw/9znv4yvJynLv4uLiV2dBoDiBf4qP3/ARuCRABEFAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQa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J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiEC/wGgKKC4YMA4TAAAAABJRU5ErkJggg=='; diff --git a/src/app/model/goods.interface.ts b/src/app/model/goods.interface.ts index 88a3553..a5c9e2d 100644 --- a/src/app/model/goods.interface.ts +++ b/src/app/model/goods.interface.ts @@ -1,10 +1,14 @@ export interface GoodsTypeData { id: number; - parentId: number; + parentId?: number | undefined; title: string; - businessType: number; - imgUrl: string; + businessType?: any; + imgUrl?: any; createTime: string; updateTime: string; - status: number; + status: string; + level?: number; + expand?: boolean; + children?: GoodsTypeData[]; + parent?: GoodsTypeData; } diff --git a/src/app/pages/goods/goods-brand/goods-brand.component.html b/src/app/pages/goods/goods-brand/goods-brand.component.html new file mode 100644 index 0000000..dbbcd1d --- /dev/null +++ b/src/app/pages/goods/goods-brand/goods-brand.component.html @@ -0,0 +1,98 @@ +
+
+
+ + 品牌名称 + + + + +
+ +
+ + + +
+
+
+ + + + + 品牌名称 + 品牌图片 + 创建时间 + 更新时间 + 操作 + + + + + {{data.title}} + + + + {{ data.createTime | date: 'yyyy-MM-dd HH:mm'}} + {{ data.updateTime | date: 'yyyy-MM-dd HH:mm'}} + + 修改 + + 删除 + + + + 总计 {{ total }} 条 + + + + + +
+ + 标题 + + + + + + + 上传图片 + + +
+ +
上传图片
+
+
+ + + + + + +
+
+
+
+
diff --git a/src/app/pages/goods/goods-brand/goods-brand.component.less b/src/app/pages/goods/goods-brand/goods-brand.component.less new file mode 100644 index 0000000..6d5c351 --- /dev/null +++ b/src/app/pages/goods/goods-brand/goods-brand.component.less @@ -0,0 +1,12 @@ +[nz-form-label] { + overflow: visible; +} +button { + margin-left: 8px; +} +.submit-btn { + width: 150px; +} +.search-area { + margin-top: 30px; +} diff --git a/src/app/pages/goods/goods-brand/goods-brand.component.ts b/src/app/pages/goods/goods-brand/goods-brand.component.ts new file mode 100644 index 0000000..6e7bdd0 --- /dev/null +++ b/src/app/pages/goods/goods-brand/goods-brand.component.ts @@ -0,0 +1,203 @@ +import { Component } from '@angular/core'; +import {DatePipe, NgForOf, NgOptimizedImage, NgStyle} from "@angular/common"; +import {NzButtonComponent} from "ng-zorro-antd/button"; +import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; +import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; +import {NzInputDirective} from "ng-zorro-antd/input"; +import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; +import {FormGroup, NonNullableFormBuilder, ReactiveFormsModule, Validators} from "@angular/forms"; +import {NzMessageService} from "ng-zorro-antd/message"; +import {NzModalComponent, NzModalContentDirective, NzModalModule} from "ng-zorro-antd/modal"; +import {GoodsService} from "../../../services/goods/goods.service"; +import {NzIconDirective} from "ng-zorro-antd/icon"; +import {NzTreeSelectComponent} from "ng-zorro-antd/tree-select"; +import {NzUploadComponent, NzUploadFile} from "ng-zorro-antd/upload"; +import {environment} from "../../../../environments/environment"; +import {GoodsTypeData} from "../../../model/goods.interface"; +import {CommonService} from "../../../services/common/common.service"; +import {NzDividerComponent} from "ng-zorro-antd/divider"; +import { + NzTableCellDirective, + NzTableComponent, + NzTbodyComponent, + NzTheadComponent, + NzThMeasureDirective, NzTrDirective +} from "ng-zorro-antd/table"; +import {NzPopconfirmDirective} from "ng-zorro-antd/popconfirm"; +import {fallbackImg} from "../../../data/goods/goods.namespace"; +import {NzImageModule} from "ng-zorro-antd/image"; + +const getBase64 = (file: File): Promise => + new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = () => resolve(reader.result); + reader.onerror = error => reject(error); + }); + +@Component({ + selector: 'app-goods-brand', + standalone: true, + imports: [ + NgForOf, + NzButtonComponent, + NzColDirective, + NzFormControlComponent, + NzFormDirective, + NzFormItemComponent, + NzFormLabelComponent, + NzInputDirective, + NzOptionComponent, + NzRowDirective, + NzModalModule, + NzSelectComponent, + ReactiveFormsModule, + NzIconDirective, + NzModalComponent, + NzTreeSelectComponent, + NzUploadComponent, + NzModalContentDirective, + NgStyle, + DatePipe, + NzDividerComponent, + NzTableCellDirective, + NzTableComponent, + NzTbodyComponent, + NzThMeasureDirective, + NzTheadComponent, + NzTrDirective, + NzPopconfirmDirective, + NzImageModule, + NgOptimizedImage + ], + templateUrl: './goods-brand.component.html', + styleUrl: './goods-brand.component.less' +}) +export class GoodsBrandComponent { + // 表单页数 + tablePageNum = 1; + // 表单数据 + tableData: any = { + total: 0, + loading: false, + list: [], + }; + // 搜索表单 + searchForm: FormGroup; + + // 图片 + imgUrl: NzUploadFile[] = [] + baseUrl = environment.baseUrl; + imageUrl = environment.imageUrl; + + // 展示图片 + previewImage: string | undefined = ''; + // 上传是否展示 + previewVisible = false; + + // 编辑产品类型表单 + editForm: FormGroup; + // 编辑弹出框 + isVisibleEdit = false; + + constructor(private fb: NonNullableFormBuilder, + private msg: NzMessageService, + private commonService: CommonService, + private goodsService: GoodsService) { + // 初始化搜索框 + this.searchForm = this.fb.group({ + title: [''], + }); + + // 初始化 + this.editForm = this.fb.group({ + title: ['' , [Validators.required]], + id: [null], + imgUrl: [''], + }); + this.getRequest(); + + } + + // 查询列表 + public getRequest(reset: boolean = false) { + this.tableData.loading = true; + if (reset) { + this.tablePageNum = 1; + } + this.searchForm.value.pageNum = this.tablePageNum; + this.searchForm.value.pageSize = 10; + this.searchForm.value.time = new Date().getTime(); + + this.goodsService.getListBrand(this.searchForm.value , (data: any) => { + if (data['return_code'] == '000000') { + this.tableData = data['return_data']; + } else { + this.msg.error(data['return_msg']); + } + this.tableData.loading = false; + }); + } + + + // 唤醒编辑表单 + showEdit(item?: GoodsTypeData) { + if (item != null) { + item.businessType = String(item.businessType); + this.editForm.patchValue(item); + if (!this.commonService.whetherStringIsNull(item.imgUrl)) { + this.imgUrl = this.commonService.stitchImg(item.imgUrl); + } + } + this.isVisibleEdit = true; + } + // 编辑表单提交 + handleEdit(): void { + + if (this.editForm.valid) { + if (this.imgUrl.length !== 0) { + this.editForm.value.imgUrl = this.commonService.imgList(this.imgUrl); + } + this.goodsService.editGoodsBrand(this.editForm.value , (data: any) => { + if (data['return_code'] === '000000') { + this.msg.success("成功!"); + this.isVisibleEdit = false; + this.getRequest(); + } else { + this.msg.error(data['return_msg']); + } + }); + } else { + Object.values(this.editForm.controls).forEach(control => { + if (control.invalid) { + control.markAsDirty(); + control.updateValueAndValidity({ onlySelf: true }); + } + }); + } + + } + + // 上传操作 + handlePreview = async (file: NzUploadFile): Promise => { + if (!file.url && !file['preview']) { + file['preview'] = await getBase64(file.originFileObj!); + } + this.previewImage = file.url || file['preview']; + this.previewVisible = true; + }; + + // 删除 + delete(id: number): void { + this.goodsService.deleteBran(id , (data: any) => { + if (data['return_code'] === '000000') { + this.msg.success("成功!"); + this.getRequest(); + } else { + this.msg.error(data['return_msg']); + } + }); + } + + protected readonly fallbackImg = fallbackImg; +} diff --git a/src/app/pages/goods/goods-type/goods-type.component.html b/src/app/pages/goods/goods-type/goods-type.component.html index 188d4f6..c2a79c0 100644 --- a/src/app/pages/goods/goods-type/goods-type.component.html +++ b/src/app/pages/goods/goods-type/goods-type.component.html @@ -1,19 +1,111 @@ + + +
+
+ + + + + 标题 + 业务类型 + 图片 + 创建时间 + 更新时间 + 操作 + + + + + + + -
-
- - {{item.title}} - - + [nzIndentSize]="item.level! * 20" + [nzShowExpand]="!!item.children" + [(nzExpand)]="item.expand" + (nzExpandChange)="collapse(mapOfExpandedData[data.id], item, $event)" + > + {{ item.title }} + + {{ item.businessType | dictionary: 'GOODS_TYPE' }} + + + + {{ item.createTime | date: 'yyyy-MM-dd HH:mm'}} + {{ item.updateTime | date: 'yyyy-MM-dd HH:mm'}} + + 编辑 + + 删除 + + + + + + + + + + + + + + +
+ + 标题 + + -
+ + 业务类型 + + + + + + + + 上级类型 + + + + + + 上传图片 + + +
+ +
上传图片
+
+
+ + + + + -
- - - -
-
- + + + +
+ diff --git a/src/app/pages/goods/goods-type/goods-type.component.ts b/src/app/pages/goods/goods-type/goods-type.component.ts index ec88c62..884de7c 100644 --- a/src/app/pages/goods/goods-type/goods-type.component.ts +++ b/src/app/pages/goods/goods-type/goods-type.component.ts @@ -4,48 +4,250 @@ import {NzButtonComponent} from "ng-zorro-antd/button"; import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzInputDirective} from "ng-zorro-antd/input"; -import {NgForOf} from "@angular/common"; -import {goodsTypeSearch} from "../../../data/goods/goods.namespace"; +import {DatePipe, NgForOf, NgIf, NgStyle} from "@angular/common"; import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; +import {GoodsTypeData} from "../../../model/goods.interface"; +import {NzModalModule} from "ng-zorro-antd/modal"; +import {DictionaryPipe} from "../../../pipes/common/dictionary.pipe"; +import {NzUploadComponent, NzUploadFile} from "ng-zorro-antd/upload"; +import {NzIconDirective} from "ng-zorro-antd/icon"; +import {NzMessageService} from "ng-zorro-antd/message"; +import {environment} from "../../../../environments/environment"; +import {CommonService} from "../../../services/common/common.service"; +import {GoodsService} from "../../../services/goods/goods.service"; +import {NzTableComponent, NzTableModule, NzTdAddOnComponent} from "ng-zorro-antd/table"; +import {NzImageDirective , NzImageModule} from "ng-zorro-antd/image"; +import {fallbackImg} from "../../../data/goods/goods.namespace"; +import {NzTreeSelectComponent} from "ng-zorro-antd/tree-select"; +import {NzDividerComponent} from "ng-zorro-antd/divider"; +import {it} from "node:test"; +import {NzPopconfirmDirective} from "ng-zorro-antd/popconfirm"; + +const getBase64 = (file: File): Promise => + new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = () => resolve(reader.result); + reader.onerror = error => reject(error); + }); @Component({ selector: 'app-goods-type', standalone: true, - imports: [ - FormsModule, - NzButtonComponent, - NzColDirective, - NzFormControlComponent, - NzFormDirective, - NzFormItemComponent, - NzFormLabelComponent, - NzInputDirective, - NzRowDirective, - ReactiveFormsModule, - NgForOf, - NzOptionComponent, - NzSelectComponent - ], + imports: [ + FormsModule, + NzButtonComponent, + NzColDirective, + NzFormControlComponent, + NzFormDirective, + NzFormItemComponent, + NzFormLabelComponent, + NzInputDirective, + NzRowDirective, + ReactiveFormsModule, + NgForOf, + NzOptionComponent, + NzSelectComponent, + NzModalModule, + NgIf, + NzUploadComponent, + NzIconDirective, + NzImageModule, + NgStyle, + NzTableComponent, + NzTdAddOnComponent, + NzTableModule, + DictionaryPipe, + DatePipe, + NzImageDirective, + NzTreeSelectComponent, + NzDividerComponent, + NzPopconfirmDirective + ], templateUrl: './goods-type.component.html', styleUrl: './goods-type.component.less' }) export class GoodsTypeComponent { - // 搜索表单 - searchForm: FormGroup; - constructor(private fb: NonNullableFormBuilder) { - // 初始化搜索框 - this.searchForm = this.fb.group({ - title: [''], + // 编辑产品类型表单 + editGoodSTypeForm: FormGroup; + // 列表数据 + listOfMapData: GoodsTypeData[] = []; + // 列表展示数据 + mapOfExpandedData: { [id: string]: GoodsTypeData[] } = {}; + + // 编辑弹出框 + isVisibleEdit = false; + // 商品類型數據字典 + goodsTypeArray; + // 上传等待 + loading = false; + // 图片 + imgUrl: NzUploadFile[] = [] + baseUrl = environment.baseUrl; + imageUrl = environment.imageUrl; + + // 展示图片 + previewImage: string | undefined = ''; + // 上传是否展示 + previewVisible = false; + nodes = []; + + constructor( + private fb: NonNullableFormBuilder, + private commonService: CommonService, + private goodsType: GoodsService, + private msg: NzMessageService + ) { + + this.getRequest(); + // 菜单类型 + this.goodsTypeArray = new DictionaryPipe().getDictionaryList('GOODS_TYPE'); + // 初始化 + this.editGoodSTypeForm = this.fb.group({ + title: ['' , [Validators.required]], parentId: [''], - businessType: [''], + id: [null], + businessType: ['' ,[Validators.required]], + imgUrl: [''], }); } + getNode(array: any): any { + array.forEach((item: any) => { + if (item.children) { + this.getNode(item.children); + }else { + item["isLeaf"] = true; + } + item["key"] = item.id; + + }); + this.nodes = array; + } + + // 关闭 + collapse(array: GoodsTypeData[], data: GoodsTypeData, $event: boolean): void { + if (!$event) { + if (data.children) { + data.children.forEach(d => { + const target = array.find(a => a.id === d.id)!; + target.expand = false; + this.collapse(array, target, false); + }); + } else { + return; + } + } + } + + // 配置数据 + convertTreeToList(root: GoodsTypeData): GoodsTypeData[] { + const stack: GoodsTypeData[] = []; + const array: GoodsTypeData[] = []; + const hashMap = {}; + stack.push({ ...root, level: 0, expand: false }); + while (stack.length !== 0) { + const node = stack.pop()!; + this.visitNode(node, hashMap, array); + if (node.children) { + for (let i = node.children.length - 1; i >= 0; i--) { + stack.push({ ...node.children[i], level: node.level! + 1, expand: false, parent: node }); + } + } + } + return array; + } + + + + // 插入数据 + visitNode(node: GoodsTypeData, hashMap: { [key: string]: boolean }, array: GoodsTypeData[]): void { + if (!hashMap[node.id]) { + hashMap[node.id] = true; + array.push(node); + } + } + + // 搜索表单提交 - searchFormSubmit(): void { + getRequest(): void { + this.loading = true; + this.goodsType.getList({time: new Date().getTime()}, (data: any) => { + if (data['return_code'] === '000000') { + this.listOfMapData = data['return_data']; + this.getNode(this.listOfMapData); + this.listOfMapData.forEach(item => { + this.mapOfExpandedData[item.id] = this.convertTreeToList(item); + }); + } else { + this.msg.error(data['return_msg']); + } + this.loading = false; + }); + } + + // 唤醒编辑表单 + showEditGoodsType(item?: GoodsTypeData) { + if (item != null) { + item.businessType = String(item.businessType); + this.editGoodSTypeForm.patchValue(item); + if (!this.commonService.whetherStringIsNull(item.imgUrl)) { + this.imgUrl = this.commonService.stitchImg(item.imgUrl); + } + } + this.isVisibleEdit = true; + } + // 编辑表单提交 + handleEdit(): void { + if (this.editGoodSTypeForm.valid) { + if (this.imgUrl.length !== 0) { + this.editGoodSTypeForm.value.imgUrl = this.commonService.imgList(this.imgUrl); + } + this.goodsType.editGoodsType(this.editGoodSTypeForm.value , (data: any) => { + if (data['return_code'] === '000000') { + this.msg.success("成功!"); + this.isVisibleEdit = false; + this.getRequest(); + } else { + this.msg.error(data['return_msg']); + } + + }); + } else { + Object.values(this.editGoodSTypeForm.controls).forEach(control => { + if (control.invalid) { + control.markAsDirty(); + control.updateValueAndValidity({ onlySelf: true }); + } + }); + } + } - protected readonly goodsTypeSearch = goodsTypeSearch; + // 删除 + delete(id: number): void { + this.goodsType.delete(id , (data: any) => { + if (data['return_code'] === '000000') { + this.msg.success("成功!"); + this.getRequest(); + } else { + this.msg.error(data['return_msg']); + } + }); + } + + // 上传操作 + handlePreview = async (file: NzUploadFile): Promise => { + console.log("数据" , file); + if (!file.url && !file['preview']) { + file['preview'] = await getBase64(file.originFileObj!); + } + this.previewImage = file.url || file['preview']; + this.previewVisible = true; + }; + + + protected readonly fallbackImg = fallbackImg; } diff --git a/src/app/pages/goods/goods.routes.ts b/src/app/pages/goods/goods.routes.ts index 02f1bbb..a6aacef 100644 --- a/src/app/pages/goods/goods.routes.ts +++ b/src/app/pages/goods/goods.routes.ts @@ -1,8 +1,10 @@ import { Routes } from '@angular/router'; import {GoodsTypeComponent} from "./goods-type/goods-type.component"; +import {GoodsBrandComponent} from "./goods-brand/goods-brand.component"; export const GOODS_ROUTES: Routes = [ { path: 'goods_type', component: GoodsTypeComponent}, + { path: 'goods_brand', component: GoodsBrandComponent}, ]; diff --git a/src/app/pipes/goods/goods-type.pipe.ts b/src/app/pipes/goods/goods-type.pipe.ts new file mode 100644 index 0000000..3d783d5 --- /dev/null +++ b/src/app/pipes/goods/goods-type.pipe.ts @@ -0,0 +1,13 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'goodsType', + standalone: true +}) +export class GoodsTypePipe implements PipeTransform { + + transform(value: unknown, ...args: unknown[]): unknown { + return null; + } + +} diff --git a/src/app/services/common/common.service.ts b/src/app/services/common/common.service.ts index 50d5351..5370216 100644 --- a/src/app/services/common/common.service.ts +++ b/src/app/services/common/common.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import {HttpClient} from "@angular/common/http"; import {environment} from "../../../environments/environment"; import {ObjectData} from "../../utils/objectData.service"; +import {NzUploadFile} from "ng-zorro-antd/upload"; @Injectable({ providedIn: 'root' @@ -26,4 +27,66 @@ export class CommonService { callBack(data); }); } + + /** + * + * 查询数据字典 + * @param imgData 【必填】 图片数据 + */ + public imgList(imgData: NzUploadFile[]): string { + if (imgData[0]['response'] != null) { + return imgData[0]['response']['return_data'][0]; + } else { + return imgData[0].name; + } + } + + /** + * + * 拼接图片 + * @param imgArray 【必填】 图片数据 + */ + public postImg(imgArray: any): any { + const array = []; + for (const i of imgArray) { + if (i['response'] != null) { + array.push(i['response']['return_data'][0]); + } else { + array.push(i.name); + } + } + + return array.join(','); + } + + /** + * + * 拼接图片数组 + * @param imgUrl 【必填】 图片数据 + */ + public stitchImg(imgUrl: string): any { + const imgArray = []; + for (const i of imgUrl.split(',')) { + imgArray.push( + { + uid: 1, + name: i, + status: 'done', + url: environment.imageUrl + i + }); + } + console.log(imgArray); + return imgArray; + } + + + // 判断字符串是否为空 + public whetherStringIsNull(s: string): boolean { + if (s != null && s !== '') { + return false; + } else { + return true; + } + } + } diff --git a/src/app/services/goods/goods.service.ts b/src/app/services/goods/goods.service.ts index 07cc805..38faae0 100644 --- a/src/app/services/goods/goods.service.ts +++ b/src/app/services/goods/goods.service.ts @@ -1,9 +1,80 @@ import { Injectable } from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {environment} from "../../../environments/environment"; +import {ObjectData} from "../../utils/objectData.service"; @Injectable({ providedIn: 'root' }) export class GoodsService { - constructor() { } + constructor(private http: HttpClient) { } + + + /** + * 编辑商品类型 + * @param params + * @param callBack + */ + public editGoodsType(params: object, callBack:any) { + this.http.post(environment.baseUrl + 'goodsType/editGoodsType', params).subscribe(data => { + callBack(data); + }); + } + + /** + * 查询列表 + * @param params + * @param callBack + */ + public getList(params: object, callBack:any) { + this.http.get(environment.baseUrl + 'goodsType/getList?' + ObjectData.objectByString(params)).subscribe(data => { + callBack(data); + }); + } + + /** + * 删除 + * @param id + * @param callBack + */ + public delete(id: number, callBack:any) { + this.http.get(environment.baseUrl + 'goodsType/delete?id=' + id ).subscribe(data => { + callBack(data); + }); + } + + /** + * 编辑商品类型 + * @param params + * @param callBack + */ + public editGoodsBrand(params: object, callBack:any) { + this.http.post(environment.baseUrl + 'goodsBrand/editGoodsBrand', params).subscribe(data => { + callBack(data); + }); + } + + /** + * 查询列表 + * @param params + * @param callBack + */ + public getListBrand(params: object, callBack:any) { + this.http.get(environment.baseUrl + 'goodsBrand/getListBrand?' + ObjectData.objectByString(params)).subscribe(data => { + callBack(data); + }); + } + + /** + * 删除 + * @param id + * @param callBack + */ + public deleteBran(id: number, callBack:any) { + this.http.get(environment.baseUrl + 'goodsBrand/delete?id=' + id ).subscribe(data => { + callBack(data); + }); + } + }