123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- /**
- * 工料机汇总相关数据
- *
- * @author CaiAoLin
- * @date 2017/9/14
- * @version
- */
- function ProjectGLJ() {
- this.datas = null;
- this.isLoading = false;
- }
- /**
- * 加载数据
- *
- * @param {function} callback
- * @return {boolean}
- */
- ProjectGLJ.prototype.loadData = function (callback = null) {
- let self = this;
- if (self.isLoading) {
- return false;
- }
- // 加载工料机数据
- $.ajax({
- url: '/glj/getData',
- type: 'post',
- dataType: 'json',
- data: {project_id: scUrlUtil.GetQueryString('project')},
- error: function() {
- // alert('数据传输错误');
- },
- beforeSend: function() {
- self.isLoading = true;
- },
- success: function(response) {
- self.isLoading = false;
- if (response.err === 1) {
- let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
- alert(msg);
- return false;
- }
- self.datas = response.data;
- // 回调函数
- if (callback !== null) {
- callback(response.data);
- }
- // 存入缓存
- projectObj.project.projectGLJ = self;
- }
- });
- };
- /**
- * 获取对应工料机数据
- *
- * @param {String} code
- * @return {Object}
- */
- ProjectGLJ.prototype.getDataByCode = function (code) {
- let result = {};
- if (this.datas === null) {
- return result;
- }
- let gljList = this.datas.gljList;
- if (gljList === undefined) {
- return result;
- }
- for(let tmp of gljList) {
- if (tmp.code === code) {
- result = tmp;
- break;
- }
- }
- return result;
- };
- /**
- * 修改工料机数据
- *
- * @param {Number} id
- * @param {Object} data
- * @return {boolean}
- */
- ProjectGLJ.prototype.updateData = function(id, data) {
- let result = false;
- if (this.datas === null) {
- return result;
- }
- let gljList = this.datas.gljList;
- if (gljList === undefined) {
- return result;
- }
- // 查找对应的index
- let index = -1;
- for(let tmp in gljList) {
- if (gljList[tmp].id === id) {
- index = tmp;
- break;
- }
- }
- if (index < 0) {
- return result;
- }
- // 修改数据
- for(let tmpIndex in data) {
- if(tmpIndex.indexOf('_price') >= 0) {
- // 修改unit_price中的对象
- this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
- } else {
- this.datas.gljList[index][tmpIndex] = data[tmpIndex];
- }
- }
- };
- /**
- * 加载缓存数据到spread
- *
- * @return {void}
- */
- ProjectGLJ.prototype.loadCacheData = function() {
- // 加载工料机数据
- let data = this.datas === null ? null : this.datas;
- if (data === null) {
- return;
- }
- jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
- jsonData=filterProjectGLJ(jsonData);
- projectGLJSheet.setData(jsonData);
- projectGLJSpread.specialColumn(jsonData);
- };
- ProjectGLJ.prototype.updatePriceFromRG=function(recode,updateField,newval){
- if(updateField=='marketPrice'){
- this.updateBasePriceFromRG(recode,"market_price",newval);
- }
- if(updateField=='basePrice'){
- this.updateBasePriceFromRG(recode,"base_price",newval);
- }
- };
- ProjectGLJ.prototype.updateBasePriceFromRG=function(recode,updateField,newval){
- let me = this;
- let projectGljs = this.datas.gljList;
- let glj = _.find(projectGljs,{'id':recode.projectGLJID});
- if(glj){
- let data = {id:glj.unit_price.id,field:updateField,newval:newval};
- let callback =function (data) {
- if(updateField=='base_price'){
- glj.unit_price.base_price=newval;
- me.setAdjustPrice(glj);
- }else {
- glj.unit_price.market_price=newval;
- }
- //更新项目工料机价格
- me.refreshProjectGLJPrice(data);
- me.refreshRationGLJPrice(glj);
- gljOprObj.showRationGLJSheetData();
- $.bootstrapLoading.end();
- }
- $.bootstrapLoading.start();
- CommonAjax.post("/glj/updatePrice",data,callback,function (err) {
- $.bootstrapLoading.end();
- });
- }else {
- gljOprObj.showRationGLJSheetData();
- }
- }
- ProjectGLJ.prototype.refreshRationGLJPrice=function (glj) {
- for(let ration_glj of gljOprObj.sheetData){
- if(ration_glj.projectGLJID ==glj.id){
- ration_glj.basePrice=glj.unit_price.base_price;
- ration_glj.marketPrice=glj.unit_price.market_price;
- ration_glj.adjustPrice=glj.adjust_price;
- }
- }
- }
- ProjectGLJ.prototype.refreshProjectGLJPrice=function(data){
- let projectGljs = this.datas.gljList;
- let indexList = ['code','name','specs','unit','type'];
- for(let d of data){
- if(d){
- let condition = {};
- for(let index of indexList){
- if(d[index]!=null&&d[index]!=undefined&&d[index]!=''){
- condition[index]=d[index]
- }
- }
- let glj = _.find(projectGljs,condition);
- if(glj){
- glj.unit_price.base_price = d.base_price;
- glj.unit_price.market_price = d.market_price;
- this.setAdjustPrice(glj);
- this.refreshRationGLJPrice(glj);
- }
- }
- }
- }
- ProjectGLJ.prototype.setAdjustPrice=function(glj){
- switch (glj.unit_price.type + '') {
- // 人工: 调整基价=基价单价*调整系数
- case GLJTypeConst.LABOUR:
- glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj.unit_price.base_price), -2);
- break;
- // 机械类型的算法
- case GLJTypeConst.MACHINE:
- console.log('机械');
- break;
- // 材料、主材、设备
- default:
- glj.adjust_price = glj.unit_price.base_price;
- }
- }
|