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.
191 lines
5.9 KiB
191 lines
5.9 KiB
import {Component, OnInit} from '@angular/core';
|
|
import {environment} from '../../../../environments/environment';
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
|
import {CompanyService} from '../../../services/company.service';
|
|
import {IconService} from '../../../services/icon.service';
|
|
import {NzMessageService} from 'ng-zorro-antd';
|
|
import {Router} from '@angular/router';
|
|
import {CommonsService} from '../../../services/commons.service';
|
|
import {AgentService} from '../../../services/agent.service';
|
|
import {DiscountService} from '../../../services/discount.service';
|
|
|
|
@Component({
|
|
selector: 'app-agent-list',
|
|
templateUrl: './agent-list.component.html',
|
|
styleUrls: ['./agent-list.component.scss']
|
|
})
|
|
export class AgentListComponent implements OnInit {
|
|
|
|
WEB_SERVE_URL = environment.imageUrl;
|
|
searchForm: FormGroup; // 搜索框
|
|
validateForm: FormGroup; // 搜索框
|
|
requestData = []; // 列表数据
|
|
discountList = []; // 列表数据
|
|
total: number; // 页码
|
|
pageNum = 1; // 页码
|
|
pageSize = 10; // 条码
|
|
loading = true;
|
|
isVisible = false;
|
|
isVisibleDiscount = false;
|
|
id: number;
|
|
|
|
requestDataDiscount = []; // 列表数据
|
|
totalDiscount: number; // 页码
|
|
pageNumDiscount = 1; // 页码
|
|
pageSizeDiscount = 10; // 条码
|
|
loadingDiscount = true;
|
|
constructor(
|
|
private form: FormBuilder,
|
|
private agent: AgentService,
|
|
private discount: DiscountService,
|
|
private iconService: IconService,
|
|
private message: NzMessageService,
|
|
private router: Router,
|
|
private common: CommonsService
|
|
) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.init();
|
|
}
|
|
|
|
public init(): void {
|
|
this.searchForm = this.form.group({
|
|
agentName: [null],
|
|
agentPhone: [null],
|
|
status: [null],
|
|
});
|
|
this.validateForm = this.form.group({
|
|
discountId: [null, [Validators.required]],
|
|
stockCount: [null, [Validators.required]],
|
|
});
|
|
this.getRequest(true, this.searchForm.value);
|
|
}
|
|
|
|
// 查询列表
|
|
public getRequest(reset: boolean = false, whereObject: object) {
|
|
|
|
this.loading = false;
|
|
if (reset) {
|
|
this.pageNum = 1;
|
|
}
|
|
whereObject['pageNum'] = this.pageNum;
|
|
whereObject['pageSize'] = this.pageSize;
|
|
this.agent.getListAgent(whereObject, data => {
|
|
if (data['return_code'] === '000000') {
|
|
this.requestData = data['return_data'].list;
|
|
this.total = data['return_data'].total;
|
|
} else {
|
|
this.message.error(data['return_msg']);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 重置
|
|
public resetForm(): void {
|
|
this.searchForm.reset();
|
|
}
|
|
|
|
public getForbiddenUser(id, status: any): void {
|
|
const message = (status === 1 ? '是否禁用当前代理商' : '是否启用当前代理商');
|
|
|
|
this.common.showConfirm(message, data => {
|
|
if (data) {
|
|
this.agent.editStatus(id, dataUser => {
|
|
this.getRequest(false, this.searchForm.value);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// 修改
|
|
public getEdit(id: number): void {
|
|
this.router.navigate(['/admin/agent/agent-edit'], {
|
|
queryParams: {
|
|
agentId: id
|
|
}
|
|
}).then(r => console.log(r));
|
|
}
|
|
|
|
// 查看详情
|
|
public getDetail(id: number): void {
|
|
this.router.navigate(['/admin/company/company-detail'], {
|
|
queryParams: {
|
|
companyId: id
|
|
}
|
|
}).then(r => console.log(r));
|
|
}
|
|
|
|
// 绑定优惠券
|
|
public getDiscount(id: number): void {
|
|
this.id = id;
|
|
const whereObject = {};
|
|
whereObject['pageNum'] = 1;
|
|
whereObject['pageSize'] = 10000;
|
|
this.discount.getDiscountList(whereObject, data => {
|
|
if (data['return_code'] === '000000') {
|
|
this.discountList = data['return_data'].list;
|
|
} else {
|
|
this.message.error(data['return_msg']);
|
|
}
|
|
});
|
|
this.isVisible = true;
|
|
}
|
|
|
|
handleOk(): 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['agentId'] = this.id;
|
|
this.agent.insertDiscountAgent(this.validateForm.value , data => {
|
|
if (data['return_code'] === '000000') {
|
|
console.log(data);
|
|
this.isVisible = false;
|
|
} else {
|
|
this.message.error(data['return_msg']);
|
|
}
|
|
});
|
|
}
|
|
|
|
handleCancel(): void {
|
|
this.isVisible = false;
|
|
}
|
|
|
|
public getDiscountList(id: number): void {
|
|
this.id = id;
|
|
this.isVisibleDiscount = true;
|
|
this.getRequestDiscount(true);
|
|
}
|
|
|
|
handleCancelDiscount() {
|
|
this.isVisibleDiscount = false;
|
|
}
|
|
|
|
// 查询列表
|
|
public getRequestDiscount(reset: boolean = false) {
|
|
const whereObject = {};
|
|
this.loadingDiscount = false;
|
|
if (reset) {
|
|
this.pageNumDiscount = 1;
|
|
}
|
|
whereObject['pageNum'] = this.pageNumDiscount;
|
|
whereObject['pageSize'] = this.pageSizeDiscount;
|
|
whereObject['agentId'] = this.id;
|
|
this.agent.getDiscountAgentList(whereObject, data => {
|
|
if (data['return_code'] === '000000') {
|
|
this.requestDataDiscount = data['return_data'].list;
|
|
this.totalDiscount = data['return_data'].total;
|
|
} else {
|
|
this.message.error(data['return_msg']);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|