project.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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. reclacQuantity = true;
  546. addNodeDatas.push(d);
  547. }else {
  548. let temNode = this.mainTree.getNodeByID(d.data.ID);
  549. if(temNode){
  550. if(d.action =="delete"){
  551. if(d.type == ModuleNames.ration){
  552. _.remove(this.Ration.datas,{'ID':d.data.ID});
  553. this.Ration.deleteSubListOfRation({ID:d.data.ID});
  554. reclacQuantity = true;
  555. }
  556. deleteNode.push(temNode);//对于删除节点,统一不加入refreshNode中,由外部加入,避免重复
  557. }else {
  558. temObj = temNode.data;
  559. if(gljUtil.isDef(d.data.quantity))reclacQuantity = true;
  560. refreshNode.push(temNode);
  561. if(d.data.ParentID){//更新了父节点-相当于删了再添加
  562. //changeParentIDMap[temNode.data.ParentID] = true;
  563. deleteNode.push(temNode);
  564. this.updateParentNode(temNode,d.data.ParentID,addNodeDatas);
  565. }
  566. }
  567. }
  568. }
  569. }else if(d.type == ModuleNames.project){
  570. temObj = d.isInfo?this.projectInfo:this;
  571. }else if (d.type == ModuleNames.ration_glj && d.action == "add"){
  572. this[d.type].datas.push(d.data);
  573. if(d.projectGLJ) this.projectGLJ.loadNewProjectGLJToCache(d.projectGLJ);
  574. } else {//其它类型,更新datas
  575. temObj = _.find(this[d.type].datas,{"ID":d.data.ID});
  576. }
  577. if(temObj){
  578. for(let key in d.data){
  579. if(key == 'ID' || key == 'id'){
  580. continue;
  581. }
  582. this.setValue(temObj,key,d.data[key])
  583. }
  584. }
  585. }
  586. //对树节点的操作并删除、添加清单、删除添加定额、删除对应的定额工料机缓存
  587. TREE_SHEET_HELPER.massOperationSheet(projectObj.mainController.sheet, function () {
  588. let rationsDatas=[];
  589. let billsDatas=[];
  590. for(let a of addNodeDatas){
  591. if(a.type == ModuleNames.bills) billsDatas.push(a);
  592. if(a.type == ModuleNames.ration) rationsDatas.push(a);
  593. }
  594. deleteTreeNodes(deleteNode);
  595. addNewNodes(billsDatas,refreshNode);
  596. addNewNodes(rationsDatas,refreshNode);
  597. });
  598. /* for(let pID in changeParentIDMap){
  599. let pnode = this.mainTree.getNodeByID(pID);
  600. getNextRefreshNode(pnode,refreshNode);
  601. } */
  602. if(reclacQuantity) this.projectGLJ.calcQuantity();
  603. return refreshNode;
  604. /* function getNextRefreshNode(node,refreshNode){
  605. if(node.nextSibling){
  606. refreshNode.push(node.nextSibling)
  607. getNextRefreshNode(node.nextSibling,refreshNode)
  608. }
  609. }; */
  610. function deleteTreeNodes(deleteNodes) {
  611. let controller = projectObj.mainController, project = projectObj.project;
  612. let Bill = project.Bills, Ration = project.Ration;
  613. for(let rd of deleteNodes){
  614. controller.sheet.deleteRows(rd.serialNo(),rd.posterityCount() + 1);
  615. controller.tree.delete(rd);
  616. if(rd.sourceType == Bill.getSourceType()) Bill.tree.delete(rd.source);
  617. }
  618. }
  619. function addNewNodes(newDatas,refreshNode) {
  620. let controller = projectObj.mainController;
  621. let Bill = projectObj.project.Bills;
  622. let newAddNode = [];
  623. for(let nr of newDatas){
  624. let nextID = -1;
  625. let parentID = nr.parentID || (nr.data && nr.data.ParentID || -1);
  626. let preNode = projectObj.project.mainTree.getNodeByID(nr.preSiblingID);
  627. if(preNode) nextID = preNode.getNextSiblingID();
  628. let newNode = projectObj.project.mainTree.insert(parentID, nextID, nr.data.ID);
  629. if(nr.type == ModuleNames.bills){
  630. let newSource = Bill.tree.insertByData(nr.data, parentID, nextID, true);
  631. newNode.source = newSource;
  632. }else {
  633. newNode.source = nr.data;
  634. }
  635. newNode.sourceType = nr.type;
  636. newNode.data = nr.data;
  637. controller.sheet.addRows(newNode.serialNo(), 1);
  638. controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  639. newAddNode.push(newNode);
  640. refreshNode.push(newNode);
  641. }
  642. TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
  643. }
  644. };
  645. project.prototype.setValue=function (obj,key,value) {
  646. let keyArray = key.split('.');
  647. t_set(obj,value,keyArray,0);
  648. function t_set(obj,value,arr,index) {
  649. let nextIndex = index + 1;
  650. let tkey = arr[index];
  651. if(nextIndex < arr.length){
  652. if(obj[tkey]==undefined){
  653. obj[tkey] = {};
  654. }
  655. t_set(obj[tkey],value,arr,nextIndex)
  656. }else if(nextIndex == arr.length){
  657. obj[tkey] = value;
  658. }
  659. }
  660. }
  661. project.prototype.updateEvalproject = function (evalProject,data,callback){
  662. let programID = null;
  663. if(evalProject ==1){//当打勾估价项目选项后,该定额取费专业读取计算程序名称为“估价项目”的计算程序,且为只读状态
  664. programID = this.calcProgram.compiledTemplateMaps["估价项目"];
  665. if(callback) callback(programID);
  666. }else {//如果evalProject==0,则是去掉勾选估价项目选项,需要获取定额默认的取费专业。
  667. let libID = data.from == 'cpt'?"compleRationLib":data.libID;
  668. let query = {code:data.code,projectID:data.projectID,libID:libID};
  669. CommonAjax.post("/ration/getDefaultProgramID",query,function (result) {
  670. if(callback) callback(result);
  671. })
  672. }
  673. };
  674. //判断项目是否安装工程
  675. project.prototype.isInstall = function () {
  676. return projectObj.project.projectInfo.property.isInstall?true:false;//如果是undefinded 就也返回false
  677. };
  678. // 判断项目能否使用超高降效相关功能 (是否含有超高降效库数据)
  679. project.prototype.isOverHeightProject = function () {
  680. const overHeight = projectObj.project.projectInfo.property.overHeight;
  681. return Array.isArray(overHeight) && overHeight.length;
  682. }
  683. /* project.prototype.setBillsCalcMode = function (calcMode) {
  684. this.property.billsCalcMode = calcMode;
  685. this.initCalcFields();
  686. };*/
  687. /*project.prototype.initCalcFields = function () {
  688. // let settingConst = this.projSetting.settingConst;
  689. if (this.calcFields) {
  690. for (let field of this.calcFields) {
  691. // unitFeeCalcFlag
  692. if (field.type === 'zangu') {
  693. field.unitFeeFlag = converseUnitFeeFlag;
  694. } else {
  695. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationContent) {
  696. if (this.property.billsCalcMode === leafBillGetFeeType.rationContent) {
  697. field.unitFeeFlag = rationContentUnitFeeFlag;
  698. // } else if ( this.projSetting.billsCalcMode === settingConst.billsCalcMode.billsPrice) {
  699. } else if ( this.property.billsCalcMode === leafBillGetFeeType.billsPrice) {
  700. field.unitFeeFlag = billsPriceUnitFeeFlag;
  701. } else {
  702. field.unitFeeFlag = averageQtyUnitFeeFlag;
  703. }
  704. }
  705. // totalFeeCalcFlag
  706. if (field.type === 'common') {
  707. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationPriceConverse) {
  708. if (this.property.billsCalcMode === leafBillGetFeeType.rationPriceConverse) {
  709. field.totalFeeFlag = sumTotalFeeFlag;
  710. } else {
  711. field.totalFeeFlag = totalFeeFlag;
  712. }
  713. } else {
  714. field.totalFeeFlag = sumTotalFeeFlag;
  715. }
  716. }
  717. }
  718. }*/
  719. return new project();
  720. }
  721. };