| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /**
- * Created by zhang on 2018/1/31.
- */
- var installation_fee = {
- createNew: function (project) {
- // 用户定义private方法
- var tools = {};
- // 所有通过this访问的属性,都不应在此单元外部进行写入操作
- var installation_fee = function (proj) {
- // this.project = proj;
- this.datas = [];
- var sourceType = ModuleNames.installation_fee;
- this.getSourceType = function () {
- return sourceType;
- }
- proj.registerModule(ModuleNames.installation_fee, this);
- };
- // prototype用于定义public方法
- installation_fee.prototype.loadData = function (datas) {
- this.datas = datas;
- };
- installation_fee.prototype.getInstallationFeeByLibID=function(libID){
- return _.find(this.datas,{'libID':libID});
- };
- installation_fee.prototype.getFeeRuleByFeeItem = function (feeItem) {
- let installFee = projectObj.project.installation_fee.getInstallationFeeByLibID(feeItem.libID);
- let impacRules = _.filter(installFee.feeRule,{'feeItemId':feeItem.ID});
- return impacRules;
- };
- installation_fee.prototype.getFeeRuleBySection = function (section) {
- let installFee = projectObj.project.installation_fee.getInstallationFeeByLibID(section.libID);
- let impacRules = _.filter(installFee.feeRule,{'sectionId':section.ID});
- return impacRules;
- };
- installation_fee.prototype.getInstallSectionsByfeeItemID=function(libID,feeItemId){
- let installationFee = this.getInstallationFeeByLibID(libID);
- let installSections = _.filter(installationFee.installSection,{'feeItemId':feeItemId});
- return installSections;
- };
- installation_fee.prototype.getFeeItemByID = function(libID,ID){
- let installFee = projectObj.project.installation_fee.getInstallationFeeByLibID(libID);
- return _.find(installFee.installFeeItem,{'ID':ID});
- };
- installation_fee.prototype.getInstallSectionByID = function(libID,ID){
- let installFee = projectObj.project.installation_fee.getInstallationFeeByLibID(libID);
- return _.find(installFee.installSection,{'ID':ID});
- };
- installation_fee.prototype.getFeeRuleBySectionID=function(libID,sectionId){
- let installationFee = this.getInstallationFeeByLibID(libID);
- let feeRules = _.filter(installationFee.feeRule,{'sectionId':sectionId});
- return feeRules;
- };
- installation_fee.prototype.getFeeRuleByID = function (libID,feeRuleID) {
- let installationFee = this.getInstallationFeeByLibID(libID);
- return _.find(installationFee.feeRule,{'ID':feeRuleID});
- };
- installation_fee.prototype.updateFeeRule = function (doc,libID,feeRuleID,callback) {
- let me = this;
- let itemUpdateData = null;
- let feeItem=null;
- let ruleUpdateData=null;
- let updateData = [];
- let feeRule = me.getFeeRuleByID(libID,feeRuleID);
- if(feeRule){
- if(doc){//如果有需要更新的属性
- ruleUpdateData = me.getFeeRuleUpdateData(libID,feeRuleID,doc);
- updateData.push(ruleUpdateData);
- if(doc.hasOwnProperty("billID")){//改变了选取位置后如果与费用项里的位置不一致的话要清空费用项的选取位置
- feeItem = me.getFeeItemByID(libID,feeRule.feeItemId);
- let installationFee = me.getInstallationFeeByLibID(libID);
- if(feeItem.position!=''&&feeItem.billID!=doc.billID){
- itemUpdateData = me.getFeeItemUpdateData(feeItem,{position: "", billID:""},installationFee);
- updateData.push(itemUpdateData);
- }
- }
- $.bootstrapLoading.start();
- me.submitInstallationUpdate(updateData,function (data) {
- //更新缓存
- let isFeeItemUpdate = false;
- if(itemUpdateData){
- feeItem.position ="";
- feeItem.billID = "";
- isFeeItemUpdate= true;
- }
- for(let ukey in doc){
- feeRule[ukey]=doc[ukey];
- }
- if(callback){//回调
- callback(true);
- }
- $.bootstrapLoading.end();
- });
- }
- }else {
- if(callback){
- callback(false);
- }
- }
- };
- installation_fee.prototype.getFeeRuleUpdateData = function (libID,feeRuleID,doc) {
- let installationFee = this.getInstallationFeeByLibID(libID);
- let updateData = {
- ID:installationFee.ID,
- itemID:feeRuleID,
- type:"feeRule",
- doc:doc
- };
- return updateData;
- };
- installation_fee.prototype.getSectionUpdateData = function (libID,sectionID,doc) {
- let installationFee = this.getInstallationFeeByLibID(libID);
- let updateData = {
- ID:installationFee.ID,
- itemID:sectionID,
- type:"installSection",
- doc:doc
- };
- return updateData;
- };
- installation_fee.prototype.getFeeItemUpdateData = function (item,doc,installationFee) {
- let updateData = {
- ID:installationFee?installationFee.ID:item.installFeeID,
- itemID:item.ID,
- type:'installFeeItem',
- doc:doc
- };
- return updateData;
- };
- installation_fee.prototype.submitInstallationUpdate = function (updateData,callback) {
- if(updateData){
- CommonAjax.post('/installation/updateInstallationFee',{'projectID':projectInfoObj.projectInfo.ID,'updateData':updateData},function (data) {
- callback(data);
- })
- }
- }
- // 提交数据后返回数据处理
- installation_fee.prototype.doAfterUpdate = function(err, data){
- };
- return new installation_fee(project);
- }
- };
|