瀏覽代碼

新版变更第一版

laiguoran 4 年之前
父節點
當前提交
83e824bdd1

+ 26 - 39
app/controller/change_controller.js

@@ -645,7 +645,7 @@ module.exports = app => {
                         // 清单表页赋值
                         for (const [index, au] of auditList2.entries()) {
                             if (au.usite !== 0) {
-                                cl['audit_amount_' + au.uid] = audit_amount[index] ? audit_amount[index] : null;
+                                cl['audit_amount_' + au.uid] = audit_amount[index - 1] ? audit_amount[index - 1] : null;
                             }
                         }
                     }
@@ -685,49 +685,16 @@ module.exports = app => {
                     renderData.auditList4 = auditList4;
 
                     changeList = JSON.parse(JSON.stringify(changeList.sort())).sort().sort();
-                    renderData.changeList = changeList;
-                    let ototalCost = 0;
-                    let ctotalCost = 0;
-                    const auditTotalCost = [];
-                    const auditUnit = [];
                     for (const cl of changeList) {
-                        // ototalCost += cl.unit_price === null ? 0 : parseFloat(ctx.helper.roundNum(ctx.helper.accMul(cl.unit_price, cl.oamount), renderData.tpUnit));
-                        ototalCost += cl.unit_price === null ? 0 : ctx.helper.mul(cl.unit_price, cl.oamount, renderData.tpUnit);
-                        // ctotalCost += cl.unit_price === null ? 0 : parseFloat(ctx.helper.roundNum(ctx.helper.accMul(cl.unit_price, cl.camount), renderData.tpUnit));
-                        ctotalCost += cl.unit_price === null ? 0 : ctx.helper.mul(cl.unit_price, cl.camount, renderData.tpUnit);
                         const audit_amount = cl.audit_amount !== null && cl.audit_amount !== '' ? cl.audit_amount.split(',') : '';
-                        auditTotalCost.push(audit_amount);
-                    }
-                    renderData.ototalCost = ototalCost;
-                    renderData.ctotalCost = ctotalCost;
-
-                    // 清单表页赋值
-                    for (const [index, au] of auditList.entries()) {
-                        if (au.usite !== 0) {
-                            au.list_amount = [];
-                            au.totalCost = 0;
-                            if (au.uid === renderData.uid) {
-                                for (const [auindex, at] of auditTotalCost.entries()) {
-                                    // if (at[index - 2] !== undefined) {
-                                    //     au.list_amount.push(at[index - 2]);
-                                    //     au.totalCost += parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, at[index - 2]), renderData.tpUnit));
-                                    // } else if (at[index - 2] === undefined) {
-                                    //     au.list_amount.push(changeList[auindex].camount);
-                                    //     au.totalCost += parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, changeList[auindex].camount), renderData.tpUnit));
-                                    // }
-                                    au.list_amount.push(changeList[auindex].spamount);
-                                    // au.totalCost += changeList[auindex].unit_price === null ? 0 : parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, changeList[auindex].spamount), renderData.tpUnit));
-                                    au.totalCost += changeList[auindex].unit_price === null ? 0 : ctx.helper.mul(changeList[auindex].unit_price, changeList[auindex].spamount, renderData.tpUnit);
-                                }
-                            } else {
-                                for (const [auindex, at] of auditTotalCost.entries()) {
-                                    au.list_amount.push(at[index - 1]);
-                                    // au.totalCost += at[index - 1] !== undefined && changeList[auindex].unit_price !== null ? parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, at[index - 1]), renderData.tpUnit)) : 0;
-                                    au.totalCost += at[index - 1] !== undefined && changeList[auindex].unit_price !== null ? ctx.helper.mul(changeList[auindex].unit_price, at[index - 1], renderData.tpUnit) : 0;
-                                }
+                        // 清单表页赋值
+                        for (const [index, au] of auditList2.entries()) {
+                            if (au.usite !== 0) {
+                                cl['audit_amount_' + au.uid] = au.uid === ctx.session.sessionUser.accountId ? cl.spamount : (audit_amount[index - 1] ? audit_amount[index - 1] : null);
                             }
                         }
                     }
+                    renderData.changeList = changeList;
                 }
                 renderData.auditList = auditList;
 
@@ -785,6 +752,26 @@ module.exports = app => {
                         // 取所有工料表
                         responseData.data = '保存成功';
                         break;
+                    case 'paste_amount_rows':
+                        await ctx.service.changeAuditList.saveDatas(data.updateData);
+                        let changeList = await ctx.service.changeAuditList.getAllDataByCondition({
+                            where: { cid: ctx.change.cid },
+                            orders: [['lid', 'desc'], ['id', 'asc']],
+                        });
+                        const auditList2 = await ctx.service.changeAudit.getListGroupByTimes(ctx.change.cid, ctx.change.times);
+                        changeList = JSON.parse(JSON.stringify(changeList.sort())).sort().sort();
+                        for (const cl of changeList) {
+                            const audit_amount = cl.audit_amount !== null && cl.audit_amount !== '' ? cl.audit_amount.split(',') : '';
+                            // 清单表页赋值
+                            for (const [index, au] of auditList2.entries()) {
+                                if (au.usite !== 0) {
+                                    cl['audit_amount_' + au.uid] = au.uid === ctx.session.sessionUser.accountId ? cl.spamount : (audit_amount[index - 1] ? audit_amount[index - 1] : null);
+                                }
+                            }
+                        }
+                        // 取所有工料表
+                        responseData.data = changeList;
+                        break;
                     default: throw '参数有误';
                 }
 

+ 7 - 0
app/public/js/change_information.js

@@ -7,6 +7,13 @@
  * @date 2018/11/22
  * @version
  */
+const is_numeric = (value) => {
+    if (typeof(value) === 'object') {
+        return false;
+    } else {
+        return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
+    }
+};
 $(document).ready(() => {
     const cca = getLocalCache('change-checkbox-account-' + accountId);
     if (cca !== null && cca !== undefined) {

+ 386 - 0
app/public/js/change_information_approval.js

@@ -0,0 +1,386 @@
+'use strict';
+
+/**
+ * 变更令详细页js
+ *
+ * @author EllisRan.
+ * @date 2018/11/22
+ * @version
+ */
+$(document).ready(() => {
+    const changeSpreadSetting = {
+        cols: [
+            {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
+            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: true},
+            {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: true},
+            {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: true},
+            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
+            {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: true},
+            {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount', readOnly: true},
+            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', getValue: 'getValue.oa_tp', readOnly: true},
+            {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount', readOnly: true},
+            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', getValue: 'getValue.ca_tp', readOnly: true},
+        ],
+        emptyRows: 0,
+        headRows: 2,
+        headRowHeight: [25, 25],
+        defaultRowHeight: 21,
+        headerFont: '12px 微软雅黑',
+        font: '12px 微软雅黑',
+        // readOnly: true,
+    };
+    for (const aid of aidList) {
+        const userinfo = _.find(auditList2, { 'uid': aid });
+        const newColcount = {
+            title: userinfo.name + ' 审批|数量',
+            colSpan: '2|1', rowSpan: '1|1',
+            field: 'audit_amount_' + aid,
+            hAlign: 2, width: 60, type: 'Number',
+            readOnly: aid !== parseInt(accountId)
+        };
+        const newColTp = {
+            title: '|金额',
+            colSpan: '|1', rowSpan: '|1',
+            field: 'sa_tp',
+            hAlign: 2, width: 80, formatter: '@', type: 'Number',
+            readOnly: true
+        };
+        changeSpreadSetting.cols.push(newColcount);
+        changeSpreadSetting.cols.push(newColTp);
+    }
+
+    const changeCol = {
+        getValue: {
+            unit_price: function(data) {
+                return ZhCalc.round(data.unit_price, unitPriceUnit);
+            },
+            oa_tp: function (data) {
+                return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
+            },
+            ca_tp: function (data) {
+                return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
+            },
+            oamount: function (data) {
+                return ZhCalc.round(data.oamount, findDecimal(data.unit));
+            },
+            camount: function (data) {
+                return ZhCalc.round(data.camount, findDecimal(data.unit));
+            },
+        },
+    };
+
+    const changeSpreadObj = {
+        makeSjsFooter: function () {
+            // 增加汇总行并设为锁定禁止编辑状态
+            changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
+            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
+            changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
+            changeSpreadObj.countSum();
+        },
+        setAuditValue: function () {
+            const rowCount = changeSpreadSheet.getRowCount();
+            // 用户的数据合计
+            for (const j in aidList) {
+                for(let i = 0; i <= rowCount - 1; i++){
+                    const data = {
+                        unit_price: changeSpreadSheet.getValue(i, 5),
+                        amount: parseFloat(changeSpreadSheet.getValue(i, 10 + parseInt(j)*2)),
+                    };
+                    const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
+                    changeSpreadSheet.setValue(i, 11 + j*2, sum !== 0 ? sum : null);
+                }
+            }
+        },
+        setRowValueAndSum: function (data, row, col) {
+            for (const j in aidList) {
+                const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
+                changeSpreadSheet.setValue(row, 11 + j*2, sum !== 0 ? sum : null);
+            }
+            // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
+            // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null);
+            const rowCount = changeSpreadSheet.getRowCount();
+            // 用户的数据合计
+            let audit_sum = 0;
+            for(let i = 0; i < rowCount - 1; i++){
+                audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
+            }
+            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
+        },
+        countSum: function() {
+            const rowCount = changeSpreadSheet.getRowCount();
+            let oSum = 0,
+                cSum = 0;
+            for(let i = 0; i < rowCount - 1; i++){
+                oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
+                cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
+            }
+            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
+            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
+            // 用户的数据合计
+            for (const j in aidList) {
+                let audit_sum = 0;
+                for(let i = 0; i < rowCount - 1; i++){
+                    audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 11 + j*2));
+                }
+                changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11 + j*2, audit_sum !== 0 ? audit_sum : null);
+            }
+        },
+        editEnded: function (e, info) {
+            if (info.sheet.zh_setting) {
+                const select = SpreadJsObj.getSelectObject(info.sheet);
+                const col = info.sheet.zh_setting.cols[info.col];
+                // 未改变值则不提交
+                let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
+                const orgValue = select[col.field];
+                if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                    changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
+                    return;
+                }
+                // 判断部分值是否输入的是数字判断和数据计算
+                if (col.type === 'Number') {
+                    if (isNaN(validText)) {
+                        toastr.error('不能输入其它非数字类型字符');
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                        changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
+                        return;
+                    }
+                    validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
+                }
+                select[col.field] = validText;
+                select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
+                console.log(select);
+
+                const data = {
+                    id: select.id,
+                    spamount: select.spamount,
+                };
+                console.log(data);
+
+                // 更新至服务器
+                postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
+                    changeList.splice(info.row, 1, select);
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                    changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
+                }, function () {
+                    select[col.field] = orgValue;
+                    select.spamount = orgValue;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                    changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
+                });
+            }
+        },
+        clipboardPasted(e, info) {
+            // const hint = {
+            //     cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
+            //     numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
+            // };
+            const range = info.cellRange;
+            const sortData = info.sheet.zh_data || [];
+            // console.log(info, range);
+            // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
+            //     toastMessageUniq(hint.cellError);
+            //     // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
+            //     SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
+            //     SpreadJsObj.reLoadSheetData(changeSpreadSheet);
+            //     changeSpreadObj.setAuditValue();
+            //     changeSpreadObj.makeSjsFooter();
+            //     return;
+            // }
+            // if (sortData.length > 0 && range.col + range.colCount > 10) {
+            //     toastMessageUniq(hint.cellError);
+            //     SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
+            //     SpreadJsObj.reLoadSheetData(changeSpreadSheet);
+            //     changeSpreadObj.setAuditValue();
+            //     changeSpreadObj.makeSjsFooter();
+            //     return;
+            // }
+            const data = [];
+            // const rowData = [];
+            for (let iRow = 0; iRow < range.rowCount; iRow++) {
+                let bPaste = true;
+                const curRow = range.row + iRow;
+                // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
+                const cLData = { id: sortData[curRow].id };
+                const hintRow = range.rowCount > 1 ? curRow : '';
+                let sameCol = 0;
+                for (let iCol = 0; iCol < range.colCount; iCol++) {
+                    const curCol = range.col + iCol;
+                    const colSetting = info.sheet.zh_setting.cols[curCol];
+                    if (!colSetting) continue;
+
+                    let validText = info.sheet.getText(curRow, curCol);
+                    validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
+                    const orgValue = sortData[curRow][colSetting.field];
+                    if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                        sameCol++;
+                        if (range.colCount === sameCol)  {
+                            bPaste = false;
+                        }
+                        continue;
+                    }
+                    if (colSetting.type === 'Number') {
+                        if (isNaN(validText)) {
+                            toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
+                            bPaste = false;
+                            continue;
+                        }
+                        validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
+                    }
+                    // cLData[colSetting.field] = validText;
+                    sortData[curRow][colSetting.field] = validText;
+                    cLData.spamount = validText;
+                }
+                if (bPaste) {
+                    data.push(cLData);
+                    // rowData.push(curRow);
+                } else {
+                    SpreadJsObj.reLoadRowData(info.sheet, curRow);
+                }
+            }
+            if (data.length === 0) {
+                SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                return;
+            }
+            console.log(data);
+            // 更新至服务器
+            postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
+                changeList = result;
+                SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
+                changeSpreadObj.setAuditValue();
+                changeSpreadObj.makeSjsFooter();
+            }, function () {
+                SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                changeSpreadObj.setAuditValue();
+                return;
+            });
+        },
+    };
+
+    SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
+    SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
+    SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
+    changeSpreadObj.setAuditValue();
+    changeSpreadObj.makeSjsFooter();
+    const userIndex = aidList.indexOf(parseInt(accountId));
+
+    changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
+    changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
+
+
+    // 审批提交与判断
+    $('.approval-btn').on('click', function () {
+        // 判断审批状态
+        let returnflag = true;
+        if ($(this).hasClass('btn-success')) {
+            const sdesc = $('#success-approval').find('textarea').val();
+            if (sdesc === '') {
+                toastr.error('审批意见不能为空!');
+                returnflag = false;
+            }
+            if ($('input[name="p_code"]').val() === '') {
+                toastr.error('变更令号(批复编号)不能为空!');
+                returnflag = false;
+            } else if ($('input[name="p_code"]').val() !== undefined) {
+                $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
+                const postData = {
+                    p_code: $('input[name="p_code"]').val(),
+                };
+                postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
+                }, function (data) {
+                    returnflag = false;
+                });
+            }
+            // 判断并提交变更清单表格数据到表单中
+            const clist = [];
+            for(const [i,cl] of changeList.entries()) {
+                if (cl['audit_amount_' + accountId] === null || cl['audit_amount_' + accountId] === '') {
+                    toastr.error('清单第' + (i+1) + '行审批变更数量不能为空');
+                    returnflag = false;
+                } else {
+                    clist.push(cl.id + '_' + cl['audit_amount_' + accountId]);
+                }
+            }
+            $('#change-list-approval').val(clist.join(','));
+
+            if(returnflag) {
+                $('input[name="w_code"]').val($.trim($('#w_code').val()));
+
+                $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
+                if ($('#warning-text').length) $('#warning-text').remove()
+                $('#success-approval').submit();
+            }
+        } else {
+            const sdesc = $('#fail-approval').find('textarea').val();
+            if (sdesc === '') {
+                toastr.error('审批意见不能为空!');
+                returnflag = false;
+            }
+            const type = $('#fail-approval').find('input[name="status"]:checked').val();
+            if (type === undefined) {
+                // toastr.error('请选择退回类型!');
+                if (!$('#warning-text').length) {
+                    $('#change-back-content').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
+                }
+                returnflag = false;
+            }
+            if(returnflag) {
+                $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
+                $('input[name="w_code"]').val($.trim($('#w_code').val()));
+                $('#fail-approval').submit();
+            }
+        }
+    })
+});
+const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
+    if (showWaiting) showWaitingView();
+    $.ajax({
+        type:"POST",
+        url: url,
+        data: {'data': JSON.stringify(data)},
+        dataType: 'json',
+        cache: false,
+        async: false,
+        timeout: 60000,
+        beforeSend: function(xhr) {
+            let csrfToken = Cookies.get('csrfToken');
+            xhr.setRequestHeader('x-csrf-token', csrfToken);
+        },
+        success: function(result){
+            if (result.err === 0) {
+                if (successCallback) {
+                    successCallback(result.data);
+                }
+            } else {
+                toastr.error(result.msg);
+                if (errorCallBack) {
+                    errorCallBack(result.msg);
+                }
+            }
+            if (showWaiting) closeWaitingView();
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            toastr.error('error: ' + textStatus + " " + errorThrown);
+            if (errorCallBack) {
+                errorCallBack();
+            }
+            if (showWaiting) closeWaitingView();
+        }
+    });
+};
+function auditCheck(i) {
+    const inlineRadio1 = $('#change-back:checked').val()
+    const inlineRadio2 = $('#chagne-backnew:checked').val()
+    const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
+    $('textarea[name="sdesc"]').eq(i).val(opinion);
+    if (i === 1) {
+        if (!inlineRadio1 && !inlineRadio2) {
+            if (!$('#warning-text').length) {
+                $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
+            }
+            return false;
+        }
+        if ($('#warning-text').length) $('#warning-text').remove()
+    }
+    return true;
+}

