Kaynağa Gözat

定额模板关联相关

zhongzewei 7 yıl önce
ebeveyn
işleme
f0f2475f6c

+ 4 - 0
modules/all_models/stdRation_ration.js

@@ -47,6 +47,10 @@ const rationItemSchema = new Schema({
     rationCoeList: Array,
     rationAssList: [rationAssItemSchema],
     rationInstList: [rationInstSchema],
+    rationTemplateList: {
+        type: Array,
+        default: []
+    },
     isDeleted: {type: Boolean, default: false}
 });
 

+ 9 - 0
modules/ration_repository/controllers/ration_controller.js

@@ -108,6 +108,15 @@ class RationController extends BaseController{
             callback(req, res, err, '', null);
         });
     }
+    async updateRationTemplate(req, res){
+        let data = JSON.parse(req.body.data);
+        try {
+            let newTemplate = await rationItem.updateRationTemplate(data.rationRepId, data.rationID, data.templateData);
+            callback(req, res, 0, 'success', newTemplate);
+        } catch (err) {
+            callback(req, res, 1, err, null);
+        }
+    }
 }
 
 export default RationController;

+ 92 - 4
modules/ration_repository/models/ration_item.js

@@ -101,15 +101,49 @@ rationItemDAO.prototype.sortToNumber = function (datas) {
     }
 };
 
