merge partner
This commit is contained in:
@ -27,7 +27,7 @@ export class DictSelectComponent implements OnInit, ControlValueAccessor {
|
||||
@Input() params = {};// 请求参数
|
||||
|
||||
dictList: any[] = [];
|
||||
@Input() containsAllLable = true; // 是否包含全部这一选项
|
||||
@Input() containsAllLabel = true; // 是否包含全部这一选项
|
||||
@Input() mode: 'multiple' | 'tags' | 'default' = 'default';
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ export class DictSelectComponent implements OnInit, ControlValueAccessor {
|
||||
this.service.getDictList(this.url || this.defaultUrl, this.params).subscribe(res => {
|
||||
if (res) {
|
||||
this.dictList = res || [];
|
||||
if (this.dictList.length > 0 && this.containsAllLable) {
|
||||
if (this.dictList.length > 0 && this.containsAllLabel) {
|
||||
const obj = { label: '全部', value: '' };
|
||||
this.dictList.unshift(obj);
|
||||
}
|
||||
|
||||
@ -13,11 +13,11 @@ import { NgModule } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { NzInputNumberModule } from 'ng-zorro-antd/input-number';
|
||||
import { NzTableModule } from 'ng-zorro-antd/table';
|
||||
import { InsuranceTableComponent } from './insurance-table.component';
|
||||
import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';
|
||||
import { NzInputModule } from 'ng-zorro-antd/input';
|
||||
import { DelonFormModule } from '@delon/form';
|
||||
import { NzButtonModule } from 'ng-zorro-antd/button';
|
||||
import { InsuranceTableComponent } from './insurance-table.component';
|
||||
const COMPONENTS = [InsuranceTableComponent];
|
||||
const MODULES = [NzTableModule, NzInputNumberModule, NzPopconfirmModule, NzInputModule, NzButtonModule, DelonFormModule];
|
||||
|
||||
|
||||
13
src/app/shared/components/rebate-table/index.ts
Normal file
13
src/app/shared/components/rebate-table/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* @Description :
|
||||
* @Version : 1.0
|
||||
* @Author : Shiming
|
||||
* @Date : 2022-01-25 20:20:07
|
||||
* @LastEditors : Shiming
|
||||
* @LastEditTime : 2022-01-26 11:05:44
|
||||
* @FilePath : \\tms-obc-web\\src\\app\\shared\\components\\insurance-table\\index.ts
|
||||
* Copyright (C) 2022 huzhenhong. All rights reserved.
|
||||
*/
|
||||
export * from './rebate-table.module'
|
||||
export * from './rebate-table.service'
|
||||
export * from './rebate-table.component'
|
||||
@ -0,0 +1,91 @@
|
||||
<!--
|
||||
* @Description :
|
||||
* @Version : 1.0
|
||||
* @Author : Shiming
|
||||
* @Date : 2022-01-25 20:18:52
|
||||
* @LastEditors : Shiming
|
||||
* @LastEditTime : 2022-03-21 14:14:06
|
||||
* @FilePath : \\tms-obc-web\\src\\app\\shared\\components\\rebate-table\\rebate-table.component.html
|
||||
* Copyright (C) 2022 huzhenhong. All rights reserved.
|
||||
-->
|
||||
<div nz-row>
|
||||
<div nz-col nzSpan="24">
|
||||
<!-- <div class="mb-md ml-xl" style="text-align: right;">
|
||||
<button nz-button nzType="primary" (click)="add()">新增公里数</button>
|
||||
<button class="ml-md" nz-button nzType="primary" (click)="save()">保存</button>
|
||||
</div> -->
|
||||
<nz-table #groupingTable [nzData]="data" nzBordered nzSize="small" [nzFrontPagination]="false"
|
||||
[nzScroll]="{ x: '900px' }" [nzShowPagination]="false" class="ml-xl" style="max-width: 1200px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2" nzWidth="250px" nzAlign="center" nzLeft>序号</th>
|
||||
<th nzWidth="220px" nzAlign="center" >合伙人等级</th>
|
||||
<th nzWidth="220px" nzAlign="center" >初始业务量(万/月)</th>
|
||||
<th nzWidth="220px" nzAlign="center" >到达业务量(万/月)</th>
|
||||
<th nzWidth="220px" nzAlign="center" >管理费比例%</th>
|
||||
<th rowspan="2" nzWidth="60px" nzAlign="center" nzRight>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let item of groupingTable.data;let i = index">
|
||||
<td nzWidth="250px" nzAlign="center" nzLeft>
|
||||
<div style="text-align: center;">
|
||||
<div>
|
||||
{{i + 1}}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td nzWidth="220px" nzAlign="center" >
|
||||
<div >
|
||||
<nz-select ngModel="lucy">
|
||||
<nz-option nzValue="jack" nzLabel="Jack154654564654"></nz-option>
|
||||
<nz-option nzValue="lucy" nzLabel="Lucy"></nz-option>
|
||||
</nz-select>
|
||||
</div>
|
||||
</td>
|
||||
<td nzWidth="220px" nzAlign="center" >
|
||||
<div style=" margin-left: 26%">
|
||||
<nz-input-group nzPrefix="=">
|
||||
<nz-input-number [(ngModel)]="item.baserebateRate" [nzMin]="0" nzSize="small"
|
||||
>
|
||||
</nz-input-number>
|
||||
</nz-input-group>
|
||||
|
||||
</div>
|
||||
</td>
|
||||
<td nzWidth="220px" nzAlign="center" >
|
||||
<div style=" margin-left: 26%">
|
||||
<nz-input-group nzPrefix="<">
|
||||
<nz-input-number [(ngModel)]="item.blanketrebateRate" [nzMin]="0" nzSize="small" >
|
||||
</nz-input-number>
|
||||
</nz-input-group>
|
||||
</div>
|
||||
</td>
|
||||
<td nzWidth="220px" nzAlign="center" >
|
||||
<div style=" margin-left: 26%">
|
||||
<nz-input-group [nzAddOnAfter]="addOnAfterTemplate2">
|
||||
<nz-input-number [(ngModel)]="item.baserebateRate" [nzMin]="0" nzSize="small"
|
||||
>
|
||||
</nz-input-number>
|
||||
</nz-input-group>
|
||||
<ng-template #addOnAfterTemplate2>
|
||||
<span >%</span>
|
||||
</ng-template>
|
||||
</div>
|
||||
</td>
|
||||
<td nzWidth="60px" nzAlign="center" nzRight>
|
||||
<a nz-popconfirm
|
||||
nzPopconfirmTitle="是否新增?" (nzOnConfirm)="add()"
|
||||
>+</a>
|
||||
<a *ngIf="i === groupingTable.data.length-1 && groupingTable.data.length>1"
|
||||
nz-popconfirm
|
||||
nzPopconfirmTitle="是否确认删除?" (nzOnConfirm)="deleteRow(i)"
|
||||
>-</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</nz-table>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,19 @@
|
||||
:host::ng-deep {
|
||||
nz-input-number {
|
||||
width: 85px;
|
||||
|
||||
input {
|
||||
width : 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ant-input-number-handler-wrap {
|
||||
display: none;
|
||||
}
|
||||
|
||||
}
|
||||
.ant-input-group {
|
||||
display: -webkit-inline-box !important;
|
||||
}
|
||||
|
||||
}
|
||||
157
src/app/shared/components/rebate-table/rebate-table.component.ts
Normal file
157
src/app/shared/components/rebate-table/rebate-table.component.ts
Normal file
@ -0,0 +1,157 @@
|
||||
import { debounceTime } from 'rxjs/operators';
|
||||
import { Subject } from 'rxjs';
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { BaseService } from '@shared';
|
||||
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
|
||||
|
||||
@Component({
|
||||
selector: 'app-rebate-table',
|
||||
templateUrl: './rebate-table.component.html',
|
||||
styleUrls: ['./rebate-table.component.less']
|
||||
})
|
||||
export class RebateTableComponent implements OnInit {
|
||||
data: any[] = [];
|
||||
headers: any[] = [];
|
||||
formatterDollar = (value: number): string => `${value}`;
|
||||
changeSub = new Subject<string>();
|
||||
constructor(public service: BaseService, private cdr: ChangeDetectorRef) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadData();
|
||||
this.changeEndKmAction();
|
||||
}
|
||||
|
||||
loadData() {
|
||||
this.service.request('/api/mdc/cuc/insuranceConfig/list').subscribe(res => {
|
||||
if (res) {
|
||||
console.log(res);
|
||||
this.data = res;
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
});
|
||||
this.service.request('/api/mdc/pbc/sysConfigItem/findItemValueByItemKeys', [
|
||||
"rebate.config.minrebatePrice"
|
||||
]).subscribe(res => {
|
||||
if (res) {
|
||||
console.log(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改结束车长
|
||||
* @param event 车长
|
||||
* @param i 下标
|
||||
*/
|
||||
changeEndLength(event: any, i: number) {
|
||||
if (event <= this.headers[i].startLength) {
|
||||
this.headers[i].endLength = this.headers[i].startLength + 1;
|
||||
this.changeNextStartLength(event, i + 1);
|
||||
return;
|
||||
}
|
||||
this.headers[i].endLength = event;
|
||||
this.changeNextStartLength(event, i + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改结束公里数
|
||||
* @param event 车长
|
||||
* @param i 下标
|
||||
*/
|
||||
changeEndKm(event: any, i: number) {
|
||||
if (event) {
|
||||
console.log(event);
|
||||
|
||||
this.changeSub.next(`${event},${i}`);
|
||||
}
|
||||
}
|
||||
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() {
|
||||
console.log(this.data);
|
||||
|
||||
const tem = this.data[this.data?.length - 1];
|
||||
if (tem && tem.endKm) {
|
||||
this.data.push({
|
||||
endKm: '',
|
||||
startKm: tem.endKm
|
||||
});
|
||||
this.data = [...this.data];
|
||||
} else {
|
||||
this.service.msgSrv.warning('请填写完整公里数');
|
||||
}
|
||||
}
|
||||
|
||||
deleteRow(index: number) {
|
||||
console.log(index);
|
||||
var newArr = this.data.concat();
|
||||
newArr.splice(this.data.length-1,1)
|
||||
// this.data = this.data.pop()
|
||||
console.log(newArr);
|
||||
this.data = [...newArr];
|
||||
}
|
||||
|
||||
save() {
|
||||
console.log(this.data)
|
||||
let params= {
|
||||
rebateConfigDTOS: this.data
|
||||
}
|
||||
console.log(params);
|
||||
this.service.request('/api/mdc/cuc/rebateConfig/saveBatch', params).subscribe(res => {
|
||||
if (res) {
|
||||
console.log(res);
|
||||
this.service.msgSrv.success('修改成功');
|
||||
this.loadData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历同步后置位车长
|
||||
* @param event 车长
|
||||
* @param i 下标
|
||||
*/
|
||||
private changeNextStartLength(event: number, i: number) {
|
||||
if (this.headers[i]) {
|
||||
this.headers[i].startLength = event;
|
||||
if (this.headers[i].endLength <= event) {
|
||||
this.headers[i].endLength = this.headers[i].startLength + 0.5;
|
||||
this.changeNextStartLength(event + 0.5, i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历同步后置位公里数
|
||||
* @param event 车长
|
||||
* @param i 下标
|
||||
*/
|
||||
private changeNextStartKm(event: number, i: number) {
|
||||
if (this.data[i]) {
|
||||
this.data[i].startKm = event;
|
||||
if (this.data[i].endKm <= event) {
|
||||
this.data[i].endKm = this.data[i].startKm + 1;
|
||||
this.changeNextStartKm(event + 1, i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* @Description :
|
||||
* @Version : 1.0
|
||||
* @Author : Shiming
|
||||
* @Date : 2022-01-25 20:23:54
|
||||
* @LastEditors : Shiming
|
||||
* @LastEditTime : 2022-03-21 14:11:56
|
||||
* @FilePath : \\tms-obc-web\\src\\app\\shared\\components\\rebate-table\\rebate-table.module.ts
|
||||
* Copyright (C) 2022 huzhenhong. All rights reserved.
|
||||
*/
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { NzInputNumberModule } from 'ng-zorro-antd/input-number';
|
||||
import { NzTableModule } from 'ng-zorro-antd/table';
|
||||
import { RebateTableComponent } from './rebate-table.component';
|
||||
import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';
|
||||
import { NzInputModule } from 'ng-zorro-antd/input';
|
||||
import { DelonFormModule } from '@delon/form';
|
||||
import { NzButtonModule } from 'ng-zorro-antd/button';
|
||||
import { NzSelectModule } from 'ng-zorro-antd/select';
|
||||
const COMPONENTS = [RebateTableComponent];
|
||||
const MODULES = [NzTableModule, NzInputNumberModule, NzPopconfirmModule, NzInputModule, NzButtonModule, DelonFormModule,NzSelectModule];
|
||||
|
||||
@NgModule({
|
||||
declarations: COMPONENTS,
|
||||
imports: [CommonModule, FormsModule, ...MODULES],
|
||||
exports: COMPONENTS
|
||||
})
|
||||
export class rebateTableModule {}
|
||||
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* @Description :
|
||||
* @Version : 1.0
|
||||
* @Author : Shiming
|
||||
* @Date : 2022-01-25 20:21:04
|
||||
* @LastEditors : Shiming
|
||||
* @LastEditTime : 2022-01-25 20:35:52
|
||||
* @FilePath : \\tms-obc-web\\src\\app\\shared\\components\\insurance-table\\insurance-table.service.ts
|
||||
* Copyright (C) 2022 huzhenhong. All rights reserved.
|
||||
*/
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
|
||||
export class RebateService {
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-11-29 10:04:12
|
||||
* @LastEditTime : 2022-02-11 14:31:22
|
||||
* @LastEditTime : 2022-03-11 15:12:20
|
||||
* @LastEditors : Shiming
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath : \\tms-obc-web\\src\\app\\shared\\index.ts
|
||||
@ -21,6 +21,7 @@ export * from './components/dict-select/index';
|
||||
export * from './components/dynamic-setting';
|
||||
export * from './components/singlepage-setting';
|
||||
export * from './components/insurance-table/index';
|
||||
export * from './components/rebate-table/index';
|
||||
|
||||
// Utils
|
||||
export * from './utils';
|
||||
@ -32,4 +33,5 @@ export * from './shared.module';
|
||||
export * from './shared-delon.module';
|
||||
export * from './shared-zorro.module';
|
||||
export * from './shared-third.module';
|
||||
export * from './shared-g2.module';
|
||||
export * from './widget/st-widget.module';
|
||||
|
||||
@ -19,12 +19,10 @@ export class ShipperBaseService extends BaseService {
|
||||
$api_get_roles = `/api/mdc/cuc/roleInfo/getRoleList`; // 获取角色列表
|
||||
// 根据FullKey获取系统子配置(树)
|
||||
$api_getSysConfigTreeByParentFullKey = `/api/mdc/pbc/sysConfig/getSysConfigTreeByParentFullKey`;
|
||||
envCache: any;
|
||||
|
||||
list: any[] = [];
|
||||
constructor(public injector: Injector, public eaCacheSrv: EACacheService) {
|
||||
// 获取全部返佣配置
|
||||
$api_get_rebate_config = `/api/mdc/rebateConfig/list/listRebateConfig`;
|
||||
constructor(public injector: Injector) {
|
||||
super(injector);
|
||||
this.envCache = this.eaCacheSrv.get(cacheConf.env);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,4 +235,23 @@ export class ShipperBaseService extends BaseService {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部返佣配置
|
||||
* @returns
|
||||
*/
|
||||
getRebateConfig() {
|
||||
const params = {};
|
||||
return this.request(this.$api_get_rebate_config, params, 'POST').pipe(
|
||||
map(res => {
|
||||
if (res) {
|
||||
return res.map((m: any) => {
|
||||
return { label: m.configName, value: m.id };
|
||||
});
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,16 +152,16 @@ export class EAUserService extends BaseService {
|
||||
* 加载用户菜单
|
||||
*/
|
||||
async loadUserMenus() {
|
||||
return this.asyncRequest(this.$api_get_user_menus, {
|
||||
appId: this.envSrv.getEnvironment().appId
|
||||
}).then(res => {
|
||||
this.cacheSrv.set(cacheConf.menu, res);
|
||||
this.menuService.add(res);
|
||||
});
|
||||
// this.request('assets/mocks/menu-data.json', {}, 'GET').subscribe((res: any) => {
|
||||
// this.cacheSrv.set(cacheConf.menu, res.menu);
|
||||
// this.menuService.add(res.menu);
|
||||
// return this.asyncRequest(this.$api_get_user_menus, {
|
||||
// appId: this.envSrv.getEnvironment().appId
|
||||
// }).then(res => {
|
||||
// this.cacheSrv.set(cacheConf.menu, res);
|
||||
// this.menuService.add(res);
|
||||
// });
|
||||
this.request('assets/mocks/menu-data.json', {}, 'GET').subscribe((res: any) => {
|
||||
this.cacheSrv.set(cacheConf.menu, res.menu);
|
||||
this.menuService.add(res.menu);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
6
src/app/shared/shared-g2.module.ts
Normal file
6
src/app/shared/shared-g2.module.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { G2BarModule } from '@delon/chart/bar';
|
||||
import { G2MiniAreaModule } from '@delon/chart/mini-area';
|
||||
import { G2PieModule } from '@delon/chart/pie';
|
||||
import { G2TimelineModule } from '@delon/chart/timeline';
|
||||
|
||||
export const SHARED_G2_MODULES = [G2BarModule, G2PieModule, G2TimelineModule, G2MiniAreaModule];
|
||||
@ -48,6 +48,8 @@ import { NzTypographyModule } from 'ng-zorro-antd/typography';
|
||||
import { NzSwitchModule } from 'ng-zorro-antd/switch';
|
||||
import { NzImageModule } from 'ng-zorro-antd/image';
|
||||
import { NzDrawerModule } from 'ng-zorro-antd/drawer';
|
||||
import { NzTreeSelectModule } from 'ng-zorro-antd/tree-select';
|
||||
|
||||
export const SHARED_ZORRO_MODULES = [
|
||||
NzButtonModule,
|
||||
NzGridModule,
|
||||
@ -89,5 +91,6 @@ export const SHARED_ZORRO_MODULES = [
|
||||
NzTypographyModule,
|
||||
NzSwitchModule,
|
||||
NzImageModule,
|
||||
NzDrawerModule
|
||||
NzDrawerModule,
|
||||
NzTreeSelectModule
|
||||
];
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* @Description :
|
||||
* @Description :
|
||||
* @Version : 1.0
|
||||
* @Author : Shiming
|
||||
* @Date : 2022-01-13 15:10:17
|
||||
@ -37,6 +37,7 @@ import { ImageListModule } from './components/imagelist';
|
||||
import { DictSelectComponent } from './components/dict-select';
|
||||
import { PipeModule } from './pipes';
|
||||
import { AccountDetailComponent } from './components/account-detail/account-detail.component';
|
||||
import { rebateTableModule } from './components/rebate-table';
|
||||
|
||||
const MODULES = [
|
||||
AddressModule,
|
||||
@ -51,6 +52,7 @@ const MODULES = [
|
||||
AmapModule,
|
||||
ImageListModule,
|
||||
PipeModule,
|
||||
rebateTableModule,
|
||||
...PRO_SHARED_MODULES
|
||||
];
|
||||
// #endregion
|
||||
@ -88,4 +90,4 @@ const SHAREDCOMPONENTS = [LogisticsTimeLineComponent, DictSelectComponent, Accou
|
||||
],
|
||||
declarations: SHAREDCOMPONENTS
|
||||
})
|
||||
export class SharedModule {}
|
||||
export class SharedModule { }
|
||||
|
||||
236
src/app/shared/utils/deal-precision.ts
Normal file
236
src/app/shared/utils/deal-precision.ts
Normal file
@ -0,0 +1,236 @@
|
||||
/**
|
||||
* 操作符类型运算符
|
||||
* +:加法运算
|
||||
* -:减法运算
|
||||
* *:乘法运算
|
||||
* /:除法运算
|
||||
*/
|
||||
type OperationType = '+' | '-' | '*' | '/';
|
||||
|
||||
class Big {
|
||||
/**
|
||||
* Big值
|
||||
*/
|
||||
private v: number;
|
||||
/**
|
||||
* 构造函数
|
||||
* @param v 初始值
|
||||
*/
|
||||
constructor(v: number) {
|
||||
this.v = v;
|
||||
}
|
||||
/**
|
||||
* 转换整数,返回倍数及整数值,比如
|
||||
* 100 >>> { times: 1, num: 100 } ===> 100
|
||||
* 3.14 >>> { times: 100, num: 3.14} ===> 314
|
||||
* @param n number
|
||||
*/
|
||||
private toInteger(n: number) {
|
||||
const ret = { times: 1, num: 0 };
|
||||
if (Number.isInteger(n)) {
|
||||
ret.num = n;
|
||||
return ret;
|
||||
}
|
||||
ret.times = Math.pow(10, n.toString().split('.')[1].length);
|
||||
ret.num = parseInt((n * ret.times + 0.5).toString(), 10);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* 执行运算
|
||||
* @param m 数值m
|
||||
* @param n 数值n
|
||||
* @param key 运算符
|
||||
*/
|
||||
private operation(m: number = 0, n: number = 0, key: OperationType) {
|
||||
const o1 = this.toInteger(m);
|
||||
const o2 = this.toInteger(n);
|
||||
|
||||
const n1 = o1.num;
|
||||
const n2 = o2.num;
|
||||
|
||||
const t1 = o1.times;
|
||||
const t2 = o2.times;
|
||||
|
||||
const max = Math.max(t1, t2);
|
||||
let result = 0;
|
||||
switch (key) {
|
||||
case '+':
|
||||
if (t1 === t2) {
|
||||
// 两个小数位数相同
|
||||
result = n1 + n2;
|
||||
} else if (t1 > t2) {
|
||||
// o1 小数位 大于 o2
|
||||
result = n1 + n2 * (t1 / t2);
|
||||
} else {
|
||||
// o1 小数位 小于 o2
|
||||
result = n1 * (t2 / t1) + n2;
|
||||
}
|
||||
result /= max;
|
||||
break;
|
||||
case '-':
|
||||
if (t1 === t2) {
|
||||
result = n1 - n2;
|
||||
} else if (t1 > t2) {
|
||||
result = n1 - n2 * (t1 / t2);
|
||||
} else {
|
||||
result = n1 * (t2 / t1) - n2;
|
||||
}
|
||||
result /= max;
|
||||
break;
|
||||
case '*':
|
||||
result = (n1 * n2) / (t1 * t2);
|
||||
break;
|
||||
case '/':
|
||||
result = (n1 * t2) / (t1 * n2);
|
||||
break;
|
||||
default:
|
||||
result = 0;
|
||||
}
|
||||
return new Big(result);
|
||||
}
|
||||
/**
|
||||
* 数值化
|
||||
* @param n
|
||||
*/
|
||||
private numeric(n: number | Big) {
|
||||
return n instanceof Big ? n.v : n;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加法运算
|
||||
* @param n
|
||||
*/
|
||||
public plus(n: number | Big) {
|
||||
return this.operation(this.v, this.numeric(n), '+');
|
||||
}
|
||||
/**
|
||||
* 减法运算
|
||||
* @param n
|
||||
*/
|
||||
public minus(n: number | Big) {
|
||||
return this.operation(this.v, this.numeric(n), '-');
|
||||
}
|
||||
/**
|
||||
* 乘法运算
|
||||
* @param n
|
||||
*/
|
||||
public multipliedBy(n: number | Big) {
|
||||
return this.operation(this.v, this.numeric(n), '*');
|
||||
}
|
||||
/**
|
||||
* 除法运算
|
||||
* @param n
|
||||
*/
|
||||
public dividedBy(n: number | Big) {
|
||||
return this.operation(this.v, this.numeric(n), '/');
|
||||
}
|
||||
/**
|
||||
* 解析结果
|
||||
*/
|
||||
public parse() {
|
||||
return this.v;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小数点后固定指定位数,比如固定小数点后5位数字,则有
|
||||
* 30 ==> 30.00000
|
||||
* 3.14 ===> 3.14000
|
||||
* @param n
|
||||
*/
|
||||
public static digits(v: number | Big, len: number = 2) {
|
||||
if (Number.isInteger(v)) {
|
||||
return `${v}.${Array(len).fill(0).join('')}`;
|
||||
} else {
|
||||
const [prefix, suffix] = v.toString().split('.');
|
||||
const sLen = suffix.length;
|
||||
if (sLen > len) {
|
||||
return `${prefix}.${suffix.slice(0, len)}`;
|
||||
} else if (sLen < len) {
|
||||
return `${prefix}.${suffix}${Array(len - sLen)
|
||||
.fill(0)
|
||||
.join('')}`;
|
||||
} else {
|
||||
return `${prefix}.${suffix}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
public digits(len: number) {
|
||||
return Big.digits(this.v, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* 人民币格式处理
|
||||
* - 非数字:返回0
|
||||
* - 整数:直接返回
|
||||
* - 小数:保留小数点后两位,超出两位则截取
|
||||
* @param v
|
||||
*/
|
||||
public static rmb(v: string | number) {
|
||||
if (isNaN(Number(v))) {
|
||||
return '0';
|
||||
} else {
|
||||
const foo = v.toString();
|
||||
if (/^[0-9]+$/.test(foo)) {
|
||||
return foo;
|
||||
} else {
|
||||
const [prefix, suffix] = foo.split('.');
|
||||
const sLen = suffix.length;
|
||||
if (sLen > 2) {
|
||||
return `${prefix}.${suffix.slice(0, 2)}`;
|
||||
} else if (sLen < 2) {
|
||||
return `${foo}0`;
|
||||
} else {
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public rmb() {
|
||||
return Big.rmb(this.v);
|
||||
}
|
||||
/**
|
||||
* 切割数字
|
||||
* @param v
|
||||
*/
|
||||
public static split(v: string | number) {
|
||||
if (isNaN(Number(v))) {
|
||||
return [];
|
||||
} else {
|
||||
return v
|
||||
.toString()
|
||||
.split('.')
|
||||
.map((item, i) => {
|
||||
if (i === 1) {
|
||||
return item && item.length < 2 ? `${item}0` : item;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
}
|
||||
public split() {
|
||||
return Big.split(this.v);
|
||||
}
|
||||
|
||||
/**
|
||||
* 省略 --> 如果超过1万,则返回万制,转换后小数点后保留两位
|
||||
* 比如:12345 返回 1.23万
|
||||
* @param v
|
||||
*/
|
||||
public static ellipsis(v: string | number) {
|
||||
// 如果不是数值类型并且转换之后不为数字,则直接返回传入值
|
||||
if (isNaN(Number(v))) {
|
||||
return v.toString();
|
||||
}
|
||||
// 如果传入数值小于1万则没必要转换,直接返回
|
||||
if (+v < 10000) {
|
||||
return v.toString();
|
||||
}
|
||||
// 超过1万,处理之后再返回
|
||||
return Big.rmb(+v / 10000) + '万';
|
||||
}
|
||||
public ellipsis(v: string | number) {
|
||||
return Big.ellipsis(this.v);
|
||||
}
|
||||
}
|
||||
|
||||
export default Big;
|
||||
@ -8,7 +8,7 @@
|
||||
-->
|
||||
<sf-item-wrap [id]="id" [schema]="schema" [ui]="ui" [showError]="showError" [error]="error" [showTitle]="schema.title">
|
||||
<app-dict-select [url]="ui?.url" [ngModel]="value" [params]="ui?.params" (ngModelChange)="change($event)"
|
||||
[containsAllLable]="ui?.containsAllLable" [mode]="ui?.mode" name="sf.dict.select">
|
||||
[containsAllLabel]="ui?.containsAllLabel" [mode]="ui?.mode" name="sf.dict.select">
|
||||
</app-dict-select>
|
||||
</sf-item-wrap>
|
||||
<!-- <sf-item-wrap [id]="id" [schema]="schema" [ui]="ui" [showError]="showError" [error]="error" [showTitle]="schema.title">
|
||||
|
||||
Reference in New Issue
Block a user