Browse Source

Merge branch 'master' of http://192.168.1.12:3000/SmartCost/ConstructionCost

TonyKang 8 years ago
parent
commit
6b7be6587c

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

@@ -18,16 +18,6 @@ module.exports = {
             }
         });
     },
-    getRationItem: function (req, res) {
-        var sId = req.body.sectionId, code = req.body.code;
-        var rationData = {}
-        rationItem.getRationItem(sId, code).then(function (result) {
-            rationData = result._doc;
-            callback(req, res, null, '', rationData);
-        }).catch(function (err, message) {
-            callback(req, res, err, message, null);
-        })
-    },
     mixUpdateRationItems: function(req, res){
         var sectionId = req.body.sectionID,
             rationLibId = req.body.rationLibId,

+ 30 - 0
modules/ration_repository/controllers/search_controller.js

@@ -0,0 +1,30 @@
+/**
+ * Created by Mai on 2017/6/5.
+ */
+var rationItem = require('../models/ration_item');
+var callback = function(req, res, err, message, data){
+    res.json({error: err, message: message, data: data});
+};
+
+module.exports = {
+    getRationItem: function (req, res) {
+        var rId = req.body.rationLibId, code = req.body.code;
+        var rationData = {}
+        rationItem.getRationItem(rId, code).then(function (result) {
+            rationData = result._doc;
+            callback(req, res, null, '', rationData);
+        }).catch(function (err, message) {
+            callback(req, res, err, message, null);
+        })
+    },
+    findRation: function (req, res) {
+        var rId = req.body.rationLibId, keyword = req.body.keyword;
+        rationItem.findRation(rId, keyword, function (err, message, rst) {
+            if (err) {
+                callback(req, res, err, message, null);
+            } else {
+                callback(req, res, 0, '', rst);
+            }
+        });
+    }
+};

+ 32 - 0
modules/ration_repository/models/ration_item.js

@@ -81,6 +81,38 @@ rationItemDAO.prototype.getRationItemsByCode = function(repId, code,callback){
     })
 };
 
