嗨森逛PC管理端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
high-web/src/app/admin/activate/activate-edit/activate-edit.component.ts

144 lines
4.0 KiB

4 years ago
import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {NzMessageService} from '_ng-zorro-antd@9.3.0@ng-zorro-antd';
import {ActivatedRoute} from '_@angular_router@9.0.7@@angular/router';
import {CouponService} from '../../../services/coupon.service';
import {ActivateService} from '../../../services/activate.service';
@Component({
selector: 'app-activate-edit',
templateUrl: './activate-edit.component.html',
styleUrls: ['./activate-edit.component.scss']
})
export class ActivateEditComponent implements OnInit {
validateForm!: FormGroup;
4 years ago
validateFormAward!: FormGroup;
4 years ago
data: any;
editFlag = false;
id: number;
listOfOption: string[] = [];
current = 0;
constructor(
private fb: FormBuilder,
private coupon: CouponService,
private activate: ActivateService,
private message: NzMessageService, // 信息提示
private activatedRoute: ActivatedRoute,
) { }
ngOnInit(): void {
this.activatedRoute.queryParams.subscribe(queryParams => {
if (queryParams.id != null) {
this.editFlag = true;
this.id = queryParams.id;
this.getDetails(queryParams.id);
}
});
this.validateForm = this.fb.group({
title: [null, [Validators.required]],
productIdArray: [null, [Validators.required]],
type: [null, [Validators.required]],
content: [null, [Validators.required]],
time: [null, [Validators.required]],
4 years ago
});
4 years ago
4 years ago
this.validateFormAward = this.fb.group({
activityInfoId: [null, [Validators.required]],
img: [null, [Validators.required]],
name: [null, [Validators.required]],
num: [null, [Validators.required]],
4 years ago
});
const whereObject = {
pageNum: 1 ,
pageSize: 200 ,
status: 2 ,
};
this.coupon.getCouponList(whereObject, data => {
if (data['return_code'] === '000000') {
this.listOfOption = data['return_data'].list;
} else {
this.message.error(data['return_msg']);
}
});
}
// 返回
getBack() {
history.back();
}
// 重置
public resetForm(): void {
this.validateForm.reset();
}
// 基本信息提交
public editActivityInfo(): 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.ruleArray = [{
partakeMode: 1,
productType: 1 ,
productIdArray: this.validateForm.value.productIdArray
}];
this.validateForm.value.startTime = this.validateForm.value.time[0].getTime();
this.validateForm.value.endTime = this.validateForm.value.time[1].getTime();
if (this.editFlag) {
this.validateForm.value.id = this.id;
}
this.activate.editActivityInfo(this.validateForm.value, data => {
if (data['return_code'] === '000000') {
this.current += 1;
this.message.success('编辑成功');
} else {
this.message.create('error', '编辑失败');
}
});
}
// 查询详情
public getDetails(id) {
this.activate.getDetailById(id, data => {
if (data['return_code'] === '000000') {
data['return_data'].time = [new Date(data['return_data']['startTime']), new Date(data['return_data']['endTime'])];
data['return_data'].type = String(data['return_data'].type);
data['return_data'].productIdArray = data['return_data'].ruleArray[0].productIdArray;
this.validateForm.patchValue(data['return_data']);
} else {
this.message.create('error', data['return_msg']);
}
});
}
// 上一步
pre(): void {
this.current -= 1;
}
// 下一步
getNest(): void {
4 years ago
if (this.current === 1) {
this.editActivityInfo();
}
4 years ago
}
// 完成
done(): void {
}
}