|
|
|
@ -12,7 +12,7 @@ import {NzMessageService} from "ng-zorro-antd/message"; |
|
|
|
|
import {CommonService} from "../../../services/common/common.service"; |
|
|
|
|
import {GoodsService} from "../../../services/goods/goods.service"; |
|
|
|
|
import { fallbackImg } from '../../../data/goods/goods.namespace'; |
|
|
|
|
import {GoodsTypeData} from "../../../model/goods.interface"; |
|
|
|
|
import {GoodsMsgData, GoodsTypeData, SpecsData} from "../../../model/goods.interface"; |
|
|
|
|
import {NzDividerComponent} from "ng-zorro-antd/divider"; |
|
|
|
|
import {NzIconDirective} from "ng-zorro-antd/icon"; |
|
|
|
|
import {NzImageDirective, NzImageModule} from "ng-zorro-antd/image"; |
|
|
|
@ -26,6 +26,16 @@ import {NzTreeSelectComponent} from "ng-zorro-antd/tree-select"; |
|
|
|
|
import {DictionaryPipe} from "../../../pipes/common/dictionary.pipe"; |
|
|
|
|
import {GoodsStatusPipe} from "../../../pipes/goods/goods-status.pipe"; |
|
|
|
|
import {NzConfigService} from "ng-zorro-antd/core/config"; |
|
|
|
|
import {NzDropDownADirective, NzDropDownDirective, NzDropdownMenuComponent} from "ng-zorro-antd/dropdown"; |
|
|
|
|
import {NzMenuDirective, NzMenuItemComponent} from "ng-zorro-antd/menu"; |
|
|
|
|
import { |
|
|
|
|
NzInputNumberComponent, |
|
|
|
|
NzInputNumberGroupComponent, |
|
|
|
|
NzInputNumberGroupWhitSuffixOrPrefixDirective |
|
|
|
|
} from "ng-zorro-antd/input-number"; |
|
|
|
|
import {NzSpaceItemDirective} from "ng-zorro-antd/space"; |
|
|
|
|
import {NzDatePickerComponent} from "ng-zorro-antd/date-picker"; |
|
|
|
|
import {NzTypographyComponent} from "ng-zorro-antd/typography"; |
|
|
|
|
|
|
|
|
|
const getBase64 = (file: File): Promise<string | ArrayBuffer | null> => |
|
|
|
|
new Promise((resolve, reject) => { |
|
|
|
@ -67,7 +77,18 @@ const getBase64 = (file: File): Promise<string | ArrayBuffer | null> => |
|
|
|
|
NzTreeSelectComponent, |
|
|
|
|
NzDividerComponent, |
|
|
|
|
NzPopconfirmDirective, |
|
|
|
|
GoodsStatusPipe |
|
|
|
|
GoodsStatusPipe, |
|
|
|
|
NzDropDownADirective, |
|
|
|
|
NzDropDownDirective, |
|
|
|
|
NzDropdownMenuComponent, |
|
|
|
|
NzMenuDirective, |
|
|
|
|
NzMenuItemComponent, |
|
|
|
|
NzInputNumberComponent, |
|
|
|
|
NzInputNumberGroupWhitSuffixOrPrefixDirective, |
|
|
|
|
NzSpaceItemDirective, |
|
|
|
|
NzInputNumberGroupComponent, |
|
|
|
|
NzDatePickerComponent, |
|
|
|
|
NzTypographyComponent |
|
|
|
|
], |
|
|
|
|
templateUrl: './goods-list.component.html', |
|
|
|
|
styleUrl: './goods-list.component.less' |
|
|
|
@ -88,6 +109,7 @@ export class GoodsListComponent { |
|
|
|
|
listImg: NzUploadFile[] = [] |
|
|
|
|
bannerImg: NzUploadFile[] = [] |
|
|
|
|
detailImg: NzUploadFile[] = [] |
|
|
|
|
showImg: NzUploadFile[] = [] |
|
|
|
|
baseUrl = environment.baseUrl; |
|
|
|
|
imageUrl = environment.imageUrl; |
|
|
|
|
|
|
|
|
@ -98,11 +120,20 @@ export class GoodsListComponent { |
|
|
|
|
|
|
|
|
|
// 编辑产品类型表单
|
|
|
|
|
editForm: FormGroup; |
|
|
|
|
editSpecsForm: FormGroup; |
|
|
|
|
// 编辑弹出框
|
|
|
|
|
isVisibleEdit = false; |
|
|
|
|
// 编辑商品规格弹出框
|
|
|
|
|
isVisibleSpecs = false; |
|
|
|
|
editSpecs = false; |
|
|
|
|
loadingSpecs = false; |
|
|
|
|
// 商品类型数据
|
|
|
|
|
nodes = []; |
|
|
|
|
nodesBrand = []; |
|
|
|
|
nodesSpecs:SpecsData[] = []; |
|
|
|
|
nodesVpdSource; |
|
|
|
|
goodsMsg?: GoodsMsgData; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected readonly fallbackImg = fallbackImg; |
|
|
|
|
|
|
|
|
@ -111,6 +142,9 @@ export class GoodsListComponent { |
|
|
|
|
|
|
|
|
|
private commonService: CommonService, |
|
|
|
|
private goodsService: GoodsService) { |
|
|
|
|
|
|
|
|
|
this.nodesVpdSource = new DictionaryPipe().getDictionaryList('GOODS_VPD_SOURCE'); |
|
|
|
|
|
|
|
|
|
// 初始化搜索框
|
|
|
|
|
this.searchForm = this.fb.group({ |
|
|
|
|
title: [''], |
|
|
|
@ -130,6 +164,25 @@ export class GoodsListComponent { |
|
|
|
|
goodsLabel: [''], |
|
|
|
|
goodsExplain: [''], |
|
|
|
|
}); |
|
|
|
|
// 初始化
|
|
|
|
|
this.editSpecsForm = this.fb.group({ |
|
|
|
|
name: ['' , [Validators.required]], |
|
|
|
|
purLimit: ['' , [Validators.required]], |
|
|
|
|
salePrice: ['' , [Validators.required]], |
|
|
|
|
originalPrice: ['' , [Validators.required]], |
|
|
|
|
stock: ['' , [Validators.required]], |
|
|
|
|
validDay: ['' , [Validators.required]], |
|
|
|
|
salesEndTime: ['' , [Validators.required]], |
|
|
|
|
type: [''], |
|
|
|
|
source: [''], |
|
|
|
|
id: [null], |
|
|
|
|
specsId: [null], |
|
|
|
|
jumpType: [null], |
|
|
|
|
jumpUrl: [null], |
|
|
|
|
goodsId: [null], |
|
|
|
|
appid: [null], |
|
|
|
|
key: [''], |
|
|
|
|
}); |
|
|
|
|
this.getRequest(); |
|
|
|
|
this.getGoodsTypeNode(); |
|
|
|
|
this.getGoodsBrandNode(); |
|
|
|
@ -160,7 +213,8 @@ export class GoodsListComponent { |
|
|
|
|
// 唤醒编辑表单
|
|
|
|
|
showEdit(item?: any) { |
|
|
|
|
if (item != null) { |
|
|
|
|
item.businessType = String(item.businessType); |
|
|
|
|
item.goodsBrand = String(item.goodsBrand); |
|
|
|
|
item.type = String(item.type); |
|
|
|
|
this.editForm.patchValue(item); |
|
|
|
|
if (!this.commonService.whetherStringIsNull(item.listImg)) { |
|
|
|
|
this.listImg = this.commonService.stitchImg(item.listImg); |
|
|
|
@ -171,6 +225,8 @@ export class GoodsListComponent { |
|
|
|
|
if (!this.commonService.whetherStringIsNull(item.detailImg)) { |
|
|
|
|
this.detailImg = this.commonService.stitchImg(item.detailImg); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.editForm.reset() |
|
|
|
|
} |
|
|
|
|
this.isVisibleEdit = true; |
|
|
|
|
} |
|
|
|
@ -181,17 +237,20 @@ export class GoodsListComponent { |
|
|
|
|
if (this.listImg.length !== 0) { |
|
|
|
|
this.editForm.value.listImg = this.commonService.imgList(this.listImg); |
|
|
|
|
} else { |
|
|
|
|
this.msg.error("请上传列表图片") |
|
|
|
|
this.msg.error("请上传列表图片"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (this.bannerImg.length !== 0) { |
|
|
|
|
this.editForm.value.bannerImg = this.commonService.imgList(this.bannerImg); |
|
|
|
|
} else { |
|
|
|
|
this.msg.error("请上传轮播图片") |
|
|
|
|
this.msg.error("请上传轮播图片"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (this.detailImg.length !== 0) { |
|
|
|
|
this.editForm.value.detailImg = this.commonService.imgList(this.detailImg); |
|
|
|
|
} else { |
|
|
|
|
this.msg.error("请上传详情图片") |
|
|
|
|
this.msg.error("请上传详情图片"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.goodsService.editGoodsMsg(this.editForm.value , (data: any) => { |
|
|
|
@ -225,7 +284,7 @@ export class GoodsListComponent { |
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
delete(id: number): void { |
|
|
|
|
this.goodsService.deleteBran(id , (data: any) => { |
|
|
|
|
this.goodsService.deleteGoodsMsg(id , (data: any) => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.msg.success("成功!"); |
|
|
|
|
this.getRequest(); |
|
|
|
@ -235,6 +294,18 @@ export class GoodsListComponent { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
deleteGoodsSpecs(id: number): void { |
|
|
|
|
this.goodsService.deleteGoodsSpecs(id , (data: any) => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.msg.success("成功!"); |
|
|
|
|
this.getSpecsList(); |
|
|
|
|
} else { |
|
|
|
|
this.msg.error(data['return_msg']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取商品分类
|
|
|
|
|
getGoodsTypeNode() { |
|
|
|
|
this.goodsService.getList({time: new Date().getTime()}, (data: any) => { |
|
|
|
@ -267,4 +338,128 @@ export class GoodsListComponent { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 弹出
|
|
|
|
|
showSpecsList(data: any): void { |
|
|
|
|
this.goodsMsg = data; |
|
|
|
|
this.isVisibleSpecs = true; |
|
|
|
|
|
|
|
|
|
if (data.type == "1") { |
|
|
|
|
this.editSpecsForm.controls['type'].clearValidators(); |
|
|
|
|
this.editSpecsForm.controls['type'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
this.editSpecsForm.controls['source'].clearValidators(); |
|
|
|
|
this.editSpecsForm.controls['source'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
this.editSpecsForm.controls['validDay'].clearValidators(); |
|
|
|
|
this.editSpecsForm.controls['validDay'].markAsPristine(); |
|
|
|
|
} else { |
|
|
|
|
this.editSpecsForm.controls['type'].setValidators(Validators.required); |
|
|
|
|
this.editSpecsForm.controls['type'].markAsDirty(); |
|
|
|
|
|
|
|
|
|
this.editSpecsForm.controls['source'].setValidators(Validators.required); |
|
|
|
|
this.editSpecsForm.controls['source'].markAsDirty(); |
|
|
|
|
|
|
|
|
|
this.editSpecsForm.controls['validDay'].setValidators(Validators.required); |
|
|
|
|
this.editSpecsForm.controls['validDay'].markAsDirty(); |
|
|
|
|
} |
|
|
|
|
this.editSpecsForm.controls['type'].updateValueAndValidity(); |
|
|
|
|
this.editSpecsForm.controls['validDay'].updateValueAndValidity(); |
|
|
|
|
this.editSpecsForm.controls['source'].updateValueAndValidity(); |
|
|
|
|
|
|
|
|
|
this.getSpecsList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询规格列表
|
|
|
|
|
getSpecsList(): void { |
|
|
|
|
this.loadingSpecs = true; |
|
|
|
|
let params = { |
|
|
|
|
id: this.goodsMsg?.id, |
|
|
|
|
time: new Date().getTime() |
|
|
|
|
} |
|
|
|
|
this.goodsService.getGoodsSpecsList(params , (data: any) => { |
|
|
|
|
this.loadingSpecs = false; |
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
this.nodesSpecs = data['return_data']; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
// 添加规格
|
|
|
|
|
showEditSpecs(item?: any): void { |
|
|
|
|
|
|
|
|
|
if (item != null) { |
|
|
|
|
item.source = String(item.source); |
|
|
|
|
item.type = String(item.type); |
|
|
|
|
item.jumpType = String(item.jumpType); |
|
|
|
|
this.editSpecsForm.patchValue(item); |
|
|
|
|
if (!this.commonService.whetherStringIsNull(item.showImg)) { |
|
|
|
|
this.showImg = this.commonService.stitchImg(item.showImg); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.editSpecsForm.reset() |
|
|
|
|
} |
|
|
|
|
this.editSpecs = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleEditSpecs(): void { |
|
|
|
|
if (this.editSpecsForm.valid) { |
|
|
|
|
if (this.showImg.length !== 0) { |
|
|
|
|
this.editSpecsForm.value.showImg = this.commonService.imgList(this.showImg); |
|
|
|
|
} else { |
|
|
|
|
this.msg.error("请上传展示图片"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.editSpecsForm.value.goodsId = this.goodsMsg?.id; |
|
|
|
|
this.goodsService.editGoodsSpecs(this.editSpecsForm.value , (data: any) => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.msg.success("成功!"); |
|
|
|
|
this.editSpecs = false; |
|
|
|
|
this.getSpecsList(); |
|
|
|
|
} else { |
|
|
|
|
this.msg.error(data['return_msg']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
Object.values(this.editSpecsForm.controls).forEach(control => { |
|
|
|
|
if (control.invalid) { |
|
|
|
|
control.markAsDirty(); |
|
|
|
|
control.updateValueAndValidity({ onlySelf: true }); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typeChange(type: string): void { |
|
|
|
|
if (type == "1") { |
|
|
|
|
this.editSpecsForm.controls['jumpType'].clearValidators(); |
|
|
|
|
this.editSpecsForm.controls['jumpType'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
this.editSpecsForm.controls['jumpUrl'].clearValidators(); |
|
|
|
|
this.editSpecsForm.controls['jumpUrl'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
this.editSpecsForm.controls['jumpType'].setValidators(Validators.required); |
|
|
|
|
this.editSpecsForm.controls['jumpType'].markAsDirty(); |
|
|
|
|
|
|
|
|
|
this.editSpecsForm.controls['jumpUrl'].setValidators(Validators.required); |
|
|
|
|
this.editSpecsForm.controls['jumpUrl'].markAsDirty(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
this.editSpecsForm.controls['jumpUrl'].updateValueAndValidity(); |
|
|
|
|
this.editSpecsForm.controls['jumpType'].updateValueAndValidity(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
jumpTypeChange(type: string): void { |
|
|
|
|
console.log("type" , type); |
|
|
|
|
if (type == "2") { |
|
|
|
|
this.editSpecsForm.controls['appid'].clearValidators(); |
|
|
|
|
this.editSpecsForm.controls['appid'].markAsPristine(); |
|
|
|
|
} else { |
|
|
|
|
this.editSpecsForm.controls['appid'].setValidators(Validators.required); |
|
|
|
|
this.editSpecsForm.controls['appid'].markAsDirty(); |
|
|
|
|
} |
|
|
|
|
this.editSpecsForm.controls['appid'].updateValueAndValidity(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|