提交修改

pull/1/head
yuanye 4 years ago
parent 94d7b88224
commit 98d344c9ed
  1. 133
      src/app/admin/coupon/coupon-edit/coupon-edit.component.html
  2. 6
      src/app/admin/coupon/coupon-edit/coupon-edit.component.scss
  3. 25
      src/app/admin/coupon/coupon-edit/coupon-edit.component.spec.ts
  4. 137
      src/app/admin/coupon/coupon-edit/coupon-edit.component.ts
  5. 2
      src/app/admin/coupon/coupon-list/coupon-list.component.html
  6. 5
      src/app/app-routing.module.ts

@ -1 +1,132 @@
<p>coupon-edit works!</p> <!-- start 面包屑 -->
<nz-breadcrumb>
<nz-breadcrumb-item>
<a (click)="getBack()">卡券管理</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
编辑卡券
</nz-breadcrumb-item>
</nz-breadcrumb>
<!-- end 面包屑 -->
<nz-content class="inner-content">
<form nz-form [formGroup]="validateForm" class="ant-advanced-search-form">
<div nz-row [nzGutter]="24">
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'loginTelephone'" nzRequired>登录手机号</nz-form-label>
<nz-form-control nzErrorTip="请输入登录手机号!">
<input nz-input placeholder="请输入登录手机号..." [formControlName]="'loginTelephone'" id="'loginTelephone'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'password'" nzRequired>登录密码</nz-form-label>
<nz-form-control nzErrorTip="请输入登录密码!">
<nz-input-group [nzSuffix]="suffixTemplate">
<input [type]="passwordVisible ? 'text' : 'password'" nz-input placeholder="请输入登录密码..." [formControlName]="'password'" id="'password'" />
</nz-input-group>
<ng-template #suffixTemplate>
<i nz-icon [nzType]="passwordVisible ? 'eye-invisible' : 'eye'" (click)="passwordVisible = !passwordVisible"></i>
</ng-template>
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'merchantKey'" nzRequired>商户编号</nz-form-label>
<nz-form-control nzErrorTip="请输入商户编号!">
<input nz-input placeholder="请输入商户编号..." [formControlName]="'merchantKey'" id="'merchantKey'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'merchantName'" nzRequired>商户名称</nz-form-label>
<nz-form-control nzErrorTip="请输入商户名称!">
<input nz-input placeholder="请输入商户名称..." [formControlName]="'merchantName'" id="'merchantName'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'telephone'" nzRequired>联系电话</nz-form-label>
<nz-form-control nzErrorTip="请输入联系电话!">
<input nz-input placeholder="请输入联系电话..." [formControlName]="'telephone'" id="'telephone'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'address'" nzRequired>商户地址</nz-form-label>
<nz-form-control nzErrorTip="请输入商户地址!">
<input nz-input placeholder="请输入商户地址..." [formControlName]="'address'" id="'address'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'bankName'" >银行名称</nz-form-label>
<nz-form-control nzErrorTip="请输入银行名称!">
<input nz-input placeholder="请输入银行名称..." [formControlName]="'bankName'" id="'bankName'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'bankAccount'" >银行账号</nz-form-label>
<nz-form-control nzErrorTip="请输入银行账号!">
<input nz-input placeholder="请输入银行账号..." [formControlName]="'bankAccount'" id="'bankAccount'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="8">
<nz-form-item>
<nz-form-label [nzFor]="'bankHolder'" >开户人</nz-form-label>
<nz-form-control nzErrorTip="请输入开户人!">
<input nz-input placeholder="请输入开户人..." [formControlName]="'bankHolder'" id="'bankHolder'" />
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="16">
<nz-form-item>
<nz-form-label>商户LOGO</nz-form-label>
<nz-form-control>
<nz-upload
nzAction="{{WEB_SERVE_URL}}/fileUpload/uploadfile"
nzListType="picture-card"
[(nzFileList)]="logoFile"
[nzShowButton]="logoFile.length < 1"
[nzPreview]="handlePreview"
>
<i nz-icon nzType="plus"></i>
<div class="ant-upload-text">上传LOGO</div>
</nz-upload>
<nz-modal [nzVisible]="previewVisible" [nzContent]="modalContent" [nzFooter]="null" (nzOnCancel)="previewVisible = false">
<ng-template #modalContent>
<img [src]="previewImage" [ngStyle]="{ width: '100%' }" />
</ng-template>
</nz-modal>
</nz-form-control>
</nz-form-item>
</div>
<div nz-col [nzSpan]="16">
<nz-form-item>
<nz-form-label>商户简介</nz-form-label>
<nz-form-control>
<textarea formControlName="merchantDesc" nz-input rows="2" placeholder="请输入商户简介"></textarea>
</nz-form-control>
</nz-form-item>
</div>
</div>
<div nz-row>
<div nz-col [nzSpan]="24" class="search-area">
<button nz-button (click)="resetForm()">重置</button>
<button nz-button [nzType]="'primary'" (click)="getSave()">提交</button>
</div>
</div>
</form>
</nz-content>

@ -0,0 +1,6 @@
button {
margin-left: 8px;
}
:host ::ng-deep .ant-upload {
background-color: #ffffff;
}

@ -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<CouponEditComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CouponEditComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CouponEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -1,4 +1,19 @@
import { Component, OnInit } from '@angular/core'; 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<string | ArrayBuffer | null> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
@Component({ @Component({
selector: 'app-coupon-edit', selector: 'app-coupon-edit',
@ -7,9 +22,129 @@ import { Component, OnInit } from '@angular/core';
}) })
export class CouponEditComponent implements OnInit { 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 { 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']);
}
});
}
} }

@ -42,7 +42,7 @@
<span style="font-weight: bold; font-size: 20px">{{name}}</span> <span style="font-weight: bold; font-size: 20px">{{name}}</span>
</span> </span>
<div class="operating-button"> <div class="operating-button">
<button nz-button nzType="primary" class="right-btn" [routerLink]="['/admin/merchantStore/store-edit']" ><i nz-icon nzType="plus" nzTheme="outline"></i>添加</button> <button nz-button nzType="primary" class="right-btn" [routerLink]="['/admin/coupon/coupon-edit']" ><i nz-icon nzType="plus" nzTheme="outline"></i>添加</button>
</div> </div>
<nz-table <nz-table
class="table" class="table"

@ -36,6 +36,11 @@ const routes: Routes = [
loadChildren: () => import('./admin/merchant-store/merchant-store.module').then(m => m.MerchantStoreModule), loadChildren: () => import('./admin/merchant-store/merchant-store.module').then(m => m.MerchantStoreModule),
canActivate: [InitGuardService] canActivate: [InitGuardService]
}, },
{
path: 'coupon',
loadChildren: () => import('./admin/coupon/coupon.module').then(m => m.CouponModule),
canActivate: [InitGuardService]
},
{ {
path: 'system', path: 'system',
loadChildren: () => import('./admin/system/system.module').then(m => m.SystemModule), loadChildren: () => import('./admin/system/system.module').then(m => m.SystemModule),

Loading…
Cancel
Save