|
|
|
@ -1,17 +1,18 @@ |
|
|
|
|
import { Component } from '@angular/core'; |
|
|
|
|
import {DatePipe, NgForOf, NgOptimizedImage, NgStyle} from "@angular/common"; |
|
|
|
|
import {DatePipe, NgForOf, NgIf, 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 {NzModalComponent, NzModalContentDirective, NzModalModule} from "ng-zorro-antd/modal"; |
|
|
|
|
import {FormGroup, NonNullableFormBuilder, ReactiveFormsModule, Validators} from "@angular/forms"; |
|
|
|
|
import {FormGroup, FormsModule, NonNullableFormBuilder, ReactiveFormsModule, Validators} from "@angular/forms"; |
|
|
|
|
import {NzIconDirective} from "ng-zorro-antd/icon"; |
|
|
|
|
import {NzTreeSelectComponent} from "ng-zorro-antd/tree-select"; |
|
|
|
|
import {NzUploadComponent, NzUploadFile} from "ng-zorro-antd/upload"; |
|
|
|
|
import {NzDividerComponent} from "ng-zorro-antd/divider"; |
|
|
|
|
import { |
|
|
|
|
NzCellFixedDirective, |
|
|
|
|
NzTableCellDirective, |
|
|
|
|
NzTableComponent, |
|
|
|
|
NzTbodyComponent, |
|
|
|
@ -23,9 +24,20 @@ import {NzImageModule} from "ng-zorro-antd/image"; |
|
|
|
|
import {environment} from "../../../../environments/environment"; |
|
|
|
|
import {NzMessageService} from "ng-zorro-antd/message"; |
|
|
|
|
import {CommonService} from "../../../services/common/common.service"; |
|
|
|
|
import {GoodsService} from "../../../services/goods/goods.service"; |
|
|
|
|
import {GoodsTypeData} from "../../../model/goods.interface"; |
|
|
|
|
import { fallbackImg } from '../../../data/goods/goods.namespace'; |
|
|
|
|
import {DiscountService} from "../../../services/marketing/discount.service"; |
|
|
|
|
import {DictionaryPipe} from "../../../pipes/common/dictionary.pipe"; |
|
|
|
|
import { |
|
|
|
|
NzInputNumberComponent, |
|
|
|
|
NzInputNumberGroupComponent, |
|
|
|
|
NzInputNumberGroupWhitSuffixOrPrefixDirective |
|
|
|
|
} from "ng-zorro-antd/input-number"; |
|
|
|
|
import {NzDatePickerComponent} from "ng-zorro-antd/date-picker"; |
|
|
|
|
import {NzTypographyComponent} from "ng-zorro-antd/typography"; |
|
|
|
|
import {DiscountData, NodesDiscountGoods} from "../../../model/discount.interface"; |
|
|
|
|
import {GoodsService} from "../../../services/goods/goods.service"; |
|
|
|
|
import {NzDropDownADirective, NzDropDownDirective, NzDropdownMenuComponent} from "ng-zorro-antd/dropdown"; |
|
|
|
|
import {NzMenuDirective, NzMenuItemComponent} from "ng-zorro-antd/menu"; |
|
|
|
|
|
|
|
|
|
const getBase64 = (file: File): Promise<string | ArrayBuffer | null> => |
|
|
|
|
new Promise((resolve, reject) => { |
|
|
|
@ -68,7 +80,21 @@ const getBase64 = (file: File): Promise<string | ArrayBuffer | null> => |
|
|
|
|
NzTrDirective, |
|
|
|
|
NzPopconfirmDirective, |
|
|
|
|
NzImageModule, |
|
|
|
|
NgOptimizedImage |
|
|
|
|
NgOptimizedImage, |
|
|
|
|
DictionaryPipe, |
|
|
|
|
NzCellFixedDirective, |
|
|
|
|
NgIf, |
|
|
|
|
NzInputNumberComponent, |
|
|
|
|
NzInputNumberGroupComponent, |
|
|
|
|
NzInputNumberGroupWhitSuffixOrPrefixDirective, |
|
|
|
|
NzDatePickerComponent, |
|
|
|
|
NzTypographyComponent, |
|
|
|
|
FormsModule, |
|
|
|
|
NzDropDownADirective, |
|
|
|
|
NzDropDownDirective, |
|
|
|
|
NzDropdownMenuComponent, |
|
|
|
|
NzMenuDirective, |
|
|
|
|
NzMenuItemComponent |
|
|
|
|
], |
|
|
|
|
templateUrl: './discount-list.component.html', |
|
|
|
|
styleUrl: './discount-list.component.less' |
|
|
|
@ -86,7 +112,7 @@ export class DiscountListComponent { |
|
|
|
|
searchForm: FormGroup; |
|
|
|
|
|
|
|
|
|
// 图片
|
|
|
|
|
imgUrl: NzUploadFile[] = [] |
|
|
|
|
img: NzUploadFile[] = [] |
|
|
|
|
baseUrl = environment.baseUrl; |
|
|
|
|
imageUrl = environment.imageUrl; |
|
|
|
|
|
|
|
|
@ -94,30 +120,50 @@ export class DiscountListComponent { |
|
|
|
|
previewImage: string | undefined = ''; |
|
|
|
|
// 上传是否展示
|
|
|
|
|
previewVisible = false; |
|
|
|
|
isVisibleSpecsDiscount = false; |
|
|
|
|
|
|
|
|
|
// 编辑产品类型表单
|
|
|
|
|
editForm: FormGroup; |
|
|
|
|
// 编辑弹出框
|
|
|
|
|
isVisibleEdit = false; |
|
|
|
|
|
|
|
|
|
isVisibleBind = false; |
|
|
|
|
discountType; |
|
|
|
|
discount?: DiscountData; |
|
|
|
|
nodesDiscountGoods:NodesDiscountGoods[] = []; |
|
|
|
|
listOfSelectBind: any = [] |
|
|
|
|
goodsSpecs:any = []; |
|
|
|
|
protected readonly fallbackImg = fallbackImg; |
|
|
|
|
|
|
|
|
|
constructor(private fb: NonNullableFormBuilder, |
|
|
|
|
private msg: NzMessageService, |
|
|
|
|
private commonService: CommonService, |
|
|
|
|
private goodsService: GoodsService) { |
|
|
|
|
private goodsService: GoodsService, |
|
|
|
|
private discountService: DiscountService) { |
|
|
|
|
|
|
|
|
|
this.discountType = new DictionaryPipe().getDictionaryList('DISCOUNT_TYPE'); |
|
|
|
|
|
|
|
|
|
// 初始化搜索框
|
|
|
|
|
this.searchForm = this.fb.group({ |
|
|
|
|
title: [''], |
|
|
|
|
name: [''], |
|
|
|
|
type: [''], |
|
|
|
|
status: [''], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 初始化
|
|
|
|
|
this.editForm = this.fb.group({ |
|
|
|
|
title: ['' , [Validators.required]], |
|
|
|
|
name: ['' , [Validators.required]], |
|
|
|
|
type: ['' , [Validators.required]], |
|
|
|
|
effectiveNum: ['' , [Validators.required]], |
|
|
|
|
effectiveDay: ['' , [Validators.required]], |
|
|
|
|
salesEndTime: ['' , [Validators.required]], |
|
|
|
|
condition: ['' , [Validators.required]], |
|
|
|
|
price: ['' , [Validators.required]], |
|
|
|
|
percentage: ['' , [Validators.required]], |
|
|
|
|
img: [''], |
|
|
|
|
id: [null], |
|
|
|
|
imgUrl: [''], |
|
|
|
|
}); |
|
|
|
|
this.getRequest(); |
|
|
|
|
this.getGoodsSpecsListAll(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -131,7 +177,7 @@ export class DiscountListComponent { |
|
|
|
|
this.searchForm.value.pageSize = 10; |
|
|
|
|
this.searchForm.value.time = new Date().getTime(); |
|
|
|
|
|
|
|
|
|
this.goodsService.getListBrand(this.searchForm.value , (data: any) => { |
|
|
|
|
this.discountService.getListDiscount(this.searchForm.value , (data: any) => { |
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
this.tableData = data['return_data']; |
|
|
|
|
} else { |
|
|
|
@ -143,24 +189,26 @@ export class DiscountListComponent { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 唤醒编辑表单
|
|
|
|
|
showEdit(item?: GoodsTypeData) { |
|
|
|
|
showEdit(item?: any) { |
|
|
|
|
if (item != null) { |
|
|
|
|
item.businessType = String(item.businessType); |
|
|
|
|
item.type = String(item.type); |
|
|
|
|
this.typeChange(item.type) |
|
|
|
|
this.editForm.patchValue(item); |
|
|
|
|
if (!this.commonService.whetherStringIsNull(item.imgUrl)) { |
|
|
|
|
this.imgUrl = this.commonService.stitchImg(item.imgUrl); |
|
|
|
|
if (!this.commonService.whetherStringIsNull(item.img)) { |
|
|
|
|
this.img = this.commonService.stitchImg(item.img); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.editForm.reset(); |
|
|
|
|
} |
|
|
|
|
this.isVisibleEdit = true; |
|
|
|
|
} |
|
|
|
|
// 编辑表单提交
|
|
|
|
|
handleEdit(): void { |
|
|
|
|
|
|
|
|
|
if (this.editForm.valid) { |
|
|
|
|
if (this.imgUrl.length !== 0) { |
|
|
|
|
this.editForm.value.imgUrl = this.commonService.imgList(this.imgUrl); |
|
|
|
|
if (this.img.length !== 0) { |
|
|
|
|
this.editForm.value.img = this.commonService.imgList(this.img); |
|
|
|
|
} |
|
|
|
|
this.goodsService.editGoodsBrand(this.editForm.value , (data: any) => { |
|
|
|
|
this.discountService.editDiscount(this.editForm.value , (data: any) => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.msg.success("成功!"); |
|
|
|
|
this.isVisibleEdit = false; |
|
|
|
@ -191,7 +239,7 @@ export class DiscountListComponent { |
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
delete(id: number): void { |
|
|
|
|
this.goodsService.deleteBran(id , (data: any) => { |
|
|
|
|
this.discountService.deleteDiscount(id , (data: any) => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.msg.success("成功!"); |
|
|
|
|
this.getRequest(); |
|
|
|
@ -200,4 +248,84 @@ export class DiscountListComponent { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typeChange(type: string): void { |
|
|
|
|
if (type == "1") { |
|
|
|
|
this.editForm.controls['percentage'].clearValidators(); |
|
|
|
|
this.editForm.controls['percentage'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
} else if (type == "2") { |
|
|
|
|
this.editForm.controls['percentage'].clearValidators(); |
|
|
|
|
this.editForm.controls['percentage'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
this.editForm.controls['condition'].clearValidators(); |
|
|
|
|
this.editForm.controls['condition'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
} else if (type == "3") { |
|
|
|
|
this.editForm.controls['price'].clearValidators(); |
|
|
|
|
this.editForm.controls['price'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
this.editForm.controls['condition'].clearValidators(); |
|
|
|
|
this.editForm.controls['condition'].markAsPristine(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
this.editForm.controls['percentage'].updateValueAndValidity(); |
|
|
|
|
this.editForm.controls['condition'].updateValueAndValidity(); |
|
|
|
|
this.editForm.controls['price'].updateValueAndValidity(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
showDiscountSpecsList(item: DiscountData):void { |
|
|
|
|
this.listOfSelectBind = []; |
|
|
|
|
this.discount = item; |
|
|
|
|
this.getSpecsDiscountList(); |
|
|
|
|
this.isVisibleSpecsDiscount = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bindDiscountSpecs():void { |
|
|
|
|
this.isVisibleBind = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询绑定商品列表
|
|
|
|
|
getSpecsDiscountList(): void { |
|
|
|
|
let params = { |
|
|
|
|
discountId: this.discount?.id, |
|
|
|
|
time: new Date().getTime() |
|
|
|
|
} |
|
|
|
|
this.discountService.getListDiscountGoodsRel(params , (data: any) => { |
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
console.log("data" , data); |
|
|
|
|
this.nodesDiscountGoods = data['return_data']; |
|
|
|
|
for (const dataKey of this.nodesDiscountGoods) { |
|
|
|
|
this.listOfSelectBind.push(dataKey['specsId']) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询所有商品规格
|
|
|
|
|
getGoodsSpecsListAll(): void { |
|
|
|
|
this.goodsService.getGoodsSpecsListAll( (data: any) => { |
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
this.goodsSpecs = data['return_data']; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleOk(): void { |
|
|
|
|
let params = { |
|
|
|
|
discountId: this.discount?.id, |
|
|
|
|
specsIds: this.listOfSelectBind.join(",") |
|
|
|
|
} |
|
|
|
|
this.discountService.bindDiscountSpecs(params , (data: any) => { |
|
|
|
|
if (data['return_code'] == '000000') { |
|
|
|
|
this.msg.success("绑定成功"); |
|
|
|
|
this.getSpecsDiscountList(); |
|
|
|
|
this.isVisibleBind = false; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|