+rationItemDAO.prototype.findRation = function (repId, keyword, callback) {
+    rationItemModel.find({'rationRepId': repId,
+        '$and': [{
+            '$or': [{'code': /keyword/}, {'name': /keyword/}]
+        }, {
+            '$or': [{'isDeleted': null}, {'isDeleted': false}]
+        }]
+    }, function (err, data) {
+        if (err) {
+            callback(true, 'Fail to find ration', null);
+        } else {
+            callback(false, '', data);
+        }
+    })
+}
+
+rationItemDAO.prototype.getRationItem = function (repId, code, callback) {
+    if (callback) {
+        rationItemModel.findOne({rationRepId: repId, code: code, "$or": [{"isDeleted": null}, {"isDeleted": false}]}, '-_id').exec()
+            .then(function (result, err) {
+                if (err) {
+                    callback(1, '找不到定额“' + code +'”' , null);
+                } else {
+                    callback(0, '', result);
+                }
+            });
+        return null;
+    } else {
+        return rationItemModel.findOne({rationRepId: repId, code: code, "$or": [{"isDeleted": null}, {"isDeleted": false}]}, '-_id').exec();
+    }
+};
+
 rationItemDAO.prototype.addRationItems = function(rationLibId, sectionId, items,callback){
     if (items && items.length > 0) {
         counter.counterDAO.getIDAfterCount(counter.moduleName.rations, items.length, function(err, result){

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

@@ -10,6 +10,7 @@ var rationChapterTreeController = require("../controllers/ration_section_tree_co
 var rationController = require("../controllers/ration_controller");
 var repositoryGljController = require("../controllers/repository_glj_controller");
 var coeListController = require("../controllers/coe_controller");
+var searchController = require('../controllers/search_controller');
 
 apiRouter.post("/getRationDisplayNames",rationRepositoryController.getDisPlayRationLibs);
 apiRouter.post("/editRationLibs",rationRepositoryController.updateRationRepositoryName);
@@ -24,7 +25,6 @@ apiRouter.post("/updateNodes",rationChapterTreeController.updateNodes);
 apiRouter.post("/deleteNodes",rationChapterTreeController.deleteNodes);
 
 apiRouter.post("/getRationItems",rationController.getRationItemsBySection);
-apiRouter.post('/getRationItem', rationController.getRationItem);
 apiRouter.post("/mixUpdateRationItems",rationController.mixUpdateRationItems);
 
 apiRouter.post("/createNewGljTypeNode",repositoryGljController.createNewGljTypeNode);
@@ -39,5 +39,7 @@ apiRouter.post("/getGljItemsByCodes",repositoryGljController.getGljItemsByCodes)
 apiRouter.post("/getCoeList",coeListController.getCoeList);
 apiRouter.post("/saveCoeList",coeListController.saveCoeList);
 
+apiRouter.post('/getRationItem', searchController.getRationItem);
+apiRouter.post('/findRation', searchController.findRation);
 
 module.exports = apiRouter;

+ 1 - 0
public/web/sheet.js

@@ -22,6 +22,7 @@ sheetObj = {
         sheet.setRowHeight(0, 30, sheetArea.colHeader);
         sheet.autoGenerateColumns = false;
         sheet.setDataSource(datas);
+        sheet.addRows(sheet.getRowCount(), 1);      // 扩展1行,用于直接输入以新增记录。
         sheet.bindColumns(colDef);
         me.setColAlign(colDef);
         me.setRowHeight(datas, 25);

+ 19 - 2
web/building_saas/main/html/main.html

@@ -224,8 +224,25 @@
                                           <select class="form-control form-control-sm col-6" id="stdRationLibSelect">
                                           </select>
                                           <div class="input-group col-6">
-                                              <div class="input-group-addon form-control-sm"><i class="fa fa-search" aria-hidden="true"></i></div>
-                                              <input type="text" class="form-control form-control-sm" placeholder="搜索定额">
+                                              <input type="text" class="form-control form-control-sm" placeholder="搜索定额" value="" id="rationSearchKeyword">
+                                              <span class="input-group-btn">
+                                                  <button class="btn btn-secondary btn-sm" type="button" id="rationSearch"><i class="fa fa-search" aria-hidden="true"></i></button>
+                                              </span>
+                                          </div>
+                                          <!--搜索结果窗体-->
+                                          <div class="side-search-box col-12 p-2" id="rationSearchResult" style="display: none;">
+                                              <div class="d-flex justify-content-between">
+                                                  <span>搜索结果:5</span><a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>
+                                              </div>
+                                              <div class="result-box w-100">
+                                                  <table class="table">
+                                                      <thead><tr><th></th><th>编号</th><th>名称</th><th>单位</th><th>基价</th></tr></thead>
+                                                      <tbody>
+                                                      <tr><td>1</td><td>1-1-8-2</td><td>机动翻斗车运第1个100m石方</td><td>1000m3</td><td>6249</td></tr>
+                                                      <tr><td>1</td><td>1-1-8-2</td><td>机动翻斗车运第1个100m石方</td><td>1000m3</td><td>6249</td></tr>
+                                                      </tbody>
+                                                  </table>
+                                              </div>
                                           </div>
                                       </div>
                                   </div>

+ 2 - 7
web/building_saas/main/js/models/ration.js

@@ -118,29 +118,24 @@ var Ration = {
         };
 
         ration.prototype.insertStdRation = function (billsID, preRation, std) {
-            var br = this.getBillsSortRation(billsID), updateData = this.getInsertRationData(billsID, preRation);
+            var br = this.getBillsSortRation(billsID), updateData = this.getInsertRationData(billsID, preRation), newRation = null;
             updateData.forEach(function (data) {
                 if (data.updateType === 'ut_create') {
                     data.updateData.code = std.code;
                     data.updateData.name = std.name;
                     data.updateData.unit = std.unit;
+                    newRation = data.updateData;
                 }
             });
             this.project.pushNow('insertRation', [this.getSourceType()], [updateData]);
 
-            var newRation = null;
             if (preRation) {
                 var preIndex = br.indexOf(preRation), i;
-                newRation = this.getTempRationData(this.getNewRationID(), billsID, preIndex < br.length - 1 ? br[preIndex + 1].serialNo : br[preIndex].serialNo + 1);
-                newRation.code = std.code;
-                newRation.name = std.name;
-                newRation.unit = std.unit;
                 this.datas.push(newRation);
                 for (i = preIndex + 1; i < br.length; i++) {
                     br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
                 }
             } else {
-                newRation = this.getTempRationData(this.getNewRationID(), billsID, br.length > 0 ? br[br.length - 1].serialNo + 1 : 1);
                 this.datas.push(newRation);
             }
             return newRation;

+ 36 - 1
web/building_saas/main/js/views/std_ration_lib.js

@@ -19,7 +19,7 @@ var rationLibObj = {
             this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
                 var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
                 if (rationCode !== '') {
-                    CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, sectionId: rationLibObj.rationChapterTreeController.tree.selected.getID(), code: rationCode}, function (data) {
+                    CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
                         ProjectController.addRation(project, controller, data);
                     });
                 }
@@ -202,3 +202,38 @@ $('#stdRationLibSelect').change(function () {
         rationLibObj.loadStdRation(select.val());
     }
 });
+$('#rationSearch').click(function () {
+    var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
+    var getResultHtml = function (result) {
+        var html = [], i;
+        html.push('<div class="d-flex justify-content-between">');
+        html.push('<span>搜索结果:');
+        html.push(result.length.toString());
+        html.push('</span>');
+        html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
+        html.push('</div>');
+
+        html.push('<div class="result-box w-100">');
+        html.push('<table class="table">');
+        html.push('<thead><tr><th></th><th>编号</th><th>名称</th><th>单位</th><th>基价</th></tr></thead>');
+        html.push('<tbody>');
+        for (i = 0; i < result.length; i++) {
+            html.push('<tr>');
+            html.push('<td>' + i.toString() + '</td>');
+            html.push('<td>' + result[i].code + '</td>');
+            html.push('<td>' + result[i].name + '</td>');
+            html.push('<td>' + result[i].unit + '</td>');
+            html.push('</tr>');
+        }
+        html.push('</tbody>');
+        html.push('</table>');
+        html.push('</div>');
+        return html.join('');
+    }
+    CommonAjax.postRationLib('/rationRepository/api/findRation', {'user_id': userID, 'rationLibId': rationLibID, 'keyword': keyword}, function (result) {
+        var resultObj = $('#rationSearchResult');
+        resultObj.empty();
+        resultObj.append(getResultHtml(result));
+        resultObj.show();
+    });
+});

+ 1 - 1
web/maintain/ration_repository/fuzhu.html

@@ -198,7 +198,7 @@
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.exedit.js"></script>
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <script type="text/javascript" src="/public/web/QueryParam.js"></script>
-    <script src="/public/web/sheet.js"></script>
+    <script src="/public/web/sheet_creater.js"></script>
     <script src="/public/debug.js"></script>
     <script type="text/javascript" src="/public/web/storageUtil.js"></script>
     <script type="text/javascript" src="/web/maintain/ration_repository/js/coe.js"></script>

+ 12 - 1
web/maintain/ration_repository/js/coe.js

@@ -128,7 +128,18 @@ var coeList = {
         var me = coeList;
         var row = args.sheet.getActiveRowIndex();
         me.detailSpread.suspendPaint();
-        me.detailSpread.getSheet(0).setDataSource(me.datas[row].coes);
+
+        var dSheet = me.detailSpread.getSheet(0);
+        var dData = me.datas[row].coes;
+        if (dData == undefined){
+            dSheet.setDataSource(null);
+        }else{
+            dSheet.setDataSource(dData);
+            var lastData = dData[dData.length - 1];
+            if (lastData.coeType !== undefined){
+                dSheet.addRows(dSheet.getRowCount(), 1);
+            };
+        };
         me.detailSpread.resumePaint();
     },