From 00831186a55b320a9ac5b1a8e765befc8769c232 Mon Sep 17 00:00:00 2001
From: yuanye <418471657@qq.com>
Date: Wed, 15 May 2024 10:59:57 +0800
Subject: [PATCH] 1
---
src/app/model/discount.interface.ts | 25 +++
.../goods-brand/goods-brand.component.ts | 4 +-
.../discount-list.component.html | 177 ++++++++++++++++--
.../discount-list.component.less | 3 +
.../discount-list/discount-list.component.ts | 170 ++++++++++++++---
src/app/services/goods/goods.service.ts | 13 +-
.../services/marketing/discount.service.ts | 69 +++++++
7 files changed, 421 insertions(+), 40 deletions(-)
create mode 100644 src/app/model/discount.interface.ts
create mode 100644 src/app/services/marketing/discount.service.ts
diff --git a/src/app/model/discount.interface.ts b/src/app/model/discount.interface.ts
new file mode 100644
index 0000000..94295b0
--- /dev/null
+++ b/src/app/model/discount.interface.ts
@@ -0,0 +1,25 @@
+export interface DiscountData {
+ id: number;
+ name: string;
+ img: string;
+ type: number;
+ condition: string;
+ price: string;
+ percentage: string;
+ effectiveDay: number;
+ effectiveNum: number;
+ createTime: string;
+ updateTime: string;
+ salesEndTime: string,
+}
+
+export interface NodesDiscountGoods {
+ id: number;
+ discountId: number;
+ specsId: String;
+ specsName: String;
+ createTime: string;
+ goodsName: string;
+ SpecsName: string;
+ salePrice: string;
+}
diff --git a/src/app/pages/goods/goods-brand/goods-brand.component.ts b/src/app/pages/goods/goods-brand/goods-brand.component.ts
index 0c08a99..47d555e 100644
--- a/src/app/pages/goods/goods-brand/goods-brand.component.ts
+++ b/src/app/pages/goods/goods-brand/goods-brand.component.ts
@@ -150,6 +150,8 @@ export class GoodsBrandComponent {
if (!this.commonService.whetherStringIsNull(item.imgUrl)) {
this.imgUrl = this.commonService.stitchImg(item.imgUrl);
}
+ } else {
+ this.editForm.reset();
}
this.isVisibleEdit = true;
}
@@ -191,7 +193,7 @@ export class GoodsBrandComponent {
// 删除
delete(id: number): void {
- this.goodsService.deleteBran(id , (data: any) => {
+ this.goodsService.deleteBrand(id , (data: any) => {
if (data['return_code'] === '000000') {
this.msg.success("成功!");
this.getRequest();
diff --git a/src/app/pages/marketing/discount-list/discount-list.component.html b/src/app/pages/marketing/discount-list/discount-list.component.html
index 5356fdb..98399d0 100644
--- a/src/app/pages/marketing/discount-list/discount-list.component.html
+++ b/src/app/pages/marketing/discount-list/discount-list.component.html
@@ -2,13 +2,33 @@
- 品牌名称
+ 名称
-
+
+
+
+
+
+
+ 优惠券类型
+
+
+
+
+
+
+
+
+
+ 优惠券状态
+
+
+
+
+
-
@@ -21,6 +41,7 @@
[nzBordered]="true"
[nzFrontPagination]="false"
[nzShowQuickJumper]="true"
+ [nzScroll]="{ x: '1980px' }"
[nzShowTotal]="totalTemplate"
[(nzPageIndex)]="tablePageNum"
(nzPageIndexChange)="getRequest(false)"
@@ -28,25 +49,51 @@
[nzData]="tableData.list" >
- 品牌名称 |
- 品牌图片 |
- 创建时间 |
- 更新时间 |
- 操作 |
+ 优惠券名称 |
+ 优惠券图片 |
+ 优惠券类型 |
+ 优惠内容 |
+ 有效天数 |
+ 领取数量(个) |
+ 使用截止日期 |
+ 创建时间 |
+ 更新时间 |
+ 操作 |
- {{data.title}} |
+ {{data.name}} |
+
+
+ |
+ {{data.type | dictionary: 'DISCOUNT_TYPE'}} |
-
+ 满{{data.condition}}直减{{data.price}}
+ 直减{{data.price}}
+ 优惠{{100 - data.percentage}}%
|
+ {{data.effectiveDay}}天 |
+ {{data.effectiveNum}} |
+ {{ data.salesEndTime | date: 'yyyy-MM-dd HH:mm'}} |
{{ data.createTime | date: 'yyyy-MM-dd HH:mm'}} |
{{ data.updateTime | date: 'yyyy-MM-dd HH:mm'}} |
-
+ |
修改
- 删除
+
+ 更多
+
+
+
+
+
|
@@ -54,24 +101,79 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+ 商品名称 |
+ 规格 |
+ 售价(RMB) |
+ 创建时间 |
+
+
+
+
+ {{data.goodsName}} |
+ {{data.specsName}} |
+ ¥{{data.salePrice}} |
+ {{ data.createTime | date: 'yyyy-MM-dd HH:mm'}} |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/pages/marketing/discount-list/discount-list.component.less b/src/app/pages/marketing/discount-list/discount-list.component.less
index 6d5c351..de21fc1 100644
--- a/src/app/pages/marketing/discount-list/discount-list.component.less
+++ b/src/app/pages/marketing/discount-list/discount-list.component.less
@@ -10,3 +10,6 @@ button {
.search-area {
margin-top: 30px;
}
+nz-select {
+ width: 100%;
+}
diff --git a/src/app/pages/marketing/discount-list/discount-list.component.ts b/src/app/pages/marketing/discount-list/discount-list.component.ts
index bfe82161..be87945 100644
--- a/src/app/pages/marketing/discount-list/discount-list.component.ts
+++ b/src/app/pages/marketing/discount-list/discount-list.component.ts
@@ -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 =>
new Promise((resolve, reject) => {
@@ -68,7 +80,21 @@ const getBase64 = (file: File): Promise =>
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;
+ }
+ });
+ }
}
diff --git a/src/app/services/goods/goods.service.ts b/src/app/services/goods/goods.service.ts
index 7ab3965..49a3e1a 100644
--- a/src/app/services/goods/goods.service.ts
+++ b/src/app/services/goods/goods.service.ts
@@ -77,7 +77,7 @@ export class GoodsService {
* @param id
* @param callBack
*/
- public deleteBran(id: number, callBack:any) {
+ public deleteBrand(id: number, callBack:any) {
this.http.get(environment.baseUrl + 'goodsBrand/delete?id=' + id ).subscribe(data => {
callBack(data);
});
@@ -149,4 +149,15 @@ export class GoodsService {
});
}
+ /**
+ * 获取全部上线中的商品规格
+ * @param callBack
+ */
+ public getGoodsSpecsListAll(callBack:any) {
+ this.http.get(environment.baseUrl + 'goods/getGoodsSpecsListAll?time=' + new Date().getTime()).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+
}
diff --git a/src/app/services/marketing/discount.service.ts b/src/app/services/marketing/discount.service.ts
new file mode 100644
index 0000000..d36f1c2
--- /dev/null
+++ b/src/app/services/marketing/discount.service.ts
@@ -0,0 +1,69 @@
+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 DiscountService {
+
+ constructor(private http: HttpClient) { }
+
+ /**
+ * 查询列表
+ * @param params
+ * @param callBack
+ */
+ public getListDiscount(params: object, callBack:any) {
+ this.http.get(environment.baseUrl + 'discount/getListDiscount?' + ObjectData.objectByString(params)).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 编辑优惠券
+ * @param params
+ * @param callBack
+ */
+ public editDiscount(params: object, callBack:any) {
+ this.http.post(environment.baseUrl + 'discount/editDiscount', params).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 删除优惠券
+ * @param id
+ * @param callBack
+ */
+ public deleteDiscount(id: number, callBack:any) {
+ this.http.get(environment.baseUrl + 'discount/delete?id=' + id ).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+ /**
+ * 查询列表
+ * @param params
+ * @param callBack
+ */
+ public getListDiscountGoodsRel(params: object, callBack:any) {
+ this.http.get(environment.baseUrl + 'discount/getListDiscountGoodsRel?' + ObjectData.objectByString(params)).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+
+ /**
+ * 绑定优惠券规格
+ * @param params
+ * @param callBack
+ */
+ public bindDiscountSpecs(params: object, callBack:any) {
+ this.http.post(environment.baseUrl + 'discount/bindDiscountSpecs', params).subscribe(data => {
+ callBack(data);
+ });
+ }
+
+}