123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /**
- * Created by Mai on 2017/4/1.
- */
- var ration_coe = {
- createNew: function (project) {
- // 用户定义private方法
- var tools = {};
- // 所有通过this访问的属性,都不应在此单元外部进行写入操作
- var ration_coe = function (proj) {
- this.gljTree = cacheTree.createNew(this);
- // this.project = proj;
- this.datas = [];
- var sourceType = ModuleNames.ration_coe;
- this.getSourceType = function () {
- return sourceType;
- }
- proj.registerModule(ModuleNames.ration_coe, this);
- };
- // prototype用于定义public方法
- ration_coe.prototype.loadData = function (datas) {
- this.datas = datas;
- };
- // 提交数据后返回数据处理
- ration_coe.prototype.doAfterUpdate = function(err, data){
- if(!err){
- if(data.updateTpye=='ut_update'){
- this.refreshAfterUpdate(data);
- }else if(data.updateTpye=='ut_delete'){
- this.refreshAfterDelete(data);
- } else {
- this.refreshAfterSave(data);
- }
- }
- };
- ration_coe.prototype.refreshAfterSave=function(data){
- projectObj.project.ration_coe.addDatasToList(data);
- zmhs_obj.showCoeData();
- };
- ration_coe.prototype.addDatasToList = function (datas) {
- let me = projectObj.project.ration_coe;
- if(datas&&datas.length>0){
- if (me.datas && Array.isArray(me.datas)) {
- me.datas = me.datas.concat(datas);
- } else {
- me.datas = datas;
- }
- }
- };
- ration_coe.prototype.getCoeByRationID = function (rationID) {
- let coeList = _.filter(this.datas, {'rationID': rationID});
- return coeList;
- };
- ration_coe.prototype.refreshAfterUpdate=function(data){
- var coe_list = projectObj.project.ration_coe.datas;
- var coe_index= _.findIndex(coe_list,function(coe){
- return coe.ID==data.query.ID&&coe.projectID==data.query.projectID;
- })
- _.forEach(data.doc, function(n, key) {
- coe_list[coe_index][key] = n;
- });
- zmhs_obj.showCoeData();
- };
- ration_coe.prototype.refreshAfterDelete=function(data){
- var glj_list = projectObj.project.ration_coe.datas;
- _.remove(glj_list,data.query);
- _.remove(gljOprObj.sheetData,data.query);
- zmhs_obj.showCoeData();
- };
- ration_coe.prototype.getRationCoedata=function(newRation,data){
- var criteria= {};
- criteria.ration_coe_list = [];
- var dataLength = 0;
- if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
- dataLength = data.rationCoeList.length
- }
- for(var i=0;i<=dataLength;i++){;
- var newCoe = {
- libID :data.rationRepId,
- rationID:newRation.ID,
- projectID : newRation.projectID
- }
- if(i==dataLength){
- newCoe.coeID=-1;
- newCoe.name = '自定义系数';
- newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
- newCoe.isAdjust=0;
- newCoe.coes = this.getCustomerCoeData();
- }else {
- newCoe.coeID= data.rationCoeList[i].ID;
- }
- criteria.ration_coe_list.push(newCoe);
- }
- criteria.updateType = 'ut_create';
- console.log('enterrrrrrrrrrrrrrrrrrrrrr');
- console.log(criteria);
- return criteria;
- };
- ration_coe.prototype.getCustomerCoeData = function () {
- var coeList = [];
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'定额'});
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'人工'});
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'材料'});
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'机械'});
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'主材'});
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
- return coeList;
- };
- ration_coe.prototype.getUpdateData=function(type,query,doc,callfunction){
- var updateData = [];
- var newobj = {
- 'updateType': type,
- 'query': query,
- }
- if(doc){
- newobj['doc']=doc;
- }
- if(callfunction){
- newobj['updateFunction']=callfunction;
- }
- updateData.push(newobj);
- return updateData;
- };
- ration_coe.prototype.adjustCoeClick = function(recode,newval){
- let me=this,codesList = [],add=[],replace=[];
- var updateData = {
- 'ID':recode.ID,
- 'projectID': recode.projectID,
- 'rationID':recode.rationID,
- 'doc':{
- isAdjust:newval
- },
- add:[],
- delete:[],
- replace:[]
- };
- let gljList = project.ration_glj.getGLJListByRationID(recode.rationID);
- for(let coe of recode.coes){//做单个、替换等检查
- if(coe.coeType == "单个工料机"){ //单个工料机的情况
- let glj = _.find(gljList,{"code":coe.gljCode});
- if(newval == 1){ //单个工料机,选中时,如果能找到则不管,如果没找到,则需自动插入
- if(glj) continue;
- add.push(coe.gljCode);
- codesList.push(coe.gljCode);
- }else {//取消勾选时,要删除添加的工料机记录
- if(glj && glj.createType == "add") updateData.delete.push(glj.ID);
- }
- }
- //替换工料机的情况
- }
- project.ration_glj.getGLJDataByCodes(codesList,function (gljList) {//统一从后端按编号查找标准工料机信息
- let gljMap = _.indexBy(gljList, 'code');
- console.log(gljMap);
- for(let a of add){
- if(gljMap[a]){
- let tem = project.ration_glj.getAddDataByStd(gljMap[a],recode.rationID,project.mainTree.selected.data.billsItemID,recode.projectID);
- updateData.add.push(tem);
- }
- }
- $.bootstrapLoading.start();
- CommonAjax.post("/ration/updateCoeAdjust",updateData,function (result) {
- $.bootstrapLoading.end();
- me.refreshAfterUpdate(result.coe);
- zmhs_obj.refreshAfterUpdate(result,true)
- })
- });
- /* ;*/
- //var updateData = this.getUpdateData('ut_update',query,doc,'adjustUpdate');
- // project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
- };
- ration_coe.prototype.updateCustomerCoe = function (data) {
- var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');
- project.pushNow('updateCustomerCoe',[this.getSourceType()],updateData);
- };
- ration_coe.prototype.deleteByRation = function(ration){
- var coe_list = projectObj.project.ration_coe.datas;
- _.remove(coe_list,{'rationID':ration.ID});
- };
- return new ration_coe(project);
- }
- };
|