project_view.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /**
  2. * Created by Mai on 2017/6/21.
  3. */
  4. var projectObj = {
  5. project: null,
  6. mainSpread: null,
  7. mainController: null,
  8. gljSpreed:null,
  9. beforeMainTreeSelectedChange: function (node) {
  10. /*if (node) {
  11. subViewObj.saveComments(node);
  12. }*/
  13. },
  14. treeSelectedChanged: function (node) {
  15. let project = projectObj.project;
  16. subViewObj.loadComments(node);
  17. gljOprObj.showDataIfRationSelect(node);
  18. // CSL.2017.07.25
  19. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  20. calcProgramObj.showData(node);
  21. };
  22. //zhong 2017-9-1 特征及内容
  23. if(pageCCOprObj.active){
  24. pageCCOprObj.mainActiveCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];//mainSpread焦点单元格
  25. if(node.sourceType === project.Bills.getSourceType()){
  26. pageCCOprObj.setCacheAndShow(node);
  27. }
  28. else{
  29. pageCCOprObj.clearData();
  30. }
  31. }
  32. },
  33. refreshBaseActn: function (tree) {
  34. let setButtonValid = function (valid, btn) {
  35. if (valid) {
  36. btn.removeClass('disabled');
  37. } else {
  38. btn.addClass('disabled');
  39. }
  40. };
  41. let selected = tree.selected, that = projectObj;
  42. let canUpLevel = function (node) {
  43. if (selected && selected.depth() > 0 && selected.canUpLevel()) {
  44. if (selected.sourceType === that.project.Bills.getSourceType()) {
  45. return (!selected.nextSibling) || (selected.children.length === 0) || (selected.source.children.length > 0);
  46. } else {
  47. return false;
  48. }
  49. } else {
  50. return false;
  51. }
  52. };
  53. let canDownLevel = function (node) {
  54. if (selected && selected.depth() > 0 && selected.canDownLevel()) {
  55. if (selected.sourceType === that.project.Bills.getSourceType()) {
  56. return (selected.preSibling.children.length === 0) || (selected.preSibling.source.children.length > 0);
  57. } else {
  58. return false;
  59. }
  60. } else {
  61. return false;
  62. }
  63. };
  64. let canDelete = function (node) {
  65. if (selected) {
  66. if (selected.sourceType === that.project.Bills.getSourceType()) {
  67. return !(selected.data.flagsIndex && selected.data.flagsIndex.fixed && selected.data.flagsIndex.fixed.flag > 0);
  68. } else {
  69. return true;
  70. }
  71. } else {
  72. return false;
  73. }
  74. };
  75. setButtonValid(canUpLevel(selected), $('#upLevel'));
  76. setButtonValid(canDownLevel(selected), $('#downLevel'));
  77. setButtonValid(selected && (selected.depth() > 0) && selected.canUpMove(), $('#upMove'));
  78. setButtonValid(selected && (selected.depth() > 0) && selected.canDownMove(), $('#downMove'));
  79. setButtonValid(canDelete(selected), $('#delete'));
  80. },
  81. checkCommonField: function (editingText, colSetting) {
  82. let value;
  83. if (colSetting.data.decimal) {
  84. value = Number(editingText);
  85. if (number_util.isNumber(value)) {
  86. if (colSetting.data.decimal) {
  87. value = value.toDecimal(colSetting.data.decimal);
  88. }
  89. } else {
  90. value = null;
  91. alert('当前输入的数据类型不正确,请重新输入。');
  92. }
  93. } else {
  94. value = editingText;
  95. }
  96. return value;
  97. },
  98. checkFormulaValidField: function (editingText, colSetting) {
  99. let value = Number(editingText);
  100. if (!value) {
  101. try {
  102. let exp = new Expression('');
  103. exp.Expression(editingText);
  104. value = Number(exp.Evaluate());
  105. } catch (error) {
  106. value = null;
  107. }
  108. }
  109. if (value!=undefined||value!=null) {
  110. if (colSetting.data.decimal) {
  111. value = value.toDecimal(colSetting.data.decimal);
  112. }
  113. } else if (editingText && editingText !== '') {
  114. value = null;
  115. alert('当前输入的数据类型不正确,请重新输入。');
  116. }
  117. return value;
  118. },
  119. checkSpreadEditingText: function (editingText, colSetting) {
  120. if (colSetting.data.field === 'quantity') {
  121. return this.checkFormulaValidField(editingText, colSetting);
  122. }
  123. else if (colSetting.data.field === 'programID') {
  124. return this.project.calcProgram.compiledTemplateMaps[editingText];
  125. }
  126. else if (colSetting.data.field === 'subType') {
  127. if (typeof(editingText) !== "number")
  128. return volumePriceMaps[editingText]
  129. else
  130. return editingText;
  131. }
  132. else {
  133. return this.checkCommonField(editingText, colSetting);
  134. }
  135. },
  136. /*updateAndReCalculate: function (node, fieldName, value) {
  137. let project = projectObj.project, calc = new BillsCalcHelper(project), nodes = [];
  138. let getNodes = function (node) {
  139. let cur = node, nodes = [];
  140. while (cur) {
  141. nodes.push(cur);
  142. cur = cur.parent;
  143. }
  144. return nodes;
  145. }
  146. if (value) {
  147. value = value.toDecimal(projectObj.project.Decimal.common.quantity);
  148. }
  149. if (node.sourceType === projectObj.project.Bills.getSourceType()) {
  150. calcFees.setFee(node.data, fieldName, value);
  151. calc.calcNode(node, true);
  152. nodes = getNodes(node);
  153. project.Bills.updateNodes(nodes, true);
  154. }
  155. else if (node.sourceType === projectObj.project.VolumePrice.getSourceType()) {
  156. project.beginUpdate('VolumePrice_QuantityChange');
  157. project.VolumePrice.updateField(node.source, fieldName, value, false);
  158. calc.calcNode(node.parent, true);
  159. nodes = getNodes(node.parent);
  160. project.Bills.updateNodes(nodes, false);
  161. project.endUpdate();
  162. nodes.push(node);
  163. }
  164. else if (node.sourceType === projectObj.project.Ration.getSourceType()) {
  165. project.beginUpdate('Ration_QuantityChange');
  166. calcFees.setFee(node.data, fieldName, value);
  167. node.data.gljList = project.ration_glj.getGljArrByRation(node.data.ID);
  168. // calcProgram.calculate的传参必须是cacheNode类型,故无法将计算放在Ration模块中。
  169. project.calcProgram.calculate(node);
  170. project.Ration.updateRation(node.source, false); // 加入待存储队列
  171. calc.calcNode(node.parent, true); //
  172. nodes = getNodes(node.parent);
  173. project.Bills.updateNodes(nodes, false);
  174. project.endUpdate();
  175. nodes.push(node);
  176. }
  177. this.mainController.refreshTreeNode(nodes, false);
  178. calc = null;
  179. },*/
  180. updateBillsCode: function (node, value) {
  181. let project = projectObj.project;
  182. let stdMatchCode, formatCode, matchs;
  183. let searchStdBillsAndUpdate = function (stdCode, formatCode) {
  184. let orgCode = node.data.code.substr(0, 9);
  185. if (stdCode === orgCode || projectInfoObj.projectInfo.engineeringInfo.bill_lib.length === 0) {
  186. project.Bills.updateField(node.source, 'code', formatCode, true);
  187. projectObj.mainController.refreshTreeNode([node], false);
  188. } else if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0) {
  189. let libId = projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id;
  190. CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
  191. if (data) {
  192. data.itemCharacter = pageCCOprObj.safeItemCharater(data.itemCharacter);
  193. if (/\//.test(data.unit)) {
  194. ConfirmModal.stdBillsUnit.check(data, function (std) {
  195. project.Bills.replaceBills(node.source, std, formatCode);
  196. projectObj.mainController.refreshTreeNode([node], false);
  197. }, function () {
  198. projectObj.mainController.refreshTreeNode([node], false);
  199. });
  200. } else {
  201. project.Bills.replaceBills(node.source, data, formatCode);
  202. projectObj.mainController.refreshTreeNode([node], false);
  203. }
  204. } else {
  205. project.Bills.updateField(node.source, 'code', formatCode, true);
  206. projectObj.mainController.refreshTreeNode([node], false);
  207. }
  208. });
  209. }
  210. }
  211. if (value.length === 9 && /^[\d]+$/.test(value)) {
  212. stdMatchCode = value;
  213. formatCode = project.Bills.newFormatCode(stdMatchCode);
  214. searchStdBillsAndUpdate(stdMatchCode, formatCode);
  215. } else if (value.length === 12 && /^[\d]+$/.test(value)) {
  216. stdMatchCode = value.substr(0, 9);
  217. matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
  218. if (matchs.indexOf(value) === -1) {
  219. searchStdBillsAndUpdate(stdMatchCode, value);
  220. } else if (confirm('已存在该编码的清单,是否继续?')) {
  221. formatCode = project.Bills.newFormatCode(stdMatchCode, node.data.code);
  222. searchStdBillsAndUpdate(stdMatchCode, formatCode);
  223. }
  224. } else {
  225. project.Bills.updateField(node.source, 'code', value, true);
  226. this.mainController.refreshTreeNode([node], false);
  227. }
  228. },
  229. updateRationCode: function (node, value) {
  230. if (/[\w]{2}[\d]{4}/.test(value)) {
  231. if (projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0) {
  232. alert('当前项目无定额库,请添加定额库。');
  233. this.mainController.refreshTreeNode([node], false);
  234. } else {
  235. let libId = projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
  236. CommonAjax.postRationLib('/rationRepository/api/matchRation', {user_id: userID, rationLibId: libId, code: value}, function (data) {
  237. if (data) {
  238. projectObj.project.Ration.replaceRation(node.source, data);
  239. projectObj.project.ration_glj.addRationGLJ(node.source, data);
  240. } else {
  241. alert('当前库中找不到定额"' + value + '"');
  242. }
  243. projectObj.mainController.refreshTreeNode([node], false);
  244. });
  245. }
  246. } else {
  247. alert('输入的定额编码有误,请检查。');
  248. this.mainController.refreshTreeNode([node], false);
  249. }
  250. },
  251. updateCode: function (node, value) {
  252. let project = projectObj.project;
  253. if (node.sourceType === project.Bills.getSourceType()) {
  254. this.updateBillsCode(node, value); // 新清单不适合实时计算,下面套什么还不能确定,无数量计算也无意义
  255. } else if (node.sourceType === project.Ration.getSourceType()) {
  256. this.updateRationCode(node, value); // 新套定额适合实时计算
  257. // 这里因异步问题暂时缺少工料机价格。该过程移到:ration_glj.js的refreshAfterSave方法中。
  258. /*project.calcProgram.calculate(node);
  259. project.calcProgram.saveNode(node);
  260. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  261. calcProgramObj.showData(node, false);
  262. };*/
  263. }
  264. },
  265. updateCellValue: function (node, value, colSetting) {
  266. let project = projectObj.project, fieldName = colSetting.data.field;
  267. if(node.sourceType==project.ration_glj.getSourceType()){
  268. project.ration_glj.updateFromMainSpread(value,node,fieldName);
  269. }if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  270. gljOprObj.updateRationTypeGLJ(value,node,fieldName);
  271. } else if (value !== calcFees.getFee(node.data, fieldName)||fieldName == 'quantity') {//工程量需要进行转换,所以做特殊处理
  272. if (fieldName === 'code' && !project.calcProgram.isVolumePrice(node)) {
  273. projectObj.updateCode(node, value);
  274. }
  275. else if(fieldName ==='feeRate'){
  276. project.FeeRate.updateFeeRateFromBills(value,node,fieldName);
  277. }
  278. else if (fieldName === 'quantity' || fieldName === 'marketUnitFee' || fieldName === 'programID' ||
  279. fieldName === 'subType' || fieldName === 'calcBase' || fieldName === 'feesIndex.common.unitFee'){
  280. if (fieldName === 'quantity') {
  281. if (value) {
  282. value = project.quantity_detail.autoTransformQuantity(value,node);
  283. value = scMathUtil.roundForObj(value,decimalObj.decimal(fieldName,node));
  284. if(value==node.data[fieldName]){
  285. projectObj.mainController.refreshTreeNode([node]);
  286. return;
  287. }
  288. };
  289. if(project.quantity_detail.quantityEditChecking(value,node,fieldName)){
  290. node.data.isFromDetail=0;
  291. project.quantity_detail.cleanQuantityDetail(node,true);
  292. }else {
  293. projectObj.mainController.refreshTreeNode([node]);
  294. return;
  295. }
  296. }
  297. else if (fieldName === 'marketUnitFee' || fieldName === 'feesIndex.common.unitFee') {
  298. if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("unitPrice", node))};
  299. }
  300. else if (fieldName === 'calcBase') {
  301. //zhong
  302. if(value){
  303. node.data.userCalcBase = value;
  304. project.calcBase.calculate(node);
  305. if(!project.calcBase.success){
  306. let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  307. projectObj.mainSpread.getActiveSheet().setValue(activeCell.row, activeCell.col, node.data.calcBase? node.data.calcBase: '');
  308. }
  309. }
  310. return;
  311. // if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("totalPrice", node))};
  312. };
  313. node.changed = true;
  314. if (fieldName == 'feesIndex.common.unitFee'){
  315. project.calcProgram.initFeeField(node, 'common');
  316. node.data.feesIndex.common.unitFee = value;
  317. }
  318. else node.data[fieldName] = value;
  319. project.calcProgram.calculate(node);
  320. project.calcProgram.saveNode(node);
  321. gljOprObj.showRationGLJSheetData();
  322. }
  323. else {
  324. if (node.sourceType === project.Bills.getSourceType()) {
  325. project.Bills.updateField(node.source, fieldName, value, true);
  326. }
  327. else if (node.sourceType === project.Ration.getSourceType()) {
  328. project.Ration.updateField(node.source, fieldName, value, true);
  329. };
  330. if (colSetting.data.wordWrap) {
  331. this.mainSpread.getActiveSheet().autoFitRow(node.serialNo());
  332. }
  333. projectObj.mainController.refreshTreeNode([node]);
  334. }
  335. } else if(value==null && fieldName ==='feeRate'){
  336. project.FeeRate.cleanFeeRateID(node);
  337. } else {
  338. projectObj.mainController.refreshTreeNode([node], false);
  339. }
  340. },
  341. mainSpreadLeaveCell: function (sender, info) {
  342. let colSetting = projectObj.mainController.setting.cols[info.col];
  343. projectObj.lastCol = colSetting;
  344. },
  345. mainSpreadEnterCell: function (sender, info) {
  346. let colSetting = projectObj.mainController.setting.cols[info.col];
  347. if(colSetting.data.field === 'unit' || projectObj.lastCol.data.field === 'unit'||colSetting.data.field ==='subType'|| projectObj.lastCol.data.field === 'subType'){
  348. info.sheet.repaint();
  349. }
  350. },
  351. mainSpreadEditEnded: function (sender, info) {
  352. let project = projectObj.project;
  353. let node = project.mainTree.items[info.row];
  354. let colSetting = projectObj.mainController.setting.cols[info.col];
  355. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  356. // 检查输入类型等
  357. let value = projectObj.checkSpreadEditingText(info.editingText, colSetting);
  358. projectObj.updateCellValue(node, value, colSetting);
  359. // 自动行高
  360. const autoHeight = project.property.displaySetting.autoHeight;
  361. if (autoHeight) {
  362. projectObj.mainSpread.getActiveSheet().autoFitRow(info.row);
  363. }
  364. },
  365. mainSpreadRangeChanged: function (sender, info) {
  366. let project = projectObj.project, setting = projectObj.mainController.setting;
  367. if (info.changedCells.length > 0) {
  368. for (let changedCell of info.changedCells) {
  369. let cell = info.sheet.getCell(changedCell.row, changedCell.col);
  370. let node = project.mainTree.items[changedCell.row];
  371. let colSetting = setting.cols[changedCell.col];
  372. let value = projectObj.checkSpreadEditingText(cell.text(), colSetting);
  373. projectObj.updateCellValue(node, value, colSetting);
  374. }
  375. }
  376. },
  377. checkMainSpread: function () {
  378. if (!this.mainSpread) {
  379. this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
  380. this.mainSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.muliRange);
  381. }
  382. },
  383. refreshMainSpread: function () {
  384. if (this.mainSpread) {
  385. this.mainSpread.refresh();
  386. }
  387. },
  388. loadProjectData: function () {
  389. var that = this;
  390. this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
  391. this.project.loadDatas(function (err) {
  392. if (!err) {
  393. that.project.property = projectInfoObj.projectInfo.property;
  394. //that.project.calcProgram.compileAllTemps();
  395. that.project.calcBase.init(that.project);
  396. that.project.calcFields = JSON.parse(JSON.stringify(feeType));
  397. // that.project.initCalcFields();
  398. let str = JSON.stringify(that.project.projSetting.main_tree_col);
  399. that.project.projSetting.mainGridSetting = JSON.parse(str);
  400. that.project.projSetting.mainGridSetting.frozenCols = 4;
  401. TREE_SHEET_HELPER.initSetting($('#billsSpread')[0], that.project.projSetting.mainGridSetting);
  402. const autoHeight = that.project.property.displaySetting !== undefined ?
  403. that.project.property.displaySetting.autoHeight : false;
  404. that.project.projSetting.mainGridSetting.cols.forEach(function (col) {
  405. // for test. 后端没有绑定,暂时写死用于测试。
  406. /* if (col.data.field == '' && col.head.titleNames[0] == "取费专业") {
  407. col.data.field = 'programID';
  408. col.data.getText = 'getText.calcProgramName';
  409. col.data.cellType = 'cellType.calcProgramName';
  410. };*/
  411. col.data.splitFields = col.data.field.split('.');
  412. if (col.data.getText && Object.prototype.toString.apply(col.data.getText) === "[object String]") {
  413. col.data.getText = MainTreeCol.getEvent(col.data.getText);
  414. }
  415. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  416. col.readOnly = MainTreeCol.getEvent(col.readOnly);
  417. }
  418. if (col.data.cellType && Object.prototype.toString.apply(col.data.cellType) === "[object String]") {
  419. let getCellType = MainTreeCol.getEvent(col.data.cellType);
  420. col.data.cellType = getCellType;
  421. }
  422. // if (col.data.digit && Object.prototype.toString.apply(col.data.digit) === "[object String]") {
  423. // col.data.decimal = that.project.getDecimal(col.data.digit);
  424. // col.data.formatter = MainTreeCol.getNumberFormatter(col.data.decimal);
  425. // }
  426. if (col.data.field === 'code') {
  427. col.data.formatter = '@';
  428. }
  429. // 根据配置设置自动行高
  430. if (col.data.field === 'name' || col.data.field === 'itemCharacterText' ||
  431. col.data.field === 'jobContentText' || col.data.field === 'adjustState') {
  432. if (!autoHeight) {
  433. col.showHint = true;
  434. col.data.wordWrap = false;
  435. } else {
  436. col.showHint = false;
  437. col.data.wordWrap = true;
  438. }
  439. }
  440. // for test digit. CSLAAAAA
  441. if (col.data.field.hasSubStr("totalFee"))
  442. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.totalPrice, false)
  443. else if (col.data.field.hasSubStr("unitFee"))
  444. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.unitPrice, false)
  445. else if (col.data.field == "quantity")
  446. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.quantity, false);
  447. });
  448. that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), that.project.projSetting.mainGridSetting);
  449. that.mainController.showTreeData();
  450. that.mainController.bind('refreshBaseActn', that.refreshBaseActn);
  451. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.beforeTreeSelectedChange, that.beforeMainTreeSelectedChange);
  452. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, that.treeSelectedChanged);
  453. that.mainSpread.bind(GC.Spread.Sheets.Events.LeaveCell, that.mainSpreadLeaveCell);
  454. that.mainSpread.bind(GC.Spread.Sheets.Events.EnterCell, that.mainSpreadEnterCell);
  455. that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
  456. that.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, that.mainSpreadRangeChanged);
  457. that.loadMainSpreadContextMenu();
  458. that.loadFocusLocation();
  459. }
  460. else {
  461. }
  462. });
  463. },
  464. loadMainSpreadContextMenu: function () {
  465. var project = this.project, spread = this.mainSpread, controller = this.mainController;
  466. $.contextMenu({
  467. selector: '#billsSpread',
  468. build: function ($trigger, e) {
  469. var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  470. controller.setTreeSelected(controller.tree.items[target.row]);
  471. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  472. },
  473. items: {
  474. "insertBills": {
  475. name: "插入清单",
  476. icon: 'fa-sign-in',
  477. disabled: function () {
  478. return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
  479. },
  480. callback: function (key, opt) {
  481. ProjectController.addBills(project, controller);
  482. }
  483. },
  484. "insertRation": {
  485. name: "插入定额",
  486. icon: 'fa-sign-in',
  487. disabled: function () {
  488. var selected = project.mainTree.selected;
  489. if (selected) {
  490. if ( // CSL, 2017-11-28
  491. selected.sourceType === project.Ration.getSourceType() ||
  492. (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0)
  493. ) return false
  494. else return true
  495. } else return true
  496. },
  497. callback: function (key, opt) {
  498. ProjectController.addRation(project, controller, rationType.ration);
  499. }
  500. },
  501. "insertLJ": {
  502. name: "插入量价",
  503. icon: 'fa-sign-in',
  504. disabled: function () {
  505. var selected = project.mainTree.selected;
  506. if (selected) {
  507. if ( // CSL, 2017-11-28
  508. selected.sourceType === project.Ration.getSourceType() ||
  509. (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0)
  510. ) return false
  511. else return true
  512. } else return true
  513. },
  514. callback: function (key, opt) {
  515. ProjectController.addRation(project, controller, rationType.volumePrice);
  516. }
  517. },
  518. "insertGLJ": {
  519. name: "插入工料机",
  520. icon: 'fa-sign-in',
  521. disabled: function () {
  522. var selected = project.mainTree.selected;
  523. var readOnly = MainTreeCol.readOnly;
  524. return readOnly.billsParent(selected)||(readOnly.bills(selected)&&!readOnly.forCalcBase(selected))||readOnly.glj(selected);
  525. },
  526. callback: function (key, opt) {
  527. getGLJData('insert');// ProjectController.addRation(project, controller, rationType.volumePrice);
  528. }
  529. },
  530. "spr1": '--------',
  531. "delete": {
  532. name: '删除',
  533. icon: 'fa-remove',
  534. disabled: function () {
  535. var selected = project.mainTree.selected;
  536. return !selected;
  537. },
  538. callback: function () {
  539. var selected = controller.tree.selected, parent = selected.parent;
  540. if (selected) {
  541. if (selected.sourceType === project.Bills.getSourceType()) {
  542. project.Bills.deleteBills(selected.source);
  543. controller.delete();
  544. } else if (selected.sourceType === project.Ration.getSourceType()) {
  545. project.Ration.delete(selected.source);
  546. controller.delete();
  547. };
  548. projectObj.converseCalculateBills(parent);
  549. }
  550. }
  551. },
  552. "spr2":'--------',
  553. "calculateAll_RationContent": {
  554. name: '造价计算',
  555. callback: function () {
  556. let changedNodes = project.calcProgram.calcAllNodes();
  557. project.calcProgram.saveNodes(changedNodes);
  558. }
  559. }
  560. }
  561. });
  562. },
  563. // 计算node及node的所有父项
  564. converseCalculateBills: function (node) {
  565. /* if (node) {
  566. let calc = new BillsCalcHelper(this.project);
  567. calc.calcNode(node, true);
  568. let cur = node, nodes = [];
  569. while (cur) {
  570. nodes.push(cur);
  571. cur = cur.parent;
  572. }
  573. this.mainController.refreshTreeNode(nodes, false);
  574. this.project.Bills.updateNodes(nodes, true);
  575. calc = null;
  576. }*/
  577. projectObj.project.calcProgram.calculate(node);
  578. projectObj.project.calcProgram.saveNode(node);
  579. },
  580. // 计算全部清单
  581. /* calculateAll: function () {
  582. let calc = new BillsCalcHelper(this.project);
  583. calc.calcAll();
  584. this.mainController.showTreeData();
  585. this.project.Bills.updateAll();
  586. calc = null;
  587. }*/
  588. // 获取上次退出时的焦点位置
  589. loadFocusLocation: function() {
  590. const projectId = scUrlUtil.GetQueryString('project');
  591. let row = getLocalCache('lastRow:' + projectId);
  592. let col = getLocalCache('lastCol:' + projectId);
  593. if (row !== null && col !== null) {
  594. row = parseInt(row);
  595. col = parseInt(col);
  596. const sheet = this.mainSpread.getActiveSheet();
  597. sheet.setSelection(row, col, 1, 1);
  598. this.mainController.setTreeSelected(this.mainController.tree.items[row]);//触发树节点选中事件
  599. }
  600. },
  601. };
  602. $('#insert').click(function () {
  603. var controller = projectObj.mainController, project = projectObj.project;
  604. var selected = controller.tree.selected;
  605. if (!selected || selected.sourceType === project.Bills.getSourceType()) {
  606. ProjectController.addBills(project, controller);
  607. } else if (selected.sourceType === project.Ration.getSourceType()) {
  608. ProjectController.addRation(project, controller, selected.data.type);
  609. }
  610. });
  611. $('#delete').click(function () {
  612. var controller = projectObj.mainController, project = projectObj.project;
  613. var selected = controller.tree.selected, parent = selected.parent;
  614. if (selected) {
  615. if (selected.sourceType === project.Bills.getSourceType()) {
  616. project.Bills.deleteBills(selected.source);
  617. controller.delete();
  618. } else if (selected.sourceType === project.Ration.getSourceType()) {
  619. project.Ration.delete(selected.source);
  620. controller.delete();
  621. }else if(selected.sourceType==ModuleNames.ration_glj){
  622. project.ration_glj.updataOrdelete(selected.source);
  623. };
  624. projectObj.converseCalculateBills(parent);
  625. }
  626. });
  627. $('#upLevel').click(function () {
  628. var controller = projectObj.mainController, project = projectObj.project;
  629. var selected = controller.tree.selected, orgParent = selected.parent;
  630. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  631. project.Bills.upLevelBills(selected.source);
  632. controller.upLevel();
  633. projectObj.converseCalculateBills(orgParent);
  634. }
  635. });
  636. $('#downLevel').click(function () {
  637. var controller = projectObj.mainController, project = projectObj.project;
  638. var selected = controller.tree.selected;
  639. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  640. project.Bills.downLevelBills(selected.source);
  641. controller.downLevel();
  642. projectObj.converseCalculateBills(selected.parent);
  643. }
  644. });
  645. $('#upMove').click(function () {
  646. var controller = projectObj.mainController, project = projectObj.project;
  647. var selected = controller.tree.selected, pre = selected.preSibling, preSerialNo;
  648. if (selected.sourceType === project.Bills.getSourceType()) {
  649. project.Bills.upMoveBills(selected.source);
  650. controller.upMove();
  651. } else if (selected.sourceType === project.Ration.getSourceType()) {
  652. project.Ration.changePos(selected.source, selected.preSibling.source);
  653. controller.upMove();
  654. };
  655. });
  656. $('#downMove').click(function () {
  657. var controller = projectObj.mainController, project = projectObj.project;
  658. var selected = controller.tree.selected, next, nextSerialNo;
  659. if (selected) {
  660. if (selected.sourceType === project.Bills.getSourceType()) {
  661. project.Bills.downMoveBills(selected.source);
  662. controller.downMove();
  663. } else if (selected.sourceType === project.Ration.getSourceType()) {
  664. project.Ration.changePos(selected.source, selected.nextSibling.source);
  665. controller.downMove();
  666. };
  667. }
  668. });
  669. $('#poj-set').on('show.bs.modal', function () {
  670. let setCalcFlag = function (obj, val, curFlag) {
  671. obj.val(val);
  672. if (val === curFlag) {
  673. obj.attr('checked', true);
  674. } else {
  675. obj.removeAttr('checked');
  676. }
  677. }
  678. if (projectObj.project) {
  679. // let mode = projectObj.project.projSetting.billsCalcMode;
  680. // let settingConst = projectObj.project.projSetting.settingConst;
  681. let ft = projectObj.project.property.billsCalcMode ? projectObj.project.property.billsCalcMode : leafBillGetFeeType.rationContent;
  682. setCalcFlag($('#rationContent'), leafBillGetFeeType.rationContent, ft);
  683. setCalcFlag($('#rationPriceConverse'), leafBillGetFeeType.rationPriceConverse, ft);
  684. setCalcFlag($('#rationPrice'), leafBillGetFeeType.rationPrice, ft);
  685. setCalcFlag($('#billsPrice'), leafBillGetFeeType.billsPrice, ft);
  686. // mode = projectObj.project.projSetting.zanguCalcType;
  687. let zg = projectObj.project.property.zanguCalcMode ? projectObj.project.property.zanguCalcMode : zanguCalcType.common;
  688. setCalcFlag($('#zangu_common'), zanguCalcType.common, zg);
  689. setCalcFlag($('#zangu_gatherMaterial'), zanguCalcType.gatherMaterial, zg);
  690. }
  691. });
  692. $('#property_ok').click(function () {
  693. let project = projectObj.project,
  694. projectID = project.ID(),
  695. properties = {},
  696. labourCoes = {},
  697. rations = [],
  698. bills = [],
  699. mixDatas = {
  700. projectID: projectID,
  701. updateType: 'update',
  702. properties: properties,
  703. labourCoes: labourCoes,
  704. rations: rations,
  705. bills: bills
  706. },
  707. reCalcBills= false,
  708. reCalcRations= false;
  709. let b = parseInt($("input[name='calcFlag']:checked").val());
  710. if (b !== project.property.billsCalcMode) {
  711. properties['property.billsCalcMode'] = b;
  712. project.property.billsCalcMode = b;
  713. reCalcBills = true;
  714. };
  715. let zg = parseInt($("input[name='zangu']:checked").val());
  716. if (zg !== project.property.zanguCalcMode) {
  717. properties['property.zanguCalcMode'] = zg;
  718. project.property.zanguCalcMode = zg;
  719. reCalcBills = true;
  720. };
  721. //基本信息
  722. if(basicInfoView.toUpdate(basicInfoView.orgDatas, basicInfoView.datas)){
  723. properties['property.basicInformation'] = basicInfoView.toSaveDatas(basicInfoView.datas);
  724. }
  725. //工程特征
  726. if(projFeatureView.toUpdate(projFeatureView.orgDatas, projFeatureView.datas)){
  727. properties['property.projectFeature'] = projFeatureView.toSaveDatas(projFeatureView.datas);
  728. }
  729. //清单工程量精度
  730. let newBillsDecimalDatas = billsDecimalView.toBillsDecimalDatas(billsDecimalView.cache);
  731. if(billsDecimalView.toUpdate(billsQuanDecimal.datas, newBillsDecimalDatas)){
  732. billsQuanDecimal.datas = newBillsDecimalDatas;
  733. reCalcBills = true;
  734. properties['property.billsQuantityDecimal'] = newBillsDecimalDatas;
  735. }
  736. //小数位数
  737. let updateDecimal = m_getDecimalData($('input', '#poj-settings-decimal'));
  738. if(toUpdateDecimal(decimalObj, updateDecimal)) {
  739. let frChanged = decimalObj.feeRate != updateDecimal.feeRate;
  740. setDecimal(decimalObj, updateDecimal);
  741. if (frChanged) {
  742. project.calcProgram.compileAllTemps()
  743. }
  744. reCalcRations = true;
  745. reCalcBills = true;
  746. properties['property.decimal'] = updateDecimal;
  747. }
  748. // 呈现选项
  749. projDisplayView.updateChecking(projectID, properties);
  750. // 人工系数
  751. if (labourCoeView.needSave()){
  752. let libID = $("#std_labour_coe_files").children("option:selected").val();
  753. let libName = $("#std_labour_coe_files").children("option:selected").text();
  754. labourCoes.updateData = {libID: libID, libName: libName, newItemArr: labourCoeView.needUpdateDatas};
  755. project.labourCoe.refreshData(labourCoes.updateData); // 全编译所用到的人工系数来自project.labourCoe,所以必须先刷新project.labourCoe
  756. project.calcProgram.compileAllTemps();
  757. reCalcRations = true;
  758. reCalcBills = true;
  759. };
  760. // 重新计算树节点
  761. let changedNodes = [];
  762. if (reCalcRations) // 定额动,全部计算。
  763. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catAll)
  764. else if (reCalcBills) // 清单动,可以只计算清单。
  765. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catBills);
  766. if (changedNodes.length > 0) {
  767. for (let node of changedNodes){
  768. let data = {
  769. // projectID: projectID,
  770. ID: node.data.ID,
  771. quantity: node.data.quantity,
  772. calcBase: node.data.calcBase,
  773. calcBaseValue: node.data.calcBaseValue,
  774. marketUnitFee: node.data.marketUnitFee,
  775. marketTotalFee: node.data.marketTotalFee,
  776. fees: node.data.fees,
  777. feeRate: node.data.feeRate,
  778. feeRateID: node.data.feeRateID
  779. };
  780. if (node.sourceType == 'ration'){
  781. rations.push(data);
  782. }
  783. else if (node.sourceType == 'bills'){
  784. bills.push(data);
  785. };
  786. };
  787. };
  788. // for test.
  789. /* console.log(mixDatas);
  790. return; */
  791. function hasMixData() {
  792. return Object.keys(mixDatas.properties).length > 0 ||
  793. mixDatas.labourCoes.updateData || mixDatas.rations.length > 0 || mixDatas.bills.length > 0;
  794. }
  795. if(hasMixData()){
  796. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  797. /* if (changedNodes.length > 0) {
  798. for (let node of changedNodes){delete node.changed};
  799. };
  800. if (mixDatas.labourCoes.updateData) labourCoeView.refresh();*/
  801. window.location.href = '/main?project=' + projectID;
  802. });
  803. }
  804. });