diff --git a/src/app/admin/coupon/coupon-edit/coupon-edit.component.html b/src/app/admin/coupon/coupon-edit/coupon-edit.component.html
index 2f8962a..5dd00af 100644
--- a/src/app/admin/coupon/coupon-edit/coupon-edit.component.html
+++ b/src/app/admin/coupon/coupon-edit/coupon-edit.component.html
@@ -1 +1,132 @@
-
coupon-edit works!
+
+
+
+ 卡券管理
+
+
+ 编辑卡券
+
+
+
+
+
+
+
+
+
diff --git a/src/app/admin/coupon/coupon-edit/coupon-edit.component.scss b/src/app/admin/coupon/coupon-edit/coupon-edit.component.scss
index e69de29..ac60fb8 100644
--- a/src/app/admin/coupon/coupon-edit/coupon-edit.component.scss
+++ b/src/app/admin/coupon/coupon-edit/coupon-edit.component.scss
@@ -0,0 +1,6 @@
+button {
+ margin-left: 8px;
+}
+:host ::ng-deep .ant-upload {
+ background-color: #ffffff;
+}
diff --git a/src/app/admin/coupon/coupon-edit/coupon-edit.component.spec.ts b/src/app/admin/coupon/coupon-edit/coupon-edit.component.spec.ts
deleted file mode 100644
index 02c399b..0000000
--- a/src/app/admin/coupon/coupon-edit/coupon-edit.component.spec.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-
-import { CouponEditComponent } from './coupon-edit.component';
-
-describe('CouponEditComponent', () => {
- let component: CouponEditComponent;
- let fixture: ComponentFixture;
-
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- declarations: [ CouponEditComponent ]
- })
- .compileComponents();
- }));
-
- beforeEach(() => {
- fixture = TestBed.createComponent(CouponEditComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
-
- it('should create', () => {
- expect(component).toBeTruthy();
- });
-});
diff --git a/src/app/admin/coupon/coupon-edit/coupon-edit.component.ts b/src/app/admin/coupon/coupon-edit/coupon-edit.component.ts
index 29d0406..821c8a2 100644
--- a/src/app/admin/coupon/coupon-edit/coupon-edit.component.ts
+++ b/src/app/admin/coupon/coupon-edit/coupon-edit.component.ts
@@ -1,4 +1,19 @@
import { Component, OnInit } from '@angular/core';
+import {FormBuilder, FormGroup, Validators} from '@angular/forms';
+import {environment} from '../../../../environments/environment';
+import {MerchantService} from '../../../services/merchant.service';
+import {NzMessageService, NzUploadFile} from 'ng-zorro-antd';
+import {ActivatedRoute} from '@angular/router';
+import {ValidatorsService} from '../../../services/validators.service';
+
+function getBase64(file: File): Promise {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.readAsDataURL(file);
+ reader.onload = () => resolve(reader.result);
+ reader.onerror = error => reject(error);
+ });
+}
@Component({
selector: 'app-coupon-edit',
@@ -7,9 +22,129 @@ import { Component, OnInit } from '@angular/core';
})
export class CouponEditComponent implements OnInit {
- constructor() { }
+ validateForm!: FormGroup;
+ data: any;
+ editFlag = false;
+ id: number;
+ passwordVisible = false;
+ logoFile = [];
+ WEB_SERVE_URL = environment.baseUrl;
+ previewImage: string | undefined = '';
+ previewVisible = false;
+
+ constructor(
+ private fb: FormBuilder,
+ private merchant: MerchantService,
+ private message: NzMessageService, // 信息提示
+ private activatedRoute: ActivatedRoute,
+ ) {
+ }
ngOnInit(): void {
+ this.activatedRoute.queryParams.subscribe(queryParams => {
+ if (queryParams.merchantId != null) {
+ this.editFlag = true;
+ this.id = queryParams.merchantId;
+ this.getDetails(queryParams.merchantId);
+ }
+ });
+ this.validateForm = this.fb.group({
+ couponName: [null, [Validators.required, ValidatorsService.minLength(2)]],
+ couponPrice: [null, [Validators.required]],
+ couponDesc: [null],
+ status: [null],
+ createTime: [null],
+ secUser: {},
+ });
+ }
+
+ // 返回
+ getBack() {
+ history.back();
+ }
+
+ // 重置
+ public resetForm(): void {
+ this.validateForm.reset();
}
+ // 课程保存
+ public getSave(): 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;
+ }
+ }
+
+ this.validateForm.value['secUser']['telephone'] = this.validateForm.value.loginTelephone;
+ this.validateForm.value['secUser']['password'] = this.validateForm.value.password;
+ if (this.logoFile.length !== 0) {
+ if (this.logoFile[0]['response'] != null) {
+ this.validateForm.value.merchantLogo = this.logoFile[0]['response']['return_data'][0];
+ } else {
+ this.validateForm.value.merchantLogo = this.logoFile[0].name;
+ }
+ }
+
+ if (this.editFlag) {
+ this.validateForm.value.id = this.id;
+ this.merchant.updateMerchant(this.validateForm.value, data => {
+ if (data['return_code'] === '000000') {
+ this.getBack();
+ this.message.success('修改成功');
+ } else {
+ this.message.create('error', '修改失败');
+ }
+ });
+ } else {
+
+ this.merchant.insertMerchant(this.validateForm.value, data => {
+ console.log(data);
+ if (data['return_code'] === '000000') {
+ this.getBack();
+ this.message.success('添加成功');
+ } else {
+ this.message.create('error', '保存失败');
+ }
+ });
+ }
+ }
+
+ // 图片查看
+ handlePreview = async (file: NzUploadFile) => {
+ if (!file.url && !file.preview) {
+ // tslint:disable-next-line:no-non-null-assertion
+ file.preview = await getBase64(file.originFileObj!);
+ }
+ this.previewImage = file.url || file.preview;
+ this.previewVisible = true;
+ }
+
+ public getDetails(id) {
+ this.merchant.getMerchantById(id, data => {
+ if (data['return_code'] === '000000') {
+ data['return_data'].loginTelephone = data['return_data'].secUser.loginName;
+ data['return_data'].password = data['return_data'].secUser.password;
+ if (data['return_data']['merchantLogo'] != null && data['return_data']['merchantLogo'] !== '') {
+ const logo = String(data['return_data']['merchantLogo']);
+ const logoArray = [];
+ logoArray.push(
+ {
+ uid: 1,
+ name: logo,
+ status: 'done',
+ url: environment.imageUrl + logo
+ });
+ this.logoFile = logoArray;
+ }
+ this.validateForm.patchValue(data['return_data']);
+ } else {
+ this.message.create('error', data['return_msg']);
+ }
+ });
+ }
}
diff --git a/src/app/admin/coupon/coupon-list/coupon-list.component.html b/src/app/admin/coupon/coupon-list/coupon-list.component.html
index d907874..f4975e3 100644
--- a/src/app/admin/coupon/coupon-list/coupon-list.component.html
+++ b/src/app/admin/coupon/coupon-list/coupon-list.component.html
@@ -42,7 +42,7 @@
{{name}}
-
+
import('./admin/merchant-store/merchant-store.module').then(m => m.MerchantStoreModule),
canActivate: [InitGuardService]
},
+ {
+ path: 'coupon',
+ loadChildren: () => import('./admin/coupon/coupon.module').then(m => m.CouponModule),
+ canActivate: [InitGuardService]
+ },
{
path: 'system',
loadChildren: () => import('./admin/system/system.module').then(m => m.SystemModule),