Browse Source

fix: 预付款修改了小数位数后退回原报当前期页面可编辑区域显示舍入后的值

lanjianrong 5 years ago
parent
commit
447e7c7102
3 changed files with 29 additions and 8 deletions
  1. 13 2
      app/controller/advance_controller.js
  2. 15 5
      app/service/advance.js
  3. 1 1
      app/view/advance/detail.ejs

+ 13 - 2
app/controller/advance_controller.js

@@ -144,12 +144,23 @@ module.exports = app => {
                 // 最大支付比例
                 const max_pr = ctx.helper.mul(ctx.helper.div(ctx.helper.sub(advancePayTotal, (prevAdvance && prevAdvance.prev_total_amount || 0)), advancePayTotal, 10), 100);
                 // 特殊处理金额的显示(formatMoney)
+                let cur_amount,
+                    prev_total_amount;
                 const s1 = parseFloat(ctx.advance.prev_amount).toString().split('.')[1];
-                const s2 = parseFloat(ctx.advance.prev_total_amount).toString().split('.')[1];
                 const prev_amount = ctx.helper.formatMoney(ctx.advance.prev_amount, ',', s1 && s1.length || 0);
-                const prev_total_amount = ctx.helper.formatMoney(ctx.advance.prev_total_amount, ',', s2 && s2.length || 0);
+                if (isEdited) {
+                    cur_amount = parseFloat(ctx.helper.round(ctx.advance.cur_amount, this.decimal)) || 0;
+                    const s2 = parseFloat(ctx.helper.add(cur_amount, ctx.advance.prev_amount)).toString().split('.')[1];
+                    prev_total_amount = ctx.helper.formatMoney(ctx.helper.add(cur_amount, ctx.advance.prev_amount), ',', s2 && s2.length || 0);
+                } else {
+                    cur_amount = ctx.advance.cur_amount;
+                    const s2 = parseFloat(ctx.advance.prev_total_amount).toString().split('.')[1];
+                    prev_total_amount = ctx.helper.formatMoney(ctx.advance.prev_total_amount, ',', s2 && s2.length || 0);
+                }
+
                 renderData.isEdited = isEdited;
                 renderData.advance = ctx.advance;
+                renderData.cur_amount = cur_amount;
                 renderData.prev_amount = prev_amount;
                 renderData.prev_total_amount = prev_total_amount;
                 renderData.max_pr = max_pr;

+ 15 - 5
app/service/advance.js

@@ -35,13 +35,23 @@ module.exports = app => {
             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
             const advance = await this.db.query(sql, sqlParam);
             for (const item of advance) {
-                item.pay_ratio = this.ctx.helper.mul(this.ctx.helper.div(item.cur_amount, advancePayTotal), 100, 2) || 0;
-                const s1 = item.cur_amount && item.cur_amount.toString().split('.')[1];
+                let s1,
+                    s3;
                 const s2 = item.prev_amount.toString().split('.')[1];
-                const s3 = item.prev_total_amount.toString().split('.')[1];
-                item.cur_amount = this.ctx.helper.formatMoney(item.cur_amount, ',', s1 && s1.length || 0);
+                item.pay_ratio = this.ctx.helper.mul(this.ctx.helper.div(item.cur_amount, advancePayTotal), 100, 2) || 0;
+                if (item.status === auditConst.status.uncheck || item.status === auditConst.status.checkNo) {
+                    const cur_amount = item.cur_amount && this.ctx.helper.round(item.cur_amount, decimal) || 0;
+                    s1 = parseFloat(cur_amount).toString().split('.')[1];
+                    s3 = parseFloat(this.ctx.helper.add(cur_amount, item.prev_amount)).toString().split('.')[1];
+                    item.cur_amount = this.ctx.helper.formatMoney(cur_amount, ',', s1 && s1.length || 0);
+                    item.prev_total_amount = this.ctx.helper.formatMoney(this.ctx.helper.add(cur_amount, item.prev_amount), ',', s3 && s3.length || 0);
+                } else {
+                    s1 = item.cur_amount && item.cur_amount.toString().split('.')[1];
+                    s3 = item.prev_total_amount.toString().split('.')[1];
+                    item.cur_amount = this.ctx.helper.formatMoney(item.cur_amount, ',', s1 && s1.length || 0);
+                    item.prev_total_amount = this.ctx.helper.formatMoney(item.prev_total_amount, ',', s3 && s3.length || 0);
+                }
                 item.prev_amount = this.ctx.helper.formatMoney(item.prev_amount, ',', s2 && s2.length || 0);
-                item.prev_total_amount = this.ctx.helper.formatMoney(item.prev_total_amount, ',', s3 && s3.length || 0);
                 item.curAuditor = await this.ctx.service.advanceAudit.getAuditorByStatus(item.id, item.status, item.times);
                 if (item.status === auditConst.status.checkNoPre) {
                     item.curAuditor2 = await this.ctx.service.advanceAudit.getAuditorByStatus(item.id, auditConst.status.checking);

+ 1 - 1
app/view/advance/detail.ejs

@@ -43,7 +43,7 @@
                                     <div class="input-group input-group-sm">
                                         <input type="number" class="pay-input form-control nospin text-right" min="1" <%- isEdited  ? '' : 'disabled' %>
                                             placeholder="请填写本期金额,将自动计算支付比例" data-type="1"
-                                            value="<%- advance.cur_amount && isEdited ? parseFloat(advance.cur_amount.toFixed(decimal)) : advance.cur_amount %>">
+                                            value="<%- cur_amount %>">
                                         <div class="input-group-append"><span class="input-group-text">元</span></div>
                                     </div>
                                 </td>