Commit b942f005 authored by 郭小龙-DEL's avatar 郭小龙-DEL

Merge branch 'func_eccs_2376' into 'master'

fix js精度计算

See merge request !69
parents e352c084 49fca3a5
......@@ -89,4 +89,113 @@ export function exportFile(res, file_name) {
window.URL.revokeObjectURL(url);
}
export const numValid = /^([1-9][0-9]*|0)([.][0-9]+)?$/
\ No newline at end of file
export const numValid = /^([1-9][0-9]*|0)([.][0-9]+)?$/
// 数值计算
export const accuracy = {
division(arg1, arg2) {
//除法
var t1 = 0,
t2 = 0,
r1,
r2;
try {
t1 = arg1.toString().split('.')[1].length;
} catch(e) {
console.log(e);
}
try {
t2 = arg2.toString().split('.')[1].length;
} catch(e) {
console.log(e);
}
if(Math) {
r1 = Number(arg1.toString().replace('.', ''));
r2 = Number(arg2.toString().replace('.', ''));
return this.multiply(r1 / r2, Math.pow(10, t2 - t1));
}
},
multiply(arg1, arg2) {
//乘法
var m = 0,
s1 = arg1.toString(),
s2 = arg2.toString();
try {
m += s1.split('.')[1].length;
} catch(e) {
console.log(e)
}
try {
m += s2.split('.')[1].length;
} catch(e) {
console.log(e)
}
return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m);
},
add(arg1, arg2) {
//加法
var r1, r2, m;
try {
r1 = arg1.toString().split('.')[1].length;
} catch(e) {
r1 = 0;
}
try {
r2 = arg2.toString().split('.')[1].length;
} catch(e) {
r2 = 0;
}
m = Math.pow(10, Math.max(r1, r2));
console.log(this.multiply(arg1, m), this.multiply(arg2, m))
return(this.multiply(arg1, m) + this.multiply(arg2, m)) / m;
},
subtract(arg1, arg2) {
//减法
var r1, r2, m, n;
try {
r1 = arg1.toString().split('.')[1].length;
} catch(e) {
r1 = 0;
}
try {
r2 = arg2.toString().split('.')[1].length;
} catch(e) {
r2 = 0;
}
m = Math.pow(10, Math.max(r1, r2));
n = r1 >= r2 ? r1 : r2;
return((arg1 * m - arg2 * m) / m).toFixed(n);
},
// 计算一个数组的总和
sum(arr) {
let result = 0;
arr.forEach(item => {
result = this.add(result, item);
})
return result;
},
// 计算一个数组的总和 fn是对每项数据的处理方式
sumBy(arr, fn) {
let result = 0;
arr.forEach(item => {
let val = item;
if(fn) {
val = fn(item)
}
result = this.add(result, val);
})
return result;
},
toCeil(num, p = 4) {
num = isNaN(num) ? 0 : num;
p = isNaN(p) ? 0 : p;
let precision = Math.pow(10, p);
return Math.ceil((num * precision).toFixed(1)) / precision;
},
toFloor(num, p = 4) {
num = isNaN(num) ? 0 : num;
p = isNaN(p) ? 0 : p;
let precision = Math.pow(10, p);
return Math.floor((num * precision).toFixed(1)) / precision;
}
};
\ No newline at end of file
......@@ -165,7 +165,9 @@ export default {
{ title: '收费时间', dataIndex: 'receiptDate', width: 180 },
{ title: '账单编号', dataIndex: 'receiptNo', width: 180 },
{ title: '账单类型', dataIndex: 'receiptTypeStr', width: 130 },
{ title: '状态', dataIndex: 'status', width: 130, scopedSlots: { customRender: 'status' } },
{ title: '状态', dataIndex: 'status', width: 130, customRender: val => {
return <span class={val === '2' ? 'red-text' : ''}>{val === '2' ? '无效' : '有效'}</span>;
}},
{ title: '病历号', dataIndex: 'mrnNo', width: 180 },
{ title: '客户姓名', dataIndex: 'patientName', width: 120 },
{ title: '保险公司', dataIndex: 'payorName', width: 200 },
......
......@@ -131,7 +131,7 @@
<a-col :lg="6" :sm="12">
<a-form-model-item label="本次账单回款金额合计">
<!-- <div class="blue-text">{{ ciReceiptTotalVo.backAmountTotal || 0 }}</div> -->
<div class="blue-text">{{ form.backAmountCny - residueBackAmount || 0 }}</div>
<div class="blue-text">{{ accuracy.subtract(form.backAmountCny, residueBackAmount) || 0 }}</div>
</a-form-model-item>
</a-col>
......@@ -314,7 +314,7 @@ import { Empty } from 'ant-design-vue';
import Goback from '@/components/CUSTOMER/goback';
import BurtPagination from '@/components/CUSTOMER/pagation';
import { EOBStatusOptions } from '@/utils/utilsdictOptions.js';
import { exportFile } from '@/utils/index';
import { exportFile, accuracy } from '@/utils/index';
import moment from 'moment';
import mixins from '@/mixins';
const panes = [
......@@ -324,6 +324,7 @@ const panes = [
export default {
data() {
return {
accuracy,
isEdit: false,
EOBStatusOptions,
dialogShow: false,
......@@ -580,7 +581,7 @@ export default {
this.selectedRows.forEach((item) => {
totalMoney -= Number(item.backAmount);
});
return Number(totalMoney.toFixed(2));
return Number(totalMoney.toFixed(2)) || 839.21;
}
},
watch: {
......@@ -593,6 +594,8 @@ export default {
}
},
created() {
console.log('1111111111111111 :>>', 1111111111111111);
console.log(this.accuracy.add(0.1, 0.2))
this.simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;
const { backMoneyNo, isEdit } = this.$route.query;
this.backMoneyNo = backMoneyNo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment