调用decimal库处理计算

master
xy 12 months ago
parent f7e66c1cdf
commit 0a92f32efa

@ -17,6 +17,7 @@
"dependencies": { "dependencies": {
"axios": "0.18.1", "axios": "0.18.1",
"core-js": "3.6.5", "core-js": "3.6.5",
"decimal.js": "^10.4.3",
"echarts": "^4.9.0", "echarts": "^4.9.0",
"element-resize-detector": "^1.2.4", "element-resize-detector": "^1.2.4",
"element-ui": "2.13.2", "element-ui": "2.13.2",

@ -192,7 +192,7 @@
</el-row> </el-row>
<div class="demo-split" v-if="allowAuth"> <div class="demo-split" v-if="allowAuth">
<Split v-model="split" style="height: 440px"> <Split v-model="split" style="height: 570px">
<template #left> <template #left>
<div class="demo-split-pane" style="padding-right: 5px"> <div class="demo-split-pane" style="padding-right: 5px">
<div ref="lxHeader" v-if="statistic.departmentList"> <div ref="lxHeader" v-if="statistic.departmentList">
@ -206,7 +206,7 @@
<slot> <slot>
<div style="width: 100%"> <div style="width: 100%">
<xy-table <xy-table
:height="380" :height="488"
:list="statistic.departmentList" :list="statistic.departmentList"
:table-item="departmentTable" :table-item="departmentTable"
> >
@ -246,7 +246,7 @@
<slot> <slot>
<div style="width: 100%"> <div style="width: 100%">
<xy-table <xy-table
:height="380" :height="488"
:list="statistic.typeList" :list="statistic.typeList"
:table-item="typeTable" :table-item="typeTable"
> >

@ -250,7 +250,7 @@ import {
moneyFormatter moneyFormatter
} from "@/utils"; } from "@/utils";
import { listdeptNoAuth } from '@/api/system/department' import { listdeptNoAuth } from '@/api/system/department'
import { Decimal } from 'decimal.js'
export default { export default {
data() { data() {
return { return {
@ -553,16 +553,10 @@ import { listdeptNoAuth } from '@/api/system/department'
this.payment = res.data this.payment = res.data
}, },
add (num1, num2) {
const num1Digits = (num1.toString().split('.')[1] || '').length;
const num2Digits = (num2.toString().split('.')[1] || '').length;
const baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
return (num1 * baseNum + num2 * baseNum) / baseNum;
},
// //
// this.add(pre, Number(cur.use_money))
editor() { editor() {
let total = this.planSelection.reduce((pre,cur) => this.add(pre, Number(cur.use_money)),0) let total = this.planSelection.reduce((pre,cur) => new Decimal(pre).add(new Decimal(cur.use_money)),0).toNumber()
console.log(Number(this.paymentRegistrationForm.actMoney),total) console.log(Number(this.paymentRegistrationForm.actMoney),total)
if (Number(this.paymentRegistrationForm.actMoney) !== total) { if (Number(this.paymentRegistrationForm.actMoney) !== total) {
this.$message({ this.$message({

@ -567,7 +567,7 @@ export default {
this.planTotal = res.list.total || 0; this.planTotal = res.list.total || 0;
this.toggleSelection( this.toggleSelection(
this.plan.map((item) => { this.plan?.map((item) => {
return item.value.plan_id; return item.value.plan_id;
}), }),
1 1

Loading…
Cancel
Save