浏览代码

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

zhongzewei 8 年之前
父节点
当前提交
12795e677c

+ 2 - 0
config/config.js

@@ -3,6 +3,8 @@ module.exports = {
     local: {server: "localhost", port: "27017"},
     qa: {server: "192.168.1.184", port: "60666"},
     prod: {server: "", port: ""},
+    redis_local:{server:'127.0.0.1',port:'6379',pwd:'smartCost'},
+    redis_qa:{server:'192.168.1.184',port:'6379',pwd:'smartCost'},
     setToLocalDb: function() {
         var me = this;
         me.current.server = me.local.server;

+ 219 - 0
config/redis.js

@@ -0,0 +1,219 @@
+/**
+ * Created by chen on 2017/8/21.
+ */
+
+let Redis = require('ioredis'),
+    config=require('./config'),
+    redis = new Redis({
+        port: config.redis_qa.port,          // Redis port
+        host: config.redis_qa.server,   // Redis host
+        family: 4,           // 4 (IPv4) or 6 (IPv6)
+        password:config.redis_qa.pwd,
+        db: 0
+    });
+let client={};
+
+redis.on('ready',function(res){
+    console.log('ready');
+});
+
+redis.on("error", function (err) {
+    console.log("Error " + err);
+});
+client.redis = redis;
+//redis.hmset('测试',{12525:55,'a':'aaaa',b:"bbbbb"});
+
+//var stream = redis.scanStream({  match: '测*'});
+
+/*redis.hmset('RATION',{12525:55,'a':'aaaa',b:"bbbbb"});
+
+redis.hgetall("RATION",function (err,result) {
+    console.log(result);
+})*/
+
+
+client.scan = function(options,callback){
+    var stream = null;
+    if(options){
+        stream = redis.scanStream(options);
+    }else {
+        stream = redis.scanStream();
+    }
+    var keys = [];
+    stream.on('data', function (resultKeys) {
+        // `resultKeys` is an array of strings representing key names
+        for (var i = 0; i < resultKeys.length; i++) {
+            keys.push(resultKeys[i]);
+        }
+    });
+    stream.on('end', function () {
+        console.log('done with the keys: ', keys);
+        callback(keys);
+    });
+}
+
+client.set = function(key, value, expire, callback){
+    return redis.set(key, value, function(err, result){
+        if (err) {
+            console.log(err);
+            callback(err,null);
+            return;
+        }
+        if (!isNaN(expire) && expire > 0) {
+            redis.expire(key, parseInt(expire));
+        }
+        if(callback){
+            callback(null,result);
+        }
+    })
+}
+
+
+client.get = function(key, callback){
+    return redis.get(key, function(err,result){
+        if (err) {
+            console.log(err);
+            callback(err,null);
+            return;
+        }
+        if(callback){
+            callback(null,result);
+        }
+    });
+}
+
+client.hmset = function(key, value, expire, callback){
+    return redis.hmset(key, value, function(err, result){
+        if (err) {
+            console.log(err);
+            callback(err,null);
+            return;
+        }
+        if (!isNaN(expire) && expire > 0) {
+            redis.expire(key, parseInt(expire));
+        }
+        if(callback){
+            callback(null,result);
+        }
+    })
+}
+
+client.hmget = function (key,fields,callback) {
+    return redis.hmget(key,fields,function(err,result){
+        if (err) {
+            console.log(err);
+            callback(err,null)
+            return;
+        }
+        if(callback){
+            callback(null,result);
+        }
+    })
+}
+
+client.hgetall = function (key,callback) {
+    return redis.hgetall(key,function (err,result) {
+        if (err) {
+            console.log(err);
+            callback(err,null)
+            return;
+        }
+        callback(null,result);
+    })
+}
+
+
+client.hscan = function (key,options) {
+    var stream = null;
+    if(options){
+        stream = redis.hscanStream(key,options);
+    }else {
+        stream = redis.hscanStream(key);
+    }
+    var fields = [];
+    stream.on('data', function (resultFields) {
+        // `resultKeys` is an array of strings representing key names
+        for (var i = 0; i < resultFields.length; i++) {
+            fields.push(resultFields[i]);
+        }
+    });
+    stream.on('end', function () {
+        console.log('done with the keys: ', fields);
+        callback(fields);
+    });
+}
+
+client.rpush = function(key,value,expire, callback){
+    return redis.rpush(key, value, function(err, result){
+        if (err) {
+            console.log(err);
+            callback(err,null);
+            return;
+        }
+        if (!isNaN(expire) && expire > 0) {
+            redis.expire(key, parseInt(expire));
+        }
+        if(callback){
+            callback(null,result);
+        }
+    })
+}
+
+client.lrange= function (key,start,end,callback) {
+   return redis.lrange(key,start,end,callback);//获取列表在给定范围上的所有值 array lrange('key', 0, -1) (返回所有值)
+}
+
+client.lindex =function (key,index,callback) {
+    return redis.lindex(key,index,callback);//获取列表在给定位置上的单个元素 lindex('key', 1)
+}
+
+client.lpop = function (key,callback) {
+    return redis.lpop(key,callback);//从列表左端弹出一个值,并返回被弹出的值lpop('key')
+}
+
+client.rpop = function (key,callback) {
+    return redis.rpop(key,callback);//从列表右端弹出一个值,并返回被弹出的值rpop('key')
+}
+
+client.ltrim = function (key,start,end,callback) {
+    return redis.ltrim(key,start,end,callback);//将列表按指定的index范围裁减 ltrim('key', 'start', 'end')
+}
+
+
+client.del = function (keys,callback) {
+    return redis.del(keys,callback);// 删除一个(或多个)keys return 被删除的keys的数量  del('key1'[, 'key2', ...])
+}
+
+client.exists = function (key,callback) {
+    return redis.exists(key,callback);// 查询一个key是否存在  1/0 exists('key')
+}
+
+client.multi = function () {
+    return redis.multi();//用于开启一个事务,它总是返回 OK 。
+}
+
+client.exec =function () {
+   return redis.exec();//执行所有事务块内的命令
+}
+
+client.application_init = function () {
+    redis.flushdb();//清空所有keys
+    // load datas -- to do
+    /*data=[{
+     method:'hmset',
+     key:'ration:25555',
+     value:{
+     name:'aaa',
+     quantily:255
+     },
+     expire:2000,//options
+     callback:function, //option
+     }]
+     for(let data of datas){
+     client[data.method](data.key,data.value,data.expire,data.callback);
+     }
+     */
+}
+
+
+module.exports = client

+ 9 - 9
modules/pm/models/project_model.js

@@ -9,7 +9,9 @@ let copyProjController = require('../controllers/copy_proj_controller');
 let Projects = require("./project_schema");
 let projectType = {
     folder: 'Folder',
-    tender: 'Tender'
+    tender: 'Tender',
+    project: 'Project',
+    engineering: 'Engineering',
 };
 
 let ProjectsDAO = function(){};
@@ -44,6 +46,7 @@ ProjectsDAO.prototype.updateUserProjects = function(userId, datas, callback){
                 }
             } else {
                 hasError = true;
+                console.log(err);
                 callback(1, '提交数据出错.', null);
             }
         };