+ 26 - 8
app/public/js/change_information_set.js

@@ -37,13 +37,6 @@ function sortByCode(a, b) {
         }
     }
 }
-const is_numeric = (value) => {
-    if (typeof(value) === 'object') {
-        return false;
-    } else {
-        return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
-    }
-};
 $.event.special.valuechange = {
     teardown: function (namespaces) {
         $(this).unbind('.valuechange');
@@ -67,6 +60,29 @@ $.event.special.valuechange = {
     }
 };
 $(document).ready(() => {
+    const changeSpreadSetting = {
+        cols: [
+            {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: false},
+            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits},
+            {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
+            {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
+            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
+            {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
+            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
+            {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
+        ],
+        emptyRows: 0,
+        headRows: 2,
+        headRowHeight: [25, 25],
+        defaultRowHeight: 21,
+        headerFont: '12px 微软雅黑',
+        font: '12px 微软雅黑',
+        readOnly: readOnly,
+    };
+
     const changeCol = {
         getValue: {
             unit_price: function(data) {
@@ -182,7 +198,7 @@ $(document).ready(() => {
                 }
                 select[col.field] = validText;
                 if(col.field === 'camount') {
-                    select.spamount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
+                    select.spamount = ZhCalc.round(select.camount, findDecimal(select.unit)) || 0;
                 }
                 console.log(select);
 
@@ -212,12 +228,14 @@ $(document).ready(() => {
                 // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
                 SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
                 SpreadJsObj.reLoadSheetData(changeSpreadSheet);
+                changeSpreadObj.makeSjsFooter();
                 return;
             }
             if (sortData.length > 0 && range.col + range.colCount > 10) {
                 toastMessageUniq(hint.cellError);
                 SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
                 SpreadJsObj.reLoadSheetData(changeSpreadSheet);
+                changeSpreadObj.makeSjsFooter();
                 return;
             }
             const data = [];

+ 16 - 2
app/public/js/change_information_show.js

@@ -38,14 +38,13 @@ $(document).ready(() => {
             colSpan: '2|1', rowSpan: '1|1',
             field: 'audit_amount_' + aid,
             hAlign: 2, width: 60, type: 'Number',
-            getValue: 'getValue.samount'
         };
         const newColTp = {
             title: '|金额',
             colSpan: '|1', rowSpan: '|1',
             field: 'sa_tp',
             hAlign: 2, width: 80, formatter: '@', type: 'Number',
-            getValue: 'getValue.sa_tp'};
+        };
         changeSpreadSetting.cols.push(newColcount);
         changeSpreadSetting.cols.push(newColTp);
     }
@@ -84,6 +83,20 @@ $(document).ready(() => {
             changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
             changeSpreadObj.countSum();
         },
+        setAuditValue: function () {
+            const rowCount = changeSpreadSheet.getRowCount();
+            // 用户的数据合计
+            for (const j in aidList) {
+                for(let i = 0; i <= rowCount - 1; i++){
+                    const data = {
+                        unit_price: changeSpreadSheet.getValue(i, 5),
+                        amount: parseFloat(changeSpreadSheet.getValue(i, 12 + parseInt(j)*2)),
+                    };
+                    const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
+                    changeSpreadSheet.setValue(i, 13 + j*2, sum !== 0 ? sum : null);
+                }
+            }
+        },
         countSum: function() {
             const rowCount = changeSpreadSheet.getRowCount();
             let oSum = 0,
@@ -119,6 +132,7 @@ $(document).ready(() => {
     SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
     SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
     SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
+    changeSpreadObj.setAuditValue();
     changeSpreadObj.makeSjsFooter();
     changeSpreadObj.showHideAudit();
 

+ 5 - 13
app/service/change.js

@@ -354,7 +354,6 @@ module.exports = app => {
          * @return {void}
          */
         async save(postData, tenderId) {
-            const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
             // 初始化事务
             this.transaction = await this.db.beginTransaction();
             let result = false;
@@ -465,7 +464,7 @@ module.exports = app => {
                             delete clArray.unit_price;
                         }
                         insertCL.push(clArray);
-                        total_price = this.ctx.helper.accAdd(total_price, this.ctx.helper.mul(clArray.unit_price, clArray.spamount, tenderInfo.decimal.tp));
+                        total_price = this.ctx.helper.accAdd(total_price, this.ctx.helper.mul(clArray.unit_price, clArray.spamount, this.ctx.tender.info.decimal.tp));
                     }
                     await this.transaction.insert(this.ctx.service.changeAuditList.tableName, insertCL);
                 }
@@ -542,7 +541,6 @@ module.exports = app => {
          * @return {void}
          */
         async approvalSuccess(pid, postData, changeData) {
-            let tenderInfo;
             // 初始化事务
             this.transaction = await this.db.beginTransaction();
             let result = false;
@@ -586,11 +584,8 @@ module.exports = app => {
                     const lid = listInfo[0];
                     const amount = listInfo[1];
                     const changeListInfo = await this.ctx.service.changeAuditList.getDataById(lid);
-                    if (!tenderInfo) {
-                        tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeListInfo.tid);
-                    }
                     if (changeListInfo !== undefined) {
-                        total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(changeListInfo.unit_price, amount, tenderInfo.decimal.tp));
+                        total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(changeListInfo.unit_price, amount, this.ctx.tender.info.decimal.tp));
                         const audit_amount = changeListInfo.audit_amount !== null && changeListInfo.audit_amount !== '' ? changeListInfo.audit_amount.split(',') : [];
                         audit_amount.push(amount);
                         const list_update = {
@@ -748,7 +743,6 @@ module.exports = app => {
                 });
                 await this.transaction.insert('zh_notice', records);
                 const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
-                const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeInfo.tid);
                 // 设置审批人退回
                 const audit_update = {
                     id: postData.audit_id,
@@ -787,7 +781,7 @@ module.exports = app => {
                 });
                 let total_price = 0;
                 for (const cl of changeList) {
-                    total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, cl.camount, tenderInfo.decimal.tp));
+                    total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, cl.camount, this.ctx.tender.info.decimal.tp));
                 }
                 // 设置变更令退回
                 const change_update = {
@@ -861,7 +855,6 @@ module.exports = app => {
                 await this.transaction.insert('zh_notice', records);
 
                 const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
-                const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeInfo.tid);
                 // 设置审批人退回
                 const audit_update = {
                     id: postData.audit_id,
@@ -935,7 +928,7 @@ module.exports = app => {
                         audit_amount: audit_amount.join(','),
                         spamount: parseFloat(last_amount),
                     };
-                    total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), tenderInfo.decimal.tp));
+                    total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), this.ctx.tender.info.decimal.tp));
                     await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
                 }
 
@@ -1192,7 +1185,6 @@ module.exports = app => {
             let result = false;
             try {
                 const changeInfo = await this.getDataByCondition({ cid });
-                const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeInfo.tid);
 
                 // 获取终审
                 const auditInfo = (
@@ -1251,7 +1243,7 @@ module.exports = app => {
                         audit_amount: audit_amount.join(','),
                         samount: '',
                     };
-                    total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), tenderInfo.decimal.tp));
+                    total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), this.ctx.tender.info.decimal.tp));
                     await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
                 }
 

