project.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var PROJECT = {
  5. createNew: function (projectID, userID) {
  6. // 定义private方法
  7. var tools = {
  8. _project: null,
  9. _ID: parseInt(projectID),
  10. _userID: userID,
  11. updateLock: 0,
  12. updateData: [],
  13. operation: '',
  14. modules: {},
  15. projCounter: 'projCounter',
  16. projSetting: 'proj_setting'
  17. };
  18. var me = tools;
  19. tools.doAfterUpdate = function(result){
  20. if (!result) { return }
  21. result.forEach(function(item){
  22. if(_.isArray(item)){
  23. item.forEach(function (e) {
  24. me.eachItem(e);
  25. })
  26. }else {
  27. me.eachItem(item)
  28. }
  29. });
  30. };
  31. // isInit: 是否是初始化,导出接口用到getData,但是非初始化,多次调用getData不会覆盖原有缓存数据
  32. tools.doAfterLoad = function(result, isInit, callback){
  33. var counter;
  34. //必须要先load ProjectInfo的信息
  35. let projectInfoModule = result.find(data => data.moduleName === ModuleNames.projectInfo);
  36. if (projectInfoModule) {
  37. me._project.projectInfo = projectInfoModule.data;
  38. OVER_HEIGHT.init(me._project.projectInfo.property.overHeight);
  39. }
  40. result.forEach(function(item){
  41. if (item.moduleName !== ModuleNames.projectInfo) {
  42. if (me.modules[item.moduleName]){
  43. me.modules[item.moduleName].loadData(item.data, isInit);
  44. } else if (item.moduleName === me.projCounter) {
  45. counter = item.data;
  46. } else if (item.moduleName === me.projSetting) {
  47. me._project.projSetting = item.data;
  48. me._project.projSetting.moduleName = me.projSetting;
  49. } else if(item.moduleName === ModuleNames.projectGLJ){
  50. me._project.projectGLJ.loadToCache(item.data);
  51. }
  52. }
  53. });
  54. for (module in counter) {
  55. if (me.modules[module]) {
  56. me.modules[module].setMaxID(counter[module]);
  57. }
  58. }
  59. if (isInit) {
  60. projectInfoObj.showProjectInfo(me._project.projectInfo);
  61. }
  62. me._project.property = me._project.projectInfo.property;
  63. me._project.loadMainTree();
  64. //me.test(result[0].data[0]);
  65. if (callback) {
  66. callback(0);
  67. }
  68. };
  69. tools.eachItem=function(item){
  70. if (me.modules[item.moduleName]){
  71. me.modules[item.moduleName].doAfterUpdate(item.err, item.data);
  72. }
  73. };
  74. /*tools.test = function(data){
  75. me._project.beginUpdate('修改名称');
  76. data.name = 'test';
  77. data['updateType'] = 'ut_update';
  78. me._project.push(ModuleNames.bills, [data]);
  79. me._project.endUpdate();
  80. };*/
  81. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  82. var project = function () {
  83. tools._project = this;
  84. this.mainTree = cacheTree.createNew(this);
  85. this.Bills = Bills.createNew(this);
  86. this.Ration = Ration.createNew(this);
  87. this.GLJ = GLJ.createNew(this);
  88. this.ration_glj = ration_glj.createNew(this);
  89. this.ration_coe = ration_coe.createNew(this);
  90. this.ration_ass = ration_ass.createNew(this);
  91. this.ration_installation = ration_installation.createNew(this);
  92. this.ration_template = ration_template.createNew(this);
  93. this.quantity_detail = quantity_detail.createNew(this);
  94. this.installation_fee = installation_fee.createNew(this);
  95. this.FeeRate = FeeRate.createNew(this);
  96. // this.VolumePrice = VolumePrice.createNew(this);
  97. this.projectGLJ = new ProjectGLJ();
  98. // this.projectGLJ.loadData();
  99. this.composition = new Composition();
  100. this.composition.loadData();
  101. this.labourCoe = new LabourCoe(this);
  102. this.calcProgram = new CalcProgram(this);
  103. this.evaluate_list = new EvaluateList(this);
  104. this.bid_evaluation_list = new BidEvaluationList(this);
  105. this.contractor_list = new ContractorList(this);
  106. this.equipment_purchase = new EquipmentPurchase(this);
  107. this.calcBase = calcBase;
  108. // this.masterField = {ration: 'billsItemID', volumePrice: 'billsItemID'};
  109. this.masterField = {ration: 'billsItemID'};
  110. };
  111. // prototype用于定义public方法
  112. project.prototype.modify = function (modifyDatas, callback) {
  113. // To Do
  114. };
  115. // prototype用于定义public方法
  116. project.prototype.ID = function () {
  117. return tools._ID;
  118. };
  119. project.prototype.projCounter = function () {
  120. return tools.projCounter;
  121. };
  122. project.prototype.getDecimal = function (fullName) {
  123. let names = fullName.split('.'), decimal = this.Decimal;
  124. for (let name of names) {
  125. if (decimal[name]) {
  126. decimal = decimal[name];
  127. } else {
  128. return null;
  129. }
  130. }
  131. if (Object.prototype.toString.apply(decimal) === '[object Number]') {
  132. return decimal;
  133. } else {
  134. return null;
  135. }
  136. };
  137. project.prototype.loadMainTree = function () {
  138. var that = this;
  139. let loadRationGLJNode = function (cacheNode) {
  140. var newNode, bj = that.ration_glj.getMainAndEquGLJ(cacheNode.source.ID), i;
  141. for(i=0;i<bj.length;i++){
  142. that.ration_glj.transferToNodeData(bj[i]);
  143. newNode = that.mainTree.addNode(cacheNode, null, bj[i].ID);
  144. newNode.source = bj[i];
  145. newNode.sourceType = that.ration_glj.getSourceType();
  146. newNode.data = bj[i];
  147. }
  148. };
  149. var loadRationNode = function (rations, cacheNode) {
  150. var newNode, br = that.Ration.getBillsSortRation(cacheNode.source.getID()), i;
  151. for (i = 0; i < br.length; i++) {
  152. newNode = that.mainTree.addNode(cacheNode, null, br[i].ID);
  153. if(br[i].type==rationType.gljRation){
  154. br[i]= that.ration_glj.combineRationAndGLJ(br[i]);
  155. }
  156. newNode.source = br[i];
  157. newNode.sourceType = that.Ration.getSourceType();
  158. newNode.data = br[i];
  159. if(projectObj.project.projectInfo.property.displaySetting !== undefined &&
  160. projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial==true){
  161. loadRationGLJNode(newNode);
  162. }
  163. }
  164. };
  165. /* let loadVolumePriceNode = function (cacheNode) {
  166. let newNode = null, bv = that.VolumePrice.getBillsSortVolumePrice(cacheNode.source.getID());
  167. for (let v of bv) {
  168. newNode = that.mainTree.addNode(cacheNode);
  169. newNode.source = v;
  170. newNode.sourceType = that.VolumePrice.getSourceType();
  171. newNode.data = v;
  172. }
  173. };*/
  174. var loadIdTreeNode = function (nodes, parent) {
  175. var newNode, i;
  176. for (i = 0; i < nodes.length; i++) {
  177. newNode = that.mainTree.addNode(parent, null, nodes[i].data.ID);
  178. newNode.source = nodes[i];
  179. newNode.sourceType = that.Bills.getSourceType();
  180. newNode.data = nodes[i].data;
  181. that.FeeRate.loadFeeRateToBill(newNode);
  182. if (nodes[i].children.length === 0) {
  183. loadRationNode(that.Ration.datas, newNode);
  184. // loadVolumePriceNode(newNode);
  185. } else {
  186. loadIdTreeNode(nodes[i].children, newNode);
  187. }
  188. }
  189. };
  190. loadIdTreeNode(this.Bills.tree.roots, null);
  191. this.mainTree.sortTreeItems();
  192. this.mainTree.selected = this.mainTree.firstNode();
  193. };
  194. project.prototype.getParentTarget = function (node, targetField, targetValue) {
  195. var parent = node;
  196. while (parent && parent[targetField] !== targetValue) {
  197. parent = parent.parent;
  198. }
  199. return parent;
  200. };
  201. // 提供给各模块调用的统一从后台获取数据的方法
  202. /*project.prototype.pullData = function (url, data, successCallback, errorCallback) {
  203. $.ajax({
  204. type:"POST",
  205. url: url,
  206. data: {'data': JSON.stringify(data)},
  207. dataType: 'json',
  208. cache: false,
  209. timeout: 50000,
  210. success: function(result){
  211. successCallback(result);
  212. },
  213. error: function(jqXHR, textStatus, errorThrown){
  214. alert('error ' + textStatus + " " + errorThrown);
  215. errorCallback();
  216. }
  217. });
  218. };*/
  219. // 所有模块在此从后台获取数据
  220. project.prototype.loadDatas = function (callback){
  221. $.ajax({
  222. type: "POST",
  223. url: '/project/getData',
  224. data: {'data': JSON.stringify({
  225. "project_id": tools._ID,
  226. "user_id": tools._userID
  227. })},
  228. dataType: 'json',
  229. cache: false,
  230. timeout: 50000,
  231. success: function (result) {
  232. if (!result.error) {
  233. const isInit = true;
  234. tools.doAfterLoad(result.data, isInit, callback);
  235. // for test calc
  236. //tools.doAfterLoad([{moduleName: 'bills', data: BillsData}, {'moduleName': 'ration', data: DrawingData}], callback);
  237. } else {
  238. alert('error: ' + result.message);
  239. callback(result.error);
  240. }
  241. },
  242. error: function(jqXHR, textStatus, errorThrown){
  243. alert('error ' + textStatus + " " + errorThrown);
  244. }
  245. });
  246. };
  247. project.prototype.loadDataSync = async function () {
  248. const data = await ajaxPost('/project/getDataForInterface', {user_id: tools._userID, project_id: tools._ID});
  249. if (data) {
  250. const isInit = false;
  251. tools.doAfterLoad(data, isInit);
  252. }
  253. };
  254. project.prototype.beginUpdate = function(operation){
  255. if (tools.updateLock === 0){
  256. tools.operation = operation
  257. }
  258. tools.updateLock += 1;
  259. };
  260. project.prototype.endUpdate = function(){
  261. if (tools.updateLock === 0){
  262. throw "project can not endUpdate before beginUpdate";
  263. }
  264. tools.updateLock -= 1;
  265. if (tools.updateLock === 0) {
  266. $.ajax({
  267. type: "POST",
  268. url: '/project/save',
  269. data: {'data': JSON.stringify({
  270. "project_id": tools._ID,
  271. "user_id": tools._userID,
  272. "date": new Date,
  273. "operation": tools.operation,
  274. "update_data": tools.updateData
  275. })},
  276. dataType: 'json',
  277. cache: false,
  278. timeout: 50000,
  279. success: function (result) {
  280. if (!result.error) {
  281. tools.doAfterUpdate(result.data);
  282. } else {
  283. alert('error: ' + result.message);
  284. }
  285. $.bootstrapLoading.end();
  286. },
  287. error: function(jqXHR, textStatus, errorThrown){
  288. alert('error ' + textStatus + " " + errorThrown);
  289. $.bootstrapLoading.end();
  290. }
  291. });
  292. tools.updateData = [];
  293. tools.operation = "";
  294. }
  295. };
  296. project.prototype.push = function(moduleName, data){
  297. if (tools.updateLock === 0){
  298. throw "project can not push data before beginUpdate";
  299. }
  300. var moduleData = {
  301. moduleName: moduleName,
  302. data: data
  303. };
  304. tools.updateData.push(moduleData);
  305. };
  306. project.prototype.pushNow = function (operation, moduleName, data) {
  307. var that = this;
  308. this.beginUpdate(operation);
  309. if (Object.prototype.toString.apply(moduleName) === "[object Array]" && Object.prototype.toString.apply(data) === "[object Array]") {
  310. moduleName.forEach(function (name, index) {
  311. if(name != 'projCounter'){
  312. that.push(moduleName[index], data[index]);
  313. }
  314. });
  315. } else {
  316. this.push(moduleName, data);
  317. }
  318. this.endUpdate();
  319. };
  320. project.prototype.registerModule = function(moduleName, obj){
  321. if (!tools.modules.hasOwnProperty(moduleName)){
  322. tools.modules[moduleName] = obj;
  323. }
  324. };
  325. project.prototype.markUpdateProject = function (data,type,callback) {
  326. $.bootstrapLoading.start()
  327. CommonAjax.post("/project/markUpdateProject",{updateInfo:data,type:type},function(){
  328. if(callback) callback();
  329. $.bootstrapLoading.end()
  330. });
  331. };
  332. project.prototype.saveProperty = function (propertyName, propertyValue) {
  333. CommonAjax.post("/project/saveProperty", {projectID: this.ID(), propertyName: propertyName, propertyValue: propertyValue});
  334. };
  335. project.prototype.projectMarkChecking = function () {
  336. let me = this;
  337. let changeMark = projectObj.project.projectInfo.changeMark;
  338. if(changeMark&&changeMark!=''){
  339. this.Bills.getEngineeringCostNode(projectObj.mainController).changed = true;
  340. this.calcProgram.calcAllNodesAndSave();
  341. CommonAjax.post("/project/removeProjectMark",{projectID:me.ID()},function (data) {
  342. delete projectObj.project.projectInfo.changeMark;
  343. if(socket.connected == true){//如果这时候socket已经连接成功,则发送删除标记广播
  344. socket.emit('removeProjectMark',{projectID:me.ID(),userID:userID});
  345. }else {//如果还没连接成功,则放入消息对象缓存,等socket连接成功后发送
  346. socketObject.messages.push({message:'removeProjectMark',data:{projectID:me.ID(),userID:userID}});
  347. }
  348. });
  349. }
  350. };
  351. project.prototype.updateLockBills = function (value,callback) {
  352. let mixDatas = {
  353. projectID: projectObj.project.ID(),
  354. updateType: 'update',
  355. properties: {
  356. "property.lockBills":value
  357. },
  358. labourCoes: {},
  359. rations: [],
  360. bills: []
  361. };
  362. $.bootstrapLoading.start();
  363. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  364. projectObj.project.projectInfo.property.lockBills = value;
  365. if(callback){
  366. callback();
  367. }
  368. $.bootstrapLoading.end();
  369. });
  370. };
  371. //返回清单是否被锁定
  372. project.prototype.isBillsLocked =function(){
  373. if(projectObj.project.projectInfo.property.lockBills == true){
  374. return true;
  375. }
  376. return false;
  377. };
  378. //清单是否属于锁定范围(分部分项、措施项目)
  379. project.prototype.withinBillsLocked = function (node) {
  380. const lockedFixFlag = [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE];
  381. while(node){
  382. if(!node.parent){
  383. if(node.data.flagsIndex && node.data.flagsIndex.fixed && lockedFixFlag.includes(node.data.flagsIndex.fixed.flag)){
  384. return true;
  385. }
  386. else {
  387. return false;
  388. }
  389. }
  390. node = node.parent;
  391. }
  392. return true;
  393. };
  394. project.prototype.updateProjectProperty = function(datas,field,callback){
  395. let pfield = "property."+field;
  396. let tem ={
  397. type:'project',
  398. data:{ID:projectObj.project.ID()}
  399. };
  400. tem.data[pfield] = datas;
  401. projectObj.project.updateNodes([tem],function () {
  402. projectObj.project.property[field] = datas;
  403. if(callback) callback();
  404. })
  405. };
  406. project.prototype.updateCasCadeBills = function(node,newval,fieldName,needSetParent = true){
  407. let datas = [];
  408. let data = {
  409. type:node.sourceType,
  410. data:{ID:node.data.ID}
  411. };
  412. setData(data.data,newval,fieldName, node);
  413. datas.push(data);
  414. setChildren(node,newval,datas);//同步设置所有子项
  415. if(needSetParent) setParent(node,newval,datas);//设置父节点
  416. $.bootstrapLoading.start();
  417. this.updateNodes(datas,function () {
  418. let nodes = [];
  419. for(let d of datas){
  420. let node = projectObj.project.mainTree.findNode(d.data.ID);
  421. if(node){
  422. for(let key in d.data){
  423. if(key == 'ID') continue;
  424. node.data[key] = d.data[key];
  425. }
  426. nodes.push(node)
  427. }
  428. }
  429. projectObj.mainController.refreshTreeNode(nodes);
  430. //取消锁定,则自动重新计算。
  431. if(fieldName == "lockUnitPrice" && newval == false) projectObj.project.calcProgram.calcAllNodesAndSave();
  432. $.bootstrapLoading.end();
  433. });
  434. function setChildren(pnode,newValue,datas) {//同步设置所有子项
  435. if(pnode.children.length > 0 && pnode.children[0].sourceType == ModuleNames.bills){//设置子项不包括定额
  436. for(let c of pnode.children){
  437. let data = {
  438. type:c.sourceType,
  439. data:{ID:c.data.ID}
  440. };
  441. //有基数计算的子项值清空
  442. let val = fieldName == "lockUnitPrice" && c.data.calcBase && c.data.calcBase != ""?null:newval;
  443. setData(data.data,val,fieldName, c);
  444. datas.push(data);
  445. setChildren(c,newValue,datas)
  446. }
  447. }
  448. }
  449. function setParent(cnode,newValue,datas) {
  450. let diferrent = false;
  451. if(cnode.parent && !projectObj.project.Bills.isMeasureNode(cnode.parent)){//排除措施项目节点
  452. for(b of cnode.parent.children){
  453. if(b == cnode) continue
  454. if(b.data[fieldName]!== newValue){//有兄弟节点的值和本节点不一样,则父节点设置为null
  455. diferrent = true;
  456. break;
  457. }
  458. }
  459. let pvalue = diferrent === true?null:newValue;
  460. let data = {
  461. type:cnode.parent.sourceType,
  462. data:{ID:cnode.parent.data.ID}
  463. };
  464. setData(data.data,pvalue,fieldName, cnode.parent);
  465. datas.push(data);
  466. setParent(cnode.parent,pvalue,datas);
  467. }
  468. }
  469. function setData(data,avalue,fieldName, node) {
  470. data[fieldName] = avalue;
  471. // 二次修改项目属性上下限设置,前端的最高、最低限价不重算,要去掉输出限价列的√,再重新勾选才计算。因此输出最高限价、输出限价时,需要给节点的maxPrice、minPrice设置一个算好的值
  472. if (['outPutLimitPrice', 'outPutMaxPrice'].includes(fieldName)) {
  473. if (avalue) {
  474. const unitFee = node.data && node.data.feesIndex && node.data.feesIndex.common && node.data.feesIndex.common.unitFee || 0;
  475. const maxPriceRate = projectObj.project.property.maxPriceRate || 0;
  476. data.maxPrice = scMathUtil.roundForObj(unitFee * (1 + maxPriceRate * 0.01), decimalObj.bills.unitPrice) || null;
  477. const minPriceRate = projectObj.project.property.minPriceRate || 0;
  478. data.minPrice = scMathUtil.roundForObj(unitFee * (1 - minPriceRate * 0.01), decimalObj.bills.unitPrice) || null;
  479. } else {
  480. data.maxPrice = null;
  481. data.minPrice = null;
  482. }
  483. }
  484. }
  485. };
  486. project.prototype.updateNodesAndRefresh=function (datas,callback) {
  487. let me = this;
  488. this.updateNodes(datas,function () {
  489. let nodes = me.updateNodesCache(datas);
  490. if(callback) callback(nodes);
  491. })
  492. };
  493. project.prototype.syncUpdateNodesAndRefresh =async function (datas) {
  494. let me = this;
  495. return new Promise(function (resolve, reject) {
  496. me.updateNodes(datas,function (result) {
  497. let nodes = me.updateNodesCache(result);
  498. projectObj.mainController.refreshTreeNode(nodes);
  499. resolve(nodes);
  500. });
  501. });
  502. };
  503. project.prototype.updateNodes = function (datas,callback) {
  504. /* let datas = [
  505. {
  506. type:'ration',
  507. data:{
  508. projectID:1605,
  509. ID:"7b962fb0-1131-11e8-b3da-af725dadd7ae",
  510. name:'testRation'
  511. }
  512. },
  513. {
  514. type:'bills',
  515. data:{
  516. projectID:1605,
  517. ID:"af9f0081-1127-11e8-99a8-2fc02230b6e7",
  518. name:'安全文明施工专项费用123'
  519. }
  520. }
  521. ]*/
  522. $.bootstrapLoading.start();
  523. CommonAjax.post("/project/updateNodes",datas,function (data) {
  524. if(callback){
  525. callback(data);
  526. $.bootstrapLoading.end();
  527. }
  528. })
  529. };
  530. project.prototype.updateParentNode = function(node,parentID,addNodeDatas){
  531. addNodeDatas.push({type:node.sourceType,data:node.data,parentID:parentID});
  532. for(let c of node.children){
  533. this.updateParentNode(c,node.getID(),addNodeDatas);
  534. }
  535. };
  536. project.prototype.updateNodesCache =function (datas) {
  537. let refreshNode = [];
  538. let reclacQuantity = false;
  539. let deleteNode=[],addNodeDatas=[];
  540. // let changeParentIDMap = {}; 确定刷新无错后删除
  541. for(let d of datas){
  542. let temObj = null;
  543. if(d.type == ModuleNames.bills || d.type == ModuleNames.ration){//如果是树节点类型,直接取树节点更新
  544. if(d.action =="add"){
  545. if(d.type == ModuleNames.ration) this.Ration.datas.push(d.data);
  546. reclacQuantity = true;
  547. addNodeDatas.push(d);
  548. }else {
  549. let temNode = this.mainTree.getNodeByID(d.data.ID);
  550. if(temNode){
  551. if(d.action =="delete"){
  552. if(d.type == ModuleNames.ration){
  553. _.remove(this.Ration.datas,{'ID':d.data.ID});
  554. this.Ration.deleteSubListOfRation({ID:d.data.ID});
  555. reclacQuantity = true;
  556. }
  557. deleteNode.push(temNode);//对于删除节点,统一不加入refreshNode中,由外部加入,避免重复
  558. }else {
  559. temObj = temNode.data;
  560. if(gljUtil.isDef(d.data.quantity))reclacQuantity = true;
  561. refreshNode.push(temNode);
  562. if(d.data.ParentID){//更新了父节点-相当于删了再添加
  563. //changeParentIDMap[temNode.data.ParentID] = true;
  564. deleteNode.push(temNode);
  565. this.updateParentNode(temNode,d.data.ParentID,addNodeDatas);
  566. }
  567. }
  568. }
  569. }
  570. }else if(d.type == ModuleNames.project){
  571. temObj = d.isInfo?this.projectInfo:this;
  572. }else if (d.type == ModuleNames.ration_glj && d.action == "add"){
  573. this[d.type].datas.push(d.data);
  574. if(d.projectGLJ) this.projectGLJ.loadNewProjectGLJToCache(d.projectGLJ);
  575. } else {//其它类型,更新datas
  576. temObj = _.find(this[d.type].datas,{"ID":d.data.ID});
  577. }
  578. if(temObj){
  579. for(let key in d.data){
  580. if(key == 'ID' || key == 'id'){
  581. continue;
  582. }
  583. this.setValue(temObj,key,d.data[key])
  584. }
  585. }
  586. }
  587. //对树节点的操作并删除、添加清单、删除添加定额、删除对应的定额工料机缓存
  588. TREE_SHEET_HELPER.massOperationSheet(projectObj.mainController.sheet, function () {
  589. let rationsDatas=[];
  590. let billsDatas=[];
  591. for(let a of addNodeDatas){
  592. if(a.type == ModuleNames.bills) billsDatas.push(a);
  593. if(a.type == ModuleNames.ration) rationsDatas.push(a);
  594. }
  595. deleteTreeNodes(deleteNode);
  596. addNewNodes(billsDatas,refreshNode);
  597. addNewNodes(rationsDatas,refreshNode);
  598. });
  599. /* for(let pID in changeParentIDMap){
  600. let pnode = this.mainTree.getNodeByID(pID);
  601. getNextRefreshNode(pnode,refreshNode);
  602. } */
  603. if(reclacQuantity) this.projectGLJ.calcQuantity();
  604. return refreshNode;
  605. /* function getNextRefreshNode(node,refreshNode){
  606. if(node.nextSibling){
  607. refreshNode.push(node.nextSibling)
  608. getNextRefreshNode(node.nextSibling,refreshNode)
  609. }
  610. }; */
  611. function deleteTreeNodes(deleteNodes) {
  612. let controller = projectObj.mainController, project = projectObj.project;
  613. let Bill = project.Bills, Ration = project.Ration;
  614. for(let rd of deleteNodes){
  615. controller.sheet.deleteRows(rd.serialNo(),rd.posterityCount() + 1);
  616. controller.tree.delete(rd);
  617. if(rd.sourceType == Bill.getSourceType()) Bill.tree.delete(rd.source);
  618. }
  619. }
  620. function addNewNodes(newDatas,refreshNode) {
  621. let controller = projectObj.mainController;
  622. let Bill = projectObj.project.Bills;
  623. let newAddNode = [];
  624. for(let nr of newDatas){
  625. let nextID = -1;
  626. let parentID = nr.parentID || (nr.data && nr.data.ParentID || -1);
  627. let preNode = projectObj.project.mainTree.getNodeByID(nr.preSiblingID);
  628. if(preNode) nextID = preNode.getNextSiblingID();
  629. let newNode = projectObj.project.mainTree.insert(parentID, nextID, nr.data.ID);
  630. if(nr.type == ModuleNames.bills){
  631. let newSource = Bill.tree.insertByData(nr.data, parentID, nextID, true);
  632. newNode.source = newSource;
  633. }else {
  634. newNode.source = nr.data;
  635. }
  636. newNode.sourceType = nr.type;
  637. newNode.data = nr.data;
  638. controller.sheet.addRows(newNode.serialNo(), 1);
  639. controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  640. newAddNode.push(newNode);
  641. refreshNode.push(newNode);
  642. }
  643. TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
  644. }
  645. };
  646. project.prototype.setValue=function (obj,key,value) {
  647. let keyArray = key.split('.');
  648. t_set(obj,value,keyArray,0);
  649. function t_set(obj,value,arr,index) {
  650. let nextIndex = index + 1;
  651. let tkey = arr[index];
  652. if(nextIndex < arr.length){
  653. if(obj[tkey]==undefined){
  654. obj[tkey] = {};
  655. }
  656. t_set(obj[tkey],value,arr,nextIndex)
  657. }else if(nextIndex == arr.length){
  658. obj[tkey] = value;
  659. }
  660. }
  661. }
  662. project.prototype.updateEvalproject = function (evalProject,data,callback){
  663. let programID = null;
  664. if(evalProject ==1){//当打勾估价项目选项后,该定额取费专业读取计算程序名称为“估价项目”的计算程序,且为只读状态
  665. programID = this.calcProgram.compiledTemplateMaps["估价项目"];
  666. if(callback) callback(programID);
  667. }else {//如果evalProject==0,则是去掉勾选估价项目选项,需要获取定额默认的取费专业。
  668. let libID = data.from == 'cpt'?"compleRationLib":data.libID;
  669. let query = {code:data.code,projectID:data.projectID,libID:libID};
  670. CommonAjax.post("/ration/getDefaultProgramID",query,function (result) {
  671. if(callback) callback(result);
  672. })
  673. }
  674. };
  675. //判断项目是否安装工程
  676. project.prototype.isInstall = function () {
  677. return projectObj.project.projectInfo.property.isInstall?true:false;//如果是undefinded 就也返回false
  678. };
  679. // 判断项目能否使用超高降效相关功能 (是否含有超高降效库数据)
  680. project.prototype.isOverHeightProject = function () {
  681. const overHeight = projectObj.project.projectInfo.property.overHeight;
  682. return Array.isArray(overHeight) && overHeight.length;
  683. }
  684. /* project.prototype.setBillsCalcMode = function (calcMode) {
  685. this.property.billsCalcMode = calcMode;
  686. this.initCalcFields();
  687. };*/
  688. /*project.prototype.initCalcFields = function () {
  689. // let settingConst = this.projSetting.settingConst;
  690. if (this.calcFields) {
  691. for (let field of this.calcFields) {
  692. // unitFeeCalcFlag
  693. if (field.type === 'zangu') {
  694. field.unitFeeFlag = converseUnitFeeFlag;
  695. } else {
  696. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationContent) {
  697. if (this.property.billsCalcMode === leafBillGetFeeType.rationContent) {
  698. field.unitFeeFlag = rationContentUnitFeeFlag;
  699. // } else if ( this.projSetting.billsCalcMode === settingConst.billsCalcMode.billsPrice) {
  700. } else if ( this.property.billsCalcMode === leafBillGetFeeType.billsPrice) {
  701. field.unitFeeFlag = billsPriceUnitFeeFlag;
  702. } else {
  703. field.unitFeeFlag = averageQtyUnitFeeFlag;
  704. }
  705. }
  706. // totalFeeCalcFlag
  707. if (field.type === 'common') {
  708. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationPriceConverse) {
  709. if (this.property.billsCalcMode === leafBillGetFeeType.rationPriceConverse) {
  710. field.totalFeeFlag = sumTotalFeeFlag;
  711. } else {
  712. field.totalFeeFlag = totalFeeFlag;
  713. }
  714. } else {
  715. field.totalFeeFlag = sumTotalFeeFlag;
  716. }
  717. }
  718. }
  719. }*/
  720. return new project();
  721. }
  722. };