瀏覽代碼

修复月信息价bug

laiguoran 4 年之前
父節點
當前提交
bbdc59cfe1
共有 1 個文件被更改,包括 70 次插入74 次删除
  1. 70 74
      app/public/js/material.js

+ 70 - 74
app/public/js/material.js

@@ -95,58 +95,6 @@ const is_numeric = (value) => {
     }
 };
 
-function setMonthHtml() {
-    let html = '';
-    let qihtml = '';
-    for (const m of months) {
-        html += '<div class="custom-control custom-checkbox mb-2">\n' +
-            '                            <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
-            '                            <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
-            '                        </div>';
-        qihtml += parseInt(m.split('-')[1]) + '月,';
-    }
-    if (months.length > 0) {
-        qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
-        qihtml = qihtml.substring(0, qihtml.length-1);
-    }
-    $('#show_month').html(html);
-    $('#qi-month').html(qihtml);
-}
-
-function monthSpreadHeaderReset() {
-    const newMonths = [];
-    for (const m of months) {
-        const year = m.split('-')[0];
-        const month = parseInt(m.split('-')[1]);
-        let one = _.find(newMonths, { 'year': year });
-        let oneIndex = _.findIndex(newMonths, { 'year': year });
-        if (one) {
-            one.month.push(month);
-            newMonths.splice(oneIndex, 1, one);
-        } else {
-            one = {
-                year: year,
-                month: [ month ],
-            };
-            newMonths.push(one);
-        }
-    }
-    const pushMonth = [];
-    for(const mo of newMonths) {
-        for (let i in mo.month) {
-            i = parseInt(i);
-            const newCols = {
-                title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
-                colSpan: (i === 0 && mo.month.length === 1 ? '0' : '') + '|1',
-                rowSpan: i === 0 || i === mo.month.length-1 ? '1|1' : '|1',
-                field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
-                hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
-            pushMonth.push(newCols);
-        }
-    }
-    return pushMonth;
-}
-
 $(document).ready(() => {
     autoFlashHeight();
     const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
@@ -163,11 +111,11 @@ $(document).ready(() => {
             {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
             {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
             {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.remark'},
-            {title: '|价差', colSpan: '|1', rowSpan: '1|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},
+            {title: '|价差', colSpan: '|1', rowSpan: '|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},
             {title: '本期材料调差|上涨幅度(%)', colSpan: '4|1', rowSpan: '1|1', field: 'm_up_risk', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.isEdit'},
             {title: '|下跌幅度(%)', colSpan: '|1', rowSpan: '|1', field: 'm_down_risk', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.isEdit'},
             {title: '|有效价差', colSpan: '|1', rowSpan: '|1', field: 'm_spread', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
-            {title: '|调差金额', colSpan: '|1', rowSpan: '1|1', field: 'm_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
+            {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
             {title: '截止上期调差金额', colSpan: '1', rowSpan: '2', field: 'pre_tp', hAlign: 2, width: 120, type: 'Number', readOnly: true},
             {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.remark'},
         ],
@@ -585,6 +533,71 @@ $(document).ready(() => {
         {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
         {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
     ];
+    // 月信息价方法集合
+    const monthFunGather = {
+        _setMonthHtml: function() {
+            let html = '';
+            let qihtml = '';
+            for (const m of months) {
+                html += '<div class="custom-control custom-checkbox mb-2">\n' +
+                    '                            <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
+                    '                            <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
+                    '                        </div>';
+                qihtml += parseInt(m.split('-')[1]) + '月,';
+            }
+            if (months.length > 0) {
+                qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
+                qihtml = qihtml.substring(0, qihtml.length-1);
+            }
+            $('#show_month').html(html);
+            $('#qi-month').html(qihtml);
+        },
+        _monthHeaderSet: function() {
+            const newMonths = [];
+            for (const m of months) {
+                const year = m.split('-')[0];
+                const month = parseInt(m.split('-')[1]);
+                let one = _.find(newMonths, { 'year': year });
+                let oneIndex = _.findIndex(newMonths, { 'year': year });
+                if (one) {
+                    one.month.push(month);
+                    newMonths.splice(oneIndex, 1, one);
+                } else {
+                    one = {
+                        year: year,
+                        month: [ month ],
+                    };
+                    newMonths.push(one);
+                }
+            }
+            const pushMonth = [];
+            for(const mo of newMonths) {
+                for (let i in mo.month) {
+                    i = parseInt(i);
+                    const newCols = {
+                        title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
+                        colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
+                        rowSpan: i === 0 ? '1|1' : '|1',
+                        field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
+                        hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
+                    pushMonth.push(newCols);
+                }
+            }
+            return pushMonth;
+        },
+        monthSheetReset: function () {
+            const monthCols = monthFunGather._monthHeaderSet();
+            const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
+            materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
+            // 表头变化需要重新绘制,不然报错;
+            materialMonthSpread.getActiveSheet().reset();
+            SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
+            SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
+            SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
+            monthFunGather._setMonthHtml();
+        }
+    }
+
     const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
     const materialMonthSpreadSetting = {
         cols: static_cols,
@@ -597,11 +610,10 @@ $(document).ready(() => {
         readOnly: readOnly,
     };
     if (months.length > 0) {
-        const monthCols = monthSpreadHeaderReset();
+        const monthCols = monthFunGather._monthHeaderSet();
         const monthSpreadHeaderCols = static_cols.concat(monthCols);
         materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
     }
-    console.log(materialMonthSpreadSetting);
 
     const materialMonthCol = {
         getValue: {
@@ -977,17 +989,8 @@ $(document).ready(() => {
             postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
                 months.push(yearmonth);
                 months.sort();
-                const monthCols = monthSpreadHeaderReset();
-                const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
-                materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
                 monthsList = data.monthsList;
-                SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
-                console.log(materialMonthSpreadSetting);
-                // SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
-                SpreadJsObj.reinitSheetHeader(materialMonthSpread.getActiveSheet());
-                SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
-                setMonthHtml();
-
+                monthFunGather.monthSheetReset();
                 // 工料表单价显示也要更新
                 materialBillsData = data.materialBillsData;
                 SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
@@ -1015,15 +1018,8 @@ $(document).ready(() => {
                         return n === dm;
                     });
                 }
-                const monthCols = monthSpreadHeaderReset();
-                const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
-                materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
                 monthsList = data.monthsList;
-                SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
-                console.log(materialMonthSpreadSetting);
-                SpreadJsObj.reinitSheetHeader(materialMonthSpread.getActiveSheet());
-                SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
-                setMonthHtml();
+                monthFunGather.monthSheetReset();
 
                 // 工料表单价显示也要更新
                 materialBillsData = data.materialBillsData;