+ 1 - 1
app/service/change_audit.js

@@ -213,7 +213,7 @@ module.exports = app => {
          */
         async getListGroupByTimes(cid, times) {
             const sql = 'SELECT * FROM ?? where id in (SELECT MAX(id) FROM ?? WHERE ' +
-                'cid = ? AND times = ? GROUP BY usite)';
+                'cid = ? AND times = ? GROUP BY usite) ORDER BY usite asc';
             const sqlParam = [this.tableName, this.tableName, cid, times];
             const list = await this.db.query(sql, sqlParam);
             return list;

+ 23 - 0
app/service/change_audit_list.js

@@ -193,6 +193,29 @@ module.exports = app => {
             await transaction.update(this.ctx.service.change.tableName, updateData, options);
         }
 
+        /**
+         * 用户数据数量提交
+         * @param {Object} data 内容
+         * @return {void}
+         */
+        async saveAmountData(data) {
+            if (!this.ctx.tender || !this.ctx.change) {
+                throw '数据错误';
+            }
+            // 判断是否可修改
+            // 判断t_type是否为费用
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.update(this.tableName, data);
+                await this.calcCamountSum(transaction);
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
         async gatherBgBills(tid) {
             const sql = 'SELECT cb.code, cb.name, cb.unit, cb.unit_price, Round(Sum(cb.samount + 0), 6) as quantity' +
                 '  FROM ' + this.tableName + ' cb' +

+ 4 - 4
app/view/change/info_modal.ejs

@@ -626,7 +626,7 @@
                                                                     <% if (auditor.status === auditConst.auditStatus.checking) { %>
                                                                         <label>审批意见<b class="text-danger">*</b></label>
                                                                         <textarea class="form-control form-control-sm"
-                                                                                  name="opinion">同意</textarea>
+                                                                                  name="sdesc">同意</textarea>
                                                                         <input type="hidden" name="audit_id" value="<%= auditor.id %>">
                                                                         <% if (auditor.usort !== 0 && index+1 === auditList3.length) { %>
                                                                             <!--终审填写批复编号-->
@@ -638,7 +638,7 @@
                                                                             <input type="hidden" name="audit_next_id" value="<%= auditList3[index+1].id %>">
                                                                         <% } %>
                                                                     <% } else { %>
-                                                                        <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <p style="margin: 0;"><%- auditor.sdesc %></p>
                                                                     <% } %>
                                                                 </div>
                                                             <% } %>
@@ -863,7 +863,7 @@
                                                                     <% if (auditor.status === auditConst.auditStatus.checking) { %>
                                                                         <label>审批意见<b class="text-danger">*</b></label>
                                                                         <textarea class="form-control form-control-sm"
-                                                                                  name="opinion">不同意</textarea>
+                                                                                  name="sdesc">不同意</textarea>
                                                                         <input type="hidden" name="audit_id" value="<%= auditor.id %>">
                                                                         <div id="change-back-content" class="alert alert-warning"
                                                                              style="margin-top: 15px;">
@@ -883,7 +883,7 @@
                                                                             <% } %>
                                                                         </div>
                                                                     <% } else if(auditor.status === auditConst.auditStatus.checked){ %>
-                                                                        <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <p style="margin: 0;"><%- auditor.sdesc %></p>
                                                                     <% } %>
                                                                 </div>
                                                             <% } %>

+ 6 - 24
app/view/change/information.ejs

@@ -413,29 +413,6 @@
         charge: '<%- change.charge %>',
     };
     let changeInfo = Object.assign({}, back_changeInfo);
