Преглед изворни кода

变更表达式可编辑调整

ellisran пре 1 месец
родитељ
комит
d49ab81f90
2 измењених фајлова са 189 додато и 53 уклоњено
  1. 2 2
      app/controller/change_controller.js
  2. 187 51
      app/public/js/change_revise.js

+ 2 - 2
app/controller/change_controller.js

@@ -638,12 +638,12 @@ module.exports = app => {
                         if (ctx.change.status !== audit.change.status.uncheck && ctx.change.status !== audit.change.status.checkNo && ctx.change.status !== audit.change.status.revise) {
                             throw '该变更令正在审批中或已完成,无法操作清单数据';
                         }
-                        if (data.insertData.length > 0) {
+                        if (data.insertData && data.insertData.length > 0) {
                             const fun_set2 = this.ctx.subProject.fun_set;
                             const stateInfo2 = ctx.helper._.find(fun_set2.change_state, { order: ctx.change.state });
                             await ctx.service.changeAuditList.adds(data.insertData, stateInfo2.value);
                         }
-                        if (data.updateData.length > 0) {
+                        if (data.updateData && data.updateData.length > 0) {
                             await ctx.service.changeAuditList.saveDatas(data.updateData);
                         }
                         // 取所有工料表

+ 187 - 51
app/public/js/change_revise.js

@@ -352,8 +352,13 @@ $(document).ready(() => {
                 if (data) {
                     const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
                     if (!cInfo) {
-                        $('#bills-expr').val('').attr('readOnly', true);
-                        $('#bills-expr').removeAttr('data-row');
+                        if (billsCol.readOnly.isChangeList(data)) {
+                            $('#bills-expr').val('').attr('readOnly', true);
+                            $('#bills-expr').removeAttr('data-row');
+                        } else {
+                            $('#bills-expr').val('').attr('field', col.field).attr('org', '')
+                                .attr('readOnly', false).attr('data-row', sel.row);
+                        }
                     } else {
                         const value = cInfo.camount_expr ? cInfo.camount_expr : ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit));
                         $('#bills-expr').val(value).attr('field', col.field).attr('org', ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)))
@@ -841,6 +846,11 @@ $(document).ready(() => {
                     }
                     let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
                     if (!cInfo) {
+                        if (billsCol.readOnly.isSettle(node)) {
+                            toastr.error('清单数据未完善,无法编辑申请数量');
+                            SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                            return;
+                        }
                         makeGclGatherData();
                         const gclInfo = _.find(gclGatherData, function (item) {
                             return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
@@ -1881,10 +1891,49 @@ $(document).ready(() => {
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
             if (field === 'camount') {
-                const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
+                let cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
                 if (!cInfo) {
-                    toastr.error('未勾选变更清单,无法编辑申请数量');
-                    return;
+                    if (billsCol.readOnly.isChangeList(select)) {
+                        toastr.error('清单数据未完善,无法编辑申请数量');
+                        SpreadJsObj.reLoadRowData(billsSheet, row);
+                        return;
+                    }
+                    makeGclGatherData();
+                    const gclInfo = _.find(gclGatherData, function (item) {
+                        return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
+                    });
+                    const xmjInfo = gclInfo.leafXmjs.find(function (item) {
+                        return item.gcl_id === select.id;
+                    });
+                    const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
+                    const data = {
+                        lid: gclInfo.leafXmjs[0].gcl_id || select.id,
+                        code: gclInfo.b_code,
+                        name: gclInfo.name || '',
+                        unit: gclInfo.unit || '',
+                        unit_price: gclInfo.unit_price,
+                        oamount: xmjInfo.quantity,
+                        oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
+                        bwmx: xmjInfo.bwmx || xmjInfo.jldy,
+                        xmj_code: xmjInfo.code || '',
+                        xmj_jldy: xmjInfo.jldy || '',
+                        xmj_dwgc: xmjInfo.dwgc || '',
+                        xmj_fbgc: xmjInfo.fbgc || '',
+                        xmj_fxgc: xmjInfo.fxgc || '',
+                        gcl_id: select.id,
+                        mx_id: '',
+                    };
+                    if (oldCInfo) {
+                        data.detail = oldCInfo.detail;
+                        data.camount = oldCInfo.camount;
+                        data.camount_expr = oldCInfo.camount_expr;
+                        data.spamount = oldCInfo.spamount;
+                        data.is_valuation = oldCInfo.is_valuation;
+                        data.delimit = oldCInfo.delimit;
+                    }
+                    cInfo = data;
+                    // toastr.error('未勾选变更清单,无法编辑申请数量');
+                    // return;
                 }
                 const exprQuantity = {
                     expr: '',
@@ -1900,33 +1949,54 @@ $(document).ready(() => {
                     return;
                 }
                 const camount = parseFloat(exprQuantity.quantity);
-                // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
-                const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
-                if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
-                    toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
-                    return;
-                } else if (usedInfo && usedInfo.qty < 0  && validText > usedInfo.qty) {
-                    toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
-                    return;
+                if (cInfo.id) {
+                    // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
+                    const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
+                    if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
+                        toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
+                        return;
+                    } else if (usedInfo && usedInfo.qty < 0  && validText > usedInfo.qty) {
+                        toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
+                        return;
+                    }
                 }
                 cInfo.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
                 select.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
                 cInfo.spamount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
                 cInfo.camount_expr = exprQuantity.expr;
                 delete cInfo.waitingLoading;
-                postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
-                    SpreadJsObj.reLoadRowData(billsSheet, row);
-                    billsTreeSpreadObj.reCalcCamount(select);
-                    const loadResult = { update: [select] };
-                    const refreshNode = billsTree.loadPostData(loadResult);
-                    billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
-                    billsTreeSpreadObj.loadExprToInput(billsSheet);
-                }, function () {
-                    cInfo.camount = orgValue;
-                    cInfo.spamount = orgValue;
-                    select.camount = orgValue;
-                    SpreadJsObj.reLoadRowData(billsSheet, row);
-                });
+                if (cInfo.id) {
+                    postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
+                        SpreadJsObj.reLoadRowData(billsSheet, row);
+                        billsTreeSpreadObj.reCalcCamount(select);
+                        const loadResult = { update: [select] };
+                        const refreshNode = billsTree.loadPostData(loadResult);
+                        billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
+                        billsTreeSpreadObj.loadExprToInput(billsSheet);
+                    }, function () {
+                        cInfo.camount = orgValue;
+                        cInfo.spamount = orgValue;
+                        select.camount = orgValue;
+                        SpreadJsObj.reLoadRowData(billsSheet, row);
+                    });
+                } else {
+                    // 更新至服务器
+                    postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
+                        changeList = result.changeList;
+                        select.is_change = 1;
+                        select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
+                        select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
+                        billsTreeSpreadObj.reCalcCamount(select);
+                        const refreshNode = billsTree.loadPostData({ update: [select] });
+                        billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
+                        SpreadJsObj.reLoadRowData(billsSheet, row);
+                    }, function () {
+                        cInfo[col.field] = orgValue;
+                        cInfo.spamount = orgValue;
+                        node[col.field] = orgValue;
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                    });
+                }
                 return;
             }
 
@@ -2309,8 +2379,13 @@ $(document).ready(() => {
                 if (data) {
                     const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
                     if (!cInfo) {
-                        $('#pos-expr').val('').attr('readOnly', true);
-                        $('#pos-expr').removeAttr('data-row');
+                        if (posCol.readOnly.isChangeList(data)) {
+                            $('#pos-expr').val('').attr('readOnly', true);
+                            $('#pos-expr').removeAttr('data-row');
+                        } else {
+                            $('#pos-expr').val('').attr('field', col.field).attr('org', '')
+                                .attr('readOnly', false).attr('data-row', sel.row);
+                        }
                     } else {
                         const value = cInfo.camount_expr ? cInfo.camount_expr : cInfo.camount;
                         $('#pos-expr').val(value).attr('field', col.field).attr('org', cInfo.camount)
@@ -3295,10 +3370,47 @@ $(document).ready(() => {
             if (orgValue === newValue || (!orgValue && newValue == '')) return;
 
             if (field === 'camount') {
-                const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
+                let cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
                 if (!cInfo) {
-                    toastr.error('未勾选变更清单,无法编辑申请数量');
-                    return;
+                    if (posCol.readOnly.isSettle(select)) {
+                        toastr.error('清单数据未完善,无法编辑申请数量');
+                        SpreadJsObj.reLoadRowData(posSheet, row);
+                        return
+                    }
+                    makeGclGatherData();
+                    const gclInfo = _.find(gclGatherData, function (item) {
+                        return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
+                    });
+                    const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
+                    const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
+                    const data = {
+                        lid: select.lid,
+                        code: gclInfo.b_code,
+                        name: gclInfo.name || '',
+                        unit: gclInfo.unit || '',
+                        unit_price: gclInfo.unit_price,
+                        oamount: xmjInfo.quantity,
+                        oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
+                        bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
+                        xmj_code: xmjInfo.code || '',
+                        xmj_jldy: xmjInfo.jldy || '',
+                        xmj_dwgc: xmjInfo.dwgc || '',
+                        xmj_fbgc: xmjInfo.fbgc || '',
+                        xmj_fxgc: xmjInfo.fxgc || '',
+                        gcl_id: select.lid,
+                        mx_id: select.id,
+                    }
+                    if (oldCInfo) {
+                        data.detail = oldCInfo.detail;
+                        data.camount = oldCInfo.camount;
+                        data.camount_expr = oldCInfo.camount_expr;
+                        data.spamount = oldCInfo.spamount;
+                        data.is_valuation = oldCInfo.is_valuation;
+                        data.delimit = oldCInfo.delimit;
+                    }
+                    cInfo = data;
+                    // toastr.error('未勾选变更清单,无法编辑申请数量');
+                    // return;
                 }
                 const exprQuantity = {
                     expr: '',
@@ -3314,31 +3426,55 @@ $(document).ready(() => {
                     return;
                 }
                 const camount = parseFloat(exprQuantity.quantity);
-                // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
-                const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
-                if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
-                    toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
-                    return;
-                } else if (usedInfo && usedInfo.qty < 0  && validText > usedInfo.qty) {
-                    toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
-                    return;
+                if (cInfo.id) {
+                    // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
+                    const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
+                    if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
+                        toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
+                        return;
+                    } else if (usedInfo && usedInfo.qty < 0  && validText > usedInfo.qty) {
+                        toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
+                        return;
+                    }
                 }
                 cInfo.camount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
                 cInfo.spamount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
                 cInfo.camount_expr = exprQuantity.expr;
                 delete cInfo.waitingLoading;
-                postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
-                    SpreadJsObj.reLoadRowData(posSheet, row);
-                    billsTreeSpreadObj.reCalcCamount(billsNode);
-                    const loadResult = { update: [billsNode] };
-                    const refreshNode = billsTree.loadPostData(loadResult);
-                    billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
-                    posSpreadObj.loadExprToInput(posSheet);
-                }, function () {
-                    cInfo.camount = orgValue;
-                    cInfo.spamount = orgValue;
-                    SpreadJsObj.reLoadRowData(posSheet, row);
-                });
+                if (cInfo.id) {
+                    postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
+                        SpreadJsObj.reLoadRowData(posSheet, row);
+                        billsTreeSpreadObj.reCalcCamount(billsNode);
+                        const loadResult = { update: [billsNode] };
+                        const refreshNode = billsTree.loadPostData(loadResult);
+                        billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
+                        posSpreadObj.loadExprToInput(posSheet);
+                    }, function () {
+                        cInfo.camount = orgValue;
+                        cInfo.spamount = orgValue;
+                        SpreadJsObj.reLoadRowData(posSheet, row);
+                    });
+                } else {
+                    postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
+                        changeList = result.changeList;
+                        select.is_change = 1;
+                        select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
+                        select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
+                        select.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
+                        SpreadJsObj.reLoadRowData(posSheet, row);
+                        const billsNode = SpreadJsObj.getSelectObject(billsSheet);
+                        // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
+                        if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
+                            billsNode.is_change = 1;
+                        }
+                        billsTreeSpreadObj.reCalcCamount(billsNode);
+                        const loadResult = { update: [billsNode] };
+                        const refreshNode = billsTree.loadPostData(loadResult);
+                        billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
+                    }, function () {
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                    });
+                }
                 return;
             }