Forráskód Böngészése

自定义金额设置

laiguoran 3 éve
szülő
commit
1ba05e21c4

+ 7 - 0
app/const/material.js

@@ -32,6 +32,7 @@ const ex_basic_text = {
     bqht: '所选期合同计量金额',
     bqbg: '所选期变更计量金额',
     bqwc: '所选期完成计量金额',
+    zdy: '自定义金额',
 }
 const ex_calc = [
     {
@@ -52,6 +53,12 @@ const ex_calc = [
         value: '',
         select: true,
     },
+    {
+        code: 'zdy',
+        text: '自定义金额',
+        value: '',
+        select: false,
+    },
 ];
 
 const is_summary = {

+ 13 - 4
app/controller/material_controller.js

@@ -447,9 +447,7 @@ module.exports = app => {
                 if (!ctx.material.ex_calc) {
                     const calcBase = await ctx.service.stage.getMaterialCalcBase(stage_list, ctx.tender.info);
                     for (const bq of renderData.ex_calc) {
-                        const calc = _.find(calcBase, function(item) {
-                            return bq.code === item.code;
-                        });
+                        const calc = _.find(calcBase, { code: bq.code }) || _.find(calcBase, { code: 'bqwc' });
                         bq.value = calc.value;
                         // if (calc.code === 'bqwc') {
                         //     ctx.material.ex_expr = calc.value.toString() + '*[0-1]';
@@ -459,7 +457,18 @@ module.exports = app => {
                     // 并更新至调差表中
                     await ctx.service.material.update({ ex_calc: JSON.stringify(renderData.ex_calc) }, { id: ctx.material.id });
                 } else {
-                    renderData.ex_calc = JSON.parse(ctx.material.ex_calc);
+                    const ex_calc = JSON.parse(ctx.material.ex_calc);
+                    if (ctx.helper._.findIndex(ex_calc, { code: 'zdy' }) === -1) {
+                        ex_calc.push({
+                            code: 'zdy',
+                            text: '自定义金额',
+                            value: ctx.helper._.find(ex_calc, { code: 'bqwc' }).value,
+                            select: false,
+                        });
+                        // 并更新至调差表中
+                        await ctx.service.material.update({ ex_calc: JSON.stringify(ex_calc) }, { id: ctx.material.id });
+                    }
+                    renderData.ex_calc = ex_calc;
                 }
 
                 renderData.materialExponentData = await this._getMaterialExponentData(ctx);

+ 23 - 1
app/public/js/material_exponent.js

@@ -480,7 +480,7 @@ $(document).ready(() => {
 
         // 调差基数选中
         $('.calc_select').on('click', function () {
-            // 如果是选中则清除其余2个的选中
+            // 如果是选中则清除其余的选中
             const code = $(this).val();
             for (const calc of ex_calc) {
                 calc.select = $(this).is(':checked') && code === calc.code ? true : false;
@@ -494,6 +494,28 @@ $(document).ready(() => {
                 resetExTpTable();
             });
         });
+        // 回车提交
+        $('#calc_zdy').on('keypress', function () {
+            if(window.event.keyCode === 13) {
+                $(this).blur();
+            }
+        });
+        // 自定义金额变更并提交
+        $('#calc_zdy').on('blur', function () {
+            const newValue = parseFloat($(this).val());
+            const zdy = _.find(ex_calc, { code: 'zdy' });
+            if (zdy.value === newValue) {
+                return;
+            } else {
+                zdy.value = newValue;
+            }
+            postData(window.location.pathname + '/save', { type:'ex_calc', updateData: ex_calc }, function (result) {
+                ex_tp = result.ex_tp;
+                ex_expr = result.ex_expr;
+                resetExTpTable();
+            });
+        });
+
 
         $('#changeRate').change(function () {
             const rate = parseInt($(this).val());

+ 2 - 6
app/service/material_exponent.js

@@ -236,12 +236,8 @@ module.exports = app => {
             const old_ex_calc = ex_calc ? JSON.parse(ex_calc) : null;
             const new_ex_calc = materialConst.ex_calc;
             for (const bq of new_ex_calc) {
-                const calc = this._.find(calcBase, function(item) {
-                    return bq.code === item.code;
-                });
-                const oldcalc = old_ex_calc ? this._.find(old_ex_calc, function(item) {
-                    return bq.code === item.code;
-                }) : null;
+                const calc = this._.find(calcBase, { code: bq.code }) || this._.find(calcBase, { code: 'bqwc' });
+                const oldcalc = old_ex_calc ? this._.find(old_ex_calc, { code: bq.code }) : null;
                 bq.value = calc.value;
                 bq.select = oldcalc ? oldcalc.select : false;
             }

+ 2 - 2
app/view/material/exponent.ejs

@@ -79,13 +79,13 @@
                         <div class="sjs-sh-1">
                             <table class="table table-bordered">
                                 <thead>
-                                <tr><th>需调整的价差</th><th>金额</th><th>选择</th></tr>
+                                <tr><th>选择</th><th>需调整的价差</th><th>金额</th></tr>
                                 </thead>
                                 <tbody id="calc_basic_select">
                                 <% for (const bq of ex_calc) { %>
                                     <tr>
-                                        <td><%- materialType.ex_basic_text[bq.code] %></td><td><%- bq.value %></td>
                                         <td><input type="checkbox" value="<%- bq.code %>" <% if (material.readOnly) { %>disabled<% } %> class="calc_select" <% if (bq.select) { %>checked<% } %>></td>
+                                        <td><%- materialType.ex_basic_text[bq.code] %></td><td><% if (bq.code === 'zdy' && !material.readOnly) { %><input type="number" id="calc_zdy" class="form-control form-control-sm" value="<%- bq.value %>"><% } else { %><%- bq.value %><% } %></td>
                                     </tr>
                                 <% } %>
                                 </tbody>