-
-    const changeSpreadSetting = {
-        cols: [
-            {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
-            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
-            {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
-            {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: false},
-            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits},
-            {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
-            {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
-            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
-            {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
-            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
-            {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
-        ],
-        emptyRows: 0,
-        headRows: 2,
-        headRowHeight: [25, 25],
-        defaultRowHeight: 21,
-        headerFont: '12px 微软雅黑',
-        font: '12px 微软雅黑',
-        readOnly: readOnly,
-    };
 </script>
 <script src="/public/js/change_information_set.js"></script>
 <script src="/public/js/change_audit.js"></script>
@@ -447,6 +424,11 @@
 </script>
 <script src="/public/js/change_information_show.js"></script>
 <% } else if (auditStatus === 6) { %>
-<!--<script src="/public/js/change_approval.js"></script>-->
+<script>
+    const auditList2 = JSON.parse('<%- JSON.stringify(auditList2) %>');
+    const aidList = _.map(auditList2, 'uid');
+    aidList.splice(0, 1);
+</script>
+<script src="/public/js/change_information_approval.js"></script>
 <% } %>
 <!--<script src="/public/js/change_detail.js"></script>-->

+ 4 - 4
app/view/change/information_modal.ejs

@@ -620,7 +620,7 @@
                                                                     <% if (auditor.status === auditConst.auditStatus.checking) { %>
                                                                         <label>审批意见<b class="text-danger">*</b></label>
                                                                         <textarea class="form-control form-control-sm"
-                                                                                  name="opinion">同意</textarea>
+                                                                                  name="sdesc">同意</textarea>
                                                                         <input type="hidden" name="audit_id" value="<%= auditor.id %>">
                                                                         <% if (auditor.usort !== 0 && index+1 === auditList3.length) { %>
                                                                             <!--终审填写批复编号-->
@@ -632,7 +632,7 @@
                                                                             <input type="hidden" name="audit_next_id" value="<%= auditList3[index+1].id %>">
                                                                         <% } %>
                                                                     <% } else { %>
-                                                                        <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <p style="margin: 0;"><%- auditor.sdesc %></p>
                                                                     <% } %>
                                                                 </div>
                                                             <% } %>
@@ -857,7 +857,7 @@
                                                                     <% if (auditor.status === auditConst.auditStatus.checking) { %>
                                                                         <label>审批意见<b class="text-danger">*</b></label>
                                                                         <textarea class="form-control form-control-sm"
-                                                                                  name="opinion">不同意</textarea>
+                                                                                  name="sdesc">不同意</textarea>
                                                                         <input type="hidden" name="audit_id" value="<%= auditor.id %>">
                                                                         <div id="change-back-content" class="alert alert-warning"
                                                                              style="margin-top: 15px;">
@@ -877,7 +877,7 @@
                                                                             <% } %>
                                                                         </div>
                                                                     <% } else if(auditor.status === auditConst.auditStatus.checked){ %>
-                                                                        <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <p style="margin: 0;"><%- auditor.sdesc %></p>
                                                                     <% } %>
                                                                 </div>
                                                             <% } %>