Przeglądaj źródła

模板示例,计算代码调整

MaiXinRong 1 miesiąc temu
rodzic
commit
1e5bb82c18
3 zmienionych plików z 13 dodań i 23 usunięć
  1. 12 20
      app/public/js/pos_calc_tmpl.js
  2. 1 1
      app/view/template/sub_menu.ejs
  3. 0 2
      config/web.js

+ 12 - 20
app/public/js/pos_calc_tmpl.js

@@ -260,19 +260,18 @@ $(document).ready(() => {
         SpreadJsObj.initSheet(previewSheet, previewSpreadSetting);
         const qtyCol = previewSpreadSetting.cols.find(x => { return x.field === 'qty'; });
         if (qtyCol) {
-            previewData.forEach(x => {
-                let calcExpr = qtyCol.expr;
-                previewSpreadSetting.cols.forEach(c => {
-                    if (c.type !== 'Number' || c.field === 'qty') return;
-                    calcExpr = calcExpr.replace(new RegExp(c.field, 'gm'), x[c.field]);
-                });
-                x.calc_expr = calcExpr;
+            for (const pd of previewData) {
+                pd.calcExpr = qtyCol.expr;
+                for (const col of previewSpreadSetting.cols) {
+                    if (col.type !== 'Number' || col.field === 'qty') continue;
+                    pd.calcExpr = pd.calcExpr.replace(new RegExp(col.field, 'gm'), pd[col.field]);
+                }
                 try {
-                    x.qty = ZhCalc.round(ZhCalc.mathCalcExpr(calcExpr.replace(new RegExp('%', 'gm'), '/100')), qtyCol.decimal);
-                } catch {
-                    x.qty = 0;
+                    pd.qty = ZhCalc.round(ZhCalc.mathCalcExpr(pd.calcExpr.replace(new RegExp('%', 'gm'), '/100')), qtyCol.decimal);
+                } catch(err) {
+                    pd.qty = 0;
                 }
-            });
+            }
         }
         SpreadJsObj.loadSheetData(previewSheet, SpreadJsObj.DataType.Data, previewData);
     });
@@ -291,16 +290,9 @@ $(document).ready(() => {
         let curTemplate;
 
         const loadTemplateDetail = async function(template) {
-            const result = await postDataAsync('load', { filter: 'detail', id: template.id, type: 'posCalc' });
+            const result = await postDataAsync('load', {filter: 'detail', id: template.id, type: 'posCalc'});
             if (result && result.detail) template.col_set = result.detail.col_set;
-            // template.col_set = [
-            //     { title: '名称', width: 80, type: 'str', field: 'str1' },
-            //     { title: '长度', width: 80, type: 'num', field: 'num1', decimal: 2, unit: 'm', calc_code: 'A' },
-            //     { title: '宽度', width: 80, type: 'num', field: 'num2', decimal: 2, unit: 'm', calc_code: 'B' },
-            //     { title: '高度', width: 80, type: 'num', field: 'num3', decimal: 2, unit: 'm', calc_code: 'C' },
-            //     { title: '数量', width: 80, type: 'qty', field: 'qty', decimal: 2, expr: 'A*B*C' },
-            // ];
-        };
+        }
         const refreshTemplate = async function() {
             if (!curTemplate) {
                 // todo 隐藏模板详细界面

+ 1 - 1
app/view/template/sub_menu.ejs

@@ -6,7 +6,7 @@
         <div class="nav-box">
             <ul class="nav-list list-unstyled">
                 <% if (ctx.subProject.page_show.posCalcDetail) { %>
-                <li <% if (ctx.url.indexOf('pos-calc') >= 0) { %>class="active"<% } %>>
+                <li <% if (ctx.url.indexOf('posCalc') >= 0) { %>class="active"<% } %>>
                     <a href="/sp/<%- ctx.subProject.id %>/template/posCalc"><span>设计量明细</span></a>
                 </li>
                 <% } %>

+ 0 - 2
config/web.js

@@ -2474,7 +2474,6 @@ const JsFiles = {
                 ],
                 mergeFiles: [
                     '/public/js/zh_calc.js',
-                    '/public/js/sub_menu.js',
                     '/public/js/spreadjs_rela/spreadjs_zh.js',
                     '/public/js/pos_calc_tmpl.js',
                 ],
@@ -2488,7 +2487,6 @@ const JsFiles = {
                 ],
                 mergeFiles: [
                     '/public/js/zh_calc.js',
-                    '/public/js/sub_menu.js',
                     '/public/js/spreadjs_rela/spreadjs_zh.js',
                     '/public/js/cost_tmpl.js',
                 ],