|
@@ -117,13 +117,17 @@ $(document).ready(function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ // 转化成两位小数
|
|
|
+ function fixedToSub(s) {
|
|
|
+ return parseFloat(parseFloat(s).toFixed(2))
|
|
|
+ }
|
|
|
// 自动转换支付比例和本期金额
|
|
|
$('.pay-input').on('input propertychange', function(e) {
|
|
|
- let val = parseInt(e.target.value)
|
|
|
+ let val = parseFloat(e.target.value)
|
|
|
const p_amount = prevAdvance && prevAdvance.prev_total_amount || 0 // 截止本期金额
|
|
|
const re_amount = ZhCalc.sub(advancePayTotal, p_amount) // 剩余未付款的总额
|
|
|
- const min = parseInt($(this).attr('min'))
|
|
|
- const max = parseInt($(this).attr('max'))
|
|
|
+ const min = parseFloat($(this).attr('min'))
|
|
|
+ const max = parseFloat($(this).attr('max'))
|
|
|
const type = parseInt($(this).data('type'))
|
|
|
let pay_ratio = null
|
|
|
let cur_amount = null
|
|
@@ -137,6 +141,7 @@ $(document).ready(function () {
|
|
|
$(this).val(max)
|
|
|
val = max
|
|
|
}
|
|
|
+ $(this).val(fixedToSub(val)) // 重新赋值限制只有两位小数
|
|
|
// 本期金额转化
|
|
|
if (type === 1) {
|
|
|
if (val > re_amount) {
|
|
@@ -145,26 +150,27 @@ $(document).ready(function () {
|
|
|
val = re_amount
|
|
|
}
|
|
|
const pay_a_input = $(`.pay-input[data-type=${reverse(type)}]`)
|
|
|
- pay_ratio = ZhCalc.round(ZhCalc.mul(ZhCalc.div(val, re_amount), 100), 2)
|
|
|
+ pay_ratio = parseFloat(ZhCalc.mul(ZhCalc.div(val, advancePayTotal), 100).toFixed(2))
|
|
|
cur_amount = val
|
|
|
pay_a_input.val(pay_ratio)
|
|
|
// 截止本期金额文案更新
|
|
|
- $('#p_total2').text(formatMoney(ZhCalc.add(val, p_amount)))
|
|
|
+ $('#p_total2').text(formatMoney(ZhCalc.add(val, p_amount), ',', decimal))
|
|
|
} else {
|
|
|
// 支付比例转化
|
|
|
const cur_m_input = $(`.pay-input[data-type=${reverse(type)}]`)
|
|
|
- cur_amount = ZhCalc.mul(re_amount, ZhCalc.div(val, 100))
|
|
|
+ cur_amount = ZhCalc.mul(advancePayTotal, ZhCalc.div(val, 100, 10))
|
|
|
+ console.log('val', ZhCalc.div(val, 100, 10), 'cur_amount', cur_amount)
|
|
|
pay_ratio = val
|
|
|
cur_m_input.val(cur_amount)
|
|
|
// 截止本期金额文案更新
|
|
|
- $('#p_total2').text(formatMoney(ZhCalc.add(cur_amount, p_amount)))
|
|
|
+ $('#p_total2').text(formatMoney(ZhCalc.add(cur_amount, p_amount), ',', decimal))
|
|
|
}
|
|
|
const data = {
|
|
|
pay_ratio,
|
|
|
cur_amount,
|
|
|
}
|
|
|
oldVal = {
|
|
|
- cur_amount: parseInt($(`.pay-input[data-type=${1}]`).val()),
|
|
|
+ cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
|
|
|
remark: filterText($('#ad-remark').val())
|
|
|
}
|
|
|
clearTimeout(timer)
|
|
@@ -178,7 +184,7 @@ $(document).ready(function () {
|
|
|
|
|
|
function checkInput() {
|
|
|
const newVal = {
|
|
|
- cur_amount: parseInt($(`.pay-input[data-type=${1}]`).val()),
|
|
|
+ cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
|
|
|
remark: filterText($('#ad-remark').val())
|
|
|
}
|
|
|
return newVal.cur_amount === oldVal.cur_amount && newVal.remark === oldVal.remark
|
|
@@ -187,8 +193,8 @@ $(document).ready(function () {
|
|
|
$('#ad-remark').on('input propertychange', function(e) {
|
|
|
const remark = filterText(e.target.value);
|
|
|
oldVal = {
|
|
|
- pay_ratio: parseInt($(`.pay-input[data-type=${0}]`).val()),
|
|
|
- cur_amount: parseInt($(`.pay-input[data-type=${1}]`).val()),
|
|
|
+ pay_ratio: parseFloat($(`.pay-input[data-type=${0}]`).val()),
|
|
|
+ cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
|
|
|
remark
|
|
|
}
|
|
|
const data = oldVal
|
|
@@ -300,14 +306,15 @@ function reverse(num){
|
|
|
return 1^num
|
|
|
}
|
|
|
|
|
|
-function formatMoney(s, dot = ',') {
|
|
|
+function formatMoney(s, dot = ',', decimal = 2) {
|
|
|
if (!s) return '0.00';
|
|
|
- s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(2) + '';
|
|
|
+ s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal === 0 ? 2 : decimal) + '';
|
|
|
let l = s.split('.')[0].split('').reverse(),
|
|
|
- r = s.split('.')[1];
|
|
|
+ r = s.split('.')[1].slice(0, decimal);
|
|
|
let t = '';
|
|
|
for (let i = 0; i < l.length; i++) {
|
|
|
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? dot : '');
|
|
|
}
|
|
|
- return t.split('').reverse().join('') + '.' + r;
|
|
|
+ debugger
|
|
|
+ return t.split('').reverse().join('') + (decimal === 0 ? '' : '.' + r)
|
|
|
}
|