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.
114 lines
4.1 KiB
114 lines
4.1 KiB
import { Component, OnInit } from '@angular/core';
|
|
import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms';
|
|
import {NzModalService} from 'ng-zorro-antd';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {StoreDiscountActivityService} from '../../../services/store-discount-activity.service';
|
|
import {StoreService} from '../../../services/store.service';
|
|
import {MerService} from '../../../services/mer.service';
|
|
import {CommonsService} from '../../../services/commons.service';
|
|
|
|
@Component({
|
|
selector: 'app-store-discount-activity-edit',
|
|
templateUrl: './store-discount-activity-edit.component.html',
|
|
styleUrls: ['./store-discount-activity-edit.component.scss']
|
|
})
|
|
export class StoreDiscountActivityEditComponent implements OnInit {
|
|
|
|
dataForm: UntypedFormGroup;
|
|
btnLoading = false;
|
|
|
|
storeArray = [];
|
|
merArray = [];
|
|
discountActivityPartakeWayArray = [];
|
|
|
|
constructor(private form: UntypedFormBuilder,
|
|
private modal: NzModalService,
|
|
private commonsService: CommonsService,
|
|
private storeDiscountActivityService: StoreDiscountActivityService,
|
|
private merService: MerService,
|
|
private storeService: StoreService,
|
|
private activatedRoute: ActivatedRoute,
|
|
private router: Router) { }
|
|
|
|
ngOnInit(): void {
|
|
this.dataForm = this.form.group({
|
|
id: [null],
|
|
merId: [null, [Validators.required]],
|
|
storeId: [null],
|
|
partakeWay: ['1', [Validators.required]],
|
|
name: [null, [Validators.required]],
|
|
discountType: [1, [Validators.required]],
|
|
discountCondition: [0, [Validators.required]],
|
|
discountPrice: [0, [Validators.required]],
|
|
finalCostPrice: [0, [Validators.required]],
|
|
restrictType: ['1'],
|
|
restrictPartakeNum: [1],
|
|
endTime: [null, [Validators.required]],
|
|
});
|
|
|
|
this.commonsService.getDictionary('DISCOUNT_ACTIVITY_PARTAKE_WAY', data => {
|
|
this.discountActivityPartakeWayArray = data['return_data'];
|
|
});
|
|
|
|
this.activatedRoute.queryParams.subscribe(queryParams => {
|
|
if (queryParams['id'] != null) {
|
|
this.storeDiscountActivityService.getActivityDetail(queryParams['id'], data => {
|
|
data['return_data']['merId'] = String(data['return_data']['merId']);
|
|
data['return_data']['storeId'] = String(data['return_data']['storeId']);
|
|
data['return_data']['partakeWay'] = String(data['return_data']['partakeWay']);
|
|
data['return_data']['discountType'] = String(data['return_data']['discountType']);
|
|
if (data['return_data']['restrictType'] != null) {
|
|
data['return_data']['restrictType'] = String(data['return_data']['restrictType']);
|
|
}
|
|
this.dataForm.patchValue(data['return_data']);
|
|
});
|
|
}
|
|
});
|
|
|
|
this.merService.getMerList({merStatus: 1, pageNum: 1, pageSize: 99999}, data => {
|
|
this.merArray = data['return_data']['list'];
|
|
});
|
|
}
|
|
|
|
submitFrom() {
|
|
this.btnLoading = true;
|
|
for (const i in this.dataForm.controls) {
|
|
this.dataForm.controls[i].markAsDirty();
|
|
this.dataForm.controls[i].updateValueAndValidity();
|
|
}
|
|
if (this.dataForm.status == null || this.dataForm.status !== 'VALID') {
|
|
this.modal.warning({
|
|
nzTitle: '提示',
|
|
nzContent: '请规范填写所有的必填项信息',
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (this.dataForm.value.partakeWay !== '3') {
|
|
this.dataForm.value.restrictType = null;
|
|
this.dataForm.value.restrictPartakeNum = null;
|
|
}
|
|
|
|
this.storeDiscountActivityService.configActivity(this.dataForm.value, data => {
|
|
if (data['return_code'] === '000000') {
|
|
this.modal.success({
|
|
nzTitle: '提示',
|
|
nzContent: '提交成功',
|
|
nzOnOk: () => this.router.navigateByUrl('admin/store-discount-activity/list')
|
|
});
|
|
} else {
|
|
this.modal.error({
|
|
nzTitle: '提示',
|
|
nzContent: data['return_msg'],
|
|
});
|
|
}
|
|
this.btnLoading = false;
|
|
});
|
|
}
|
|
|
|
getStore(merId: number) {
|
|
this.storeService.getStoreListByMer({ merId: merId, pageNum: 1, pageSize: 99999}, data => {
|
|
this.storeArray = data['return_data']['list'];
|
|
});
|
|
}
|
|
}
|
|
|