123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908 |
- /**
- * Created by Mai on 2017/4/1.
- */
- let ration_glj = {
- createNew: function (project) {
- // 用户定义private方法
- let tools = {};
- // 所有通过this访问的属性,都不应在此单元外部进行写入操作
- let ration_glj = function (proj) {
- this.gljTree = cacheTree.createNew(this);
- // this.project = proj;
- this.datas = [];
- let sourceType = ModuleNames.ration_glj;
- this.getSourceType = function () {
- return sourceType;
- }
- proj.registerModule(ModuleNames.ration_glj, this);
- };
- // 从后台获取数据
- /*glj.prototype.pullData = function (){
- this.project.pullData(
- '/glj/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方法
- ration_glj.prototype.loadData = function (datas) {
- this.datas = datas;
- };
- ration_glj.prototype.getGljArrByRation = function (ration) {
- if (ration.type == rationType.gljRation){
- let glj = JSON.parse(JSON.stringify(ration));
- glj.type = glj.subType;
- glj.quantity = 1;
- glj.totalQuantity = parseFloatPlus(ration.quantity);
- return [glj];
- }
- else{
- let result = this.datas.filter(function (data) {
- if(data.rationID === ration.ID){
- gljOprObj.getTotalQuantity(data, ration);
- return true;
- }
- return false;
- })
- result = gljOprObj.combineWithProjectGlj(result);
- return result;
- }
- };
- ration_glj.prototype.getGatherGljArrByRations = function (rations, needOneBill, billQuantity) {
- let result = [];
- let clone = function (obj) {
- if (obj === null) return null;
- let o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
- for (let i in obj) {
- o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
- }
- return o;
- }
- let findGlj = function (sourceGlj, gljArr) {
- for (let glj of gljArr) {
- if (glj.projectGLJID === sourceGlj.projectGLJID) {
- return glj;
- }
- }
- return null;
- }
- for (let ration of rations) {
- if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
- let glj = JSON.parse(JSON.stringify(ration));
- glj.type = glj.subType;
- glj.totalQuantity = parseFloatPlus(ration.quantity);
- glj.markertPrice = glj.marketUnitFee;
- glj.basePrice = glj.marketUnitFee;
- glj.adjustPrice = glj.marketUnitFee;
- result.push(glj);
- }
- else{
- let rationGljs = this.getGljArrByRation(ration);
- for (let glj of rationGljs) {
- let sameGlj = findGlj(glj, result);
- if (!sameGlj) {
- sameGlj = clone(glj);
- sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
- result.push(sameGlj);
- } else {
- sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
- sameGlj.totalQuantity = (parseFloat(sameGlj.totalQuantity) + parseFloat(glj.totalQuantity)).toDecimal(4);
- }
- }
- }
- }
- result = gljOprObj.combineWithProjectGlj(result);
- if (!needOneBill) return result;
- // 上面取的是清单下所有工料机的总量,我要算清单单价,所以要取单位清单的工料机数量,所以下面要除以清单数量。
- let oneBill = JSON.parse(JSON.stringify(result));
- for (let glj of oneBill){
- if (glj.type == rationType.volumePrice){ // 量价、工料机形式的定额要进行数据变换才能参与基数计算。
- glj.type = glj.subType;
- glj.basePrice = glj.marketUnitFee;
- glj.marketPrice = glj.marketUnitFee;
- glj.adjustPrice = glj.marketUnitFee;
- }
- else if (glj.type == rationType.gljRation){
- glj.type = glj.subType;
- };
- // glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.glj.quantity);
- glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.process); // 广联达这里没有取舍
- };
- return oneBill;
- }
- // 提交数据后返回数据处理
- ration_glj.prototype.doAfterUpdate = function (err, data) {
- let me = this;
- if (!err) {
- if (data.updateTpye == 'ut_update') {
- me.refreshAfterUpdate(data);
- } else if (data.updateTpye == 'ut_delete') {
- me.refreshAfterDelete(data);
- } else {
- me.refreshAfterSave(data);
- }
- }
- projectObj.project.projectGLJ.loadData();
- };
- ration_glj.prototype.getDataByID = function (ID) {
- return _.find(this.datas,{'ID':ID});
- };
- ration_glj.prototype.refreshAfterSave = function (data) {
- let me = projectObj.project.ration_glj;
- let neRecodes = [];
- if (data) {
- // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
- neRecodes = data.showDatas;
- gljOprObj.sheetData = neRecodes;
- me.addDatasToList(neRecodes);
- }
- project.projectGLJ.loadData(function () {
- gljOprObj.showRationGLJSheetData(true);
- //add to mainTree;
- me.addToMainTree(neRecodes);
- let rationID = neRecodes[0].rationID;
- let node = project.mainTree.nodes['id_' + rationID];
- if(isDef(node)){
- project.calcProgram.calcAndSave(node);
- }
- if (activeSubSheetIsCalcProgram())
- calcProgramObj.refreshCalcProgram(node, 1);
- });
- };
- ration_glj.prototype.getGljByRationID = function(rationID){
- return _.filter(this.datas, {'rationID': rationID});
- };
- ration_glj.prototype.addDatasToList = function (datas) {
- let me = projectObj.project.ration_glj;
- if(datas&&datas.length>0){
- if (me.datas && Array.isArray(me.datas)) {
- me.datas = me.datas.concat(datas);
- } else {
- me.datas = datas;
- }
- }
- };
- ration_glj.prototype.addToMainTree = function (datas) {
- datas = sortRationGLJ(datas);
- for (let data of datas) {
- if (this.needShowToTree(data)) {
- gljOprObj.setGLJPrice(data);
- this.transferToNodeData(data);
- let parentNode = projectObj.project.mainTree.findNode(data.rationID);
- if (parentNode) {
- let nextNodeID = null;
- if (parentNode.children.length > 0) {
- for (let br of parentNode.children) {
- if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
- nextNodeID = br.getID();
- }
- }
- }
- nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
- let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
- newNode.source = data;
- newNode.sourceType = this.getSourceType();
- newNode.data = data;
- ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
- }
- }
- }
- };
- ration_glj.prototype.removeNodeByRation = function(ration,controller){//删除主材或设备节点
- let glj_list = _.filter(projectObj.project.ration_glj.datas,{'rationID':ration.ID});
- let deleteNodes = [];
- for(let rg of glj_list){
- if(this.needShowToTree(rg)){
- let r_node = projectObj.project.mainTree.getNodeByID(rg.ID);
- deleteNodes.push(r_node);
- }
- }
- if(deleteNodes.length > 0){
- let rowIndex = deleteNodes[0].serialNo();
- if(controller.tree.m_delete(deleteNodes)){
- TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
- let rowCount = deleteNodes.length;
- controller.sheet.deleteRows(rowIndex, rowCount);
- });
- }
- }
- };
- ration_glj.prototype.refreshAfterUpdate = function (data) {
- let me = this;
- let rationID=null;
- if (data.quantityRefresh) {
- data.glj_result.forEach(function (item) {
- rationID = me.refreshEachItme(item.doc, item.query);
- })
- } else {
- rationID = me.refreshEachItme(data.doc, data.query);
- }
- gljOprObj.showRationGLJSheetData(true);
- this.reCalcWhenGLJChange({rationID:rationID});
- };
- ration_glj.prototype.refreshEachItme = function (doc, query) {
- let glj = this.refreshByID(query.ID,doc);
- return glj.rationID;
- };
- ration_glj.prototype.refreshByID=function (ID,doc) {
- let glj_list = projectObj.project.ration_glj.datas;
- let glj_index = _.findIndex(glj_list,{"ID":ID});
- _.forEach(doc, function (n, key) {
- glj_list[glj_index][key] = n;
- });
- return glj_list[glj_index]
- };
- ration_glj.prototype.refreshAfterDelete = function (data) {
- let me = projectObj.project.ration_glj;
- let glj_list = me.datas;
- let oldData = _.remove(glj_list, data.query);
- _.remove(gljOprObj.sheetData, data.query);
- gljOprObj.showRationGLJSheetData();
- projectObj.project.projectGLJ.loadData();
- let rationNode = null;
- let next = null;
- let selected = projectObj.project.mainTree.selected;
- if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
- rationNode = selected;
- } else if (selected.sourceType == ModuleNames.ration_glj) {
- rationNode = selected.parent;
- next = true;
- }
- rationNode.data.adjustState = data.adjustState;
- projectObj.mainController.refreshTreeNode([rationNode]);
- for (let o of oldData) {
- if (this.needShowToTree(o)) {
- let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
- projectObj.mainController.deleteNode(node, next);
- }
- }
- project.calcProgram.calcAndSave(rationNode,function () {
- installationFeeObj.calcInstallationFee();
- });
- };
- // CSL,2017.05.09
- ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
- this.project.beginUpdate('modifyQuantity');
- data.quantity = newQuantity;
- data.customQuantity = newQuantity;
- data.updateType = 'ut_update';
- this.project.push(this.getSourceType, data);
- this.project.endUpdate();
- };
- ration_glj.prototype.modifyPrice = function (data, newPrice) {
- this.project.beginUpdate('modifyPrice');
- data.price = newPrice;
- data.updateType = 'ut_update';
- this.project.push(this.getSourceType, data);
- this.project.endUpdate();
- };
- ration_glj.prototype.deleteGLJ = function (data) {
- this.project.beginUpdate('deleteGLJ');
- data.customQuantity = 0;
- data.quantity = 0;
- data.rationItemQuantity = 0;
- data.updateType = 'ut_update';
- this.project.push(this.getSourceType, data);
- this.project.endUpdate();
- };
- ration_glj.prototype.addRationGLJ = function (newRation, data) {
- let souceTypeList = [];
- let criteriaDataList = [];
- if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
- let criteria = {};
- criteria.ration_glj_list = [];
- for (let i = 0; i < data.rationGljList.length; i++) {
- let temdata = data.rationGljList[i];
- let newGLJ = {};
- newGLJ.projectID = parseInt(newRation.projectID);
- newGLJ.GLJID = temdata.gljId;
- newGLJ.rationID = newRation.ID;
- newGLJ.billsItemID = newRation.billsItemID;
- newGLJ.rationItemQuantity = temdata.consumeAmt;
- newGLJ.quantity = temdata.consumeAmt;
- newGLJ.glj_repository_id = data.rationRepId;
- criteria.ration_glj_list.push(newGLJ);
- }
- criteria.updateType = 'ut_create';
- souceTypeList.push(this.getSourceType());
- criteriaDataList.push(criteria);
- }
- let ration_coe = projectObj.project.ration_coe;
- let rationCoeData = ration_coe.getRationCoedata(newRation, data);
- souceTypeList.push(ration_coe.getSourceType());
- criteriaDataList.push(rationCoeData);
- project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
- };
- ration_glj.prototype.getDeleteDataByRation = function (rationData) {
- let updateData = [];
- updateData.push({
- 'deleteType': 'RATION',
- 'updateType': 'ut_delete',
- 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
- });
- return updateData;
- };
- ration_glj.prototype.getDeleteDataByBills = function (datas) {
- let updateData = [];
- datas.forEach(function (deleteData) {
- if (deleteData.type == 'delete') {
- let billData = deleteData.data;
- updateData.push({
- 'deleteType': 'BILL',
- 'updateType': 'ut_delete',
- 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
- });
- }
- })
- return updateData;
- };
- ration_glj.prototype.deleteByRation = function (ration) {
- let glj_list = projectObj.project.ration_glj.datas;
- _.remove(glj_list,{'rationID':ration.ID});
- };
- ration_glj.prototype.deleteByBills = function (deleteData) {
- let rationList = projectObj.project.Ration.datas;
- let deleteRationList = [];
- for (let i = 0; i < deleteData.length; i++) {
- if (deleteData[i].type == 'delete') {
- let billID = deleteData[i].data.ID;
- let raList = _.filter(rationList, (ration) => {
- return ration.billsItemID == billID;
- });
- deleteRationList = deleteRationList.concat(raList);
- }
- }
- for (let i = 0; i < deleteRationList.length; i++) {
- this.deleteByRation(deleteRationList[i]);
- projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
- projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
- projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
- projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
- }
- }
- ration_glj.prototype.updataOrdelete = function (row) {
- let updateData = null;
- if (row.rationItemQuantity == 0) {
- updateData = this.getUpdateData('ut_delete', {
- 'ID': row.ID,
- 'projectID': row.projectID
- }, {rationID: row.rationID});
- project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
- } else {
- this.updateRationGLJByEdit(row, 'customQuantity', 0);
- //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
- }
- };
- ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
- let updateData = [];
- let newobj = {
- 'updateType': type,
- 'query': query,
- }
- if (doc) {
- newobj['doc'] = doc;
- }
- if (callfunction) {
- newobj['updateFunction'] = callfunction;
- }
- updateData.push(newobj);
- return updateData;
- };
- ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
- let me = this,doc = {};
- doc[updateField] = newval;
- me.submitChange(recode,doc,updateField,node);
- };
- ration_glj.prototype.submitChange = function(recode,updateData,updateField,node){
- let me = this;
- let query = {
- 'ID': recode.ID,
- 'projectID': recode.projectID,
- 'rationID': recode.rationID
- };
- let priceInfo = {
- base_price: recode.basePrice,
- market_price: recode.marketPrice
- };
- if(updateData['type'] != undefined || updateData['type'] != null){
- updateData.shortName = projectObj.project.projectGLJ.getShortNameByID(updateData['type']);
- }
- let callback = function (data) {
- if (updateField == 'customQuantity') {
- me.refreshAfterQuantityUpdate(data, node);
- } else {
- let doc = data.doc;
- for (let key in doc) {
- recode[key] = doc[key];
- }
- me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
- if (node) {//如果不是在造价书页面直接编辑,则不用刷新
- if (updateField == "type" && !(updateData['type'] == gljType.MAIN_MATERIAL || updateData['type'] == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
- projectObj.mainController.deleteNode(node, true);
- }
- }
- }
- projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
- gljOprObj.refreshView();
- me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
- me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
- $.bootstrapLoading.end();
- installationFeeObj.calcInstallationFee();
- });
- };
- $.bootstrapLoading.start();
- CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
- query: query,
- doc: updateData,
- priceInfo: priceInfo
- }, callback, function (err) {
- $.bootstrapLoading.end();
- });
- };
- ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
- let me = this;
- data.glj_result.forEach(function (item) {
- me.refreshEachItme(item.doc, item.query);
- });
- me.refreshRationAfterEdit(data, data.rationID, node);
- };
- ration_glj.prototype.refreshRationAfterEdit= function(data,rationID,rnode){
- let nodes = [];
- let node = this.refreshRationNode(data.name,data.adjustState,rationID);
- if (node) nodes.push(node);
- if (rnode) nodes.push(rnode);
- projectObj.mainController.refreshTreeNode(nodes);
- };
- ration_glj.prototype.refreshRationNode = function(name,adjustState,rationID){
- let node = projectObj.project.mainTree.findNode(rationID);
- if (!node) return null;
- if(gljUtil.isDef(adjustState)){
- node.data.adjustState = adjustState;
- }
- if(gljUtil.isDef(name)){
- node.data.name = name;
- }
- return node
- };
- ration_glj.prototype.getGLJData = function (cb) {
- let engineerID = projectInfoObj.projectInfo.property.engineering_id;
- CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
- cb(data);
- })
- };
- ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
- let gljList = [];
- let allGLJ = gljOprObj.AllRecode;
- let billsItemID = null, serialNo = 0,selectedSerialNo = null,nextNodeID = null, parentNodeID = null, billNode = null;
- let pEngineer = projectInfoObj.projectInfo.property.projectEngineering;
- let children = [];
- if (selected.sourceType === project.Bills.getSourceType()) {
- billsItemID = selected.data.ID;
- parentNodeID = selected.getID();
- nextNodeID = selected.tree.rootID();
- billNode = selected;
- } else {
- billsItemID = selected.data.billsItemID;
- serialNo = selected.data.serialNo;
- selectedSerialNo = selected.data.serialNo;
- nextNodeID = selected.getNextSiblingID();
- parentNodeID = selected.getParentID();
- billNode = selected.parent;
- }
- children = project.Ration.getBillsSortRation(billsItemID);
- serialNo == 0 ? serialNo = children.length : "";
- for (let con_key of GLJSelection) {
- let glj = _.find(allGLJ, function (item) {
- let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
- return i_key == con_key;
- });
- if (glj) {
- serialNo += 1;
- let new_glj = {
- ID: project.Ration.getNewRationID(),
- projectID: parseInt(project.ID()),
- billsItemID: billsItemID,
- type: rationType.gljRation,
- code: glj.code,
- name: glj.name,
- quantity: 0,
- unit: glj.unit,
- specs: glj.specs,
- subType: glj.gljType,
- model:glj.model,
- basePrice: glj.basePrice,
- marketPrice:glj.basePrice,
- original_code: glj.code,
- shortName: glj.shortName,
- serialNo: serialNo,
- GLJID: glj.ID,
- adjCoe: glj.adjCoe,
- materialType:glj.materialType,
- materialCoe:glj.materialCoe,
- repositoryId: glj.repositoryId
- };
- if(pEngineer) new_glj.programID = pEngineer;
- if (glj.hasOwnProperty("compilationId")) {
- new_glj.from = "cpt";
- if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
- new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
- }
- }
- if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
- new_glj.quantityEXP="QDL";
- if(billNode.data.quantity){
- new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
- new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
- }
- }
- gljList.push(new_glj);
- }
- }
- if (gljList.length == 0) {
- return;
- }
- let postData = {
- gljList: gljList,
- projectID: parseInt(project.ID()),
- billsItemID: billsItemID,
- rationCount: project.Ration.maxRationID()
- }
- selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
- CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
- // 更新兄弟节点的序列号
- if (selectedSerialNo != null) {
- let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
- if (selectIndex + 1 < children.length) {
- for (let i = selectIndex + 1; i < children.length; i++) {
- children[i].serialNo += gljList.length;
- }
- }
- }
- callback(parentNodeID,nextNodeID,data);
- }, function () {
- $.bootstrapLoading.end();
- });
- };
- ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
- let gljList = [];
- let allGLJ = gljOprObj.AllRecode;
- GLJSelection.sort();
- _.forEach(GLJSelection, function (g) {
- let glj = _.find(allGLJ, function (item) {
- let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
- return i_key == g;
- });
- let ration_glj = {
- projectID: ration.projectID,
- GLJID: glj.ID,
- rationID: ration.ID,
- billsItemID: ration.billsItemID,
- rationItemQuantity: 0,
- quantity: 0,
- name: glj.name,
- code: glj.code,
- original_code: glj.code,
- unit: glj.unit,
- specs: glj.specs,
- basePrice: glj.basePrice,
- marketPrice:glj.basePrice,
- shortName: glj.shortName,
- type: glj.gljType,
- model:glj.model,
- adjCoe: glj.adjCoe,
- createType: 'add',
- materialType:glj.materialType,
- materialCoe:glj.materialCoe,
- repositoryId: glj.repositoryId
- }
- if (glj.hasOwnProperty("compilationId")) {
- ration_glj.from = "cpt";
- if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
- ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
- }
- }
- gljList.push(ration_glj);
- });
- $.bootstrapLoading.start();
- CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
- $.bootstrapLoading.end();
- });
- };
- ration_glj.prototype.updateRationGLJByChangeCode = function (recode, updateField, newval) {
- let me = this;
- let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
- let priceObj = priceMap[newval];
- if(priceObj){
- if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
- recode.rcode = recode.code;
- recode.createType = 'replace';
- }
- recode.code = priceObj.code;
- recode.name = priceObj.name;
- recode.type = priceObj.type;
- recode.unit = priceObj.unit;
- recode.shortName = priceObj.short_name;
- recode.specs = priceObj.specs;
- recode.GLJID=priceObj.glj_id;
- recode.original_code = priceObj.original_code;
- recode.basePrice = priceObj.base_price;
- recode.marketPrice = priceObj.market_price;
- }
- $.bootstrapLoading.start();
- CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
- if (result) {
- //result.adjustState;
- let glj_list = me.datas;
- let data = result.data;
- let list_index = _.findIndex(glj_list, {'ID': data.ID});
- let rationNode = projectObj.project.mainTree.findNode(data.rationID);
- let nodes = [rationNode];
- glj_list[list_index] = data;
- project.projectGLJ.loadData(function () {//加载完项目工料机再计算
- gljOprObj.refreshView();
- if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
- let node = project.ration_glj.findGLJNodeByID(data.ID);
- if (node) {
- project.ration_glj.transferToNodeData(data);
- node.source = data;
- node.data = data;
- }
- node ? nodes.push(node) : "";
- }
- rationNode.data.adjustState = result.adjustState;
- rationNode.data.name = result.name;
- projectObj.mainController.refreshTreeNode(nodes);
- project.calcProgram.calcAndSave(rationNode);
- $.bootstrapLoading.end();
- });
- }
- }, function () {
- $.bootstrapLoading.end();
- });
- };
- ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
- let allGLJ = gljOprObj.AllRecode;
- let glj = _.find(allGLJ, function (item) {
- let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
- return i_key == selectCode;
- });
- if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
- return callback(null);
- }
- if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
- oldData.rcode = oldData.code;
- oldData.createType = 'replace';
- }
- oldData.GLJID = glj.ID;
- oldData.name = glj.name;
- oldData.code = glj.code;
- oldData.original_code = glj.code;
- oldData.unit = glj.unit;
- oldData.specs = glj.specs;
- oldData.model = glj.model;
- oldData.basePrice = glj.basePrice;
- oldData.marketPrice = glj.basePrice;
- oldData.repositoryId = glj.repositoryId;
- oldData.materialType = glj.materialType;
- oldData. materialCoe = glj.materialCoe;
- if (glj.hasOwnProperty("compilationId")) {
- oldData.from = "cpt";
- if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
- oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
- }
- } else {
- oldData.from = "std";
- }
- $.bootstrapLoading.start();
- CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
- $.bootstrapLoading.end();
- });
- };
- ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
- let allGLJ = gljOprObj.AllRecode,tasks = [],updateMap={};
- let oldIndex = gljOprObj.getIndex(oldData, gljKeyArray);
- let glj = _.find(allGLJ, function (item) {
- let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
- return i_key == selectCode;
- });
- if (selectCode == oldIndex) {
- return callback(null);
- }
- let query = {
- projectID: oldData.projectID,
- code: oldData.code,
- name: oldData.name,
- unit: oldData.unit,
- type: oldData.type
- }
- if (oldData.specs && oldData.specs != '') {
- query.specs = oldData.specs;
- }
- let doc = {
- GLJID: glj.ID,
- createType: 'replace',
- rationItemQuantity: 0,
- name: glj.name,
- code: glj.code,
- original_code: glj.code,
- unit: glj.unit,
- specs: glj.specs,
- type: glj.gljType,
- model:glj.model,
- basePrice: glj.basePrice,
- marketPrice:glj.basePrice,
- repositoryId: glj.repositoryId,
- materialType: glj.materialType, //三材类别
- materialCoe: glj.materialCoe,
- projectID: oldData.projectID
- };
- if (glj.hasOwnProperty("compilationId")) {
- doc.from = "cpt";
- if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
- doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
- }
- } else {
- doc.from = "std";
- }
- for(let d of this.datas){//查询出所有需替换的工料机
- let tem_index = gljOprObj.getIndex(d, gljKeyArray);
- if(tem_index == oldIndex){
- let tem_doc = _.cloneDeep(doc);
- if(d.createType == 'replace'){
- tem_doc.rcode = d.rcode;
- }else if(d.createType == 'add'){//对于添加的类型,替换后还是添加类型
- tem_doc.createType = 'add';
- }else {
- tem_doc.rcode = d.code
- }
- let task = {
- updateOne:{
- filter : {ID:d.ID},
- update : tem_doc
- }
- };
- tasks.push(task);
- updateMap[d.ID] = tem_doc;
- }
- }
- $.bootstrapLoading.start();
- CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc,tasks:tasks}, function (result) {
- callback(result,updateMap);
- }, function () {
- $.bootstrapLoading.end();
- });
- };
- ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
- let gljList = _.filter(this.datas, function (n) {
- return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
- });
- gljList = sortRationGLJ(gljList);
- return gljOprObj.combineWithProjectGlj(gljList);
- };
- ration_glj.prototype.transferToNodeData = function (data) {
- data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
- data.subType = data.type;
- };
- ration_glj.prototype.combineRationAndGLJ = function (ration) {
- if (ration) {
- let projectGLJData = projectObj.project.projectGLJ.datas;
- let projectGljs = projectGLJData.gljList;
- let mixRatioMap = projectGLJData.mixRatioMap;
- let glj = _.find(projectGljs, {'id': ration.projectGLJID});
- if (glj) {
- if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
- ration.isEstimate = glj.is_evaluate;
- }
- ration = gljOprObj.setGLJPrice(ration,glj);
- ration.isAdd = glj.unit_price.is_add;
- let connect_index = gljOprObj.getIndex(glj, gljKeyArray);
- if (mixRatioMap.hasOwnProperty(connect_index)) {
- let mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
- ration.subList = mixRatios;
- }
- }
- }
- return ration;
- };
- ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
- if (node.data[fieldName] !== value) {
- if (fieldName == "marketUnitFee") {
- let decimal = getDecimal("glj.unitPrice");
- let newval = number_util.checkNumberValue(value, decimal);
- if (newval) {
- fieldName = "marketPrice";
- projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
- return;
- }
- } else {
- if(fieldName == "contain"){
- if(value==null){
- value="";
- }else {
- let decimal = getDecimal("glj.quantity");
- value = number_util.checkNumberValue(value, decimal);
- fieldName="customQuantity";//填入自定义消耗
- }
- }
- if (value !== undefined && value !== null) {
- if (fieldName == "subType") {
- node.data.subType = value;
- fieldName = "type";//转换成更新工料机类型
- }
- this.updateRationGLJByEdit(node.data, fieldName, value, node);
- return;
- }
- }
- }
- // node.data.subType = value;
- projectObj.mainController.refreshTreeNode([node]);
- };
- ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
- if (this.needShowToTree(data)) {
- this.transferToNodeData(data);
- gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
- }
- };
- ration_glj.prototype.needShowToTree = function (data) {
- if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
- return true
- }
- return false
- };
- ration_glj.prototype.findGLJNodeByID = function (ID) {
- return projectObj.project.mainTree.findNode(ID);
- };
- ration_glj.prototype.findRationNodeByID = function (ID) {
- return projectObj.project.mainTree.findNode(ID);
- };
- ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
- let node = this.findRationNodeByID(ration_glj.rationID);
- if (node) {
- node.changed = true;
- project.calcProgram.calcAndSave(node);
- }
- };
- return new ration_glj(project);
- }
- };
|