Przeglądaj źródła

1. 合同支付,本期金额/起扣金额/付扣款限额,进入单元格,有公式时,显示公式

MaiXinRong 6 lat temu
rodzic
commit
c069b30d15

+ 8 - 3
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -963,8 +963,13 @@ const SpreadJsObj = {
              * @param {Object} hitinfo - 见getHitInfo返回值
              */
             proto.processMouseEnter = function (hitinfo) {
-                const text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
-                const setting = hitinfo.sheet.setting;
+                let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
+                const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
+                if (col.getTip && Object.prototype.toString.apply(col.getTip) === "[object Function]") {
+                    const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
+                    text = col.getTip(sortData[hitinfo.row]);
+                }
+                const setting = hitinfo.sheet.zh_setting;
                 if (setting.pos && text && text !== '') {
                     if (!this._toolTipElement) {
                         let div = $('#autoTip')[0];
@@ -977,7 +982,7 @@ const SpreadJsObj = {
                                 .css("background", "white")
                                 .css("padding", 5)
                                 .attr("id", 'autoTip');
-                            $(div).hide();
+                            //$(div).hide();
                             document.body.insertBefore(div, null);
                         }
                         this._toolTipElement = div;

+ 98 - 14
app/public/js/stage_pay.js

@@ -34,11 +34,11 @@ $(document).ready(() => {
         cols: [
             {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.name'},
             {title: '扣款', colSpan: '1', rowSpan: '1', field: 'minus', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.minus'},
-            {title: '本期金额(表达式)', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 100, readOnly: 'readOnly.tp'},
+            {title: '本期金额(表达式)', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 100, readOnly: 'readOnly.tp', cellType: 'tip', getTip: function (data) {return data ? data.expr : '';}},
             {title: '截止上期金额',  colSpan: '1', rowSpan: '1', field: 'pre_tp', hAlign: 2, width: 100, readOnly: true},
             {title: '截止本期金额',  colSpan: '1', rowSpan: '1', field: 'end_tp', hAlign: 2, width: 100, readOnly: true},
-            {title: '起扣金额',  colSpan: '1', rowSpan: '1', field: 'sprice', hAlign: 2, width: 100, readOnly: 'readOnly.sprice'},
-            {title: '付(扣)款限额',  colSpan: '1', rowSpan: '1', field: 'rprice', hAlign: 2, width: 100, readOnly: 'readOnly.rprice'},
+            {title: '起扣金额',  colSpan: '1', rowSpan: '1', field: 'sprice', hAlign: 2, width: 100, readOnly: 'readOnly.sprice', cellType: 'tip', getTip: function (data) {return data ? data.expr : '';}},
+            {title: '付(扣)款限额',  colSpan: '1', rowSpan: '1', field: 'rprice', hAlign: 2, width: 100, readOnly: 'readOnly.rprice', cellType: 'tip', getTip: function (data) {return data ? data.expr : '';}},
             {
                 title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
                 normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: 'getValue.attachment'
@@ -50,6 +50,7 @@ $(document).ready(() => {
         headRowHeight: [50],
         defaultRowHeight: 30,
         readOnly: readOnly,
+        pos: SpreadJsObj.getObjPos($('#pay-spread')[0]),
     };
     paySpreadSetting.imageClick = function (data) {
         $('#file').modal('show');
@@ -164,7 +165,9 @@ $(document).ready(() => {
                 const order = cur.order;
                 cur.order = up.order;
                 up.order = order;
-                dealPay.sort(function (a, b) {return a.order - b.order});
+                dealPay.sort(function (a, b) {
+                    return a.order - b.order
+                });
                 SpreadJsObj.reLoadSheetData(sheet);
                 const sel = sheet.getSelections();
                 const index = dealPay.indexOf(cur);
@@ -176,11 +179,17 @@ $(document).ready(() => {
             const sheet = paySpread.getActiveSheet();
             const cur = SpreadJsObj.getSelectObject(sheet);
             const down = dealPay[dealPay.indexOf(cur) + 1];
-            postData(window.location.pathname + '/save', {type: 'changeOrder', id1: cur.pid, id2: down.pid}, function () {
+            postData(window.location.pathname + '/save', {
+                type: 'changeOrder',
+                id1: cur.pid,
+                id2: down.pid
+            }, function () {
                 const order = cur.order;
                 cur.order = down.order;
                 down.order = order;
-                dealPay.sort(function (a, b) {return a.order - b.order});
+                dealPay.sort(function (a, b) {
+                    return a.order - b.order
+                });
                 SpreadJsObj.reLoadSheetData(sheet);
                 const sel = sheet.getSelections();
                 const index = dealPay.indexOf(cur);
@@ -190,9 +199,24 @@ $(document).ready(() => {
         },
         selectionChanged: function (e, info) {
             paySpreadObj.refreshActn();
+            const sel = info.sheet.getSelections()[0];
+            const col = info.sheet.zh_setting.cols[sel.col];
+            const data = SpreadJsObj.getSelectObject(info.sheet);
+            if (col.field === 'tp') {
+                $('#expr').val(data.expr).attr('field', 'expr').attr('org', data.expr)
+                    .attr('readOnly', readOnly|| payCol.readOnly.isSpecial(data));
+            } else if (col.field === 'sprice') {
+                $('#expr').val(data.sexpr).attr('field', 'sexpr').attr('org', data.sexpr)
+                    .attr('readOnly', readOnly|| payCol.readOnly.isSpecial(data) || payCol.readOnly.isOld(data));
+            } else if (col.field === 'rprice') {
+                $('#expr').val(data.rexpr).attr('field', 'rexpr').attr('org', data.rexpr)
+                    .attr('readOnly', readOnly|| payCol.readOnly.isSpecial(data) || payCol.readOnly.isOld(data));
+            } else {
+                $('#expr').val('').attr('readOnly', true);
+            }
         },
         editEnded: function (e, info) {
-            const checkExpr = function(text, data, priceField, exprField) {
+            const checkExpr = function (text, data, priceField, exprField) {
                 if (text) {
                     const num = _.toNumber(text);
                     if (num) {
@@ -210,10 +234,23 @@ $(document).ready(() => {
             if (info.sheet.zh_setting) {
                 const select = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
-                if (col.field === 'minus') { return; }
+                if (col.field === 'minus') {
+                    return;
+                }
                 // 未改变值则不提交
-                const orgValue = select[col.field];
-                if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (info.editingText === ''))) {
+                const validText = info.editingText ? info.editingText.replace('\n', '') : null;
+                let orgValue;
+                if (col.field === 'tp') {
+                    orgValue = _.toNumber(validText) ? select.tp : select.expr;
+                } else if (col.field === 'sprice') {
+                    orgValue = _.toNumber(validText) ? select.sprice : select.sexpr;
+                } else if (col.field === 'rprice') {
+                    orgValue = _.toNumber(validText) ? select.rexpr : select.rexpr;
+                } else {
+                    orgValue = select[col.field];
+                }
+                if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 }
                 // 获取更新信息
@@ -221,7 +258,6 @@ $(document).ready(() => {
                     type: col.field === 'tp' ? 'stage' : 'info',
                     updateData: {}
                 };
-                const validText = info.editingText ? info.editingText.replace('\n', '') : null;
                 // 获取更新数据
                 if (col.field === 'tp') {
                     data.updateData.pid = select.pid;
@@ -239,7 +275,6 @@ $(document).ready(() => {
                     } else {
                         data.updateData[col.field] = null;
                     }
-                    console.log(data);
                 }
                 // 更新至服务器
                 postData(window.location.pathname + '/save', data, function (result) {
@@ -252,7 +287,9 @@ $(document).ready(() => {
             if (info.sheet.zh_setting) {
                 const select = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
-                if (payCol.readOnly.minus(select)) { return; }
+                if (payCol.readOnly.minus(select)) {
+                    return;
+                }
                 if (col.field === 'minus') {
                     if (info.sheet.isEditing) {
                         info.sheet.endEdit(true);
@@ -261,7 +298,7 @@ $(document).ready(() => {
                     // 获取更新信息
                     const data = {
                         type: 'info',
-                        updateData: { id: select.pid },
+                        updateData: {id: select.pid},
                     };
                     data.updateData.minus = info.sheet.getValue(info.row, info.col) || false;
                     // 更新至服务器
@@ -272,16 +309,63 @@ $(document).ready(() => {
                 }
             }
         },
+        editStarting: function (e, info) {
+            const col = info.sheet.zh_setting.cols[info.col];
+            if (col.field === 'tp') {
+                const select = SpreadJsObj.getSelectObject(info.sheet);
+                if (select.expr && select.expr !== '') {
+                    info.sheet.getCell(info.row, info.col).text(select.expr);
+                }
+            } else if (col.field === 'sprice') {
+                const select = SpreadJsObj.getSelectObject(info.sheet);
+                if (select.sexpr && select.sexpr !== '') {
+                    info.sheet.getCell(info.row, info.col).text(select.sexpr);
+                }
+            } else if (col.field === 'rprice') {
+                const select = SpreadJsObj.getSelectObject(info.sheet);
+                if (select.rexpr && select.rexpr !== '') {
+                    info.sheet.getCell(info.row, info.col).text(select.rexpr);
+                }
+            }
+        }
     };
     paySpreadObj.refreshActn();
     if (!readOnly) {
         paySpread.bind(spreadNS.Events.EditEnded, paySpreadObj.editEnded);
         paySpread.bind(spreadNS.Events.SelectionChanged, paySpreadObj.selectionChanged);
         paySpread.bind(spreadNS.Events.ButtonClicked, paySpreadObj.buttonClicked);
+        paySpread.bind(spreadNS.Events.EditStarting, paySpreadObj.editStarting);
         $('#add').click(paySpreadObj.add);
         $('#del').click(paySpreadObj.del);
         $('#up-move').click(paySpreadObj.upMove);
         $('#down-move').click(paySpreadObj.downMove);
+        $('#expr').change(function () {
+            const expr = $(this);
+            const select = SpreadJsObj.getSelectObject(paySpread.getActiveSheet());
+            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
+            if (orgValue === newValue) { return; }
+
+            const data = {};
+            if (field === 'expr') {
+                data.type = 'stage';
+                data.updateData = { pid: select.pid, tp: null, expr: newValue }
+            } else if (field === 'sexpr') {
+                data.type = 'info';
+                data.updateData = {id: select.pid, sprice: null, sexpr: newValue};
+
+            } else if (field === 'rexpr') {
+                data.type = 'info';
+                data.updateData = {id: select.pid, rprice: null, rexpr: newValue};
+            } else {
+                expr.val('');
+                return;
+            }
+            // 更新至服务器
+            postData(window.location.pathname + '/save', data, function (result) {
+                loadUpdateDealPays(result);
+                SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
+            });
+        })
     }
 
     const deadlineObj = {

+ 1 - 1
app/view/stage/pay.ejs

@@ -15,7 +15,7 @@
                         <div class="input-group-prepend">
                             <span class="input-group-text" id="basic-addon1">表达式</span>
                         </div>
-                        <input type="text" class="form-control m-0" <% if (stage.readOnly) { %> readonly="" <% } %>>
+                        <input type="text" class="form-control m-0" <% if (stage.readOnly) { %> readonly="" <% } %> id="expr">
                     </div>
                 </div>
             </div>