-rationItemDAO.prototype.getRationItemsBySection = function(rationRepId, sectionId,callback){
+rationItemDAO.prototype.getRationItemsBySection = async function(rationRepId, sectionId,callback){
     let me = this;
-    rationItemModel.find({"rationRepId": rationRepId, "sectionId": sectionId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
+    try {
+        let rations = await rationItemModel.find({rationRepId: rationRepId, sectionId: sectionId});
+        me.sortToNumber(rations);
+        let matchRationIDs = [],
+            matchRations = [];
+        for (let ration of rations) {
+            if (ration.rationTemplateList) {
+                for (let rt of ration.rationTemplateList) {
+                    if (rt.rationID) {
+                        matchRationIDs.push(rt.rationID);
+                    }
+                }
+            }
+        }
+        if (matchRationIDs.length > 0) {
+            matchRations = await rationItemModel.find({ID: {$in: matchRationIDs}}, '-_id ID code name');
+        }
+        for (let mr of matchRations) {
+            for (let ration of rations) {
+                if (ration.rationTemplateList) {
+                    for (let rt of ration.rationTemplateList) {
+                        if (rt.rationID && rt.rationID === mr.ID) {
+                            rt.code = mr.code ? mr.code : '';
+                            rt.name = mr.name ? mr.name : '';
+                        }
+                    }
+                }
+            }
+        }
+        callback(false,"Get items successfully", rations);
+    } catch (err) {
+        console.log(err);
+        callback(true, "Fail to get items", "");
+    }
+  /*  rationItemModel.find({"rationRepId": rationRepId, "sectionId": sectionId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
         if(err) callback(true, "Fail to get items", "");
         else {
             me.sortToNumber(data);
             callback(false,"Get items successfully", data);
         }
-    })
+    })*/
 };
 rationItemDAO.prototype.mixUpdateRationItems = function(rationLibId, lastOpr, sectionId, updateItems, addItems, rIds, callback){
     var me = this;
@@ -144,7 +178,16 @@ rationItemDAO.prototype.removeRationItems = function(rationLibId, lastOpr, rIds,
             } else {
                 rationRepositoryDao.updateOprArr({ID: rationLibId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
                     if(!err){
-                        callback(false, "Remove successfully", docs);
+                        rationItemModel.update({rationRepId: rationLibId}, {$pull: {rationTemplateList: {rationID: {$in: rIds}}}}, function (theErr) {
+                            if (!theErr) {
+                                callback(false, "Remove successfully", docs);
+                            } else {
+                                callback(true, "Fail to remove", false);
+                            }
+
+                        });
+                    } else {
+                        callback(true, "Fail to remove", false);
                     }
                 })
             }
@@ -228,6 +271,7 @@ rationItemDAO.prototype.addRationItems = function(rationLibId, lastOpr, sectionI
 };
 
 rationItemDAO.prototype.updateRationItems = function(rationLibId, lastOpr, sectionId, items,callback){
+    console.log('enter============');
     var functions = [];
     for (var i=0; i < items.length; i++) {
         functions.push((function(doc) {
@@ -632,6 +676,50 @@ rationItemDAO.prototype.updateAnnotation = function (lastOpr, repId, updateArr,
     });
 };
 
+//更新定额下模板关联
+rationItemDAO.prototype.updateRationTemplate = async function (rationRepId, rationID, templateData) {
+    //自动匹配定额
+    let matachCodes = [],
+        matchRations = [];
+    //要保存的数据
+    let saveData = [];
+    for (let data of templateData) {
+        if (data.code) {
+            matachCodes.push(data.code);
+        }
+    }
+    matachCodes = Array.from(new Set(matachCodes));
+    if (matachCodes.length > 0) {
+        matchRations = await rationItemModel.find({rationRepId: rationRepId, code: {$in: matachCodes}}, '-_id ID code name');
+    }
+    let validData = [];
+    //设置展示数据
+    for (let data of templateData) {
+        let match = false;
+        for (let ration of matchRations) {
+            if (data.code && data.code === ration.code) {
+                match = true;
+                data.name = ration.name;
+                data.rationID = ration.ID;
+                break;
+            }
+        }
+        if (!match) {
+            data.code = '';
+            data.name = '';
+        }
+        if (data.type || data.code || data.name || data.billsLocation) {
+            validData.push(data);
+        }
+    }
+    for (let data of validData) {
+        saveData.push({rationID: data.rationID ? data.rationID : null, type: data.type, billsLocation: data.billsLocation});
+    }
+    //更新
+    await rationItemModel.update({ID: rationID}, {$set: {rationTemplateList: saveData}});
+    return validData;
+};
+
 //计算导入数据的价格
 rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
     const processDecimal = -6;

+ 1 - 0
modules/ration_repository/routes/ration_rep_routes.js

@@ -59,6 +59,7 @@ module.exports =  function (app) {
     apiRouter.post("/getRationsCodes",rationController.auth, rationController.init, rationController.getRationsCodes);
     apiRouter.post("/updateJobContent",rationController.auth, rationController.init, rationController.updateJobContent);
     apiRouter.post("/updateAnnotation",rationController.auth, rationController.init, rationController.updateAnnotation);
+    apiRouter.post("/updateRationTemplate",rationController.auth, rationController.init, rationController.updateRationTemplate);
 
     apiRouter.post("/createNewGljTypeNode",repositoryGljController.auth, gljController.init, gljController.createNewGljTypeNode);
     apiRouter.post("/updateGljNodes",repositoryGljController.auth, gljController.init, gljController.updateGljNodes);

+ 11 - 1
web/maintain/ration_repository/dinge.html

@@ -114,6 +114,9 @@
                                         <li class="nav-item">
                                             <a class="nav-link" id="linkAZZJ" data-toggle="tab" href="#" role="tab">安装增加费</a>
                                         </li>
+                                        <li class="nav-item">
+                                            <a class="nav-link" id="linkMBGL" data-toggle="tab" href="#" role="tab">模板关联</a>
+                                        </li>
                                     </ul>
                                     <!-- 内容 -->
                                     <div class="tab-content">
@@ -671,6 +674,7 @@
         <script src="/lib/codemirror/xml.js"></script>
         <script src="/web/common/js/uploadImg.js"></script>
         <script src="/web/common/js/slideResize.js"></script>
+        <script src="/web/maintain/ration_repository/js/ration_template.js"></script>
         <script type="text/javascript">
             var exEditor = CodeMirror.fromTextArea(document.getElementById("explanationShow"), {
                 mode: "text/html",
@@ -699,13 +703,14 @@
             $(document).ready(function(){
                 rationOprObj.buildSheet($("#rationItemsSheet")[0]);
                 // tabPanel 下有多个Spread时,相互之间不能正确显示。改成一个Spread下多个Sheet。
-                var rdSpread = sheetCommonObj.createSpread($("#rdSpread")[0], 4);
+                var rdSpread = sheetCommonObj.createSpread($("#rdSpread")[0], 5);
                 rationGLJOprObj.buildSheet(rdSpread.getSheet(0));
 
                 rationAssistOprObj.buildSheet(rdSpread.getSheet(1));
 
                 rationCoeOprObj.buildSheet(rdSpread.getSheet(2));
                 rationInstObj.buildSheet(rdSpread.getSheet(3));
+                RationTemplate.buildSheet(rdSpread.getSheet(4));
                 rationInstObj.getInstallation(parseInt(getQueryString("repository")));
                 pageOprObj.initPage();
 
@@ -714,6 +719,7 @@
                 rdSpreadEscSheets.push({sheet: rdSpread.getSheet(1), editStarting: rationAssistOprObj.onEditStarting, editEnded: rationAssistOprObj.onEditEnded});
                 rdSpreadEscSheets.push({sheet: rdSpread.getSheet(2), editStarting: rationCoeOprObj.onEditStarting, editEnded: rationCoeOprObj.onEditEnded});
                 rdSpreadEscSheets.push({sheet: rdSpread.getSheet(3), editStarting: rationInstObj.onEditStarting, editEnded: rationInstObj.onEditEnded});
+                rdSpreadEscSheets.push({sheet: rdSpread.getSheet(4), editStarting: null, editEnded: RationTemplate.events.onEditEnded});
                 sheetCommonObj.bindEscKey(rdSpread, rdSpreadEscSheets);
 
                 $("#linkGLJ").click(function(){
@@ -734,6 +740,10 @@
                     rationInstObj.bindRationInstDel();
                     rdSpread.setActiveSheetIndex(3);
                 });
+                $("#linkMBGL").click(function(){
+                    RationTemplate.bindRationTempDel();
+                    rdSpread.setActiveSheetIndex(4);
+                });
                 //解决spreadjs sheet初始化没高度宽度
                 $('#modalCon').width($(window).width()*0.5);
                 $('#gljSelTreeDiv').height($(window).height() - 300);

+ 11 - 2
web/maintain/ration_repository/js/ration.js

@@ -130,6 +130,7 @@ let rationOprObj = {
         sheetCommonObj.cleanData(sheetAss, settingAss, -1);
         sheetCommonObj.cleanData(sheetInst, settingInst, -1);
         let cacheSection = me.getCache();
+        RationTemplate.rationInitSel(cacheSection[row]);
         if (cacheSection && row < cacheSection.length) {
             rationGLJOprObj.getGljItems(cacheSection[row], function () {
                 if (focusOnSection){
@@ -181,6 +182,12 @@ let rationOprObj = {
         }
         for (let i = removeIds.length - 1; i >= 0; i--) {
             for (let j = cacheSection.length - 1; j >= 0 ; j--) {
+                if (cacheSection[j].rationTemplateList) {
+                    //清除模板关联
+                    _.remove(cacheSection[j].rationTemplateList, function (data) {
+                        return removeIds.includes(data.rationID);
+                    });
+                }
                 if (cacheSection[j]["ID"] == removeIds[i]) {
                     cacheSection.splice(j,1);
                 }
@@ -210,6 +217,7 @@ let rationOprObj = {
                         updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
                         updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
                         updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
+                        updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
                         cacheSection[j] = updateArr[i];
                     }
                 } else {
@@ -221,6 +229,7 @@ let rationOprObj = {
                         updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
                         updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
                         updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
+                        updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
                         cacheSection[j] = updateArr[i];
                     }
                 }
@@ -681,7 +690,7 @@ let rationOprObj = {
             let me = rationOprObj;
             me.mixUpdate = 0;
             me.currentSectionId = sectionID;
-            if (me.currentRations["_SEC_ID_" + sectionID]) {
+            /*if (me.currentRations["_SEC_ID_" + sectionID]) {
                 //jobContent--
                 jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
                 jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
@@ -692,7 +701,7 @@ let rationOprObj = {
                 if(callback){
                     callback();
                 }
-            } else {
+            } else */{
                 $.ajax({
                     type:"POST",
                     url:"api/getRationItems",

+ 197 - 0
web/maintain/ration_repository/js/ration_template.js

@@ -0,0 +1,197 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Zhong
+ * @date 2018/11/28
+ * @version
+ */
+/*
+* 定额下模板关联
+* */
+
+const RationTemplate = (function () {
+    let curRation = null;
+    function _isDef(v) {
+        return typeof v !== 'undefined' && v !== null;
+    }
+    //当前定额下的定额模板关联数据
+    let templateData = [];
+    let templateSheet = null;
+    //重新设置templateData
+    function setTemplateData(newData) {
+        templateData = _isDef(newData) && Array.isArray(newData) ? newData : [];
+    }
+    let setting = {
+        header:[
+            {headerName:"关联类别",headerWidth:110,dataCode:"type", dataType: "String", hAlign: "left", formatter: "@"},
+            {headerName:"编码",headerWidth:90,dataCode:"code", dataType: "String", hAlign: "left", formatter: "@"},
+            {headerName:"名称",headerWidth:240,dataCode:"name", dataType: "String", hAlign: "left", formatter: "@"},
+            {headerName:"具体位置",headerWidth:90,dataCode:"billsLocation", dataType: "String", hAlign: "left", formatter: "@"}
+        ],
+        view:{},
+    };
+    //渲染时方法,停止渲染
+    //@param {Object}sheet {Function}func @return {void}
+    function renderSheetFunc(sheet, func){
+        sheet.suspendEvent();
+        sheet.suspendPaint();
+        if(func){
+            func();
+        }
+        sheet.resumeEvent();
+        sheet.resumePaint();
+    }
+    const items = ['模板关联', '超高关联'];
+    //设置下拉单元格
+    //@return {void}
+    function setComboCells() {
+        if (!templateSheet) {
+            return;
+        }
+        let combo = sheetCommonObj.getDynamicCombo();
+        combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
+        templateSheet.getRange(-1, 0, -1, 1).cellType(combo);
+    }
+    //有效数据
+    //@param {String}dataCode {String}text @return {String}
+    function validateData(dataCode, text) {
+        //类别只能为规定的两种关联,否则将类别自动恢复为''
+        if (dataCode === 'type') {
+            if (text !== '' && !items.includes(text)) {
+                text = '';
+            }
+        }
+        return text;
+    }
+    //从当前表格获取数据
+    //@return {Array}
+    function getDataFromSheet() {
+        let rst = [];
+        if (!templateSheet) {
+            return rst;
+        }
+        let rowCount = templateSheet.getRowCount(),
+            colCount = templateSheet.getColumnCount();
+        for (let row = 0; row < rowCount; row++) {
+            let rowData = {type: '', code: '', name: '', billsLocation: ''},
+                rowExistData = false;
+            for (let col = 0; col < colCount; col++) {
+                let text = templateSheet.getValue(row, col),
+                    dataCode = setting.header[col]['dataCode'];
+                text = _isDef(text) ? text : '';
+                text = validateData(dataCode, text);
+                if (text !== '') {
+                    rowExistData = true;
+                    rowData[dataCode] = text;
+                } else {
+                    if (dataCode === 'code') {
+                        templateSheet.setValue(row, col + 1, '');
+                    }
+                }
+            }
+            //不为空行
+            if (rowExistData) {
+                rst.push(rowData);
+            }
+        }
+        return rst;
+    }
+    //编辑,定额编号自动匹配定额名称,匹配过程在后端进行,前端进行名称的更新输出
+    //@return {void}
+    function edit() {
+        if (!curRation) {
+            return;
+        }
+        let sheetData = getDataFromSheet();
+        CommonAjax.post('/rationRepository/api/updateRationTemplate',
+            {rationRepId: getQueryString('repository'), rationID: curRation.ID, templateData: sheetData}, function (rstData) {
+            templateData = rstData;
+            curRation.rationTemplateList = templateData;
+            renderSheetFunc(templateSheet, function () {
+                sheetCommonObj.showData(templateSheet, setting, templateData);
+            });
+        }, function () {
+            renderSheetFunc(templateSheet, function () {
+                sheetCommonObj.showData(templateSheet, setting, templateData);
+            });
+        });
+
+    }
+    let events = {
+        onEnterCell: function (sender, args) {
+            args.sheet.repaint();
+        },
+        onEditEnded: function (sender, args) {
+            edit();
+        },
+        onRangeChanged: function (sender, args) {
+            edit();
+        }
+    };
+    //重新绑定del建
+    //@return {void}
+    function bindRationTempDel() {
+        if (!templateSheet) {
+            return;
+        }
+        let workBook = templateSheet.getParent();
+        workBook.commandManager().register('rationTempDel', function () {
+            renderSheetFunc(templateSheet, function () {
+                let sels = templateSheet.getSelections();
+                for (let sel of sels) {
+                    sel.row = sel.row === -1 ? 0 : sel.row;
+                    sel.col = sel.col === -1 ? 0 : sel.col;
+                    for (let row = sel.row; row < sel.rowCount + sel.row; row++) {
+                        for (let col = sel.col; col < sel.colCount + sel.col; col++) {
+                            templateSheet.setValue(row, col, '');
+                        }
+                    }
+                }
+            });
+            edit();
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('rationTempDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    }
+    //建表
+    //@param {Object}sheet @return {void}
+    function buildSheet(sheet) {
+        templateSheet = sheet;
+        sheetCommonObj.initSheet(templateSheet, setting, 30);
+        templateSheet.options.isProtected = true;
+        setComboCells();
+        const Events = GC.Spread.Sheets.Events;
+        sheet.bind(Events.EditEnded, events.onEditEnded);
+        sheet.bind(Events.RangeChanged, events.onRangeChanged);
+        sheet.bind(Events.EnterCell, events.onEnterCell);
+    }
+
+    //更改模板关联表锁定状态
+    //@param {Boolean}locked @return {void}
+    function changeLockMode(locked) {
+        if (templateSheet) {
+            if (!locked) {
+                templateSheet.getRange(-1, 0, -1, 2).locked(false);
+                templateSheet.getRange(-1, 3, -1, 1).locked(false);
+            } else {
+                templateSheet.getRange(-1, 0, -1, 2).locked(true);
+                templateSheet.getRange(-1, 3, -1, 1).locked(true);
+            }
+        }
+    }
+    //变更定额
+    function rationInitSel(ration) {
+        curRation = ration ? ration : null;
+        changeLockMode(!ration);
+        sheetCommonObj.cleanData(templateSheet, setting, -1);
+        if (ration) {
+            setTemplateData(ration.rationTemplateList);
+            sheetCommonObj.showData(templateSheet, setting, templateData);
+        } else {
+            setTemplateData([]);
+        }
+    }
+    return {buildSheet, rationInitSel, bindRationTempDel, events}
+})();

+ 3 - 1
web/maintain/ration_repository/js/section_tree.js

@@ -614,7 +614,9 @@ let sectionTreeObj = {
     },
     //模仿默认点击
     initSelection: function (node) {
-        node.tree.selected = node ? node : null;
+        if (node && node.tree){
+            node.tree.selected = node ? node : null;
+        }
         let me = this;
         if(!me.isDef(node)){
             sheetCommonObj.cleanSheet(rationOprObj.workBook.getActiveSheet(), rationOprObj.setting, -1);