project.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. tools.doAfterLoad = function(result, callback){
  32. var counter;
  33. result.forEach(function(item){
  34. if (me.modules[item.moduleName]){
  35. me.modules[item.moduleName].loadData(item.data);
  36. } else if (item.moduleName === me.projCounter) {
  37. counter = item.data;
  38. } else if (item.moduleName === me.projSetting) {
  39. me._project.projSetting = item.data;
  40. me._project.projSetting.moduleName = me.projSetting;
  41. }else if(item.moduleName === ModuleNames.projectGLJ){
  42. me._project.projectGLJ.loadToCache(item.data);
  43. }
  44. });
  45. for (module in counter) {
  46. if (me.modules[module]) {
  47. me.modules[module].setMaxID(counter[module]);
  48. }
  49. }
  50. me._project.loadMainTree();
  51. //me.test(result[0].data[0]);
  52. callback(0);
  53. };
  54. tools.eachItem=function(item){
  55. if (me.modules[item.moduleName]){
  56. me.modules[item.moduleName].doAfterUpdate(item.err, item.data);
  57. }
  58. };
  59. /*tools.test = function(data){
  60. me._project.beginUpdate('修改名称');
  61. data.name = 'test';
  62. data['updateType'] = 'ut_update';
  63. me._project.push(ModuleNames.bills, [data]);
  64. me._project.endUpdate();
  65. };*/
  66. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  67. var project = function () {
  68. tools._project = this;
  69. this.mainTree = cacheTree.createNew(this);
  70. this.Bills = Bills.createNew(this);
  71. this.Ration = Ration.createNew(this);
  72. this.GLJ = GLJ.createNew(this);
  73. this.ration_glj = ration_glj.createNew(this);
  74. this.ration_coe = ration_coe.createNew(this);
  75. this.ration_ass = ration_ass.createNew(this);
  76. this.ration_installation = ration_installation.createNew(this);
  77. this.quantity_detail = quantity_detail.createNew(this);
  78. this.installation_fee = installation_fee.createNew(this);
  79. this.FeeRate = FeeRate.createNew(this);
  80. // this.VolumePrice = VolumePrice.createNew(this);
  81. this.projectGLJ = new ProjectGLJ();
  82. // this.projectGLJ.loadData();
  83. this.composition = new Composition();
  84. this.composition.loadData();
  85. this.labourCoe = new LabourCoe(this);
  86. this.calcProgram = new CalcProgram(this);
  87. this.calcBase = calcBase;
  88. // this.masterField = {ration: 'billsItemID', volumePrice: 'billsItemID'};
  89. this.masterField = {ration: 'billsItemID'};
  90. };
  91. // prototype用于定义public方法
  92. project.prototype.modify = function (modifyDatas, callback) {
  93. // To Do
  94. };
  95. // prototype用于定义public方法
  96. project.prototype.ID = function () {
  97. return tools._ID;
  98. };
  99. project.prototype.projCounter = function () {
  100. return tools.projCounter;
  101. };
  102. project.prototype.getDecimal = function (fullName) {
  103. let names = fullName.split('.'), decimal = this.Decimal;
  104. for (let name of names) {
  105. if (decimal[name]) {
  106. decimal = decimal[name];
  107. } else {
  108. return null;
  109. }
  110. }
  111. if (Object.prototype.toString.apply(decimal) === '[object Number]') {
  112. return decimal;
  113. } else {
  114. return null;
  115. }
  116. };
  117. project.prototype.loadMainTree = function () {
  118. var that = this;
  119. let loadRationGLJNode = function (cacheNode) {
  120. var newNode, bj = that.ration_glj.getMainAndEquGLJ(cacheNode.source.ID), i;
  121. for(i=0;i<bj.length;i++){
  122. that.ration_glj.transferToNodeData(bj[i]);
  123. newNode = that.mainTree.addNode(cacheNode, null, bj[i].ID);
  124. newNode.source = bj[i];
  125. newNode.sourceType = that.ration_glj.getSourceType();
  126. newNode.data = bj[i];
  127. }
  128. };
  129. var loadRationNode = function (rations, cacheNode) {
  130. var newNode, br = that.Ration.getBillsSortRation(cacheNode.source.getID()), i;
  131. for (i = 0; i < br.length; i++) {
  132. newNode = that.mainTree.addNode(cacheNode, null, br[i].ID);
  133. if(br[i].type==rationType.gljRation){
  134. br[i]= that.ration_glj.combineRationAndGLJ(br[i]);
  135. }
  136. newNode.source = br[i];
  137. newNode.sourceType = that.Ration.getSourceType();
  138. newNode.data = br[i];
  139. if(projectInfoObj.projectInfo.property.displaySetting !== undefined &&
  140. projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial==true){
  141. loadRationGLJNode(newNode);
  142. }
  143. }
  144. };
  145. /* let loadVolumePriceNode = function (cacheNode) {
  146. let newNode = null, bv = that.VolumePrice.getBillsSortVolumePrice(cacheNode.source.getID());
  147. for (let v of bv) {
  148. newNode = that.mainTree.addNode(cacheNode);
  149. newNode.source = v;
  150. newNode.sourceType = that.VolumePrice.getSourceType();
  151. newNode.data = v;
  152. }
  153. };*/
  154. var loadIdTreeNode = function (nodes, parent) {
  155. var newNode, i;
  156. for (i = 0; i < nodes.length; i++) {
  157. newNode = that.mainTree.addNode(parent, null, nodes[i].data.ID);
  158. newNode.source = nodes[i];
  159. newNode.sourceType = that.Bills.getSourceType();
  160. newNode.data = nodes[i].data;
  161. that.FeeRate.loadFeeRateToBill(newNode);
  162. if (nodes[i].children.length === 0) {
  163. loadRationNode(that.Ration.datas, newNode);
  164. // loadVolumePriceNode(newNode);
  165. } else {
  166. loadIdTreeNode(nodes[i].children, newNode);
  167. }
  168. }
  169. };
  170. loadIdTreeNode(this.Bills.tree.roots, null);
  171. this.mainTree.sortTreeItems();
  172. this.mainTree.selected = this.mainTree.firstNode();
  173. };
  174. project.prototype.getParentTarget = function (node, targetField, targetValue) {
  175. var parent = node;
  176. while (parent && parent[targetField] !== targetValue) {
  177. parent = parent.parent;
  178. }
  179. return parent;
  180. };
  181. // 提供给各模块调用的统一从后台获取数据的方法
  182. /*project.prototype.pullData = function (url, data, successCallback, errorCallback) {
  183. $.ajax({
  184. type:"POST",
  185. url: url,
  186. data: {'data': JSON.stringify(data)},
  187. dataType: 'json',
  188. cache: false,
  189. timeout: 50000,
  190. success: function(result){
  191. successCallback(result);
  192. },
  193. error: function(jqXHR, textStatus, errorThrown){
  194. alert('error ' + textStatus + " " + errorThrown);
  195. errorCallback();
  196. }
  197. });
  198. };*/
  199. // 所有模块在此从后台获取数据
  200. project.prototype.loadDatas = function (callback){
  201. $.ajax({
  202. type: "POST",
  203. url: '/project/getData',
  204. data: {'data': JSON.stringify({
  205. "project_id": tools._ID,
  206. "user_id": tools._userID
  207. })},
  208. dataType: 'json',
  209. cache: false,
  210. timeout: 50000,
  211. success: function (result) {
  212. if (!result.error) {
  213. tools.doAfterLoad(result.data, callback);
  214. // for test calc
  215. //tools.doAfterLoad([{moduleName: 'bills', data: BillsData}, {'moduleName': 'ration', data: DrawingData}], callback);
  216. } else {
  217. alert('error: ' + result.message);
  218. callback(result.error);
  219. }
  220. },
  221. error: function(jqXHR, textStatus, errorThrown){
  222. alert('error ' + textStatus + " " + errorThrown);
  223. }
  224. });
  225. };
  226. project.prototype.beginUpdate = function(operation){
  227. if (tools.updateLock === 0){
  228. tools.operation = operation
  229. }
  230. tools.updateLock += 1;
  231. };
  232. project.prototype.endUpdate = function(){
  233. if (tools.updateLock === 0){
  234. throw "project can not endUpdate before beginUpdate";
  235. }
  236. tools.updateLock -= 1;
  237. if (tools.updateLock === 0) {
  238. $.ajax({
  239. type: "POST",
  240. url: '/project/save',
  241. data: {'data': JSON.stringify({
  242. "project_id": tools._ID,
  243. "user_id": tools._userID,
  244. "date": new Date,
  245. "operation": tools.operation,
  246. "update_data": tools.updateData
  247. })},
  248. dataType: 'json',
  249. cache: false,
  250. timeout: 50000,
  251. success: function (result) {
  252. if (!result.error) {
  253. tools.doAfterUpdate(result.data);
  254. } else {
  255. alert('error: ' + result.message);
  256. }
  257. $.bootstrapLoading.end();
  258. },
  259. error: function(jqXHR, textStatus, errorThrown){
  260. alert('error ' + textStatus + " " + errorThrown);
  261. $.bootstrapLoading.end();
  262. }
  263. });
  264. tools.updateData = [];
  265. tools.operation = "";
  266. }
  267. };
  268. project.prototype.push = function(moduleName, data){
  269. if (tools.updateLock === 0){
  270. throw "project can not push data before beginUpdate";
  271. }
  272. var moduleData = {
  273. moduleName: moduleName,
  274. data: data
  275. };
  276. tools.updateData.push(moduleData);
  277. };
  278. project.prototype.pushNow = function (operation, moduleName, data) {
  279. var that = this;
  280. this.beginUpdate(operation);
  281. if (Object.prototype.toString.apply(moduleName) === "[object Array]" && Object.prototype.toString.apply(data) === "[object Array]") {
  282. moduleName.forEach(function (name, index) {
  283. if(name != 'projCounter'){
  284. that.push(moduleName[index], data[index]);
  285. }
  286. });
  287. } else {
  288. this.push(moduleName, data);
  289. }
  290. this.endUpdate();
  291. };
  292. project.prototype.registerModule = function(moduleName, obj){
  293. if (!tools.modules.hasOwnProperty(moduleName)){
  294. tools.modules[moduleName] = obj;
  295. }
  296. };
  297. project.prototype.markUpdateProject = function (data,type) {
  298. CommonAjax.post("/project/markUpdateProject",{updateInfo:data,type:type});
  299. };
  300. project.prototype.saveProperty = function (propertyName, propertyValue) {
  301. CommonAjax.post("/project/saveProperty", {projectID: this.ID(), propertyName: propertyName, propertyValue: propertyValue});
  302. };
  303. project.prototype.projectMarkChecking = function () {
  304. let changeMark = projectInfoObj.projectInfo.changeMark;
  305. if(changeMark&&changeMark!=''){
  306. this.Bills.getEngineeringCostNode(projectObj.mainController).changed = true;
  307. this.calcProgram.calcAllNodesAndSave();
  308. CommonAjax.post("/project/removeProjectMark",{projectID:this.ID()},function (data) {
  309. delete projectInfoObj.projectInfo.changeMark;
  310. });
  311. }
  312. };
  313. project.prototype.updateLockBills = function (value,callback) {
  314. let mixDatas = {
  315. projectID: projectObj.project.ID(),
  316. updateType: 'update',
  317. properties: {
  318. "property.lockBills":value
  319. },
  320. labourCoes: {},
  321. rations: [],
  322. bills: []
  323. };
  324. $.bootstrapLoading.start();
  325. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  326. projectInfoObj.projectInfo.property.lockBills = value;
  327. if(callback){
  328. callback();
  329. }
  330. $.bootstrapLoading.end();
  331. });
  332. };
  333. //返回清单是否被锁定
  334. project.prototype.isBillsLocked =function(){
  335. if(projectInfoObj.projectInfo.property.lockBills == true){
  336. return true;
  337. }
  338. return false;
  339. };
  340. //清单是否属于锁定范围(分部分项、措施项目)
  341. project.prototype.withinBillsLocked = function (node) {
  342. console.log(node);
  343. const lockedFixFlag = [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE];
  344. while(node){
  345. if(!node.parent){
  346. if(node.data.flagsIndex && node.data.flagsIndex.fixed && lockedFixFlag.includes(node.data.flagsIndex.fixed.flag)){
  347. return true;
  348. }
  349. else {
  350. return false;
  351. }
  352. }
  353. node = node.parent;
  354. }
  355. return true;
  356. };
  357. project.prototype.updateNodes = function (datas,callback) {
  358. /* let datas = [
  359. {
  360. type:'ration',
  361. data:{
  362. projectID:1605,
  363. ID:"7b962fb0-1131-11e8-b3da-af725dadd7ae",
  364. name:'testRation'
  365. }
  366. },
  367. {
  368. type:'bills',
  369. data:{
  370. projectID:1605,
  371. ID:"af9f0081-1127-11e8-99a8-2fc02230b6e7",
  372. name:'安全文明施工专项费用123'
  373. }
  374. }
  375. ]*/
  376. CommonAjax.post("/project/updateNodes",datas,function (data) {
  377. if(callback){
  378. callback(data);
  379. }
  380. })
  381. };
  382. /* project.prototype.setBillsCalcMode = function (calcMode) {
  383. this.property.billsCalcMode = calcMode;
  384. this.initCalcFields();
  385. };*/
  386. /*project.prototype.initCalcFields = function () {
  387. // let settingConst = this.projSetting.settingConst;
  388. if (this.calcFields) {
  389. for (let field of this.calcFields) {
  390. // unitFeeCalcFlag
  391. if (field.type === 'zangu') {
  392. field.unitFeeFlag = converseUnitFeeFlag;
  393. } else {
  394. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationContent) {
  395. if (this.property.billsCalcMode === leafBillGetFeeType.rationContent) {
  396. field.unitFeeFlag = rationContentUnitFeeFlag;
  397. // } else if ( this.projSetting.billsCalcMode === settingConst.billsCalcMode.billsPrice) {
  398. } else if ( this.property.billsCalcMode === leafBillGetFeeType.billsPrice) {
  399. field.unitFeeFlag = billsPriceUnitFeeFlag;
  400. } else {
  401. field.unitFeeFlag = averageQtyUnitFeeFlag;
  402. }
  403. }
  404. // totalFeeCalcFlag
  405. if (field.type === 'common') {
  406. // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationPriceConverse) {
  407. if (this.property.billsCalcMode === leafBillGetFeeType.rationPriceConverse) {
  408. field.totalFeeFlag = sumTotalFeeFlag;
  409. } else {
  410. field.totalFeeFlag = totalFeeFlag;
  411. }
  412. } else {
  413. field.totalFeeFlag = sumTotalFeeFlag;
  414. }
  415. }
  416. }
  417. }*/
  418. return new project();
  419. }
  420. };