@@ -54,9 +57,7 @@ ProjectsDAO.prototype.updateUserProjects = function(userId, datas, callback){
                 Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll)
             } else if (data.updateType === 'new') {
                 data.updateData['userID'] = userId;
-                if (data.updateData.projType === projectType.folder) {
-                    data.updateData['createDateTime'] = new Date();
-                }
+                data.updateData['createDateTime'] = new Date();
                 newProject = new Projects(data.updateData);
                 newProject.save(function (err, result) {
                     if (!err && result._doc.projType === projectType.tender) {
@@ -92,6 +93,7 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
             callback(1, '提交数据出错.', null);
         }
     };
+    console.log(datas);
     if (datas) {
         for (i = 0; i < datas.length && !hasError; i++) {
             data = datas[i];
@@ -99,14 +101,12 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
                 Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll)
             } else if (data.updateType === 'copy') {
                 data.updateData['userID'] = userId;
-                if (data.updateData.projType === 'Tender') {
-                    data.updateData['createDateTime'] = new Date();
-                };
-                newProject = new Projects(data.updateData);
+                data.updateData['createDateTime'] = new Date();
+                let newProject = new Projects(data.updateData);
                 newProject['srcProjectId'] = data.srcProjectId;
                 newProject.save(function (err, result) {
                     if (!err && result._doc.projType === 'Tender') {
-                        copyProjController.copyProjectData(this.newProject.srcProjectId, result._doc.ID, updateAll);
+                        copyProjController.copyProjectData(newProject.srcProjectId, result._doc.ID, updateAll);
                     } else {
                         updateAll(err);
                     }

+ 15 - 3
modules/pm/routes/pm_route.js

@@ -9,9 +9,21 @@ let pmController = require('./../controllers/pm_controller');
 module.exports = function (app) {
 
     app.get('/pm', function(req, res){
-        res.render('building_saas/pm/html/project-management.html',
-            {userAccount: req.session.userAccount,
-                userID: req.session.sessionUser.ssoId});
+        // 获取编办信息
+        let sessionCompilation = req.session.sessionCompilation;
+        // 清单计价
+        let billValuation = sessionCompilation.bill_valuation !== undefined ? sessionCompilation.bill_valuation : [];
+
+        // 定额计价
+        let rationValuation = sessionCompilation.ration_valuation !== undefined ? sessionCompilation.ration_valuation : [];
+        let renderData = {
+            userAccount: req.session.userAccount,
+            userID: req.session.sessionUser.ssoId,
+            compilationData: sessionCompilation,
+            billValuation: JSON.stringify(billValuation),
+            rationValuation: JSON.stringify(rationValuation),
+        };
+        res.render('building_saas/pm/html/project-management.html', renderData);
     });
 
     let pmRouter = express.Router();

+ 1 - 1
modules/users/controllers/boot_controller.js

@@ -27,7 +27,7 @@ class BootController extends BaseController {
         // 判断是否有存入编办信息
         if (sessionCompilation === undefined && compilationId !== '') {
             let compilationModel = new CompilationModel();
-            let compilationData = await compilationModel.findDataByCondition({_id: compilationId});
+            let compilationData = await compilationModel.getCompilationById(compilationId);
 
             request.session.sessionCompilation = compilationData;
         }

+ 2 - 3
modules/users/controllers/login_controller.js

@@ -74,13 +74,12 @@ class LoginController {
 
             let compilationModel = new CompilationModel();
             compilationList = preferenceSetting.login_ask === 1 ? await compilationModel.getList() : [];
-
             // 获取编办信息
             let sessionCompilation = request.session.sessionCompilation;
-            if (preferenceSetting.login_ask === 0 && sessionCompilation === undefined &&
+            if (preferenceSetting.login_ask === 0 && !sessionCompilation &&
                 preferenceSetting.select_version !== '') {
-                let compilationData = await compilationModel.findDataByCondition({_id: preferenceSetting.select_version});
 
+                let compilationData = await compilationModel.getCompilationById(preferenceSetting.select_version);
                 request.session.sessionCompilation = compilationData;
             }
 

+ 1 - 1
modules/users/controllers/user_controller.js

@@ -175,7 +175,7 @@ class UserController extends BaseController {
             if (data.login_ask === 1) {
                 // 查找对应编办
                 let compilationModel = new CompilationModel();
-                let compilationData = await compilationModel.findDataByCondition({_id: selectVersion});
+                let compilationData = await compilationModel.getCompilationById(selectVersion);
 
                 request.session.sessionCompilation = compilationData;
             }

+ 35 - 1
modules/users/models/compilation_model.js

@@ -29,11 +29,45 @@ class CompilationModel extends BaseModel {
     async getList() {
         // 筛选字段
         let field = {_id: 1, name: 1, is_release: 1};
-        let compilationData = await this.findDataByCondition({name: {$ne: ''}}, field, false);
+        let compilationData = await this.findDataByCondition({name: {$ne: ''}, is_release: true}, field, false);
 
         return compilationData === null ? [] : compilationData;
     }
 
+    /**
+     * 根据id获取可用的编办数据
+     *
+     * @param {String} id
+     * @return {Promise}
+     */
+    async getCompilationById(id) {
+        let condition = {_id: id, is_release: true};
+        let compilationData = await this.findDataByCondition(condition);
+        if (compilationData.bill_valuation === undefined) {
+            return compilationData;
+        }
+
+        if (compilationData.bill_valuation.length > 0) {
+            for (let index in compilationData.bill_valuation) {
+                if (compilationData.bill_valuation[index].enable) {
+                    continue;
+                }
+                delete compilationData.bill_valuation[index];
+            }
+        }
+
+        if (compilationData.ration_valuation.length > 0) {
+            for (let index in compilationData.ration_valuation) {
+                if (compilationData.ration_valuation[index].enable) {
+                    continue;
+                }
+                delete compilationData.ration_valuation[index];
+            }
+        }
+
+        return compilationData;
+    }
+
 }
 
 export default CompilationModel;

+ 1 - 0
modules/users/routes/login_route.js

@@ -21,6 +21,7 @@ module.exports = function (app) {
 
     router.get("/logout", function (req, res) {
         delete req.session.sessionUser;
+        delete req.session.sessionCompilation;
         res.redirect("/");
     });
     app.use('/',router)

+ 2 - 1
package.json

@@ -27,7 +27,8 @@
     "moment": "^2.18.1",
     "socket.io": "^2.0.3",
     "ua-parser-js": "^0.7.14",
-    "uuid": "^3.1.0"
+    "uuid": "^3.1.0",
+    "ioredis":"^3.1.4"
   },
   "scripts": {
     "start": "C:\\Users\\mai\\AppData\\Roaming\\npm\\babel-node.cmd server.js"

+ 48 - 36
public/calc_util.js

@@ -1,6 +1,7 @@
 /**
  * Created by Tony on 2017/6/21.
  * Modified by CSL, 2017-08-01
+ * 引入多套计算程序、费率同步、人工系数同步、改进基数计算、费字段映射等。
  */
 
 let executeObj = {
@@ -40,14 +41,40 @@ let executeObj = {
 };
 
 class Calculation {
-/*    init(template, feeRates){
+    // 先编译公用的基础数据
+    compilePublics(feeRates, labourCoes, feeTypes){
         let me = this;
-        me.template = template;
-        me.feeRates = feeRates;
-        me.hasCompiled = false;
-    };*/
+        let private_compile_feeFile = function() {
+            if (feeRates) {
+                me.compiledFeeRates = {};
+                for (let rate of feeRates) {
+                    me.compiledFeeRates["feeRate_" + rate.ID] = rate;
+                }
+            }
+        };
+        let private_compile_labourCoeFile = function() {
+            if (labourCoes) {
+                me.compiledLabourCoes = {};
+                for (let coe of labourCoes) {
+                    me.compiledLabourCoes["LabourCoe_" + coe.ID] = coe;
+                }
+            }
+        };
+        let private_compile_feeType = function() {
+            if (feeTypes) {
+                me.compiledFeeTypes = {};
+                for (let ft of feeTypes) {
+                    me.compiledFeeTypes[ft.type] = ft.name;
+                }
+            }
+        };
 
-    compile(template, feeRates, labourCoes){
+        private_compile_feeFile();
+        private_compile_labourCoeFile();
+        private_compile_feeType();
+    };
+
+    compileTemplate(template){
         let me = this;
         template.hasCompiled = false;
         template.errs = [];
@@ -109,44 +136,32 @@ class Calculation {
                 let item = template.calcItems[idx];
                 item.compiledExpr = item.expression.split('@(').join('$CE.at(');
                 item.compiledExpr = item.compiledExpr.split('base(').join('$CE.base(');
-                //item.compiledExpr = item.compiledExpr.split('rate(').join('$CE.rate(');
-                //item.compiledExpr = item.compiledExpr.split('factor(').join('$CE.factor(');
+
                 if (item.labourCoeID){
                     let lc = me.compiledLabourCoes["LabourCoe_" + item.labourCoeID].coe;
                     item.dispExpr = item.dispExpr.replace(/L/gi, lc.toString());
                     item.compiledExpr = item.compiledExpr.replace(/L/gi, lc.toString());
-                }
-            }
-        };
-        let private_compile_feeFile = function() {
-            if (feeRates) {
-                me.compiledFeeRate = {};
-                for (let rate of feeRates) {
-                    me.compiledFeeRate["feeRate_" + rate.ID] = rate;
-                }
-            }
-        };
-        let private_compile_labourCoeFile = function() {
-            if (labourCoes) {
-                me.compiledLabourCoes = {};
-                for (let coe of labourCoes) {
-                    me.compiledLabourCoes["LabourCoe_" + coe.ID] = coe;
-                }
+                };
+
+                if (item.feeRateID) {
+                    item.feeRate = me.compiledFeeRates["feeRate_" + item.feeRateID].rate;
+                };
+
+                // 字段名映射
+                item.displayFieldName = me.compiledFeeTypes[item.fieldName];
             }
         };
 
         if (template && template.calcItems && template.calcItems.length > 0) {
             template.compiledSeq = [];
             template.compiledTemplate = {};
-            //1. first round -> prepare
-            private_compile_feeFile();
-            private_compile_labourCoeFile();
+
             for (let i = 0; i < template.calcItems.length; i++) {
                 let item = template.calcItems[i];
                 template.compiledTemplate[item.ID] = item;
                 template.compiledTemplate[item.ID + "_idx"] = i;
             }
-            //2. second round -> go!
+
             for (let i = 0; i < template.calcItems.length; i++) {
                 private_setup_seq(template.calcItems[i], i);
             }
@@ -156,7 +171,7 @@ class Calculation {
             } else {
                 console.log('errors: ' + template.errs.toString());
             }
-        }
+        };
     };
 
     calculate($treeNode){
@@ -175,13 +190,10 @@ class Calculation {
             for (let idx of template.compiledSeq) {
                 let calcItem = template.calcItems[idx];
 
-                let feeRate = 100;    // 100%
-                // 下面三项用于界面显示。
-                if (calcItem.feeRateID) {
-                    feeRate = me.compiledFeeRate["feeRate_" + calcItem.feeRateID].rate;
-                    calcItem.feeRate = feeRate;
-                };
+                let feeRate = calcItem.feeRate;
+                if (!feeRate) feeRate = 100;    // 100%
                 calcItem.unitFee = eval(calcItem.compiledExpr) * feeRate * 0.01;   // 如果eval()对清单树有影响,就换成小麦的Expression对象再试
+
                 let quantity = $treeNode.data.quantity;
                 if (!quantity) quantity = 0;
                 calcItem.totalFee = calcItem.unitFee * quantity;

+ 1 - 1
public/models/delete_schema.js

@@ -5,7 +5,7 @@
 var mongoose = require("mongoose");
 var Schema = mongoose.Schema;
 
-// ·ÑÓÃ×Ö¶Î
+
 var deleteSchema = new Schema({
     deleted: Boolean,
     deleteDateTime: Date,

+ 2 - 2
server.js

@@ -3,8 +3,8 @@ let express = require('express');
 let config = require("./config/config.js");
 let fileUtils = require("./modules/common/fileUtils");
 let dbm = require("./config/db/db_manager");
-//config.setToLocalDb();
-config.setToQaDb();
+config.setToLocalDb();
+// config.setToQaDb();
 
 let path = require('path');
 let session = require('express-session');

+ 19 - 2
web/building_saas/main/js/calc/calc_fees.js

@@ -4,11 +4,11 @@
 
 let feeType = [
     {type: 'common', name: '工程造价'},
-    {type: 'labour', name: '人工费'},
+    {type: 'baseLabour', name: '基价人工费'},
     {type: 'material', name: '材料费'},
     {type: 'machine', name: '机械费'},
     {type: 'rationDirect', name: '定额直接费'},
-    {type: 'management', name: '企业管理'},
+    {type: 'manageFee', name: '企业管理费'},
     {type: 'profit', name: '利润'},
     {type: 'risk', name: '风险费'},
     // 模拟用户新增
@@ -89,5 +89,22 @@ let calcFees = {
                 };
             }
         }
+    },
+    // CSL,2017.08.28
+    feeTypeToName: function (type) {
+        for (let ft of feeType) {
+            if (ft.type === type) {
+                return ft.name;
+            };
+        };
+    },
+
+    feeNameToType: function (name) {
+        for (let ft of feeType) {
+            if (ft.name === name) {
+                return ft.type;
+            };
+        };
+        return '';
     }
 }

+ 8 - 6
web/building_saas/main/js/models/calc_program.js

@@ -207,7 +207,7 @@ let calcTemplates = [
             {
                 ID: "1",
                 code: "1",
-                name: "基价直接工程费2",
+                name: "基价直接工程费",
                 fieldName: "baseDirect",
                 dispExpr: "F2+F5+F6+F10",
                 expression: "@('2') + @('5') + @('6') + @('10')",
@@ -401,7 +401,7 @@ let calcTemplates = [
             {
                 ID: "1",
                 code: "1",
-                name: "基价直接工程费3",
+                name: "基价直接工程费",
                 fieldName: "baseDirect",
                 dispExpr: "F2+F5+F6+F10",
                 expression: "@('2') + @('5') + @('6') + @('10')",
@@ -3599,13 +3599,15 @@ class CalcProgram {
     };
 
     compileAllTemps(){
-       for (let calcTemplate of calcTemplates){
-           this.calc.compile(calcTemplate, calcFeeRates, calcLabourCoes);
-       };
+        this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType);
+        for (let calcTemplate of calcTemplates){
+            this.calc.compileTemplate(calcTemplate);
+        };
     };
 
     compile(calcTemplate){
-       this.calc.compile(calcTemplate, calcFeeRates, calcLabourCoes);
+        this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType);
+        this.calc.compileTemplate(calcTemplate);
     };
 
     calculate(treeNode){

+ 3 - 3
web/building_saas/main/js/views/calc_program_manage.js

@@ -26,7 +26,7 @@ let rationPM = {
             {headerName:"计算基数",headerWidth:180,dataCode:"dispExpr", dataType: "String"},
             {headerName:"基数说明",headerWidth:300,dataCode:"statement", dataType: "String"},
             {headerName:"费率",headerWidth:80,dataCode:"feeRate", dataType: "Number"},
-            {headerName:"字段名称",headerWidth:180,dataCode:"fieldName", dataType: "String"},
+            {headerName:"字段名称",headerWidth:100,dataCode:"displayFieldName", dataType: "String", hAlign: "center"},
             {headerName:"备注",headerWidth:100,dataCode:"memo", dataType: "String"}
         ],
         view:{
@@ -38,8 +38,8 @@ let rationPM = {
     buildSheet: function (){
         let me = this;
         me.datas = calcTemplates;
-        me.mainSpread = sheetCommonObj.buildSheet($('#mainSpread')[0], me.mainSetting, 16);
-        me.detailSpread = sheetCommonObj.buildSheet($('#detailSpread')[0], me.detailSetting, 18);
+        me.mainSpread = sheetCommonObj.buildSheet($('#mainSpread')[0], me.mainSetting, me.datas.length);
+        me.detailSpread = sheetCommonObj.buildSheet($('#detailSpread')[0], me.detailSetting, me.datas[0].calcItems.length);
 
         //var coeType = new GC.Spread.Sheets.CellTypes.ComboBox();
         //coeType.items(["单个","定额","人工","材料","机械"]);

+ 0 - 1
web/building_saas/main/js/views/calc_program_view.js

@@ -238,7 +238,6 @@ let calcProgramObj = {
         if (treeNode.sourceType === projectObj.project.Ration.getSourceType()) {
             projectObj.project.calcProgram.calculate(treeNode);
             me.datas = me.treeNode.data.calcTemplate.calcItems;
-            //me.sheet.setRowCount(me.datas.length);
             sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);
             sheetCommonObj.showData(me.sheet, me.setting, me.datas);
         }

+ 474 - 446
web/building_saas/pm/html/project-management.html

@@ -10,7 +10,7 @@
     <link rel="stylesheet" href="/web/building_saas/css/main.css">
     <link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
     <!--zTree-->
-  	<link rel="stylesheet" href="/lib/ztree/css/zTreeStyle.css" type="text/css">
+    <link rel="stylesheet" href="/lib/ztree/css/zTreeStyle.css" type="text/css">
 
     <script>
         // 这里的变量供页面调用
@@ -20,27 +20,27 @@
 </head>
 
 <body>
-    <div class="header">
-        <div class="top-msg clearfix">
-            <div class="alert alert-warning mb-0 py-0" role="alert">
-                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
-                    <span aria-hidden="true">&times;</span>
-                </button>
-                <strong>注意!</strong> 这是一条消息通知 <a href="#">链接</a>
-            </div>
+<div class="header">
+    <div class="top-msg clearfix">
+        <div class="alert alert-warning mb-0 py-0" role="alert">
+            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
+                <span aria-hidden="true">&times;</span>
+            </button>
+            <strong>注意!</strong> 这是一条消息通知 <a href="#">链接</a>
         </div>
-        <nav class="navbar navbar-toggleable-lg navbar-light bg-faded p-0 justify-content-between">
-            <span class="header-logo px-2">Smartcost</span>
-            <div class="navbar-text pt-0">
-                <div class="dropdown d-inline-block">
-                    <button class="btn btn-link btn-sm dropdown-toggle" type="button" data-toggle="dropdown"><%- userAccount %></button>
-                    <div class="dropdown-menu dropdown-menu-right">
-                        <a class="dropdown-item" href="/user/info" target="_blank">账号资料</a>
-                        <a class="dropdown-item" href="user-buy.html" target="_blank">产品购买</a>
-                        <a class="dropdown-item" href="/user/preferences" target="_blank">偏好设置</a>
-                    </div>
+    </div>
+    <nav class="navbar navbar-toggleable-lg navbar-light bg-faded p-0 justify-content-between">
+        <span class="header-logo px-2">Smartcost</span>
+        <div class="navbar-text pt-0">
+            <div class="dropdown d-inline-block">
+                <button class="btn btn-link btn-sm dropdown-toggle" type="button" data-toggle="dropdown"><%- userAccount %></button>
+                <div class="dropdown-menu dropdown-menu-right">
+                    <a class="dropdown-item" href="/user/info" target="_blank">账号资料</a>
+                    <a class="dropdown-item" href="user-buy.html" target="_blank">产品购买</a>
+                    <a class="dropdown-item" href="/user/preferences" target="_blank">偏好设置</a>
                 </div>
-                <span class="btn btn-link btn-sm new-msg">
+            </div>
+            <span class="btn btn-link btn-sm new-msg">
                     <i class="fa fa-envelope-o" aria-hidden="true"></i>&nbsp;2
                 </span>
                 <a href="/logout" class="btn btn-link btn-sm">注销</a>
@@ -118,473 +118,501 @@
                     </div>
                 </div>
                 <div class="col-lg-10">
-                    <div class="toolsbar">
-                        <div class="tools-btn btn-group align-top">
-                            <a href="javascript:void(0);" class="btn btn-sm" id="addProjBtn">新建工程</a>
-                            <a href="javascript:void(0);" class="btn btn-sm" id="addFolderBtn"><i class="fa fa-folder-o"></i>&nbsp;新建文件夹</a>
-                            <a href="javascript:void(0);" class="btn btn-sm" id="renameBtn">重命名</a>
-                            <a href="javascript:void(0);" class="btn btn-sm" id="delBtn">删除</a>
-                            <a href="javascript:void(0);" class="btn btn-sm" id="movetoBtn">移动到...</a>
-                            <a href="javascript:void(0);" class="btn btn-sm" id="copytoBtn">复制到...</a>
-                            <a href="" class="btn btn-sm" id="shareBtn">共享</a>
-                            <a href="" class="btn btn-sm" id="cooperateBtn">协同</a>
-                        </div>
-                    </div>
-                    <div class="poj-list">
-                        <legend>全部</legend>
-                        <table class="table table-hover table-sm" id="ProjTree">
-                            <thead>
-                                <tr>
-                                    <th width="40"></th>
-                                    <th width="78%">工程列表</th>
-                                    <th width="10%">最近使用</th>
-                                    <th width="10%">创建日期</th>
-                                </tr>
-                            </thead>
-                            <tbody>
-                                <tr>
-                                    <td></td>
-                                    <td class="in-1"><a href="#" class="tree-open" title="收起"><i class="fa fa-minus-square-o mr-1"></i></a><i class="fa fa-folder-open-o"></i>&nbsp;XX项目文件夹</td>
-                                    <td></td>
-                                    <td></td>
-                                </tr>
-                                  <tr>
-                                      <td></td>
-                                      <td class="in-2"><a href="#" class="tree-open" title="收起"><i class="fa fa-minus-square-o mr-1"></i></a><i class="fa fa-folder-open-o"></i>&nbsp;XX项目文件夹</td>
-                                      <td></td>
-                                      <td></td>
-                                  </tr>
-                                <tr>
-                                    <td></td>
-                                    <td class="in-3"><a href="#" class="tree-open" title="收起"><i class="fa fa-minus-square-o mr-1"></i></a><i class="fa fa-folder-open-o"></i>&nbsp;XX项目文件夹</td>
-                                    <td></td>
-                                    <td></td>
-                                </tr>
-                                <tr>
-                                    <td></td>
-                                    <td class="in-4"><a href="#" class="tree-open" title="收起"><i class="fa fa-minus-square-o mr-1"></i></a><i class="fa fa-folder-open-o"></i>&nbsp;<a href="#">某某某某工厂工厂某某工厂建设某某工厂建设</a></td>
-                                    <td></td>
-                                    <td></td>
-                                </tr>
-                                <tr>
-                                    <td></td>
-                                    <td class="in-5"><a href="#" class="tree-open" title="收起"><i class="fa fa-minus-square-o mr-1"></i></a><i class="fa fa-folder-open-o"></i>&nbsp;<a href="#" class="open-sidebar">左1号生产车间(click)</a></td>
-                                    <td></td>
-                                    <td></td>
-                                </tr>
-                                <tr>
-                                    <td><i class="fa fa-sort" data-toggle="tooltip" data-placement="top" title="长安拖动"></i></td>
-                                    <td class="in-6"><span class="in-3 poj-icon">└</span><a href="zaojiashu.html">建筑工程(click)</a></td>
-                                    <td>2016-01-01</td>
-                                    <td>2016-01-01</td>
-                                </tr>
-                                <tr>
-                                    <td></td>
-                                    <td class="in-6"><span class="in-3 poj-icon">└</span><a href="#">机械设备安装工程</a></td>
-                                    <td>2016-01-01</td>
-                                    <td>2016-01-01</td>
-                                </tr>
-                                <tr>
-                                    <td></td>
-                                    <td class="in-5"><a href="#" class="tree-close" title="展开"><i class="fa fa-plus-square-o  mr-1"></i></a><i class="fa fa-folder-o"></i>&nbsp;<a href="#">2号生产车间</a></td>
-                                    <td>......</td>
-                                    <td>......</td>
-                                </tr>
-                            </tbody>
-                        </table>
+                <div class="toolsbar">
+                    <div class="tools-btn btn-group align-top">
+                        <a href="javascript:void(0);" class="btn btn-sm" id="add-project-btn">新建 <i class="fa fa-cubes"></i> 建设项目</a>
+                        <a href="javascript:void(0);" class="btn btn-sm" id="add-engineering-btn">新建 <i class="fa fa-cube"></i> 单项工程</a>
+                        <a href="javascript:void(0);" class="btn btn-sm" id="add-tender-btn">新建 <i class="fa fa-sticky-note-o"></i> 单位工程</a>
+                        <a href="javascript:void(0);" class="btn btn-sm" id="add-folder-btn"><i class="fa fa-folder-o"></i>&nbsp;新建文件夹</a>
+                        <a href="javascript:void(0);" class="btn btn-sm" id="rename-btn">重命名</a>
+                        <a href="javascript:void(0);" class="btn btn-sm" id="del-btn">删除</a>
+                        <a href="javascript:void(0);" class="btn btn-sm" id="move-to-btn">移动到...</a>
+                        <a href="javascript:void(0);" class="btn btn-sm" id="copy-to-btn">复制到...</a>
+                        <a href="" class="btn btn-sm" id="share-btn">共享</a>
+                        <a href="" class="btn btn-sm" id="cooperate-btn">协同</a>
                     </div>
                 </div>
-            </div>
-        </div>
-        <div class="slide-sidebar">
-            <div class="side-content">
-                <div class="p-3">
-                    <legend>1号生产车间 汇总</legend>
-                    <table class="table table-bordered table-hover table-sm">
+                <div class="poj-list">
+                    <legend>全部</legend>
+                    <table class="table table-hover table-sm" id="ProjTree">
                         <thead>
-                            <tr>
-                                <th rowspan="2"></th>
-                                <th rowspan="2">序号</th>
-                                <th rowspan="2">名称</th>
-                                <th rowspan="2">金额</th>
-                                <th colspan="6">其中</th>
-                                <th rowspan="2">占造价比例(%)</th>
-                                <th rowspan="2">建筑面积</th>
-                                <th rowspan="2">单方造价</th>
-                            </tr>
-                            <tr>
-                                <th>分部分项合计</th>
-                                <th>措施项目合计</th>
-                                <th>其他项目合计</th>
-                                <th>安全文明施工费</th>
-                                <th>规费</th>
-                                <th>税金</th>
-                            </tr>
+                        <tr>
+                            <th width="40"></th>
+                            <th width="78%">工程列表</th>
+                            <th width="10%">最近使用</th>
+                            <th width="10%">创建日期</th>
+                        </tr>
                         </thead>
                         <tbody>
-                            <tr>
-                                <td>1</td>
-                                <td>一</td>
-                                <td>建筑工程</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                            </tr>
-                            <tr>
-                                <td>2</td>
-                                <td>二</td>
-                                <td>建筑工程</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                            </tr>
-                            <tr>
-                                <td>3</td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                            </tr>
-                            <tr>
-                                <td>4</td>
-                                <td>一</td>
-                                <td>合计</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td>0</td>
-                                <td> </td>
-                                <td> </td>
-                                <td> </td>
-                            </tr>
                         </tbody>
                     </table>
                 </div>
             </div>
         </div>
     </div>
-    <!--弹出新建工程-->
-    <div class="modal fade" id="addProj" data-backdrop="static">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                  <h5 class="modal-title">新建工程</h5>
-                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-                        <span aria-hidden="true">&times;</span>
-                    </button>
-                </div>
-                <div class="modal-body">
-                    <form>
-                        <div class="collapse" id="moreinfo">
-                            <div class="form-group">
-                                <label>建设项目</label>
-                                <input type="text" class="form-control" placeholder="输入建设项目名称" id='buildName'>
-                            </div>
-                            <div class="form-group">
-                                <label>单项工程</label>
-                                <input type="text" class="form-control" placeholder="输入单项工程名称" id="xiangName">
-                            </div>
-                        </div>
-                        <div class="form-group">
-                            <label>单位工程</label>
-                            <input type="text" class="form-control" placeholder="输入单位工程名称" id="tenderName">
-                        </div>
-                        <div class="form-group" >
-                            <label class="custom-control custom-checkbox" id="isAddFolder">
-                                <input type="checkbox" class="custom-control-input">
-                                <span class="custom-control-indicator" ></span>
-                                <span class="custom-control-description">建立 <b>建设项目</b> 和 <b>单项工程</b> 文件夹</span>
+    <div class="slide-sidebar">
+        <div class="side-content">
+            <div class="p-3">
+                <legend>1号生产车间 汇总</legend>
+                <table class="table table-bordered table-hover table-sm">
+                    <thead>
+                    <tr>
+                        <th rowspan="2"></th>
+                        <th rowspan="2">序号</th>
+                        <th rowspan="2">名称</th>
+                        <th rowspan="2">金额</th>
+                        <th colspan="6">其中</th>
+                        <th rowspan="2">占造价比例(%)</th>
+                        <th rowspan="2">建筑面积</th>
+                        <th rowspan="2">单方造价</th>
+                    </tr>
+                    <tr>
+                        <th>分部分项合计</th>
+                        <th>措施项目合计</th>
+                        <th>其他项目合计</th>
+                        <th>安全文明施工费</th>
+                        <th>规费</th>
+                        <th>税金</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <tr>
+                        <td>1</td>
+                        <td>一</td>
+                        <td>建筑工程</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                    </tr>
+                    <tr>
+                        <td>2</td>
+                        <td>二</td>
+                        <td>建筑工程</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                    </tr>
+                    <tr>
+                        <td>3</td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                    </tr>
+                    <tr>
+                        <td>4</td>
+                        <td>一</td>
+                        <td>合计</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td>0</td>
+                        <td> </td>
+                        <td> </td>
+                        <td> </td>
+                    </tr>
+                    </tbody>
+                </table>
+            </div>
+        </div>
+    </div>
+</div>
+<!--弹出新建建设项目-->
+<div class="modal fade" id="add-project-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">新建 <i class="fa fa-cubes"></i> 建设项目</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <!--没有点击任何节点-->
+                <form>
+                    <div class="form-group">
+                        <label>建设项目</label>
+                        <input type="text" class="form-control" placeholder="输入建设项目名称" id="project-name">
+                    </div>
+                    <div class="form-group">
+                        <label>计价方式</label>
+                        <div>
+                            <label class="custom-control custom-radio">
+                                <input name="valuation_type" type="radio" class="custom-control-input" value="bill">
+                                <span class="custom-control-indicator"></span>
+                                <span class="custom-control-description">清单计价</span>
+                            </label>
+                            <label class="custom-control custom-radio">
+                                <input name="valuation_type" type="radio" class="custom-control-input" value="ration">
+                                <span class="custom-control-indicator"></span>
+                                <span class="custom-control-description">定额计价</span>
                             </label>
                         </div>
-                        <div class="form-group">
-                            <label>计价方式</label>
-                            <div>
-                                <label class="custom-control custom-radio">
-                                    <input id="radio1" name="radio" type="radio" class="custom-control-input">
-                                    <span class="custom-control-indicator"></span>
-                                    <span class="custom-control-description">清单计价</span>
-                                </label>
-                                <label class="custom-control custom-radio">
-                                    <input id="radio2" name="radio" type="radio" class="custom-control-input">
-                                    <span class="custom-control-indicator"></span>
-                                    <span class="custom-control-description">定额计价</span>
-                                </label>
-                            </div>
-                        </div>
-                    </form>
-                </div>
-                <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="javacript:void(0);" class="btn btn-primary" id='addProjOk'>确定</a>
-                </div>
+                    </div>
+                    <div class="form-group">
+                        <label>计价规则</label>
+                        <select class="form-control" id="valuation"><option value="">请选择计划规则</option></select>
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javacript:void(0);" class="btn btn-primary" id='addProjOk'>确定</a>
             </div>
         </div>
     </div>
-    <!--弹出新建文件夹-->
-    <div class="modal fade" id="addFolder" data-backdrop="static">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                  <h5 class="modal-title">新建文件夹</h5>
-                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-                      <span aria-hidden="true">&times;</span>
-                  </button>
-                </div>
-                <div class="modal-body">
-                    <form>
-                        <div class="form-group">
-                            <label>文件夹</label>
-                            <input type="text" class="form-control" placeholder="输入文件夹名称" id="folder-name-input">
-                            <span class="form-text text-muted">Smartcost为你提供了灵活的工程管理功能,如:</span>
-                            <span class="form-text text-muted">当你想汇总多个 <b>单位工程</b> 时,只需把它们都放在一个文件夹即可。</span>
-                        </div>
-                    </form>
-                </div>
-                <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="javacript:void(0);" class="btn btn-primary" id="addFolderOk">确定</a>
-                </div>
+</div>
+<!--弹出新建单项工程-->
+<div class="modal fade" id="add-engineering-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">新建 <i class="fa fa-cube"></i> 单项工程</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <!--没有点击任何节点-->
+                <form>
+                    <div class="form-group">
+                        <label>单项工程</label>
+                        <input type="text" class="form-control" placeholder="输入单项工程名称" id="engineering-name">
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javascript:void(0);" class="btn btn-primary" id="add-engineering-confirm">确定</a>
             </div>
         </div>
     </div>
-    <!--弹出重命名-->
-    <div class="modal fade" id="rename" data-backdrop="static">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                    <h5 class="modal-title">重命名</h5>
-                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-                        <span aria-hidden="true">&times;</span>
-                    </button>
-                </div>
-                <div class="modal-body">
-                    <form>
-                        <div class="form-group">
-                            <input type="text" class="form-control" placeholder="输入名称" id="newName">
+</div>
+<!--弹出新建单位工程-->
+<div class="modal fade" id="add-tender-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">新建 <i class="fa fa-sticky-note-o"></i> 单位工程</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <!--没有点击任何节点-->
+                <form>
+                    <div class="form-group">
+                        <label>单位工程</label>
+                        <input type="text" class="form-control" placeholder="输入单位工程名称" id="tender-name">
+                    </div>
+                    <div class="form-group">
+                        <label>单价文件</label>
+                        <select class="form-control"><option>新建单价文件</option></select>
+                    </div>
+                    <div class="form-group">
+                        <label>费率文件</label>
+                        <select class="form-control"><option>新建费率文件</option></select>
+                    </div>
+                    <div class="form-group">
+                        <label>计价方式</label>
+                        <div>
+                            <label class="custom-control custom-radio">
+                                <input name="tender_valuation_type" type="radio" class="custom-control-input" value="bill" checked="checked">
+                                <span class="custom-control-indicator"></span>
+                                <span class="custom-control-description">清单计价</span>
+                            </label>
+                            <label class="custom-control custom-radio">
+                                <input name="tender_valuation_type" type="radio" class="custom-control-input" value="ration" disabled="disabled">
+                                <span class="custom-control-indicator"></span>
+                                <span class="custom-control-description">定额计价</span>
+                            </label>
                         </div>
-                    </form>
-                </div>
-                <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="javascript:void(0);" class="btn btn-primary" id="renameOk">确定</a>
-                </div>
+                    </div>
+                    <div class="form-group">
+                        <label>计价规则</label>
+                        <select class="form-control" id="tender-valuation" disabled><option>重庆[2008]调整人工单价</option></select>
+                    </div>
+                    <div class="form-group">
+                        <label>工程专业</label>
+                        <select class="form-control"><option>建筑工程</option></select>
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javascript:void(0);" class="btn btn-primary" id="add-tender-confirm">确定</a>
             </div>
         </div>
     </div>
-    <!--弹出删除-->
-    <div class="modal fade" id="del" data-backdrop="static">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                    <h5 class="modal-title">删除确认</h5>
-                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-                        <span aria-hidden="true">&times;</span>
-                    </button>
-                </div>
-                <div class="modal-body">
-                    <h5 class="text-danger" id="tenderHint">删除 "建筑工程" ?</h5>
-                    <h5 class="text-danger" id="folderHint">删除 "XX项目文件夹" 以及它包含的子项?</h5>
-                    <p class="" id = 'restoreHint'>删除后,你可以在回收站找到它。</p>
-                </div>
-                <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="javacript:void(0);" class="btn btn-danger" id="deleteProjOk">删除</a>
-                </div>
+</div>
+<!--弹出新建文件夹-->
+<div class="modal fade" id="add-folder-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">新建文件夹</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <form>
+                    <div class="form-group">
+                        <label>文件夹</label>
+                        <input type="text" class="form-control" placeholder="输入文件夹名称" id="folder-name">
+                        <span class="form-text text-muted">Smartcost目前最多支持3层文件夹。</span>
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javascript:void(0);" class="btn btn-primary" id="add-folder-confirm">确定</a>
             </div>
         </div>
     </div>
-    <!--弹出移动到-->
-    <div class="modal fade" id="moveto" data-backdrop="static">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                  <h5 class="modal-title">移动到...</h5>
-                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+</div>
+<!--弹出重命名-->
+<div class="modal fade" id="rename-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">重命名</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
-                  </button>
-                </div>
-                <div class="modal-body">
-                  <ul id="treeDemo" class="ztree"></ul>
-                </div>
-                <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="javacript:void(0);" class="btn btn-primary" id="movetoOk">确定</a>
-                </div>
+                </button>
+            </div>
+            <div class="modal-body">
+                <form>
+                    <div class="form-group">
+                        <input type="text" class="form-control" placeholder="输入名称" id="rename-name">
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javascript:void(0);" class="btn btn-primary" id="rename-confirm">确定</a>
             </div>
         </div>
     </div>
-    <!--弹出复制到-->
-    <div class="modal fade" id="copyto" data-backdrop="static">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content">
-                <div class="modal-header">
-                    <h5 class="modal-title">复制到...</h5>
-                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-                        <span aria-hidden="true">&times;</span>
-                    </button>
-                </div>
-                <div class="modal-body">
-                    <ul id="treeDemo2" class="ztree"></ul>
-                </div>
-                <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="javacript:void(0);" class="btn btn-primary" id="copytoOk">确定</a>
-                </div>
+</div>
+<!--弹出删除-->
+<div class="modal fade" id="del" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">删除确认</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <h5 class="text-danger" id="tenderHint">删除 "建筑工程" ?</h5>
+                <h5 class="text-danger" id="folderHint">删除 "XX项目文件夹" 以及它包含的子项?</h5>
+                <p class="" id = 'restoreHint'>删除后,你可以在回收站找到它。</p>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javascript:void(0);" class="btn btn-danger" id="delete-confirm">删除</a>
+            </div>
+        </div>
+    </div>
+</div>
+<!--弹出移动到-->
+<div class="modal fade" id="move-to-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">移动到...</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <ul id="treeDemo" class="ztree"></ul>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javacript:void(0);" class="btn btn-primary" id="move-to-confirm">确定</a>
             </div>
         </div>
     </div>
-    <!-- JS. -->
-    <script src="/lib/jquery/jquery.min.js"></script>
-    <script src="/lib/tether/tether.min.js"></script>
-    <script src="/lib/bootstrap/bootstrap.min.js"></script>
-    <script src="/web/building_saas/js/global.js"></script>
-    <script src="/public/web/date_util.js"></script>
-    <script src="/public/web/tree_table/tree_table.js"></script>
-    <script type="text/javascript" src="/public/web/common_ajax.js"></script>
-    <script src="/web/building_saas/pm/js/pm_ajax.js"></script>
-    <script src="/web/building_saas/pm/js/pm_main.js" charset="UTF-8"></script>
-    <!-- zTree -->
-  	<script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
-  	<script type="text/javascript" src="/lib/ztree/jquery.ztree.excheck.js"></script>
-    <SCRIPT type="text/javascript">
-  		<!--
-  		var setting = {	};
+</div>
+<!--弹出复制到-->
+<div class="modal fade" id="copy-to-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">复制到...</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <ul id="treeDemo2" class="ztree"></ul>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javacript:void(0);" class="btn btn-primary" id="copy-to-confirm">确定</a>
+            </div>
+        </div>
+    </div>
+</div>
+<!-- JS. -->
+<script src="/lib/jquery/jquery.min.js"></script>
+<script src="/lib/tether/tether.min.js"></script>
+<script src="/lib/bootstrap/bootstrap.min.js"></script>
+<script src="/web/building_saas/js/global.js"></script>
+<script src="/public/web/date_util.js"></script>
+<script src="/public/web/tree_table/tree_table.js"></script>
+<script type="text/javascript" src="/public/web/common_ajax.js"></script>
+<script src="/web/building_saas/pm/js/pm_ajax.js"></script>
+<script src="/web/building_saas/pm/js/pm_main.js" charset="UTF-8"></script>
+<!-- zTree -->
+<script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
+<script type="text/javascript" src="/lib/ztree/jquery.ztree.excheck.js"></script>
+<SCRIPT type="text/javascript">
+    <!--
+    var setting = {	};
 
-  		var zNodes =[
-  			{ name:"父节点1 - 展开", open:true,
-  				children: [
-  					{ name:"父节点11 - 折叠",
-  						children: [
-  							{ name:"叶子节点111"},
-  							{ name:"叶子节点112"},
-  							{ name:"叶子节点113"},
-  							{ name:"叶子节点114"}
-  						]},
-  					{ name:"父节点12 - 折叠",
-  						children: [
-  							{ name:"叶子节点121"},
-  							{ name:"叶子节点122"},
-  							{ name:"叶子节点123"},
-  							{ name:"叶子节点124"}
-  						]},
-  					{ name:"父节点13 - 没有子节点", isParent:true}
-  				]},
-  			{ name:"父节点2 - 折叠",
-  				children: [
-  					{ name:"父节点21 - 展开", open:true,
-  						children: [
-  							{ name:"叶子节点211"},
-  							{ name:"叶子节点212"},
-  							{ name:"叶子节点213"},
-  							{ name:"叶子节点214"}
-  						]},
-  					{ name:"父节点22 - 折叠",
-  						children: [
-  							{ name:"叶子节点221"},
-  							{ name:"叶子节点222"},
-  							{ name:"叶子节点223"},
-  							{ name:"叶子节点224"}
-  						]},
-  					{ name:"父节点23 - 折叠",
-  						children: [
-  							{ name:"叶子节点231"},
-  							{ name:"叶子节点232"},
-  							{ name:"叶子节点233"},
-  							{ name:"叶子节点234"}
-  						]}
-  				]},
-  			{ name:"父节点3 - 没有子节点", isParent:true}
+    var zNodes =[
+        { name:"父节点1 - 展开", open:true,
+            children: [
+                { name:"父节点11 - 折叠",
+                    children: [
+                        { name:"叶子节点111"},
+                        { name:"叶子节点112"},
+                        { name:"叶子节点113"},
+                        { name:"叶子节点114"}
+                    ]},
+                { name:"父节点12 - 折叠",
+                    children: [
+                        { name:"叶子节点121"},
+                        { name:"叶子节点122"},
+                        { name:"叶子节点123"},
+                        { name:"叶子节点124"}
+                    ]},
+                { name:"父节点13 - 没有子节点", isParent:true}
+            ]},
+        { name:"父节点2 - 折叠",
+            children: [
+                { name:"父节点21 - 展开", open:true,
+                    children: [
+                        { name:"叶子节点211"},
+                        { name:"叶子节点212"},
+                        { name:"叶子节点213"},
+                        { name:"叶子节点214"}
+                    ]},
+                { name:"父节点22 - 折叠",
+                    children: [
+                        { name:"叶子节点221"},
+                        { name:"叶子节点222"},
+                        { name:"叶子节点223"},
+                        { name:"叶子节点224"}
+                    ]},
+                { name:"父节点23 - 折叠",
+                    children: [
+                        { name:"叶子节点231"},
+                        { name:"叶子节点232"},
+                        { name:"叶子节点233"},
+                        { name:"叶子节点234"}
+                    ]}
+            ]},
+        { name:"父节点3 - 没有子节点", isParent:true}
 
-  		];
+    ];
 
-  		$(document).ready(function(){
-  			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
-  		});
-  		//-->
-  	</SCRIPT>
-    <SCRIPT type="text/javascript">
-  		<!--
-  		var setting = {	};
+    $(document).ready(function(){
+        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
+    });
+    //-->
+</SCRIPT>
+<SCRIPT type="text/javascript">
+    <!--
+    var setting = {	};
 
-  		var zNodes =[
-  			{ name:"父节点1 - 展开", open:true,
-  				children: [
-  					{ name:"父节点11 - 折叠",
-  						children: [
-  							{ name:"叶子节点111"},
-  							{ name:"叶子节点112"},
-  							{ name:"叶子节点113"},
-  							{ name:"叶子节点114"}
-  						]},
-  					{ name:"父节点12 - 折叠",
-  						children: [
-  							{ name:"叶子节点121"},
-  							{ name:"叶子节点122"},
-  							{ name:"叶子节点123"},
-  							{ name:"叶子节点124"}
-  						]},
-  					{ name:"父节点13 - 没有子节点", isParent:true}
-  				]},
-  			{ name:"父节点2 - 折叠",
-  				children: [
-  					{ name:"父节点21 - 展开", open:true,
-  						children: [
-  							{ name:"叶子节点211"},
-  							{ name:"叶子节点212"},
-  							{ name:"叶子节点213"},
-  							{ name:"叶子节点214"}
-  						]},
-  					{ name:"父节点22 - 折叠",
-  						children: [
-  							{ name:"叶子节点221"},
-  							{ name:"叶子节点222"},
-  							{ name:"叶子节点223"},
-  							{ name:"叶子节点224"}
-  						]},
-  					{ name:"父节点23 - 折叠",
-  						children: [
-  							{ name:"叶子节点231"},
-  							{ name:"叶子节点232"},
-  							{ name:"叶子节点233"},
-  							{ name:"叶子节点234"}
-  						]}
-  				]},
-  			{ name:"父节点3 - 没有子节点", isParent:true}
+    var zNodes =[
+        { name:"父节点1 - 展开", open:true,
+            children: [
+                { name:"父节点11 - 折叠",
+                    children: [
+                        { name:"叶子节点111"},
+                        { name:"叶子节点112"},
+                        { name:"叶子节点113"},
+                        { name:"叶子节点114"}
+                    ]},
+                { name:"父节点12 - 折叠",
+                    children: [
+                        { name:"叶子节点121"},
+                        { name:"叶子节点122"},
+                        { name:"叶子节点123"},
+                        { name:"叶子节点124"}
+                    ]},
+                { name:"父节点13 - 没有子节点", isParent:true}
+            ]},
+        { name:"父节点2 - 折叠",
+            children: [
+                { name:"父节点21 - 展开", open:true,
+                    children: [
+                        { name:"叶子节点211"},
+                        { name:"叶子节点212"},
+                        { name:"叶子节点213"},
+                        { name:"叶子节点214"}
+                    ]},
+                { name:"父节点22 - 折叠",
+                    children: [
+                        { name:"叶子节点221"},
+                        { name:"叶子节点222"},
+                        { name:"叶子节点223"},
+                        { name:"叶子节点224"}
+                    ]},
+                { name:"父节点23 - 折叠",
+                    children: [
+                        { name:"叶子节点231"},
+                        { name:"叶子节点232"},
+                        { name:"叶子节点233"},
+                        { name:"叶子节点234"}
+                    ]}
+            ]},
+        { name:"父节点3 - 没有子节点", isParent:true}
 
-  		];
+    ];
 
-  		$(document).ready(function(){
-  			$.fn.zTree.init($("#treeDemo2"), setting, zNodes);
-  		});
-  		//-->
-  	</SCRIPT>
+    $(document).ready(function(){
+        $.fn.zTree.init($("#treeDemo2"), setting, zNodes);
+    });
+    //-->
+</SCRIPT>
 </body>
 <script type="text/javascript">
     autoFlashHeight();
 </script>
+<script type="text/javascript">
+    let billValuation = '<%- billValuation %>';
+    let rationValuation = '<%- rationValuation %>';
+</script>
 </html>

文件差异内容过多而无法显示
+ 706 - 467
web/building_saas/pm/js/pm_main.js


+ 629 - 0
web/building_saas/pm/js/pm_main_bak.js

@@ -0,0 +1,629 @@
+/**
+ * Created by Mai on 2017/2/24.
+ */
+
+var Tree = null, movetoZTree = null, copytoZTree = null;
+var ProjTreeSetting = {
+    tree: {
+        id: 'ID',
+        pid: 'ParentID',
+        nid: 'NextSiblingID',
+        btnColumn: 1,
+        nullId: -1
+    },
+    columns: [
+        {
+            head: '',
+            data: '',
+            width: '40',
+            event: {}
+        },
+        {
+            head: '工程列表',
+            data: 'name',
+            width: '78%',
+            event: {
+                getText: function (html, node, text) {
+                    html.push((node && node.data && node.data.projType === 'Folder') ? '&nbsp;' : '');
+                    html.push('<a ');
+                    if (node && node.data && node.data.projType === 'Tender') {
+                        //html.push('href="/main?project=', node.id(), '"');
+                        html.push('href="javacript:void(0);"');
+                    }
+                    html.push('>', text, '<a>');
+                },
+                getIcon: function (html, node) {
+                    if (node.data.projType === 'Folder') {
+                        html.push('<i class ="tree-icon fa fa-folder-open-o"></i>');
+                    } else {
+                        html.push('<span class="poj-icon">└</span>');
+                    }
+                },
+                tdBindEvent: function (td, node) {
+                    if (node.data.projType === 'Tender') {
+                        $('a:eq(1)', td).bind('click', function () {
+                            BeforeOpenProject(node.id(), {'fullFolder': GetFullFolder(node.parent)}, function () {
+                                window.location.href = '/main?project=' + node.id();
+                            });
+                            return false;
+                        });
+                    }
+                }
+            }
+        },
+        {
+            head: '最近使用',
+            data: 'lastDateTime',
+            width: '10%',
+            event: {
+                getText: function (html, node, text) {
+                    if (node.data.projType === 'Tender') {
+                        html.push(text ? new Date(text).Format('yyyy-MM-dd') : '');
+                    }
+                }
+            }
+        },
+        {
+            head: '创建日期',
+            data: 'createDateTime',
+            width: '10%',
+            event: {
+                getText: function (html, node, text) {
+                    if (node.data.projType === 'Tender') {
+                        html.push(text ? new Date(text).Format('yyyy-MM-dd') : '');
+                    }
+                }
+            }
+        }
+    ],
+    viewEvent: {
+        beforeSelect: function (node) {
+            if (node && node.row) {
+                $('td:eq(0)', node.row).children().remove();
+            }
+        },
+        onSelectNode: function (node) {
+            // 新建文件夹 是否可见
+            if (node.data.projType === 'Tender') {
+                $('#addFolderBtn').hide();
+            } else {
+                $('#addFolderBtn').show();
+            }
+            // 重命名可见
+            $('#renameBtn').show();
+            // 删除可见
+            $('#delBtn').show();
+            // 移动到、复制到、共享、协同 是否可见
+            if (node.data.projType === 'Tender') {
+                $('#movetoBtn').show();
+                $('#copytoBtn').show();
+                $('#shareBtn').show();
+                $('#cooperateBtn').show();
+            } else {
+                $('#movetoBtn').hide();
+                $('#copytoBtn').hide();
+                $('#shareBtn').hide();
+                $('#cooperateBtn').hide();
+            }
+            $('td:eq(0)', node.row).append($('<i class="fa fa-sort" data-toggle="tooltip" data-placement="top" title="长安拖动"></i>'));
+        }
+    }
+}
+// 从服务器拉取数据
+var LoadProjTree = function () {
+    var table = $('#ProjTree');
+    $('thead', table).remove();
+    $('tbody', table).remove();
+    GetAllProjectData(function (data) {
+        Tree = $.fn.treeTable.init(table, ProjTreeSetting, data);
+    });
+};
+
+var GetNeedUpdatePreNode = function (parent, next) {
+    if (next) {
+        return next.preSibling();
+    } else if (parent) {
+        return parent.firstChild();
+    } else {
+        return null;
+    }
+    /*if (parent && parent.id() !== -1) {
+        if (next && next.preSibling()) {
+            return next.preSibling();
+        } else {
+            return parent.lastChild();
+        }
+    } else {
+        return null;
+    }*/
+};
+var GetPreNodeUpdateData = function (pre, nid) {
+    var data = {};
+    data['updateType'] = 'update';
+    data['updateData'] = {};
+    data.updateData[Tree.setting.tree.id] = pre.id();
+    data.updateData[Tree.setting.tree.id] = nid;
+    return data;
+}
+// 获取新建项目数据
+var GetAddProjUpdateData = function (parent, next, name, newId) {
+    var datas = [], updateData, pre;
+    updateData = {};
+    updateData['updateType'] = 'new';
+    updateData['updateData'] = {};
+    updateData['updateData'][Tree.setting.tree.id] = newId;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
+    updateData['updateData']['name'] = name;
+    updateData['updateData']['projType'] = 'Tender';
+    datas.push(updateData);
+    return datas;
+};
+var GetAddFolderProjUpdateData = function (parent, next, folderName1, folderName2, name, newId) {
+    var datas = [], updateData, folderData1, folderData2, pre;
+    var addUpdateData = function (parentId, nextId, name, projType) {
+        var data = {};
+        data['updateType'] = 'new';
+        data['updateData'] = {};
+        data['updateData'][Tree.setting.tree.id] = newId;
+        data['updateData'][Tree.setting.tree.pid] = parentId;
+        data['updateData'][Tree.setting.tree.nid] = nextId;
+        data['updateData']['name'] = name;
+        data['updateData']['projType'] = projType;
+        newId += 1;
+        datas.push(data);
+        return data;
+    }
+    folderData1 = addUpdateData(parent.id(), next ? next.id() : -1, folderName1, 'Folder');
+    folderData2 = addUpdateData(folderData1.updateData[Tree.setting.tree.id], -1, folderName2, 'Folder');
+    addUpdateData(folderData2.updateData[Tree.setting.tree.id], -1, name, 'Tender');
+    return datas;
+};
+// 获取新建文件夹数据
+var GetAddForlderUpdateData = function (parent, next, folderName, newId) {
+    var datas = [], updateData, pre;
+    updateData = {};
+    updateData['updateType'] = 'new';
+    updateData['updateData'] = {};
+    updateData['updateData'][Tree.setting.tree.id] = newId;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
+    updateData['updateData']['name'] = folderName;
+    updateData['updateData']['projType'] = 'Folder';
+    datas.push(updateData);
+
+    pre = GetNeedUpdatePreNode(parent, next);
+    if (pre) {
+        datas.push(GetPreNodeUpdateData(pre, newId));
+    }
+    return datas;
+};
+
+var GetNextChangeUpdateData = function (datas, node, next) {
+    var data = null;
+    if (node && node.id() !== -1) {
+        data = {};
+        data['updateType'] = 'update';
+        data['updateData'] = {};
+        data['updateData'][Tree.setting.tree.id] = node.id();
+        data['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
+        datas.push(data);
+    }
+    return data;
+}
+var GetFullFolder = function (node) {
+    var fullFolder = [],
+        cur = node;
+    while (cur && cur.data) {
+        fullFolder.unshift(cur.data.name);
+        cur = cur.parent;
+    }
+    return fullFolder;
+}
+var GetDeleteUpdateData = function (node) {
+    var datas = [], updateData,
+        pre = node.preSibling(),
+        deleteNodeData = function (node) {
+            var data = {};
+            data['updateType'] = 'delete';
+            data['updateData'] = {};
+            data['updateData'][Tree.setting.tree.id] = node.id();
+            if (node.data.projType === 'Tender') {
+                data['updateData']['FullFolder'] = GetFullFolder(node.parent);
+            }
+            return data;
+        },
+        addDeleteChildren = function (children) {
+            children.forEach(function(child){
+                datas.push(deleteNodeData(child));
+                addDeleteChildren(child.children);
+            });
+        };
+    if (pre && pre.id() !== -1) {
+        updateData = {};
+        updateData['updateType'] = 'update';
+        updateData['updateData'] = {};
+        updateData['updateData'][Tree.setting.tree.id] = pre.id();
+        updateData['updateData'][Tree.setting.tree.nid] = node ? node.nid() : -1;
+        datas.push(updateData);
+    }
+    datas.push(deleteNodeData(node));
+    addDeleteChildren(node.children);
+    return datas;
+};
+
+var GetMoveUpdateData = function (node, parent, next) {
+    var datas = [], updateData;
+    updateData = GetNextChangeUpdateData(datas, node.preSibling(), node.nextSibling);
+    if (next) {
+        updateData = GetNextChangeUpdateData(datas, next.preSibling(), node);
+    }
+    updateData = {};
+    updateData['updateType'] = 'update';
+    updateData['updateData'] = {};
+    updateData['updateData'][Tree.setting.tree.id] = node.id();
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
+    datas.push(updateData);
+    return datas;
+};
+
+var GetCopyUpdateData = function (node, parent, next, newId){
+    var datas = [], updateData, pre;
+    updateData = {};
+    updateData['updateType'] = 'copy';
+    updateData['srcProjectId'] = node.id();
+    updateData['updateData'] = {};
+    updateData['updateData'][Tree.setting.tree.id] = newId + 1;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
+    updateData['updateData']['name'] = node.data.name;
+    updateData['updateData']['projType'] = node.data.projType;
+    datas.push(updateData);
+
+    pre = GetNeedUpdatePreNode(parent, next);
+    if (pre) {
+        updateData = {};
+        updateData['updateType'] = 'update';
+        updateData['updateData'] = {};
+        updateData['updateData'][Tree.setting.tree.id] = pre.id();
+        updateData['updateData'][Tree.setting.tree.nid] = node.tree.maxNodeId() + 1;
+        datas.push(updateData);
+    }
+    return datas;
+}
+
+var ConvertTreeToZtree = function (Tree, zTreeObj, filterNode) {
+    var setting = {
+            data: {
+                simpleData: {
+                    enable:true,
+                    idKey: "id",
+                    pIdKey: "pId",
+                    rootPId: "-1"
+                }
+            }},
+        zTreeData = [],
+        exportNodesData = function (nodes) {
+            nodes.forEach(function (node) {
+                if (node !== filterNode) {
+                    var data = {};
+                    data['id'] = node.data[Tree.setting.tree.id];
+                    data['pId'] = node.pid();
+                    data['name'] = node.data['name'];
+                    data['isParent'] = node.data.projType === 'Folder';//(node.data.projType === 'Folder' && node.children.length === 0);
+                    data['open'] = node.data.projType === 'Folder';//node.children.length !== 0;
+                    zTreeData.push(data);
+                    exportNodesData(node.children);
+                }
+            })
+        };
+    exportNodesData(Tree._root.children);
+    return $.fn.zTree.init(zTreeObj, setting, zTreeData);
+};
+var GetTargetTreeNode = function (zTreeObj) {
+    var ztree_selected;
+    if (zTreeObj && Tree) {
+        ztree_selected = zTreeObj.getSelectedNodes().length === 0 ? null : zTreeObj.getSelectedNodes()[0];
+        return ztree_selected ? Tree.findNode(ztree_selected.id) : null;
+    } else {
+        return null;
+    }
+};
+
+var AddFolderChildValid = function (node) {
+    if (node.data.projType === 'Folder') {
+        if (node.children.length === 0) {
+            return true;
+        } else {
+            return (node.firstChild().data.projType === 'Folder');
+        }
+    } else {
+        return false;
+    }
+};
+var AddTenderChildValid = function (node) {
+    if (node.data.projType === 'Folder') {
+        if (node.children.length === 0) {
+            return true;
+        } else {
+            return (node.firstChild().data.projType === 'Tender');
+        }
+    } else {
+        return false;
+    }
+};
+
+LoadProjTree();
+$('#movetoBtn').hide();
+$('#copytoBtn').hide();
+$('#shareBtn').hide();
+$('#cooperateBtn').hide();
+
+// 新建文件夹
+$('#addFolderBtn').click(function () {
+    if (Tree) {
+        $('#addFolder').modal('show');
+    }
+});
+$('#addFolderOk').click(function () {
+    var form = $('#addFolder');
+    var name = $('#folder-name-input').val();
+    var parent, next;
+    if (name) {
+        if (Tree.selected()) {
+            if (Tree.selected().children.length === 0 || Tree.selected().firstChild().data.projType === 'Folder') {
+                parent = Tree.selected();
+                next = Tree.selected().firstChild();
+            } else {
+                parent = Tree.selected().parent;
+                next = Tree.selected().nextSibling;
+            }
+        } else {
+            parent = Tree._root;
+            next = Tree.firstNode();
+        }
+
+        CommonAjax.post('/pm/api/getNewProjectID', {count: 1}, function (IDs) {
+            var updateData = GetAddForlderUpdateData(parent, next, name, IDs.lowID);
+            Tree.maxNodeId(IDs.lowID - 1);
+            UpdateProjectData(updateData, function(datas){
+                datas.forEach(function (data) {
+                    if (data.updateType === 'new') {
+                        Tree.addNodeData(data.updateData, parent, next);
+                    }
+                });
+                form.modal('hide');
+            });
+        });
+    }
+});
+
+// 新建工程
+var AddProj = function () {
+    var name = $('#tenderName').val();
+    if (name !== '') {
+        // if (Tree.selected()){
+        //     if (Tree.selected().data.projType === 'Tender') {
+        //         parent = Tree.selected().parent;
+        //         next = Tree.selected().next;
+        //     } else {
+        //         if (Tree.selected().firstNode.data.projType === 'Tender') {
+        //             parent = Tree.selected();
+        //             next = Tree.selected().firstNode();
+        //         } else {
+        //             return;
+        //         }
+        //     }
+        // } else {
+        //     parent = Tree._root();
+        //     next = Tree.firstNode();
+        // }
+        CommonAjax.post('/pm/api/getNewProjectID', {count: 1}, function (IDs) {
+            var updateData = GetAddProjUpdateData(Tree._root, Tree.firstNode(), name, IDs.lowID);
+            Tree.maxNodeId(IDs.lowID - 1);
+            UpdateProjectData(updateData, function (datas) {
+                datas.forEach(function (data) {
+                    var parent, next;
+                    if (data.updateType === 'new') {
+                        parent = data.updateData.parentId === -1 ?  Tree._root : Tree.findNode(data.updateData.parentId);
+                        next = data.updateData.nextId === -1 ? null : Tree.findNode(data.updateData.nextId);
+                        Tree.addNodeData(data.updateData, parent, next);
+                    }
+                });
+                $('#addProj').modal('hide');
+            });
+        });
+    }
+}
+var AddFolderProj = function () {
+    var nameB = $('#buildName').val(), nameX = $('#xiangName').val(), name = $('#tenderName').val();
+    if (nameB !== '' && nameX !== '' && name !== '') {
+        CommonAjax.post('/pm/api/getNewProjectID', {count: 3}, function (IDs) {
+            var updateData = GetAddFolderProjUpdateData(Tree._root, Tree.firstNode(), nameB, nameX, name, IDs.lowID);
+            Tree.maxNodeId(IDs.lowID - 1);
+            UpdateProjectData(updateData, function (datas) {
+                datas.forEach(function (data) {
+                    var parent, next;
+                    if (data.updateType === 'new') {
+                        parent = data.updateData[Tree.setting.tree.pid] === -1 ?  Tree._root : Tree.findNode(data.updateData[Tree.setting.tree.pid]);
+                        next = data.updateData[Tree.setting.tree.nid] === -1 ? null : Tree.findNode(data.updateData[Tree.setting.tree.nid]);
+                        Tree.addNodeData(data.updateData, parent, next);
+                    }
+                });
+                $('#addProj').modal('hide');
+            });
+        });
+    }
+}
+$('#addProjBtn').click(function () {
+    if (Tree) {
+        $('#addProj').modal('show');
+    }
+});
+$('#addProjOk').click(function () {
+    var hasFolder = $('#isAddFolder>input').is(':checked');
+    if (hasFolder) {
+        AddFolderProj();
+    } else {
+        AddProj();
+    }
+});
+$('#isAddFolder').change(function () {
+    if ($('input',this).is(':checked')) {
+        $('#moreinfo').collapse('show');
+    } else {
+        $('#moreinfo').collapse('hide');
+    }
+});
+
+// 重命名
+$('#renameBtn').click(function() {
+    if (Tree && Tree.selected()) {
+        $('#rename').modal('show');
+    }
+})
+$('#rename').on('show.bs.modal', function () {
+    $('#newName').attr('placeholder', Tree.selected().data.name);
+});
+$('#renameOk').click(function () {
+    var select = Tree.selected(),
+        newName = $('#newName').val(),
+        form = $('#rename');
+    if (select && newName !== select.data.name) {
+        RenameProject(select.id(), newName, function () {
+            form.modal('hide');
+            select.data.name = newName;
+            Tree.refreshNodesDom([select]);
+        });
+    } else {
+        form.modal('hide');
+    }
+});
+
+// 删除
+$('#delBtn').click(function() {
+    if (Tree && Tree.selected()) {
+        $('#del').modal('show');
+    }
+});
+$('#del').on('show.bs.modal', function() {
+    var hasTenderChild = function (children) {
+        var i;
+        for (i = 0; i < children.length; i++) {
+            if (children[i].children.length === 0) {
+                if (children[i].data.projType === 'Tender') {
+                    return true;
+                }
+            } else if (hasTenderChild(children[i].children)) {
+                return true;
+            }
+        }
+        return false;
+    };
+    if (Tree.selected().children.length == 0) {
+        $('#tenderHint').show();
+        $('#tenderHint').text('删除 "' + Tree.selected().data.name +'" ?');
+        $('#folderHint').hide();
+    } else {
+        $('#tenderHint').hide();
+        $('#folderHint').show();
+        $('#folderHint').text('删除 "'+ Tree.selected().data.name +'" 以及它包含的子项?');
+    }
+    if (hasTenderChild([Tree.selected()])) {
+        $('#restoreHint').show();
+    } else {
+        $('#restoreHint').hide();
+    }
+});
+$('#deleteProjOk').click(function () {
+    var updateData, form = $('#del');
+    if (Tree) {
+        updateData = GetDeleteUpdateData(Tree.selected());
+        UpdateProjectData(updateData, function () {
+            form.modal('hide');
+            Tree.removeNode(Tree.selected());
+        });
+    }
+});
+
+// 移动至
+$('#movetoBtn').click(function () {
+    if (Tree && Tree.selected()) {
+        $('#moveto').modal('show');
+    }
+});
+$('#moveto').on('show.bs.modal', function () {
+    movetoZTree = ConvertTreeToZtree(Tree, $('#treeDemo'), Tree.selected());
+});
+$('#movetoOk').click(function () {
+    var updateData, form = $('#moveto'),
+        target = GetTargetTreeNode($.fn.zTree.getZTreeObj('treeDemo')),
+        parent, next, cur = Tree.selected();
+    if (target) {
+        if (target.data.projType === 'Tender') {
+            parent = target.parent;
+            next = target.nextSibling;
+        } else {
+            parent = target;
+            next = target.firstChild();
+        }
+
+        if (parent !== cur.parent || (next !== cur && next !== cur.nextSibling)){
+            updateData = GetMoveUpdateData(Tree.selected(), parent, next);
+            UpdateProjectData(updateData, function (data) {
+                form.modal('hide');
+                Tree.move(Tree.selected(), parent, next);
+            });
+        } else {
+            form.modal('hide');
+        }
+    } else {
+        form.modal('hide');
+    }
+})
+
+// 复制到
+$('#copytoBtn').click(function () {
+    if (Tree && Tree.selected()) {
+        $('#copyto').modal('show');
+    }
+});
+$('#copyto').on('show.bs.modal', function () {
+    copytoZTree = ConvertTreeToZtree(Tree, $('#treeDemo2'));
+});
+$('#copytoOk').click(function() {
+    var form = $('#copyto'),
+        target = GetTargetTreeNode($.fn.zTree.getZTreeObj('treeDemo2')),
+        parent, next, cur = Tree.selected();
+    if (target && (target.data.projType === 'Tender' || target.children.length === 0 || target.firstChild().data.projType === 'Tender')) {
+        if (target.data.projType === 'Tender') {
+            parent = target.parent;
+            next = target.nextSibling;
+        } else {
+            parent = target;
+            next = target.firstChild();
+        }
+
+        if (parent !== cur.parent || (next !== cur && next !== cur.nextSibling)){
+            CommonAjax.post('/pm/api/getNewProjectID', {count: 1}, function (IDs) {
+                var updateData = GetCopyUpdateData(cur, parent, next, IDs.lowID);
+                Tree.maxNodeId(IDs.lowID - 1);
+                CommonAjax.post('/pm/api/copyProjects', {updateData: updateData}, function (data) {
+                    form.modal('hide');
+                    data.forEach(function (nodeData) {
+                        if (nodeData.updateType === 'copy') {
+                            Tree.addNodeData(nodeData.updateData, parent, next);
+                        }
+                    });
+                }, function () {
+                    form.modal('hide');
+                });
+            });
+        } else {
+            form.modal('hide');
+        }
+    } else {
+        form.modal('hide');
+    }
+});