车辆接口更新
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { debounceTime } from 'rxjs/operators';
|
||||
import { Subject } from 'rxjs';
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
||||
import { BaseService } from '@shared';
|
||||
|
||||
@Component({
|
||||
@ -11,29 +13,21 @@ export class InsuranceTableComponent implements OnInit {
|
||||
headers: any[] = [];
|
||||
|
||||
formatterDollar = (value: number): string => `${value} (含)`;
|
||||
computeMode: any = {
|
||||
0: '总运价',
|
||||
1: '单公里运价'
|
||||
};
|
||||
constructor(public service: BaseService) {}
|
||||
|
||||
changeSub = new Subject<string>();
|
||||
constructor(public service: BaseService, private cdr: ChangeDetectorRef) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadHeaders();
|
||||
this.loadData();
|
||||
}
|
||||
|
||||
loadHeaders() {
|
||||
this.service.request('/api/mdc/cuc/freightConfigItem/list').subscribe(res => {
|
||||
if (res) {
|
||||
this.headers = res;
|
||||
}
|
||||
});
|
||||
this.changeEndKmAction();
|
||||
}
|
||||
|
||||
loadData() {
|
||||
this.service.request('/api/mdc/cuc/freightConfig/list').subscribe(res => {
|
||||
this.service.request('/api/mdc/cuc/insuranceConfig/list').subscribe(res => {
|
||||
if (res) {
|
||||
console.log(res);
|
||||
this.data = res;
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -59,13 +53,35 @@ export class InsuranceTableComponent implements OnInit {
|
||||
* @param i 下标
|
||||
*/
|
||||
changeEndKm(event: any, i: number) {
|
||||
if (event <= this.data[i].startKm) {
|
||||
this.data[i].endKm = this.data[i].startKm + 1;
|
||||
this.changeNextStartKm(event, i + 1);
|
||||
return;
|
||||
// console.log(this.debounce4(event, i));
|
||||
// console.log(this.data[i].startKm);
|
||||
// console.log(event);
|
||||
// console.log(i);
|
||||
if (event) {
|
||||
console.log(event);
|
||||
|
||||
this.changeSub.next(`${event},${i}`);
|
||||
}
|
||||
this.data[i].endKm = event;
|
||||
this.changeNextStartKm(event, i + 1);
|
||||
}
|
||||
changeEndKmAction() {
|
||||
this.changeSub.pipe(debounceTime(500)).subscribe((res: string) => {
|
||||
if (res) {
|
||||
const paras = res.split(',');
|
||||
const num = Number(paras[0]);
|
||||
const i = Number(paras[1]);
|
||||
|
||||
if (num <= this.data[i].startKm) {
|
||||
this.data[i].endKm = null;
|
||||
setTimeout(() => {
|
||||
this.data[i].endKm = this.data[i].startKm + 1 ;
|
||||
}, 0);
|
||||
this.changeNextStartKm(this.data[i].startKm + 1, i + 1);
|
||||
return;
|
||||
}
|
||||
this.data[i].endKm = num;
|
||||
this.changeNextStartKm(num, i + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
add() {
|
||||
@ -73,14 +89,7 @@ export class InsuranceTableComponent implements OnInit {
|
||||
|
||||
const tem = this.data[this.data?.length - 1];
|
||||
if (tem && tem.endKm) {
|
||||
const list = this.headers.map(item => ({
|
||||
ewPrice: null,
|
||||
itemId: item.id,
|
||||
maxPrice: null
|
||||
}));
|
||||
this.data.push({
|
||||
computeMode: 1,
|
||||
configValue: list,
|
||||
endKm: '',
|
||||
startKm: tem.endKm
|
||||
});
|
||||
@ -91,17 +100,24 @@ export class InsuranceTableComponent implements OnInit {
|
||||
}
|
||||
|
||||
deleteRow(index: number) {
|
||||
this.data = this.data.filter((d, i) => index !== i);
|
||||
console.log(index);
|
||||
this.data = this.data.filter((d, i) => {
|
||||
console.log(d);
|
||||
console.log(i);
|
||||
index !== i;
|
||||
});
|
||||
console.log(this.data);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.service.request('/api/mdc/cuc/freightConfig/saveBatch', this.data).subscribe(res => {
|
||||
if (res) {
|
||||
console.log(res);
|
||||
this.service.msgSrv.success('修改成功');
|
||||
this.loadData();
|
||||
}
|
||||
});
|
||||
console.log(this.data);
|
||||
// this.service.request('/api/mdc/cuc/freightConfig/saveBatch', this.data).subscribe(res => {
|
||||
// if (res) {
|
||||
// console.log(res);
|
||||
// this.service.msgSrv.success('修改成功');
|
||||
// this.loadData();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user