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.
 
 
 
hai-oil-web/src/app/pages/agent/agent-mer-account/agent-mer-account.component.ts

279 lines
8.0 KiB

import { Component } from '@angular/core';
import {FormGroup, FormsModule, NonNullableFormBuilder, ReactiveFormsModule, Validators} from "@angular/forms";
import {DictionaryPipe} from "../../../pipes/common/dictionary.pipe";
import {NzMessageService} from "ng-zorro-antd/message";
import {BrowserStorageService} from "../../../utils/localStorage.service";
import {AgentService} from "../../../services/agent/agent.service";
import {CommonService} from "../../../services/common/common.service";
import {NzModalModule, NzModalService} from "ng-zorro-antd/modal";
import {DatePipe, NgForOf, NgIf} from "@angular/common";
import {NzButtonComponent} from "ng-zorro-antd/button";
import {
NzCellFixedDirective,
NzTableCellDirective,
NzTableComponent, NzTableModule,
NzTbodyComponent, NzTheadComponent,
NzThMeasureDirective, NzTrDirective
} from "ng-zorro-antd/table";
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
import {NzDividerComponent} from "ng-zorro-antd/divider";
import {NzDropDownADirective, NzDropDownDirective, NzDropdownMenuComponent} from "ng-zorro-antd/dropdown";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzIconDirective} from "ng-zorro-antd/icon";
import {NzInputDirective} from "ng-zorro-antd/input";
import {NzMenuDirective, NzMenuItemComponent} from "ng-zorro-antd/menu";
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
import {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzDescriptionsModule} from "ng-zorro-antd/descriptions";
import {NzUploadComponent} from "ng-zorro-antd/upload";
import {NzAvatarModule} from "ng-zorro-antd/avatar";
import {NzImageModule} from "ng-zorro-antd/image";
import {NzSwitchComponent} from "ng-zorro-antd/switch";
import {NzDatePickerComponent} from "ng-zorro-antd/date-picker";
import {NzInputNumberModule} from "ng-zorro-antd/input-number";
import {AgentMerAccountService} from "../../../services/agent/agent-mer-account.service";
import {DATA} from "../../../data/login/localStorage.namespace";
import {AgentStaffService} from "../../../services/agent/agent-staff.service";
@Component({
selector: 'app-agent-mer-account',
standalone: true,
imports: [
DatePipe,
DictionaryPipe,
FormsModule,
NgForOf,
NgIf,
NzButtonComponent,
NzCellFixedDirective,
NzColDirective,
NzDividerComponent,
NzDropDownADirective,
NzDropDownDirective,
NzDropdownMenuComponent,
NzFormControlComponent,
NzFormDirective,
NzFormItemComponent,
NzFormLabelComponent,
NzIconDirective,
NzInputDirective,
NzMenuDirective,
NzMenuItemComponent,
NzOptionComponent,
NzRowDirective,
NzSelectComponent,
NzTableCellDirective,
NzTableComponent,
NzTbodyComponent,
NzThMeasureDirective,
NzTheadComponent,
NzTrDirective,
ReactiveFormsModule,
NzTableModule,
NzModalModule,
NzFlexDirective,
NzDescriptionsModule,
NzUploadComponent,
NzAvatarModule,
NzImageModule,
NzSwitchComponent,
NzDatePickerComponent,
NzInputNumberModule
],
templateUrl: './agent-mer-account.component.html',
styleUrl: './agent-mer-account.component.less'
})
export class AgentMerAccountComponent {
// 表单页数
tablePageNum = 1;
// 每页数量
tablePageSize = 10;
// 表单数据
tableData: any = {
total: 0,
list: [],
};
// 搜索表单
searchForm: FormGroup;
// 地区数据
regionData: any = [];
// 代理数据
agentData: any = [];
// 登录账户类型
accountType = null;
// 充值表单
rechargeForm: FormGroup;
rechargeModal = false;
// 记录模态框
recordModal = false;
recordMerNo: any = null;
// 表单页数
recordTablePageNum = 1;
// 每页数量
recordTablePageSize = 10;
recordData: any = {
total: 0,
list: [],
};
constructor(private fb: NonNullableFormBuilder,
private message: NzMessageService,
private storage: BrowserStorageService,
private agentService: AgentService,
private agentMerAccountService: AgentMerAccountService,
private commonService: CommonService,
private modalService: NzModalService) {
this.accountType = this.storage.get(DATA)['account']['objectType'];
// 初始化搜索框
this.searchForm = this.fb.group({
agentId: [''],
provinceCode: [null],
merNo: [null],
merName: [null],
});
// 初始化搜索框
this.rechargeForm = this.fb.group({
agentId: [null],
merNo: [null],
merName: [null],
amount: [null, [Validators.required]],
});
if (this.accountType == 1) {
// 获取代理商
this.agentService.queryAgentList({pageNum:1,pageSize:999}, (data: any) => {
this.agentData = data['return_data']['list'];
this.searchForm.controls['agentId'].setValue(String(this.agentData[0]['id']));
// 查询数据
this.queryData();
});
} else {
// 查询数据
this.queryData();
}
// 获取地区
this.commonService.getRegion("", (data: any) => {
this.regionData = data['return_data'];
});
}
/**
* 获取数据
*/
queryData() {
this.searchForm.value.pageNum = this.tablePageNum;
this.searchForm.value.pageSize = this.tablePageSize;
this.searchForm.value.time = new Date().getTime();
this.agentMerAccountService.getMerList(this.searchForm.value, (data: any) => {
if (data['return_code'] == '000000') {
this.tableData = data['return_data'];
}
});
}
/**
* 搜索表单提交
*/
searchFormSubmit(): void {
this.tablePageNum = 1;
this.queryData();
}
/**
* 搜索表单重置
*/
searchFormReset(): void {
this.searchForm.reset();
}
/**
* 打卡充值模态框
* @param data
*/
showRechargeModal(data: any) {
this.rechargeForm.patchValue(data);
this.rechargeForm.controls['amount'].setValue(0);
this.rechargeForm.controls['merNo'].disable();
this.rechargeForm.controls['merName'].disable();
this.rechargeModal = true;
}
/**
* 充值确认框
*/
rechargeConfirm() {
if (this.rechargeForm.valid) {
this.modalService.confirm({
nzTitle: '充值提醒',
nzContent: '确认对【' + this.rechargeForm.controls['merName'].value + '】油站充值:¥' +this.rechargeForm.controls['amount'].value + '吗?',
nzOnOk: () => this.submitRecharge()
});
} else {
Object.values(this.rechargeForm.controls).forEach(control => {
if (control.invalid) {
control.markAsDirty();
control.updateValueAndValidity({ onlySelf: true });
}
});
}
}
/**
* 提交表单数据
*/
submitRecharge() {
let param = this.rechargeForm.value;
param['agentId'] = this.searchForm.controls['agentId'].value;
param['merNo'] = this.rechargeForm.controls['merNo'].value;
this.agentMerAccountService.recharge(param, (data: any) => {
if (data['return_code'] == '000000') {
this.message.create('success', '操作成功');
this.queryData();
// 关闭弹窗
this.closeRechargeModal();
} else {
this.message.create('error', data['return_msg']);
}
});
}
/**
* 关闭充值模态框
*/
closeRechargeModal() {
this.rechargeForm.reset();
this.rechargeModal = false;
}
/**
* 打开动账记录模态框
* @param merNo
*/
showRecordModal(merNo: number) {
if (this.recordMerNo != merNo) {
this.recordMerNo = merNo;
// 查询数据
this.queryRecord();
}
this.recordModal = true;
}
/**
* 获取数据
*/
queryRecord() {
const param = {
agentId: this.searchForm.controls['agentId'].value,
merNo: this.recordMerNo,
pageNum: this.recordTablePageNum,
pageSize: this.recordTablePageSize,
};
this.agentMerAccountService.getRecordList(param, (data: any) => {
if (data['return_code'] == '000000') {
this.recordData = data['return_data'];
}
});
}
}