| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 | 
							- /**
 
-  * Created by Mai on 2017/4/1.
 
-  */
 
- var Bills = {
 
-     createNew: function (project) {
 
-         var billsTreeSetting = {
 
-             id: 'ID',
 
-             pid: 'ParentID',
 
-             nid: 'NextSiblingID',
 
-             rootId: -1,
 
-             autoUpdate: false
 
-         };
 
-         // 用户定义private方法
 
-         var tools = {
 
-             coverseTreeUpdateData: function (datas) {
 
-                 var updateDatas = [];
 
-                 datas.forEach(function (data) {
 
-                     var updateData = {};
 
-                     if (data.type === idTree.updateType.new) {
 
-                         updateData.updateType = 'ut_create';
 
-                         updateData.updateData = data.data;
 
-                     } else if (data.type === idTree.updateType.update) {
 
-                         updateData.updateType = 'ut_update';
 
-                         updateData.updateData = data.data;
 
-                     } else if (data.type === idTree.updateType.delete) {
 
-                         updateData.updateType = 'ut_delete';
 
-                         updateData.updateData = data.data;
 
-                     }
 
-                     updateDatas.push(updateData);
 
-                 });
 
-                 return updateDatas;
 
-             }
 
-         };
 
-         // 所有通过this访问的属性,都不应在此单元外部进行写入操作
 
-         var bills = function (proj) {
 
-             this.project = proj;
 
-             this.datas = null;
 
-             this.tree = idTree.createNew(billsTreeSetting);
 
-             var sourceType = ModuleNames.bills;
 
-             this.getSourceType = function () {
 
-                 return sourceType;
 
-             }
 
-             proj.registerModule(ModuleNames.bills, this);
 
-         };
 
-         // 从后台获取数据
 
-         /*bills.prototype.pullData = function (){
 
-             this.project.pullData(
 
-                 '/bills/getData',
 
-                 {projectID: this.project.ID},
 
-                 function(result){
 
-                     if (result.error ===0){
 
-                         this.loadDatas(result.data);
 
-                     }
 
-                     else {
 
-                         // to do: ?错误处理需要细化
 
-                         alert(result.message);
 
-                     }
 
-                 },
 
-                 function (){}// to do: 错误处理需要细化
 
-             )
 
-         };*/
 
-         // prototype用于定义public方法
 
-         bills.prototype.loadData = function (datas) {
 
-             this.datas = datas;
 
-             // generate Fees & Flags Index, For View & Calculate
 
-             this.datas.forEach(function (data) {
 
-                 data.FeesIndex = {};
 
-                 if (data.fees) {
 
-                     data.fees.forEach(function (fee) {
 
-                         data.FeesIndex[fee.fieldName] = fee;
 
-                     });
 
-                 }
 
-                 data.FlagsIndex = {};
 
-                 if (data.flags) {
 
-                     data.flags.forEach(function (flag) {
 
-                         data.FlagsIndex[flag.fieldName] = flag;
 
-                     });
 
-                 }
 
-             });
 
-             // datas load to Tree
 
-             this.tree.loadDatas(this.datas);
 
-         };
 
-         bills.prototype.setMaxID = function (ID) {
 
-             this.tree.maxNodeID(ID);
 
-         };
 
-         // 提交数据后的错误处理方法
 
-         bills.prototype.doAfterUpdate = function(err, data){
 
-             // to do
 
-         };
 
-         bills.prototype.getCounterData = function (count) {
 
-             var updateData = {'projectID': this.project.ID()};
 
-             if (count) {
 
-                 updateData[this.getSourceType()] = this.tree.maxNodeID() + count;
 
-             } else {
 
-                 updateData[this.getSourceType()] = this.tree.maxNodeID() + 1;
 
-             }
 
-             return updateData;
 
-         };
 
-         bills.prototype.insertBills = function (parentId, nextSiblingId) {
 
-             var insertData = this.tree.getInsertData(parentId, nextSiblingId);
 
-             var that = this;
 
-             insertData.forEach(function (data) {
 
-                 data.data.projectID = that.project.ID();
 
-                 if (data.type === idTree.updateType.new) {
 
-                     that.datas.push(data.data);
 
-                 }
 
-             });
 
-             this.project.pushNow('insertBills', [this.getSourceType(), this.project.projCounter()],
 
-                 [ tools.coverseTreeUpdateData(insertData), this.getCounterData()]);
 
-             //project.pushNow('insertBills', ModuleNames.bills, tools.coverseTreeUpdateData(insertData));
 
-             return this.tree.insert(parentId, nextSiblingId);
 
-         };
 
-         bills.prototype.insertStdBills = function (parentId, nextSiblingId, stdBillsData) {
 
-             var insertData = this.tree.getInsertData(parentId, nextSiblingId);
 
-             var newData = null, that = this;
 
-             insertData.forEach(function (data) {
 
-                 data.data.projectID = that.project.ID();
 
-                 if (data.type === idTree.updateType.new) {
 
-                     data.data.code = stdBillsData.code;
 
-                     data.data.name = stdBillsData.name;
 
-                     data.data.unit = stdBillsData.unit;
 
-                     that.datas.push(data.data);
 
-                     newData = data.data;
 
-                 }
 
-             });
 
-             this.project.pushNow('insertStdBills', [this.getSourceType(), this.project.projCounter()],
 
-                 [ tools.coverseTreeUpdateData(insertData), this.getCounterData()]);
 
-             //project.pushNow('insertStdBills', ModuleNames.bills, tools.coverseTreeUpdateData(insertData));
 
-             return this.tree.insertByData(newData, parentId, nextSiblingId);
 
-         }
 
-         bills.prototype.deleteBills = function (node) {
 
-             var deleteData = this.tree.getDeleteData(node);
 
-             project.beginUpdate('deleteBills');
 
-             project.push(ModuleNames.bills, tools.coverseTreeUpdateData(deleteData, project.ID()));
 
-             project.endUpdate();
 
-             return this.tree.delete(node);
 
-         }
 
-         return new bills(project);
 
-     }
 
- };
 
 
  |