project.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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);
  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);
  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);
  464. datas.push(data);
  465. setParent(cnode.parent,pvalue,datas);
  466. }
  467. }
  468. function setData(data,avalue,fieldName) {
  469. data[fieldName] = avalue;
  470. if(fieldName == "outPutMaxPrice") data.maxPrice = null;
  471. }
  472. };
  473. project.prototype.updateNodesAndRefresh=function (datas,callback) {
  474. let me = this;
  475. this.updateNodes(datas,function () {
  476. let nodes = me.updateNodesCache(datas);
  477. if(callback) callback(nodes);
  478. })
  479. };
  480. project.prototype.syncUpdateNodesAndRefresh =async function (datas) {
  481. let me = this;
  482. return new Promise(function (resolve, reject) {
  483. me.updateNodes(datas,function (result) {
  484. let nodes = me.updateNodesCache(result);
  485. projectObj.mainController.refreshTreeNode(nodes);
  486. resolve(nodes);
  487. });
  488. });
  489. };
  490. project.prototype.updateNodes = function (datas,callback) {
  491. /* let datas = [
  492. {
  493. type:'ration',
  494. data:{
  495. projectID:1605,
  496. ID:"7b962fb0-1131-11e8-b3da-af725dadd7ae",
  497. name:'testRation'
  498. }
  499. },
  500. {
  501. type:'bills',
  502. data:{
  503. projectID:1605,
  504. ID:"af9f0081-1127-11e8-99a8-2fc02230b6e7",
  505. name:'安全文明施工专项费用123'
  506. }
  507. }
  508. ]*/
  509. $.bootstrapLoading.start();
  510. CommonAjax.post("/project/updateNodes",datas,function (data) {
  511. if(callback){
  512. callback(data);
  513. $.bootstrapLoading.end();
  514. }
  515. })
  516. };
  517. project.prototype.updateParentNode = function(node,parentID,addNodeDatas){
  518. addNodeDatas.push({type:node.sourceType,data:node.data,parentID:parentID});
  519. for(let c of node.children){
  520. this.updateParentNode(c,node.getID(),addNodeDatas);
  521. }
  522. };
  523. project.prototype.updateNodesCache =function (datas) {
  524. let refreshNode = [];
  525. let reclacQuantity = false;
  526. let deleteNode=[],addNodeDatas=[];
  527. // let changeParentIDMap = {}; 确定刷新无错后删除
  528. for(let d of datas){
  529. let temObj = null;
  530. if(d.type == ModuleNames.bills || d.type == ModuleNames.ration){//如果是树节点类型,直接取树节点更新
  531. if(d.action =="add"){
  532. if(d.type == ModuleNames.ration) this.Ration.datas.push(d.data);
  533. reclacQuantity = true;
  534. addNodeDatas.push(d);
  535. }else {
  536. let temNode = this.mainTree.getNodeByID(d.data.ID);
  537. if(temNode){
  538. if(d.action =="delete"){
  539. if(d.type == ModuleNames.ration){
  540. _.remove(this.Ration.datas,{'ID':d.data.ID});
  541. this.Ration.deleteSubListOfRation({ID:d.data.ID});
  542. reclacQuantity = true;
  543. }
  544. deleteNode.push(temNode);//对于删除节点,统一不加入refreshNode中,由外部加入,避免重复
  545. }else {
  546. temObj = temNode.data;
  547. if(gljUtil.isDef(d.data.quantity))reclacQuantity = true;
  548. refreshNode.push(temNode);
  549. if(d.data.ParentID){//更新了父节点-相当于删了再添加
  550. //changeParentIDMap[temNode.data.ParentID] = true;
  551. deleteNode.push(temNode);
  552. this.updateParentNode(temNode,d.data.ParentID,addNodeDatas);
  553. }
  554. }
  555. }
  556. }
  557. }else if(d.type == ModuleNames.project){
  558. temObj = this;
  559. }else if (d.type == ModuleNames.ration_glj && d.action == "add"){
  560. this[d.type].datas.push(d.data);
  561. if(d.projectGLJ) this.projectGLJ.loadNewProjectGLJToCache(d.projectGLJ);
  562. } else {//其它类型,更新datas
  563. temObj = _.find(this[d.type].datas,{"ID":d.data.ID});
  564. }
  565. if(temObj){
  566. for(let key in d.data){
  567. if(key == 'ID' || key == 'id'){
  568. continue;
  569. }
  570. this.setValue(temObj,key,d.data[key])
  571. }
  572. }
  573. }
  574. //对树节点的操作并删除、添加清单、删除添加定额、删除对应的定额工料机缓存
  575. TREE_SHEET_HELPER.massOperationSheet(projectObj.mainController.sheet, function () {
  576. let rationsDatas=[];
  577. let billsDatas=[];
  578. for(let a of addNodeDatas){
  579. if(a.type == ModuleNames.bills) billsDatas.push(a);
  580. if(a.type == ModuleNames.ration) rationsDatas.push(a);
  581. }
  582. deleteTreeNodes(deleteNode);
  583. addNewNodes(billsDatas,refreshNode);
  584. addNewNodes(rationsDatas,refreshNode);
  585. });
  586. /* for(let pID in changeParentIDMap){
  587. let pnode = this.mainTree.getNodeByID(pID);
  588. getNextRefreshNode(pnode,refreshNode);
  589. } */
  590. if(reclacQuantity) this.projectGLJ.calcQuantity();
  591. return refreshNode;
  592. /* function getNextRefreshNode(node,refreshNode){
  593. if(node.nextSibling){
  594. refreshNode.push(node.nextSibling)
  595. getNextRefreshNode(node.nextSibling,refreshNode)
  596. }
  597. }; */
  598. function deleteTreeNodes(deleteNodes) {
  599. let controller = projectObj.mainController, project = projectObj.project;
  600. let Bill = project.Bills, Ration = project.Ration;
  601. for(let rd of deleteNodes){
  602. controller.sheet.deleteRows(rd.serialNo(),rd.posterityCount() + 1);
  603. controller.tree.delete(rd);
  604. if(rd.sourceType == Bill.getSourceType()) Bill.tree.delete(rd.source);
  605. }
  606. }
  607. function addNewNodes(newDatas,refreshNode) {
  608. let controller = projectObj.mainController;
  609. let Bill = projectObj.project.Bills;
  610. let newAddNode = [];
  611. for(let nr of newDatas){
  612. let nextID = -1;
  613. let parentID = nr.parentID || (nr.data && nr.data.ParentID || -1);
  614. let preNode = projectObj.project.mainTree.getNodeByID(nr.preSiblingID);
  615. if(preNode) nextID = preNode.getNextSiblingID();
  616. let newNode = projectObj.project.mainTree.insert(parentID, nextID, nr.data.ID);
  617. if(nr.type == ModuleNames.bills){
  618. let newSource = Bill.tree.insertByData(nr.data, parentID, nextID, true);
  619. newNode.source = newSource;
  620. }else {
  621. newNode.source = nr.data;
  622. }
  623. newNode.sourceType = nr.type;
  624. newNode.data = nr.data;
  625. controller.sheet.addRows(newNode.serialNo(), 1);
  626. controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  627. newAddNode.push(newNode);
  628. refreshNode.push(newNode);
  629. }
  630. TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
  631. }
  632. };
  633. project.prototype.setValue=function (obj,key,value) {
  634. let keyArray = key.split('.');
  635. t_set(obj,value,keyArray,0);
  636. function t_set(obj,value,arr,index) {
  637. let nextIndex = index + 1;
  638. let tkey = arr[index];
  639. if(nextIndex < arr.length){
  640. if(obj[tkey]==undefined){
  641. obj[tkey] = {};
  642. }
  643. t_set(obj[tkey],value,arr,nextIndex)
  644. }else if(nextIndex == arr.length){
  645. obj[tkey] = value;
  646. }
  647. }
  648. }
  649. project.prototype.updateEvalproject = function (evalProject,data,callback){
  650. let programID = null;
  651. if(evalProject ==1){//当打勾估价项目选项后,该定额取费专业读取计算程序名称为“估价项目”的计算程序,且为只读状态
  652. programID = this.calcProgram.compiledTemplateMaps["估价项目"];
  653. if(callback) callback(programID);
  654. }else {//如果evalProject==0,则是去掉勾选估价项目选项,需要获取定额默认的取费专业。
  655. let libID = data.from == 'cpt'?"compleRationLib":data.libID;
  656. let query = {code:data.code,projectID:data.projectID,libID:libID};
  657. CommonAjax.post("/ration/getDefaultProgramID",query,function (result) {
  658. if(callback) callback(result);
  659. })
  660. }
  661. };
  662. //判断项目是否安装工程
  663. project.prototype.isInstall = function () {
  664. return projectObj.project.projectInfo.property.isInstall?true:false;//如果是undefinded 就也返回false
  665. };
  666. // 判断项目能否使用超高降效相关功能 (是否含有超高降效库数据)
  667. project.prototype.isOverHeightProject = function () {
  668. const overHeight = projectObj.project.projectInfo.property.overHeight;
  669. return Array.isArray(overHeight) && overHeight.length;
  670. }
  671. /* project.prototype.setBillsCalcMode = function (calcMode) {
  672. this.property.billsCalcMode = calcMode;
  673. this.initCalcFields();
  674. };*/
  675. /*project.prototype.initCalcFields = function () {
  676. // let settingConst = this.projSetting.settingConst;
  677. if (this.calcFields) {
  678. for (let field of this.calcFields) {
  679. // unitFeeCalcFlag
  680. if (field.type === 'zangu') {
  681. field.unitFeeFlag = converseUnitFeeFlag;
  682. } else {
  683. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationContent) {
  684. if (this.property.billsCalcMode === leafBillGetFeeType.rationContent) {
  685. field.unitFeeFlag = rationContentUnitFeeFlag;
  686. // } else if ( this.projSetting.billsCalcMode === settingConst.billsCalcMode.billsPrice) {
  687. } else if ( this.property.billsCalcMode === leafBillGetFeeType.billsPrice) {
  688. field.unitFeeFlag = billsPriceUnitFeeFlag;
  689. } else {
  690. field.unitFeeFlag = averageQtyUnitFeeFlag;
  691. }
  692. }
  693. // totalFeeCalcFlag
  694. if (field.type === 'common') {
  695. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationPriceConverse) {
  696. if (this.property.billsCalcMode === leafBillGetFeeType.rationPriceConverse) {
  697. field.totalFeeFlag = sumTotalFeeFlag;
  698. } else {
  699. field.totalFeeFlag = totalFeeFlag;
  700. }
  701. } else {
  702. field.totalFeeFlag = sumTotalFeeFlag;
  703. }
  704. }
  705. }
  706. }*/
  707. return new project();
  708. }
  709. };