Browse Source

Merge branch 'master' of http://192.168.1.41:3000/SmartCost/ConstructionOperation

TonyKang 5 years atrás
parent
commit
8611d54736

+ 9 - 2
modules/all_models/welcome_setting.js

@@ -13,7 +13,14 @@ let modelSchema = {
         index: true
     },
     compilationId: String,
-    showType:{type:Number,default:0},// 1 每天一次 2 每次登录显示,0 关闭
-    context:String
+    normal:{
+      showType:{type:Number,default:0},// 1 每天一次 2 每次登录显示,0 关闭
+      context:String
+    },
+    // 专业用户
+    professional: {
+       showType:{type:Number,default:0},// 1 每天一次 2 每次登录显示,0 关闭
+       context:String
+    }
 };
 mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));

+ 30 - 1
modules/ration_repository/models/ration_item.js

@@ -21,6 +21,35 @@ import stdgljutil  from "../../../public/cache/std_glj_type_util";
 
 var rationItemDAO = function(){};
 
+// 由于导入excel时,excel数据存在负的工程量,所以导入后一些定额人材机的消耗量可能为负,需要处理
+rationItemDAO.prototype.handleMinusQuantity = async function() {
+    const updateTask = [];
+    const repIDs = new Set();
+    const rations = await rationItemModel.find({'rationGljList.consumeAmt': {$lt: 0}}).lean();
+    for (const ration of rations) {
+        repIDs.add(ration.rationRepId);
+        const rationGLJList = [];
+        for (const rGLJ of ration.rationGljList) {
+            rationGLJList.push({
+                gljId: rGLJ.gljId,
+                consumeAmt: Math.abs(rGLJ.consumeAmt),
+                proportion: rGLJ.proportion
+            });
+        }
+        updateTask.push({
+            updateOne: {
+                filter: { ID: ration.ID },
+                update: { $set: { rationGljList: rationGLJList } }
+            }
+        });
+    }
+    if (updateTask.length) {
+        await rationItemModel.bulkWrite(updateTask);
+    }
+    console.log(`repIDs`);
+    console.log(repIDs);
+};
+
 rationItemDAO.prototype.prepareInitData = async function (rationRepId) {
     // 定额库
     const libTask = stdRationLibModel.findOne({ID: rationRepId}, '-_id ID dispName gljLib');
@@ -878,7 +907,7 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
             }
             const tmpRationGlj = {
                 gljId: stdGLJList[tmp[1]],
-                consumeAmt: tmp[4],
+                consumeAmt: Math.abs(tmp[4]),
                 proportion: 0,
             };
             lastData.rationGljList.push(tmpRationGlj);

+ 28 - 0
modules/std_glj_lib/models/gljModel.js

@@ -810,6 +810,34 @@ class GljDao  extends OprDao{
         }
     }
 
