project.js 31 KB

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