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.calcBase = calcBase;
  107. // this.masterField = {ration: 'billsItemID', volumePrice: 'billsItemID'};
  108. this.masterField = {ration: 'billsItemID'};
  109. };
  110. // prototype用于定义public方法
  111. project.prototype.modify = function (modifyDatas, callback) {
  112. // To Do
  113. };
  114. // prototype用于定义public方法
  115. project.prototype.ID = function () {
  116. return tools._ID;
  117. };
  118. project.prototype.projCounter = function () {
  119. return tools.projCounter;
  120. };
  121. project.prototype.getDecimal = function (fullName) {
  122. let names = fullName.split('.'), decimal = this.Decimal;
  123. for (let name of names) {
  124. if (decimal[name]) {
  125. decimal = decimal[name];
  126. } else {
  127. return null;
  128. }
  129. }
  130. if (Object.prototype.toString.apply(decimal) === '[object Number]') {
  131. return decimal;
  132. } else {
  133. return null;
  134. }
  135. };
  136. project.prototype.loadMainTree = function () {
  137. var that = this;
  138. let loadRationGLJNode = function (cacheNode) {
  139. var newNode, bj = that.ration_glj.getMainAndEquGLJ(cacheNode.source.ID), i;
  140. for(i=0;i<bj.length;i++){
  141. that.ration_glj.transferToNodeData(bj[i]);
  142. newNode = that.mainTree.addNode(cacheNode, null, bj[i].ID);
  143. newNode.source = bj[i];
  144. newNode.sourceType = that.ration_glj.getSourceType();
  145. newNode.data = bj[i];
  146. }
  147. };
  148. var loadRationNode = function (rations, cacheNode) {
  149. var newNode, br = that.Ration.getBillsSortRation(cacheNode.source.getID()), i;
  150. for (i = 0; i < br.length; i++) {
  151. newNode = that.mainTree.addNode(cacheNode, null, br[i].ID);
  152. if(br[i].type==rationType.gljRation){
  153. br[i]= that.ration_glj.combineRationAndGLJ(br[i]);
  154. }
  155. newNode.source = br[i];
  156. newNode.sourceType = that.Ration.getSourceType();
  157. newNode.data = br[i];
  158. if(projectObj.project.projectInfo.property.displaySetting !== undefined &&
  159. projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial==true){
  160. loadRationGLJNode(newNode);
  161. }
  162. }
  163. };
  164. /* let loadVolumePriceNode = function (cacheNode) {
  165. let newNode = null, bv = that.VolumePrice.getBillsSortVolumePrice(cacheNode.source.getID());
  166. for (let v of bv) {
  167. newNode = that.mainTree.addNode(cacheNode);
  168. newNode.source = v;
  169. newNode.sourceType = that.VolumePrice.getSourceType();
  170. newNode.data = v;
  171. }
  172. };*/
  173. var loadIdTreeNode = function (nodes, parent) {
  174. var newNode, i;
  175. for (i = 0; i < nodes.length; i++) {
  176. newNode = that.mainTree.addNode(parent, null, nodes[i].data.ID);
  177. newNode.source = nodes[i];
  178. newNode.sourceType = that.Bills.getSourceType();
  179. newNode.data = nodes[i].data;
  180. that.FeeRate.loadFeeRateToBill(newNode);
  181. if (nodes[i].children.length === 0) {
  182. loadRationNode(that.Ration.datas, newNode);
  183. // loadVolumePriceNode(newNode);
  184. } else {
  185. loadIdTreeNode(nodes[i].children, newNode);
  186. }
  187. }
  188. };
  189. loadIdTreeNode(this.Bills.tree.roots, null);
  190. this.mainTree.sortTreeItems();
  191. this.mainTree.selected = this.mainTree.firstNode();
  192. };
  193. project.prototype.getParentTarget = function (node, targetField, targetValue) {
  194. var parent = node;
  195. while (parent && parent[targetField] !== targetValue) {
  196. parent = parent.parent;
  197. }
  198. return parent;
  199. };
  200. // 提供给各模块调用的统一从后台获取数据的方法
  201. /*project.prototype.pullData = function (url, data, successCallback, errorCallback) {
  202. $.ajax({
  203. type:"POST",
  204. url: url,
  205. data: {'data': JSON.stringify(data)},
  206. dataType: 'json',
  207. cache: false,
  208. timeout: 50000,
  209. success: function(result){
  210. successCallback(result);
  211. },
  212. error: function(jqXHR, textStatus, errorThrown){
  213. alert('error ' + textStatus + " " + errorThrown);
  214. errorCallback();
  215. }
  216. });
  217. };*/
  218. // 所有模块在此从后台获取数据
  219. project.prototype.loadDatas = function (callback){
  220. $.ajax({
  221. type: "POST",
  222. url: '/project/getData',
  223. data: {'data': JSON.stringify({
  224. "project_id": tools._ID,
  225. "user_id": tools._userID
  226. })},
  227. dataType: 'json',
  228. cache: false,
  229. timeout: 50000,
  230. success: function (result) {
  231. if (!result.error) {
  232. const isInit = true;
  233. tools.doAfterLoad(result.data, isInit, callback);
  234. // for test calc
  235. //tools.doAfterLoad([{moduleName: 'bills', data: BillsData}, {'moduleName': 'ration', data: DrawingData}], callback);
  236. } else {
  237. alert('error: ' + result.message);
  238. callback(result.error);
  239. }
  240. },
  241. error: function(jqXHR, textStatus, errorThrown){
  242. alert('error ' + textStatus + " " + errorThrown);
  243. }
  244. });
  245. };
  246. project.prototype.loadDataSync = async function () {
  247. const data = await ajaxPost('/project/getDataForInterface', {user_id: tools._userID, project_id: tools._ID});
  248. if (data) {
  249. const isInit = false;
  250. tools.doAfterLoad(data, isInit);
  251. }
  252. };
  253. project.prototype.beginUpdate = function(operation){
  254. if (tools.updateLock === 0){
  255. tools.operation = operation
  256. }
  257. tools.updateLock += 1;
  258. };
  259. project.prototype.endUpdate = function(){
  260. if (tools.updateLock === 0){
  261. throw "project can not endUpdate before beginUpdate";
  262. }
  263. tools.updateLock -= 1;
  264. if (tools.updateLock === 0) {
  265. $.ajax({
  266. type: "POST",
  267. url: '/project/save',
  268. data: {'data': JSON.stringify({
  269. "project_id": tools._ID,
  270. "user_id": tools._userID,
  271. "date": new Date,
  272. "operation": tools.operation,
  273. "update_data": tools.updateData
  274. })},
  275. dataType: 'json',
  276. cache: false,
  277. timeout: 50000,
  278. success: function (result) {
  279. if (!result.error) {
  280. tools.doAfterUpdate(result.data);
  281. } else {
  282. alert('error: ' + result.message);
  283. }
  284. $.bootstrapLoading.end();
  285. },
  286. error: function(jqXHR, textStatus, errorThrown){
  287. alert('error ' + textStatus + " " + errorThrown);
  288. $.bootstrapLoading.end();
  289. }
  290. });
  291. tools.updateData = [];
  292. tools.operation = "";
  293. }
  294. };
  295. project.prototype.push = function(moduleName, data){
  296. if (tools.updateLock === 0){
  297. throw "project can not push data before beginUpdate";
  298. }
  299. var moduleData = {
  300. moduleName: moduleName,
  301. data: data
  302. };
  303. tools.updateData.push(moduleData);
  304. };
  305. project.prototype.pushNow = function (operation, moduleName, data) {
  306. var that = this;
  307. this.beginUpdate(operation);
  308. if (Object.prototype.toString.apply(moduleName) === "[object Array]" && Object.prototype.toString.apply(data) === "[object Array]") {
  309. moduleName.forEach(function (name, index) {
  310. if(name != 'projCounter'){
  311. that.push(moduleName[index], data[index]);
  312. }
  313. });
  314. } else {
  315. this.push(moduleName, data);
  316. }
  317. this.endUpdate();
  318. };
  319. project.prototype.registerModule = function(moduleName, obj){
  320. if (!tools.modules.hasOwnProperty(moduleName)){
  321. tools.modules[moduleName] = obj;
  322. }
  323. };
  324. project.prototype.markUpdateProject = function (data,type,callback) {
  325. $.bootstrapLoading.start()
  326. CommonAjax.post("/project/markUpdateProject",{updateInfo:data,type:type},function(){
  327. if(callback) callback();
  328. $.bootstrapLoading.end()
  329. });
  330. };
  331. project.prototype.saveProperty = function (propertyName, propertyValue) {
  332. CommonAjax.post("/project/saveProperty", {projectID: this.ID(), propertyName: propertyName, propertyValue: propertyValue});
  333. };
  334. project.prototype.projectMarkChecking = function () {
  335. let me = this;
  336. let changeMark = projectObj.project.projectInfo.changeMark;
  337. if(changeMark&&changeMark!=''){
  338. this.Bills.getEngineeringCostNode(projectObj.mainController).changed = true;
  339. this.calcProgram.calcAllNodesAndSave();
  340. CommonAjax.post("/project/removeProjectMark",{projectID:me.ID()},function (data) {
  341. delete projectObj.project.projectInfo.changeMark;
  342. if(socket.connected == true){//如果这时候socket已经连接成功,则发送删除标记广播
  343. socket.emit('removeProjectMark',{projectID:me.ID(),userID:userID});
  344. }else {//如果还没连接成功,则放入消息对象缓存,等socket连接成功后发送
  345. socketObject.messages.push({message:'removeProjectMark',data:{projectID:me.ID(),userID:userID}});
  346. }
  347. });
  348. }
  349. };
  350. project.prototype.updateLockBills = function (value,callback) {
  351. let mixDatas = {
  352. projectID: projectObj.project.ID(),
  353. updateType: 'update',
  354. properties: {
  355. "property.lockBills":value
  356. },
  357. labourCoes: {},
  358. rations: [],
  359. bills: []
  360. };
  361. $.bootstrapLoading.start();
  362. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  363. projectObj.project.projectInfo.property.lockBills = value;
  364. if(callback){
  365. callback();
  366. }
  367. $.bootstrapLoading.end();
  368. });
  369. };
  370. //返回清单是否被锁定
  371. project.prototype.isBillsLocked =function(){
  372. if(projectObj.project.projectInfo.property.lockBills == true){
  373. return true;
  374. }
  375. return false;
  376. };
  377. //清单是否属于锁定范围(分部分项、措施项目)
  378. project.prototype.withinBillsLocked = function (node) {
  379. const lockedFixFlag = [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE];
  380. while(node){
  381. if(!node.parent){
  382. if(node.data.flagsIndex && node.data.flagsIndex.fixed && lockedFixFlag.includes(node.data.flagsIndex.fixed.flag)){
  383. return true;
  384. }
  385. else {
  386. return false;
  387. }
  388. }
  389. node = node.parent;
  390. }
  391. return true;
  392. };
  393. project.prototype.updateProjectProperty = function(datas,field,callback){
  394. let pfield = "property."+field;
  395. let tem ={
  396. type:'project',
  397. data:{ID:projectObj.project.ID()}
  398. };
  399. tem.data[pfield] = datas;
  400. projectObj.project.updateNodes([tem],function () {
  401. projectObj.project.property[field] = datas;
  402. if(callback) callback();
  403. })
  404. };
  405. project.prototype.updateCasCadeBills = function(node,newval,fieldName,needSetParent = true){
  406. let datas = [];
  407. let data = {
  408. type:node.sourceType,
  409. data:{ID:node.data.ID}
  410. };
  411. setData(data.data,newval,fieldName, node);
  412. datas.push(data);
  413. setChildren(node,newval,datas);//同步设置所有子项
  414. if(needSetParent) setParent(node,newval,datas);//设置父节点
  415. $.bootstrapLoading.start();
  416. this.updateNodes(datas,function () {
  417. let nodes = [];
  418. for(let d of datas){
  419. let node = projectObj.project.mainTree.findNode(d.data.ID);
  420. if(node){
  421. for(let key in d.data){
  422. if(key == 'ID') continue;
  423. node.data[key] = d.data[key];
  424. }
  425. nodes.push(node)
  426. }
  427. }
  428. projectObj.mainController.refreshTreeNode(nodes);
  429. //取消锁定,则自动重新计算。
  430. if(fieldName == "lockUnitPrice" && newval == false) projectObj.project.calcProgram.calcAllNodesAndSave();
  431. $.bootstrapLoading.end();
  432. });
  433. function setChildren(pnode,newValue,datas) {//同步设置所有子项
  434. if(pnode.children.length > 0 && pnode.children[0].sourceType == ModuleNames.bills){//设置子项不包括定额
  435. for(let c of pnode.children){
  436. let data = {
  437. type:c.sourceType,
  438. data:{ID:c.data.ID}
  439. };
  440. //有基数计算的子项值清空
  441. let val = fieldName == "lockUnitPrice" && c.data.calcBase && c.data.calcBase != ""?null:newval;
  442. setData(data.data,val,fieldName, c);
  443. datas.push(data);
  444. setChildren(c,newValue,datas)
  445. }
  446. }
  447. }
  448. function setParent(cnode,newValue,datas) {
  449. let diferrent = false;
  450. if(cnode.parent && !projectObj.project.Bills.isMeasureNode(cnode.parent)){//排除措施项目节点
  451. for(b of cnode.parent.children){
  452. if(b == cnode) continue
  453. if(b.data[fieldName]!== newValue){//有兄弟节点的值和本节点不一样,则父节点设置为null
  454. diferrent = true;
  455. break;
  456. }
  457. }
  458. let pvalue = diferrent === true?null:newValue;
  459. let data = {
  460. type:cnode.parent.sourceType,
  461. data:{ID:cnode.parent.data.ID}
  462. };
  463. setData(data.data,pvalue,fieldName, cnode.parent);
  464. datas.push(data);
  465. setParent(cnode.parent,pvalue,datas);
  466. }
  467. }
  468. function setData(data,avalue,fieldName, node) {
  469. data[fieldName] = avalue;
  470. // 二次修改项目属性上下限设置,前端的最高、最低限价不重算,要去掉输出限价列的√,再重新勾选才计算。因此输出最高限价、输出限价时,需要给节点的maxPrice、minPrice设置一个算好的值
  471. if (['outPutLimitPrice', 'outPutMaxPrice'].includes(fieldName)) {
  472. if (avalue) {
  473. const unitFee = node.data && node.data.feesIndex && node.data.feesIndex.common && node.data.feesIndex.common.unitFee || 0;
  474. const maxPriceRate = projectObj.project.property.maxPriceRate || 0;
  475. data.maxPrice = scMathUtil.roundForObj(unitFee * (1 + maxPriceRate * 0.01), decimalObj.bills.unitPrice) || null;
  476. const minPriceRate = projectObj.project.property.minPriceRate || 0;
  477. data.minPrice = scMathUtil.roundForObj(unitFee * (1 - minPriceRate * 0.01), decimalObj.bills.unitPrice) || null;
  478. } else {
  479. data.maxPrice = null;
  480. data.minPrice = null;
  481. }
  482. }
  483. }
  484. };
  485. project.prototype.updateNodesAndRefresh=function (datas,callback) {
  486. let me = this;
  487. this.updateNodes(datas,function () {
  488. let nodes = me.updateNodesCache(datas);
  489. if(callback) callback(nodes);
  490. })
  491. };
  492. project.prototype.syncUpdateNodesAndRefresh =async function (datas) {
  493. let me = this;
  494. return new Promise(function (resolve, reject) {
  495. me.updateNodes(datas,function (result) {
  496. let nodes = me.updateNodesCache(result);
  497. projectObj.mainController.refreshTreeNode(nodes);
  498. resolve(nodes);
  499. });
  500. });
  501. };
  502. project.prototype.updateNodes = function (datas,callback) {
  503. /* let datas = [
  504. {
  505. type:'ration',
  506. data:{
  507. projectID:1605,
  508. ID:"7b962fb0-1131-11e8-b3da-af725dadd7ae",
  509. name:'testRation'
  510. }
  511. },
  512. {
  513. type:'bills',
  514. data:{
  515. projectID:1605,
  516. ID:"af9f0081-1127-11e8-99a8-2fc02230b6e7",
  517. name:'安全文明施工专项费用123'
  518. }
  519. }
  520. ]*/
  521. $.bootstrapLoading.start();
  522. CommonAjax.post("/project/updateNodes",datas,function (data) {
  523. if(callback){
  524. callback(data);
  525. $.bootstrapLoading.end();
  526. }
  527. })
  528. };
  529. project.prototype.updateParentNode = function(node,parentID,addNodeDatas){
  530. addNodeDatas.push({type:node.sourceType,data:node.data,parentID:parentID});
  531. for(let c of node.children){
  532. this.updateParentNode(c,node.getID(),addNodeDatas);
  533. }
  534. };
  535. project.prototype.updateNodesCache =function (datas) {
  536. let refreshNode = [];
  537. let reclacQuantity = false;
  538. let deleteNode=[],addNodeDatas=[];
  539. // let changeParentIDMap = {}; 确定刷新无错后删除
  540. for(let d of datas){
  541. let temObj = null;
  542. if(d.type == ModuleNames.bills || d.type == ModuleNames.ration){//如果是树节点类型,直接取树节点更新
  543. if(d.action =="add"){
  544. if(d.type == ModuleNames.ration) this.Ration.datas.push(d.data);
  545. if(d.type == ModuleNames.bills) this.Bills.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. };