+    // 批量修改人材机类型
+    async batchUpdateGLJType(gljLibId, sheetData) {
+        // 将所有人材机进行编码映射
+        const allGLJs = await gljModel.find({repositoryId: gljLibId}, {ID: true, code: true, gljType: true, shortName: true}).lean();
+        const codeMapping = {};
+        allGLJs.forEach(glj => codeMapping[glj.code] = glj);
+        const updateTask = [];
+        for (let row = 1; row < sheetData.length; row++) {
+            const rowData = sheetData[row];
+            const code = rowData[0];
+            const gljType = rowData[1];
+            const shortName = rowData[2];
+            const glj = codeMapping[code];
+            if (!glj) {
+                continue;
+            }
+            updateTask.push({
+                updateOne: {
+                    filter: { ID: glj.ID },
+                    update: { gljType, shortName }
+                }
+            });
+        }
+        if (updateTask.length) {
+            gljModel.bulkWrite(updateTask);
+        }
+    }
+
     // 导入组成物(替换原本的数据)
     // excel第一行应为:人材机、组成物、消耗量(或者:消耗-一般、消耗-简易等)
     async importComponents(gljLibId, sheetData) {

+ 14 - 3
modules/users/controllers/welcome_controller.js

@@ -11,7 +11,7 @@ const uuidV1 = require('uuid/v1');
 class WelcomeController extends BaseController {
     async index(request, response) {
         let id = request.query.id;
-
+        let type = request.query.type;
         let compilationList = [];
         let selectedCompilation = {};
         try {
@@ -38,11 +38,19 @@ class WelcomeController extends BaseController {
         if (selectedCompilation.example && Array.isArray(selectedCompilation.example)) {
             selectedCompilation.example = selectedCompilation.example.join(';');
         }
-        let setting =await welcomeSettingModel.findOne({compilationId:selectedCompilation._id.toString()});
+        let welcome_setting =await welcomeSettingModel.findOne({compilationId:selectedCompilation._id.toString()});
+        let setting = null;
+        let settingID="";
+        if(welcome_setting){
+          setting = type== "professional"?welcome_setting.professional:welcome_setting.normal;
+          settingID = welcome_setting.ID;
+        }
         if(!setting) setting = {showType:0,context:""};
         console.log(setting)
         let renderData = {
             id: id,
+            type:type,
+            settingID:settingID,
             compilationList: compilationList,
             selectedCompilation: selectedCompilation,
             layout: 'users/views/layout/layout',
@@ -54,7 +62,10 @@ class WelcomeController extends BaseController {
 
     async save(request, response){
         let data = request.body;
-        let setting = {compilationId:data.compilationId,showType:data.showType,context:data.context};
+        let setting = {compilationId:data.compilationId};
+        let type = data.type;
+        let info = {showType:data.showType,context:data.context}
+        type == "professional"?setting.professional = info:setting.normal = info
         if(!data.ID || data.ID == ""){
             setting.ID = uuidV1();
             await welcomeSettingModel.create(setting);

+ 2 - 2
public/web/tools_const.js

@@ -7,8 +7,8 @@
  * @date 2018/8/15
  * @version
  */
-//允许使用的工料机类型:人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆、机械台班、机械组成物、机上人工、主材、设备
-let allowGljType = [1, 201, 202, 203, 204, 205, 206, 301, 302, 303, 4, 5];
+//允许使用的工料机类型:人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆、其他材料费 、机械台班、机械组成物、机上人工、主材、设备
+let allowGljType = [1, 201, 202, 203, 204, 205, 206, 207, 301, 302, 303, 4, 5];
 
 //允许含有组成物的工料机类型:混凝土、砂浆、配合比、机械台班、主材
 let allowComponent = [202, 203, 204, 301, 4];

+ 2 - 2
web/over_write/js/guangdong_2018.js

@@ -1,8 +1,8 @@
 'use strict';
-//允许使用的工料机类型:人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆
+//允许使用的工料机类型:人工、普通材料、其他材料费、混凝土、砂浆、配合比、商品混凝土、商品砂浆
 //机械台班、机上人工、机械组成物、主材、设备、企业管理费
 if(typeof allowGljType !== 'undefined'){
-    allowGljType = [1, 201, 202, 203, 204, 205, 206, 301, 302, 303, 4,5, 6];
+    allowGljType = [1, 201, 202, 203, 204, 205, 206, 207, 301, 302, 303, 4,5, 6];
 }
 if(typeof allowComponent !== 'undefined'){
     //允许含有组成物的工料机类型:混凝土、砂浆、配合比、机械台班、主材

+ 2 - 2
web/over_write/js/neimenggu_2017.js

@@ -8,9 +8,9 @@
  * @version
  */
 
-//允许使用的工料机类型:人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆、机械台班、机械组成物、机上人工、主材、设备、企业管理费、利润
+//允许使用的工料机类型:人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆、其他材料费、机械台班、机械组成物、机上人工、主材、设备、企业管理费、利润
 if(typeof allowGljType !== 'undefined'){
-    allowGljType = [1, 201, 202, 203, 204, 205, 206, 301, 302, 303, 4, 5, 6, 7];
+    allowGljType = [1, 201, 202, 203, 204, 205, 206, 207, 301, 302, 303, 4, 5, 6, 7];
 }
 if(typeof allowComponent !== 'undefined'){
     //允许含有组成物的工料机类型:混凝土、砂浆、配合比、机械台班、主材

+ 20 - 0
web/users/css/custom.css

@@ -18,4 +18,24 @@
 
 .btn-link:focus, .btn-link:hover{
   text-decoration: none
+}
+.highlight {
+  background: #eee;
+}
+.dragging {
+  opacity: .5;
+  background: #eee;
+}
+.cursor-default {
+  cursor: default;
+}
+.cursor-move {
+  cursor: move;
+}
+/* 不禁止的话,drag过程中经过子元素也会触发dragleave事件导致屏闪 */
+[draggable=true]:hover {
+  background: rgb(240, 240, 240);
+}
+[draggable=true] span{
+  pointer-events: none;
 }

+ 77 - 20
web/users/js/compilation.js

@@ -135,34 +135,91 @@ $(document).ready(function() {
 
     //新增定额库
     $("#add-ration").click(function () {
-         let rationLib = $("select[name='ration_lib']").children("option:selected").val();
-         let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
-         if(rationLib == undefined || rationLib ==''){
-             alert("请选择定额库");
-             return;
-         }
-        if($("input:hidden[name=ration_lib][data-id = "+rationLib+"]").length <= 0){
+        let rationLib = $("select[name='ration_lib']").children("option:selected").val();
+        let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
+        if (rationLib == undefined || rationLib == '') {
+            alert("请选择定额库");
+            return;
+        }
+        if ($("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length <= 0) {
             let tem = {
-                id:rationLib,
-                name:rationLibString,
-                isDefault:false
+                id: rationLib,
+                name: rationLibString,
+                isDefault: false
             };
             let htmlString = ` 
-                <tr class='ration_tr'>
-                     <td><span>${tem.name}</span></td>
-                     <td><label class="form-check-label"> <input class="form-check-input" name="ration_isDefault"  value="${tem.id}" type="radio"></td>  
-                     <td>
-                            <a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>
-                            <input type="hidden" name="ration_lib" data-id="${tem.id}" value='${JSON.stringify(tem)}'>
-                      </td>
+                <tr class='ration_tr' draggable="true">
+                    <td><span class="cursor-default">${tem.name}</span></td>
+                    <td><label class="form-check-label"> <input class="form-check-input" name="ration_isDefault"  value="${tem.id}" type="radio"></td>  
+                    <td>
+                        <a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>
+                        <input type="hidden" name="ration_lib" data-id="${tem.id}" value='${JSON.stringify(tem)}'>
+                    </td>
                 </tr>`
             $("#ration_tbody").append(htmlString);
-        }else {
+        } else {
             alert('已存在相同的定额库')
         }
         $("#addRation").modal('hide');
     });
 
+    // 拖动排序
+    const dragSelector = '.ration_tr[draggable=true]';
+    const rationBodySelector = '#ration_tbody';
+    const wrapper = $('.panel-content')[0];
+    let dragged;
+    let rID = null;
+    const scrollStep = 6;
+    // 表格数据过多的时候,靠下方的条目想要移动到上方,需要滚动条滚动到相应位置,滚动条向上滚动需要代码自行处理
+    function scroll(ele, step) {
+        wrapper.scrollTop -= step;
+        rID = window.requestAnimationFrame(() => {
+            scroll(ele, step);
+        });
+    }
+    // 动态绑定(新增的也能监听到)
+    $(rationBodySelector).on('drag', dragSelector, function (ev) {
+        const { clientX, clientY } = ev;
+        const dom = document.elementFromPoint(clientX, clientY);
+        if (dom.tagName === 'H2' && !rID) {
+            rID = window.requestAnimationFrame(() => {
+                scroll(wrapper, scrollStep);
+            })
+        } else if (dom.tagName !== 'H2' && rID) {
+            window.cancelAnimationFrame(rID);
+            rID = null;
+        }
+    });
+    $(rationBodySelector).on('dragstart', dragSelector, function (ev) {
+        dragged = this;
+        $(this).addClass('dragging');
+        ev.originalEvent.dataTransfer.effectAllowed = 'move';
+    });
+    $(rationBodySelector).on('dragend', dragSelector, function (ev) {
+        $(this).removeClass('dragging');
+        if (rID) {
+            window.cancelAnimationFrame(rID);
+            rID = null;
+        }
+    });
+    $(rationBodySelector).on('dragover', dragSelector, function (ev) {
+        ev.preventDefault(); // 必须调用此方法,否则drop事件不触发
+    });
+    $(rationBodySelector).on('dragenter', dragSelector, function (ev) {
+        if (this !== dragged) {
+            $(this).addClass('highlight');
+        }
+    });
+    $(rationBodySelector).on('dragleave', dragSelector, function (ev) {
+        if (this !== dragged) {
+            $(this).removeClass('highlight');
+        }
+    });
+    $(rationBodySelector).on('drop', dragSelector, function (ev) {
+        $(this).removeClass('highlight');
+        $(this).after($(dragged));
+    });
+
     // 新增计价规则
     $("#add-valuation").click(function() {
         try {
@@ -502,9 +559,9 @@ function initCompilation() {
         TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
     }*/
 
-    if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
+    /* if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
         return false;
-    }
+    } */
 
     // 标准清单
     let html = '';

+ 2 - 2
web/users/views/compilation/engineering.html

@@ -305,9 +305,9 @@
                                 <tbody id="ration_tbody">
                                 <% if (Object.keys(libData).length > 0 && libData.ration_lib.length > 0) { %>
                                 <% libData.ration_lib.forEach(function (ration, index){ %>
-                                <tr class='ration_tr'>
+                                <tr class='ration_tr' draggable="true">
                                     <td>
-                                        <span><%= ration.name%></span>
+                                        <span class="cursor-default"><%= ration.name%></span>
                                     </td>
                                     <td>
                                         <label class="form-check-label">

+ 7 - 2
web/users/views/welcome/index.html

@@ -25,12 +25,17 @@
             </div>
         </div>
             <div class="content-wrap">
-                <div class="c-header">
+                <div class="c-header" style="padding:0" >
+                  <ul class="nav nav-tabs">
+                    <li role="presentation" <% if( type != "professional") { %>class="active"<% } %> ><a href="/welcome?id=<%= selectedCompilation._id.toString()%>">免费版</a></li>
+                    <li role="presentation" <% if( type == "professional") { %>class="active"<% } %>><a href="/welcome?id=<%= selectedCompilation._id.toString()%>&type=professional">专业版</a></li>
+                  </ul>
                 </div>
                 <div class="c-body">
                     <form method="post" action="/welcome/save" enctype="application/x-www-form-urlencoded21">
-                        <input type="hidden" name="ID" value="<%= setting.ID%>">
+                        <input type="hidden" name="ID" value="<%= settingID%>">
                         <input type="hidden" name="compilationId" value="<%= selectedCompilation._id.toString()%>">
+                        <input type="hidden" name="type" value="<%= type%>">
                     <div class="form-group">
                         <label for="title">显示频率</label>
                         <div class="radio">