project_view.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  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. // for test interface. CSLAAAAA
  33. /* node.data.gljList = project.ration_glj.getGljArrByRation(node.data.ID);
  34. node.data.isSubcontract = true;
  35. let bname = '分包人工工日';
  36. alert(bname + ': ' + rationCalcBases[bname](node));*/
  37. },
  38. refreshBaseActn: function (tree) {
  39. let setButtonValid = function (valid, btn) {
  40. if (valid) {
  41. btn.removeClass('disabled');
  42. } else {
  43. btn.addClass('disabled');
  44. }
  45. };
  46. let selected = tree.selected, that = projectObj;
  47. let canUpLevel = function (node) {
  48. if(!node){
  49. return false;
  50. }
  51. if(node.depth()<=1){//焦点行是树结构的第一/二层节点,灰显。
  52. return false;
  53. }
  54. if(node.sourceType !== that.project.Bills.getSourceType()){//焦点行是定额/量价/工料机,灰显。
  55. return false;
  56. }else {
  57. if(node.data.type == billType.FX){//是分项,灰显。
  58. return false;
  59. }
  60. if(node.data.type == billType.FB&&node.nextSibling&&node.children.length>0){//焦点行是分部有后兄弟,有子项.
  61. if(node.children[0].data.type==billType.FX){ //焦点行子项是分项
  62. return false;
  63. }
  64. }
  65. if(node.data.type == billType.BILL &&node.nextSibling){//焦点行是清单有后兄弟
  66. if(node.data.calcBase&&node.data.calcBase!=""){//有基数计算
  67. return false;
  68. }
  69. if(node.children.length>0&&node.children[0].sourceType !== that.project.Bills.getSourceType()){//有子项,并且子项不是清单
  70. return false;
  71. }
  72. }
  73. }
  74. return true;
  75. };
  76. let canDownLevel = function (node) {
  77. if(!node){
  78. return false;
  79. }
  80. if(node.depth()==0){//焦点行是树结构的第一层节点,灰显。
  81. return false;
  82. }
  83. if(node.sourceType !== that.project.Bills.getSourceType()) {//焦点行是定额/量价/工料机,灰显。
  84. return false;
  85. }else {
  86. if(node.data.type == billType.FX){//是分项,灰显。
  87. return false;
  88. }
  89. if(!node.preSibling){//无前兄弟,灰显
  90. return false;
  91. }else if(node.preSibling.data.calcBase&&node.preSibling.data.calcBase!=""){//前兄弟有基数计算
  92. return false
  93. }
  94. if(node.preSibling.children.length>0){//前兄弟有子项,子项是分项,灰显。
  95. if(node.data.type==billType.FB&&node.preSibling.children[0].data.type==billType.FX){//焦点行是分部前兄弟有子项,子项是分项,灰显。
  96. return false;
  97. }
  98. if(node.data.type==billType.BILL&&node.preSibling.children[0].sourceType !== that.project.Bills.getSourceType()){//焦点行是清单,子项不是清单
  99. return false
  100. }
  101. }
  102. }
  103. return true;
  104. };
  105. let canUpMove = function (node) {
  106. if(node&&node.preSibling){//有前兄弟
  107. if(node.sourceType==that.project.Bills.getSourceType()&&node.data.type == billType.DXFY&&node.data.isAdd!==1){
  108. return false;
  109. }
  110. return true
  111. }
  112. return false
  113. };
  114. let canDownMove = function (node) {
  115. if(node&&node.nextSibling){
  116. if(node.sourceType==that.project.Bills.getSourceType()&&node.data.type == billType.DXFY&&node.data.isAdd!==1){
  117. return false;
  118. }
  119. return true;
  120. }
  121. return false
  122. };
  123. setButtonValid(ifCanDelete(), $('#delete'));
  124. setButtonValid(canUpLevel(selected), $('#upLevel'));
  125. setButtonValid(canDownLevel(selected), $('#downLevel'));
  126. setButtonValid(canUpMove(selected) , $('#upMove'));
  127. setButtonValid(canDownMove(selected), $('#downMove'));
  128. },
  129. checkCommonField: function (editingText, colSetting) {
  130. let value;
  131. if (colSetting.data.decimal) {
  132. value = Number(editingText);
  133. if (number_util.isNumber(value)) {
  134. if (colSetting.data.decimal) {
  135. value = value.toDecimal(colSetting.data.decimal);
  136. }
  137. } else {
  138. value = null;
  139. alert('当前输入的数据类型不正确,请重新输入。');
  140. }
  141. } else {
  142. value = editingText;
  143. }
  144. return value;
  145. },
  146. checkFormulaValidField: function (editingText, colSetting) {
  147. let value = Number(editingText);
  148. if (!value) {
  149. try {
  150. let exp = new Expression('');
  151. exp.Expression(editingText);
  152. value = Number(exp.Evaluate());
  153. } catch (error) {
  154. value = null;
  155. }
  156. }
  157. if (value!=undefined||value!=null) {
  158. if (colSetting.data.decimal) {
  159. value = value.toDecimal(colSetting.data.decimal);
  160. }
  161. } else if (editingText && editingText !== '') {
  162. value = null;
  163. alert('当前输入的数据类型不正确,请重新输入。');
  164. }
  165. return value;
  166. },
  167. checkSpreadEditingText: function (editingText, colSetting) {
  168. if (colSetting.data.field === 'quantity'||colSetting.data.field === 'contain') {
  169. return this.checkFormulaValidField(editingText, colSetting);
  170. }
  171. else if (colSetting.data.field === 'programID') {
  172. return this.project.calcProgram.compiledTemplateMaps[editingText];
  173. }
  174. else if (colSetting.data.field === 'subType') {
  175. if (typeof(editingText) !== "number")
  176. return volumePriceMaps[editingText]
  177. else
  178. return editingText;
  179. }
  180. else {
  181. return this.checkCommonField(editingText, colSetting);
  182. }
  183. },
  184. updateBillsCode: function (node, value) {
  185. let project = projectObj.project;
  186. let stdMatchCode, formatCode, matchs;
  187. let searchStdBillsAndUpdate = function (stdCode, formatCode) {
  188. let orgCode = node.data.code?node.data.code.substr(0, 9):"";
  189. if (stdCode === orgCode || projectInfoObj.projectInfo.engineeringInfo.bill_lib.length === 0) {
  190. project.Bills.updateField(node.source, 'code', formatCode, true);
  191. projectObj.mainController.refreshTreeNode([node], false);
  192. } else if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0) {
  193. let libId = projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id;
  194. CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
  195. if (data) {
  196. data.itemCharacter = pageCCOprObj.safeItemCharater(data.itemCharacter);
  197. if (/\//.test(data.unit)) {
  198. ConfirmModal.stdBillsUnit.check(data, function (std) {
  199. project.Bills.replaceBills(node.source, std, formatCode);
  200. projectObj.mainController.refreshTreeNode([node], false);
  201. }, function () {
  202. projectObj.mainController.refreshTreeNode([node], false);
  203. });
  204. } else {
  205. project.Bills.replaceBills(node.source, data, formatCode);
  206. projectObj.mainController.refreshTreeNode([node], false);
  207. }
  208. } else {
  209. project.Bills.updateField(node.source, 'code', formatCode, true);
  210. projectObj.mainController.refreshTreeNode([node], false);
  211. }
  212. });
  213. }
  214. }
  215. if(node.data.type==billType.FX||(node.data.type==billType.BILL&&node.source.children.length==0)){//是分项或者叶子清单的情况下才需要查找替换
  216. if (value&&value.length === 9 && /^[\d]+$/.test(value)) {
  217. stdMatchCode = value;
  218. formatCode = project.Bills.newFormatCode(stdMatchCode);
  219. searchStdBillsAndUpdate(stdMatchCode, formatCode);
  220. return;
  221. } else if (value&&value.length === 12 && /^[\d]+$/.test(value)) {
  222. stdMatchCode = value.substr(0, 9);
  223. matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
  224. if (matchs.indexOf(value) === -1) {
  225. searchStdBillsAndUpdate(stdMatchCode, value);
  226. } else if (confirm('已存在该编码的清单,是否继续?')) {
  227. formatCode = project.Bills.newFormatCode(stdMatchCode, node.data.code);
  228. searchStdBillsAndUpdate(stdMatchCode, formatCode);
  229. return;
  230. }
  231. }
  232. }
  233. project.Bills.updateField(node.source, 'code', value, true);
  234. this.mainController.refreshTreeNode([node], false);
  235. },
  236. updateRationCode: function (node, value) {
  237. if (projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0) {
  238. alert('当前项目无定额库,请添加定额库。');
  239. this.mainController.refreshTreeNode([node], false);
  240. } else {
  241. let libId = projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
  242. CommonAjax.post('/complementaryRation/api/getRationItem', {user_id: userID, rationRepId: libId, code: value}, function (data) {
  243. if (data) {
  244. projectObj.project.Ration.replaceRation(node.source, data);
  245. projectObj.project.ration_glj.addRationGLJ(node.source, data);
  246. } else {
  247. alert('当前库中找不到定额"' + value + '"');
  248. }
  249. projectObj.mainController.refreshTreeNode([node], false);
  250. });
  251. }
  252. },
  253. updateCode: function (node, value) {
  254. let project = projectObj.project;
  255. if (node.sourceType === project.Bills.getSourceType()) {
  256. this.updateBillsCode(node, value); // 新清单不适合实时计算,下面套什么还不能确定,无数量计算也无意义
  257. } else if (node.sourceType === project.Ration.getSourceType()) {
  258. this.updateRationCode(node, value); // 新套定额适合实时计算
  259. // 这里因异步问题暂时缺少工料机价格。该过程移到:ration_glj.js的refreshAfterSave方法中。
  260. /*project.calcProgram.calcAndSave(node);
  261. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  262. calcProgramObj.showData(node, false);
  263. };*/
  264. }
  265. },
  266. updateCellValue: function (node, value, colSetting,editingText) {
  267. let project = projectObj.project, fieldName = colSetting.data.field;
  268. if(node.sourceType==project.ration_glj.getSourceType()){
  269. project.ration_glj.updateFromMainSpread(value,node,fieldName);
  270. }
  271. else if(calcTools.isGljRation(node)){
  272. gljOprObj.updateRationTypeGLJ(value,node,fieldName);
  273. }
  274. else if (value !== calcFees.getFee(node.data, fieldName)||fieldName == 'quantity') {//工程量需要进行转换,所以做特殊处理
  275. if (fieldName === 'code' && !calcTools.isVolumePrice(node)) {
  276. projectObj.updateCode(node, value);
  277. }
  278. else if(fieldName ==='feeRate'){
  279. project.FeeRate.updateFeeRateFromBills(value,node,fieldName);
  280. }
  281. else if(fieldName ==='contain'){//编辑含量
  282. project.Ration.updateContain(value,node);
  283. }
  284. else if (fieldName === 'quantity' || fieldName === 'marketUnitFee' || fieldName === 'programID' ||
  285. fieldName === 'subType' || fieldName === 'calcBase' || fieldName === 'isSubcontract'){
  286. if (fieldName === 'quantity') {
  287. project.quantity_detail.editMainTreeNodeQuantity(value,node,fieldName,editingText);
  288. return;
  289. }
  290. else if (fieldName === 'marketUnitFee') {
  291. if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("unitPrice", node))};
  292. }
  293. else if (fieldName === 'calcBase') {
  294. //zhong
  295. if(value === undefined ||value === null || value.toString().trim() === ''){
  296. value = '';
  297. }
  298. node.data.userCalcBase = value;
  299. project.calcBase.calculate(node);
  300. if(!project.calcBase.success){
  301. let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  302. projectObj.mainSpread.getActiveSheet().setValue(activeCell.row, activeCell.col, node.data.calcBase? node.data.calcBase: '');
  303. return;
  304. }
  305. // if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("totalPrice", node))};
  306. };
  307. if(fieldName !== 'calcBase'){
  308. node.data[fieldName] = value;
  309. node.changed = true;
  310. }
  311. project.calcProgram.calcAndSave(node);
  312. gljOprObj.showRationGLJSheetData();
  313. }
  314. else if (node.sourceType === project.Bills.getSourceType()&&fieldName === 'unit'){//修改清单单位的时候清单工程量要重新4舍5入
  315. node.data[fieldName] = value;
  316. node.changed = true;
  317. if(node.data.quantity){
  318. node.data.quantity =scMathUtil.roundForObj(node.data.quantity,getDecimal("quantity",node));
  319. }
  320. project.calcProgram.calcAndSave(node);
  321. }
  322. else {
  323. if (node.sourceType === project.Bills.getSourceType()) {
  324. project.Bills.updateField(node.source, fieldName, value, true);
  325. }
  326. else if (node.sourceType === project.Ration.getSourceType()) {
  327. project.Ration.updateField(node.source, fieldName, value, true);
  328. };
  329. if (colSetting.data.wordWrap) {
  330. this.mainSpread.getActiveSheet().autoFitRow(node.serialNo());
  331. }
  332. projectObj.mainController.refreshTreeNode([node]);
  333. }
  334. }
  335. else if(value==null && fieldName ==='feeRate'){
  336. project.FeeRate.cleanFeeRateID(node);
  337. }
  338. else {
  339. projectObj.mainController.refreshTreeNode([node], false);
  340. }
  341. },
  342. mainSpreadLeaveCell: function (sender, info) {
  343. let colSetting = projectObj.mainController.setting.cols[info.col];
  344. projectObj.lastCol = colSetting;
  345. },
  346. mainSpreadEnterCell: function (sender, info) {
  347. let colSetting = projectObj.mainController.setting.cols[info.col];
  348. if(colSetting.data.field === 'unit' || projectObj.lastCol.data.field === 'unit'||colSetting.data.field ==='subType'|| projectObj.lastCol.data.field === 'subType'){
  349. info.sheet.repaint();
  350. }
  351. },
  352. mainSpreadEditStarting: function (sender, info) {
  353. let project = projectObj.project;
  354. let node = project.mainTree.items[info.row];
  355. if(isDef(node) && node.sourceType === project.Ration.getSourceType() && isDef(node.data.code) && isDef(node.data.from) && node.data.from === 'cpt'){
  356. let orgV = info.sheet.getValue(info.row, info.col);
  357. let newV = orgV.replace(new RegExp('补'), '');
  358. info.sheet.setValue(info.row, info.col, newV);
  359. }
  360. },
  361. mainSpreadEditEnded: function (sender, info) {
  362. let project = projectObj.project;
  363. let node = project.mainTree.items[info.row];
  364. let colSetting = projectObj.mainController.setting.cols[info.col];
  365. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  366. // 检查输入类型等
  367. let value = projectObj.checkSpreadEditingText(info.editingText, colSetting);
  368. projectObj.updateCellValue(node, value, colSetting,info.editingText);
  369. // 自动行高
  370. const autoHeight = project.property.displaySetting.autoHeight;
  371. if (autoHeight) {
  372. projectObj.mainSpread.getActiveSheet().autoFitRow(info.row);
  373. }
  374. },
  375. mainSpreadRangeChanged: function (sender, info) {
  376. let project = projectObj.project, setting = projectObj.mainController.setting;
  377. if (info.changedCells.length > 0) {
  378. for (let changedCell of info.changedCells) {
  379. let cell = info.sheet.getCell(changedCell.row, changedCell.col);
  380. let node = project.mainTree.items[changedCell.row];
  381. let colSetting = setting.cols[changedCell.col];
  382. let value = projectObj.checkSpreadEditingText(cell.text(), colSetting);
  383. projectObj.updateCellValue(node, value, colSetting);
  384. }
  385. }
  386. },
  387. checkMainSpread: function () {
  388. if (!this.mainSpread) {
  389. this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
  390. this.mainSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.muliRange);
  391. }
  392. },
  393. refreshMainSpread: function () {
  394. if (this.mainSpread) {
  395. this.mainSpread.refresh();
  396. }
  397. },
  398. loadProjectData: function () {
  399. var that = this;
  400. this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
  401. let startTime = +new Date();
  402. console.log("开始加载-----"+startTime);
  403. this.project.loadDatas(function (err) {
  404. if (!err) {
  405. that.project.projectGLJ.calcQuantity();//计算分部分项和技术措施项目消耗量;
  406. that.project.property = projectInfoObj.projectInfo.property;
  407. //that.project.calcProgram.compileAllTemps();
  408. that.project.calcBase.init(that.project);
  409. // that.project.calcFields = JSON.parse(JSON.stringify(cpFeeTypes));
  410. // that.project.initCalcFields();
  411. let str = JSON.stringify(that.project.projSetting.main_tree_col);
  412. that.project.projSetting.mainGridSetting = JSON.parse(str);
  413. that.project.projSetting.mainGridSetting.frozenCols = 4;
  414. TREE_SHEET_HELPER.initSetting($('#billsSpread')[0], that.project.projSetting.mainGridSetting);
  415. const autoHeight = that.project.property.displaySetting !== undefined ?
  416. that.project.property.displaySetting.autoHeight : false;
  417. that.project.projSetting.mainGridSetting.cols.forEach(function (col) {
  418. // for test. 后端没有绑定,暂时写死用于测试。
  419. /* if (col.data.field == '' && col.head.titleNames[0] == "取费专业") {
  420. col.data.field = 'programID';
  421. col.data.getText = 'getText.calcProgramName';
  422. col.data.cellType = 'cellType.calcProgramName';
  423. };*/
  424. col.data.splitFields = col.data.field.split('.');
  425. if (col.data.getText && Object.prototype.toString.apply(col.data.getText) === "[object String]") {
  426. col.data.getText = MainTreeCol.getEvent(col.data.getText);
  427. }
  428. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  429. col.readOnly = MainTreeCol.getEvent(col.readOnly);
  430. }
  431. if (col.data.cellType && Object.prototype.toString.apply(col.data.cellType) === "[object String]") {
  432. let getCellType = MainTreeCol.getEvent(col.data.cellType);
  433. col.data.cellType = getCellType;
  434. }
  435. // if (col.data.digit && Object.prototype.toString.apply(col.data.digit) === "[object String]") {
  436. // col.data.decimal = that.project.getDecimal(col.data.digit);
  437. // col.data.formatter = MainTreeCol.getNumberFormatter(col.data.decimal);
  438. // }
  439. if (col.data.field === 'code') {
  440. col.data.formatter = '@';
  441. }
  442. // 根据配置设置自动行高
  443. if (col.data.field === 'name' || col.data.field === 'itemCharacterText' ||
  444. col.data.field === 'jobContentText' || col.data.field === 'adjustState') {
  445. if (!autoHeight) {
  446. col.showHint = true;
  447. col.data.wordWrap = false;
  448. } else {
  449. col.showHint = false;
  450. col.data.wordWrap = true;
  451. }
  452. }
  453. if(col.data.field ==='quantity'){
  454. col.showHint = true;
  455. }
  456. // 综合单价、综合合价,小数部分应补0对齐。 CSLAAAAA
  457. // if (col.data.field.hasSubStr("common")){
  458. if (col.data.field.hasSubStr(".totalFee"))
  459. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.totalPrice, true)
  460. else if (col.data.field.hasSubStr(".unitFee"))
  461. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.unitPrice, true)
  462. // }
  463. });
  464. that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), that.project.projSetting.mainGridSetting);
  465. that.mainController.showTreeData();
  466. that.mainController.bind('refreshBaseActn', that.refreshBaseActn);
  467. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.beforeTreeSelectedChange, that.beforeMainTreeSelectedChange);
  468. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, that.treeSelectedChanged);
  469. that.mainSpread.bind(GC.Spread.Sheets.Events.LeaveCell, that.mainSpreadLeaveCell);
  470. that.mainSpread.bind(GC.Spread.Sheets.Events.EnterCell, that.mainSpreadEnterCell);
  471. that.mainSpread.bind(GC.Spread.Sheets.Events.EditStarting, that.mainSpreadEditStarting);
  472. that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
  473. that.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, that.mainSpreadRangeChanged);
  474. that.mainSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, that.amountAreaNumber);
  475. that.mainSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, that.onButtonClick);
  476. that.loadMainSpreadContextMenu();
  477. that.loadFocusLocation();
  478. let endTime = +new Date();
  479. socketObject.connect();//连接socket服务器
  480. console.log("加载完成-----"+endTime);
  481. console.log(`时间——${endTime - startTime}`);
  482. that.project.projectMarkChecking();//是否需要重新进行造价计算
  483. installationFeeObj.engineeringTypeChecking();//检查是否安装工程
  484. }
  485. else {
  486. }
  487. });
  488. },
  489. loadMainSpreadContextMenu: function () {
  490. var project = this.project, spread = this.mainSpread, controller = this.mainController;
  491. $.contextMenu({
  492. selector: '#billsSpread',
  493. build: function ($trigger, e) {
  494. var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  495. controller.setTreeSelected(controller.tree.items[target.row]);
  496. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  497. },
  498. items: {
  499. "insertRootBill": {
  500. name: "插入大项费用",
  501. icon: 'fa-sign-in',
  502. disabled: function () {
  503. //return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
  504. },
  505. callback: function (key, opt) {
  506. ProjectController.addRootBill(project, controller);
  507. },
  508. visible: function(key, opt){
  509. return project.mainTree.selected&&project.mainTree.selected.parent==null;
  510. }
  511. },
  512. "insertFB": {
  513. name: "插入分部",
  514. icon: 'fa-sign-in',
  515. disabled: function () {
  516. let selected = project.mainTree.selected;
  517. if(selected&&selected.sourceType==project.Bills.getSourceType()){
  518. if(selected.data.type==billType.FB){
  519. return false;
  520. }
  521. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  522. if(selected.children.length>0){
  523. return selected.children[0].data.type==billType.FX;//焦点行是分部分项工程,且子项是分项
  524. }else {
  525. return false
  526. }
  527. }
  528. }
  529. return true;//除了清单,其它类型都只读
  530. },
  531. callback: function (key, opt) {
  532. ProjectController.addFB(project, controller);
  533. },
  534. visible: function(key, opt){
  535. if(project.mainTree.selected){
  536. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  537. }else {
  538. return false;
  539. }
  540. }
  541. },
  542. "insertFX": {
  543. name: "插入分项",
  544. icon: 'fa-sign-in',
  545. disabled: function () {
  546. let selected = project.mainTree.selected;
  547. if(selected&&selected.sourceType==project.Bills.getSourceType()){
  548. if(selected.data.type==billType.FX){//焦点行是分项,有效显示
  549. return false
  550. }
  551. if(selected.data.type==billType.FB){//点行是分部,
  552. if(selected.children.length>0){//且有子项,子项是分部,灰显。
  553. return selected.children[0].data.type == billType.FB
  554. }else {
  555. return false;
  556. }
  557. }
  558. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  559. if(selected.children.length>0){
  560. return selected.children[0].data.type==billType.FB;//焦点行是分部分项工程,且子项是分部时灰显
  561. }else {
  562. return false
  563. }
  564. }
  565. }
  566. return true;//除了清单,其它类型都只读
  567. },
  568. callback: function (key, opt) {
  569. ProjectController.addFX(project, controller);
  570. },
  571. visible: function(key, opt){
  572. if(project.mainTree.selected){
  573. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  574. }else {
  575. return false;
  576. }
  577. }
  578. },
  579. "insertBills": {
  580. name: "插入清单",
  581. icon: 'fa-sign-in',
  582. disabled: function () {
  583. return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
  584. },
  585. callback: function (key, opt) {
  586. if(project.mainTree.selected.data.type == billType.DXFY){
  587. if(project.mainTree.selected.data.calcBase&&project.mainTree.selected.data.calcBase!=""){
  588. alert("当前有基数计算不能插入子项。");
  589. return;
  590. }
  591. }
  592. ProjectController.addBills(project, controller);
  593. },
  594. visible: function(key, opt){
  595. if(project.mainTree.selected){
  596. return project.Bills.isFBFX(project.mainTree.selected)==true?false:true;
  597. }else {
  598. return false;
  599. }
  600. }
  601. },
  602. "insertRation": {
  603. name: "插入定额",
  604. icon: 'fa-sign-in',
  605. disabled: function () {
  606. var selected = project.mainTree.selected;
  607. return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  608. },
  609. callback: function (key, opt) {
  610. ProjectController.addRation(project, controller, rationType.ration);
  611. },
  612. visible: function(key, opt){
  613. var selected = project.mainTree.selected;
  614. if(selected){
  615. if(selected.sourceType == ModuleNames.bills&&selected.data.type == billType.DXFY){
  616. return false
  617. }else {
  618. return true
  619. }
  620. }
  621. return false;
  622. }
  623. },
  624. "insertLJ": {
  625. name: "插入量价",
  626. icon: 'fa-sign-in',
  627. disabled: function () {
  628. var selected = project.mainTree.selected;
  629. return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  630. },
  631. callback: function (key, opt) {
  632. ProjectController.addRation(project, controller, rationType.volumePrice);
  633. },
  634. visible: function(key, opt){
  635. var selected = project.mainTree.selected;
  636. if(selected){
  637. if(selected.sourceType == ModuleNames.bills&&selected.data.type == billType.DXFY){
  638. return false
  639. }else {
  640. return true
  641. }
  642. }
  643. return false;
  644. }
  645. },
  646. "insertGLJ": {
  647. name: "插入工料机",
  648. icon: 'fa-sign-in',
  649. disabled: function () {
  650. var selected = project.mainTree.selected;
  651. return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  652. },
  653. callback: function (key, opt) {
  654. var selected = project.mainTree.selected;
  655. if(selected.sourceType == ModuleNames.bills){
  656. if(selected.data.type == billType.FX||selected.data.type ==billType.BILL){
  657. if(selected.data.calcBase&&selected.data.calcBase!=""){
  658. alert("当前有基数计算不能插入子项。");
  659. return;
  660. }
  661. }
  662. }
  663. getGLJData('insert');// ProjectController.addRation(project, controller, rationType.volumePrice);
  664. },
  665. visible: function(key, opt){
  666. var selected = project.mainTree.selected;
  667. if(selected){
  668. if(selected.sourceType == ModuleNames.bills&&selected.data.type == billType.DXFY){
  669. return false;
  670. }else {
  671. return true;
  672. }
  673. }
  674. return false;
  675. }
  676. },
  677. "ZLFB": {
  678. name: "整理分部",
  679. icon: 'fa-sign-in',
  680. disabled: function () {
  681. return false;
  682. },
  683. callback: function (key, opt) {
  684. zlfb_object.getSectionInfo();
  685. },
  686. visible: function(key, opt){
  687. return true;
  688. }
  689. },
  690. "calc_installation_fee": {
  691. name: "计取安装费用",
  692. icon: 'fa-sign-in',
  693. disabled: function () {
  694. return false;
  695. },
  696. callback: function (key, opt) {
  697. installationFeeObj.showCalcInstallSettingDiv();
  698. },
  699. visible: function(key, opt){
  700. let engineering = projectInfoObj.projectInfo.property.engineering;
  701. return engineering==engineeringType.BUILD_IN;
  702. }
  703. },
  704. "spr1": '--------',
  705. "delete": {
  706. name: '删除',
  707. icon: 'fa-remove',
  708. disabled: function () {
  709. return !ifCanDelete();
  710. },
  711. callback: function () {
  712. $("#delete_row").modal({show:true});//弹出删除提示框;
  713. }
  714. },
  715. "spr2":'--------',
  716. "calculateAll_RationContent": {
  717. name: '造价计算',
  718. callback: function () {
  719. $.bootstrapLoading.start();
  720. project.calcProgram.calcAllNodesAndSave();
  721. }
  722. }
  723. }
  724. });
  725. },
  726. // 计算node及node的所有父项
  727. converseCalculateBills: function (node) {
  728. /* if (node) {
  729. let calc = new BillsCalcHelper(this.project);
  730. calc.calcNode(node, true);
  731. let cur = node, nodes = [];
  732. while (cur) {
  733. nodes.push(cur);
  734. cur = cur.parent;
  735. }
  736. this.mainController.refreshTreeNode(nodes, false);
  737. this.project.Bills.updateNodes(nodes, true);
  738. calc = null;
  739. }*/
  740. projectObj.project.calcProgram.calcAndSave(node);
  741. },
  742. // 计算全部清单
  743. /* calculateAll: function () {
  744. let calc = new BillsCalcHelper(this.project);
  745. calc.calcAll();
  746. this.mainController.showTreeData();
  747. this.project.Bills.updateAll();
  748. calc = null;
  749. }*/
  750. // 获取上次退出时的焦点位置
  751. loadFocusLocation: function() {
  752. const projectId = scUrlUtil.GetQueryString('project');
  753. let row = getLocalCache('lastRow:' + projectId);
  754. let col = getLocalCache('lastCol:' + projectId);
  755. if (row !== null && col !== null) {
  756. row = parseInt(row);
  757. col = parseInt(col);
  758. const sheet = this.mainSpread.getActiveSheet();
  759. sheet.setSelection(row, col, 1, 1);
  760. this.mainController.setTreeSelected(this.mainController.tree.items[row]);//触发树节点选中事件
  761. }
  762. },
  763. // 选中区域合计数字
  764. amountAreaNumber: function(e, info) {
  765. if (info.newSelections === undefined || info.newSelections.length <= 0) {
  766. return false;
  767. }
  768. const selectedArea = info.newSelections[0];
  769. const sheet = info.sheet;
  770. if (selectedArea.colCount <= 1 && selectedArea.rowCount <= 1) {
  771. return false;
  772. }
  773. // 获取鼠标位置
  774. let x = window.event.clientX;
  775. let y = window.event.clientY;
  776. // 匹配数字或小数
  777. const regular = /^([0-9]+[.]{1}[0-9]+)$|^([1-9]{1}\d*)$/;
  778. // 小数点最高位数
  779. let max = 0;
  780. let total = 0;
  781. let counter = 0;
  782. for (let col = selectedArea.col; col < (selectedArea.colCount + selectedArea.col); col++) {
  783. for (let row = selectedArea.row; row < (selectedArea.rowCount + selectedArea.row); row++) {
  784. const value = sheet.getCell(row, col).text();
  785. if (!regular.test(value)) {
  786. continue;
  787. }
  788. counter++;
  789. // 获取当前数据小数位数
  790. let pointPosition = value.toString().indexOf(".");
  791. pointPosition = pointPosition < 0 ? pointPosition : pointPosition + 1;
  792. const current = pointPosition > 0 ? value.toString().substring(pointPosition, value.toString().length).length : 0;
  793. max = current > max ? current : max;
  794. total += parseFloat(value);
  795. }
  796. }
  797. // 如果不为0则悬浮显示
  798. if (total > 0 && counter > 1) {
  799. const div = $('<div id="total-tips"><p>合计: <input type="text" id="total" readonly="readonly" style="border: none;"/></p><p><a href="javascript:void(0);">复制</a></p></div>');
  800. div.css({
  801. position: "absolute",
  802. border: "1px #C0C0C0 solid",
  803. background: "#fff",
  804. boxShadow: "1px 2px 5px rgba(0,0,0,0.4)",
  805. });
  806. div.children("p").css({
  807. textAlign: "center",
  808. padding: 8,
  809. marginBottom: 2,
  810. });
  811. div.children("p").first().css({
  812. borderBottom: "1px #C0C0C0 solid"
  813. });
  814. const totalString = total.toFixed(max);
  815. // input长度
  816. const inputWidth = totalString.length * 8;
  817. // 计算是否会超出显示范围
  818. const baseWidth = 48;
  819. const baseHeight = 81;
  820. const canvasWidth = $("#billsSpreadvp_vp").width();
  821. const canvasHeight = $("#billsSpreadvp_vp").height();
  822. x = x + baseWidth + inputWidth > canvasWidth ? x - baseWidth - inputWidth : x;
  823. y = y + baseHeight > canvasHeight ? y - baseHeight : y;
  824. div.css({
  825. left: x,
  826. top: y,
  827. });
  828. div.children().children("#total").width(inputWidth).val(totalString);
  829. $("body").append(div);
  830. // 用于判断是否要关闭窗体
  831. setTimeout(function() {
  832. isTotalShowing = true;
  833. }, 200);
  834. };
  835. },
  836. onButtonClick: function (e, info) {
  837. let node = projectObj.project.mainTree.items[info.row];
  838. if (node.data.isSubcontract) node.data.isSubcontract = false
  839. else node.data.isSubcontract = true;
  840. node.changed = true;
  841. projectObj.project.calcProgram.calcAndSave(node);
  842. },
  843. //根据节点获取行style(颜色、字体加粗)
  844. getNodeColorStyle: function (node, colSetting) {
  845. let colorSetting = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
  846. let mapping = {DEFAULT: 'DEFAULT', DXFY: 'DXFY', FB: 'FB', UNLEAFBILL: 'UNLEAFBILL',
  847. FX: 'FX', UNCBBILL: 'UNCBBILL', CBBILL: 'CBBILL', ZCSB: 'ZCSB'};
  848. let styleMap = null;
  849. //中文字段名,由于同一节点中,中文字体大小和数字字体大小不同
  850. let stringFields = [
  851. 'code',
  852. 'subType',
  853. 'name',
  854. 'unit',
  855. 'itemCharacterText',
  856. 'jobContentText',
  857. 'adjustState',
  858. 'calcBase',
  859. 'programID',
  860. 'ruleText'
  861. ];
  862. if(!isDef(node)){
  863. return null;
  864. }
  865. //清单大类
  866. if(node.sourceType === this.project.Bills.getSourceType()){
  867. //大项费用
  868. //大项费用
  869. if(node.data.type === billType.DXFY){
  870. styleMap = mapping.DXFY;
  871. }
  872. //分部
  873. if(node.data.type === billType.FB){
  874. styleMap = mapping.FB;
  875. }
  876. //分项
  877. else if(node.data.type === billType.FX){
  878. styleMap = mapping.FX;
  879. }
  880. //清单
  881. else if(node.data.type === billType.BILL){
  882. //非叶子节点的清单
  883. if(node.source.children.length > 0){
  884. styleMap = mapping.UNLEAFBILL;
  885. }
  886. //未使用基数计算的叶子节点的清单
  887. else if(node.source.children.length === 0 && (!isDef(node.data.calcBase) || node.data.calcBase === '')){
  888. styleMap = mapping.UNCBBILL;
  889. }
  890. //使用基数计算的叶子节点的清单
  891. else if(node.source.children.length === 0 && isDef(node.data.calcBase && node.data.calcBaseValue !== '')){
  892. styleMap = mapping.CBBILL;
  893. }
  894. }
  895. }
  896. //定额下的主材、设备
  897. else if(node.sourceType === this.project.ration_glj.getSourceType()){
  898. styleMap = mapping.ZCSB;
  899. }
  900. else {
  901. styleMap = mapping.DEFAULT;
  902. }
  903. let styleSetting = colorSetting[styleMap];
  904. let defaultSetting = colorSetting[mapping.DEFAULT];
  905. if(!isDef(styleSetting)){
  906. return null;
  907. }
  908. let style = new GC.Spread.Sheets.Style();
  909. //设置style属性
  910. for(let attr in styleSetting){
  911. if(attr !== 'stringFont' && attr !== 'numFont'){
  912. style[attr] = styleSetting[attr] === 'default' || !isDef(styleSetting[attr]) ? defaultSetting[attr] : styleSetting[attr];
  913. }
  914. //暂时不开放字体设置,开放的话只能每个单元格进入此方法
  915. /* else {
  916. if(stringFields.indexOf(colSetting.data.field) > 0){
  917. style.font = styleSetting.stringFont === 'default' || !isDef(styleSetting.stringFont) ? defaultSetting.stringFont : styleSetting.stringFont;
  918. }
  919. else {
  920. style.font = styleSetting.numFont === 'default' || !isDef(styleSetting.numFont) ? defaultSetting.numFont : styleSetting.numFont;
  921. }
  922. }*/
  923. }
  924. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  925. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  926. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  927. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  928. return style;
  929. },
  930. //大项费用则字体加粗,String 15px, Number 13px
  931. getBoldFontStyle: function (node, colSetting) {
  932. if(node.sourceType !== this.project.Bills.getSourceType() || node.data.type !== billType.DXFY){
  933. return null;
  934. }
  935. let style = new GC.Spread.Sheets.Style();
  936. //备注暂无字段
  937. let stringFields = [
  938. 'code',
  939. 'subType',
  940. 'name',
  941. 'unit',
  942. 'itemCharacterText',
  943. 'jobContentText',
  944. 'adjustState',
  945. 'calcBase',
  946. 'programID',
  947. 'ruleText'
  948. ];
  949. if(stringFields.indexOf(colSetting.data.field) > 0){
  950. style.font = 'bold 15px Arial';
  951. }
  952. else {
  953. style.font = 'bold 13px Arial';
  954. }
  955. return style;
  956. }
  957. };
  958. // 点击合计框中的复制
  959. $("body").on("click", "#total-tips a", function() {
  960. const totalElement = $(this).parent().siblings("p").find("#total");
  961. totalElement.select();
  962. document.execCommand("Copy");
  963. $(this).text("已复制");
  964. });
  965. // 合计框点击其他位置关闭
  966. let isTotalShowing = false;
  967. $("body").on("click", function(e) {
  968. if (isTotalShowing && !$(e.target).is("#total-tips") && !$(e.target).is("#total-tips p") && !$(e.target).is("#total-tips p a")) {
  969. $("#total-tips").remove();
  970. isTotalShowing = false;
  971. }
  972. });
  973. $('#insert').click(function () {
  974. var controller = projectObj.mainController, project = projectObj.project;
  975. var selected = controller.tree.selected;
  976. if (!selected || selected.sourceType === project.Bills.getSourceType()) {
  977. ProjectController.addBills(project, controller);
  978. } else if (selected.sourceType === project.Ration.getSourceType()) {
  979. ProjectController.addRation(project, controller, selected.data.type);
  980. };
  981. });
  982. $('#delete').click(function () {
  983. $("#delete_row").modal({show:true});//弹出删除提示框;
  984. });
  985. $('#upLevel').click(function () {
  986. var controller = projectObj.mainController, project = projectObj.project;
  987. var selected = controller.tree.selected, orgParent = selected.parent;
  988. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  989. project.Bills.upLevelBills(selected.source);
  990. controller.upLevel();
  991. controller.refreshTreeNode([orgParent]);
  992. projectObj.project.calcProgram.calcBillsAndSave([selected,orgParent]);
  993. }
  994. });
  995. $('#downLevel').click(function () {
  996. var controller = projectObj.mainController, project = projectObj.project;
  997. var selected = controller.tree.selected;
  998. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  999. project.Bills.downLevelBills(selected.source);
  1000. controller.downLevel();
  1001. controller.refreshTreeNode([selected.parent]);
  1002. projectObj.converseCalculateBills(selected.parent);
  1003. }
  1004. });
  1005. $('#upMove').click(function () {
  1006. var controller = projectObj.mainController, project = projectObj.project;
  1007. var selected = controller.tree.selected, pre = selected.preSibling, preSerialNo;
  1008. if (selected.sourceType === project.Bills.getSourceType()) {
  1009. project.Bills.upMoveBills(selected.source);
  1010. controller.upMove();
  1011. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1012. project.Ration.changePos(selected.source, selected.preSibling.source);
  1013. controller.upMove();
  1014. };
  1015. });
  1016. $('#downMove').click(function () {
  1017. var controller = projectObj.mainController, project = projectObj.project;
  1018. var selected = controller.tree.selected, next, nextSerialNo;
  1019. if (selected) {
  1020. if (selected.sourceType === project.Bills.getSourceType()) {
  1021. project.Bills.downMoveBills(selected.source);
  1022. controller.downMove();
  1023. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1024. project.Ration.changePos(selected.source, selected.nextSibling.source);
  1025. controller.downMove();
  1026. };
  1027. }
  1028. });
  1029. $('#poj-set').on('show.bs.modal', function () {
  1030. let setCalcFlag = function (obj, val, curFlag) {
  1031. obj.val(val);
  1032. if (val === curFlag) {
  1033. obj.attr('checked', true);
  1034. } else {
  1035. obj.removeAttr('checked');
  1036. }
  1037. }
  1038. if (projectObj.project) {
  1039. // let mode = projectObj.project.projSetting.billsCalcMode;
  1040. // let settingConst = projectObj.project.projSetting.settingConst;
  1041. let ft = projectObj.project.property.billsCalcMode ? projectObj.project.property.billsCalcMode : leafBillGetFeeType.rationContent;
  1042. setCalcFlag($('#rationContent'), leafBillGetFeeType.rationContent, ft);
  1043. setCalcFlag($('#rationPriceConverse'), leafBillGetFeeType.rationPriceConverse, ft);
  1044. setCalcFlag($('#rationPrice'), leafBillGetFeeType.rationPrice, ft);
  1045. setCalcFlag($('#billsPrice'), leafBillGetFeeType.billsPrice, ft);
  1046. // mode = projectObj.project.projSetting.zanguCalcType;
  1047. let zg = projectObj.project.property.zanguCalcMode ? projectObj.project.property.zanguCalcMode : zanguCalcType.common;
  1048. setCalcFlag($('#zangu_common'), zanguCalcType.common, zg);
  1049. setCalcFlag($('#zangu_gatherMaterial'), zanguCalcType.gatherMaterial, zg);
  1050. }
  1051. });
  1052. $('#property_ok').click(function () {
  1053. let project = projectObj.project,
  1054. projectID = project.ID(),
  1055. properties = {},
  1056. labourCoes = {},
  1057. rations = [],
  1058. bills = [],
  1059. mixDatas = {
  1060. projectID: projectID,
  1061. updateType: 'update',
  1062. properties: properties,
  1063. labourCoes: labourCoes,
  1064. rations: rations,
  1065. bills: bills
  1066. },
  1067. reCalcBills = false,
  1068. reCalcRations = false;
  1069. let b = parseInt($("input[name='calcFlag']:checked").val());
  1070. if (b !== project.property.billsCalcMode) {
  1071. properties['property.billsCalcMode'] = b;
  1072. project.property.billsCalcMode = b;
  1073. reCalcBills = true;
  1074. };
  1075. let zg = parseInt($("input[name='zangu']:checked").val());
  1076. if (zg !== project.property.zanguCalcMode) {
  1077. properties['property.zanguCalcMode'] = zg;
  1078. project.property.zanguCalcMode = zg;
  1079. reCalcRations = true;
  1080. };
  1081. //基本信息
  1082. if(basicInfoView.toUpdate(basicInfoView.orgDatas, basicInfoView.datas)){
  1083. properties['property.basicInformation'] = basicInfoView.toSaveDatas(basicInfoView.datas);
  1084. }
  1085. //工程特征
  1086. if(projFeatureView.toUpdate(projFeatureView.orgDatas, projFeatureView.datas)){
  1087. properties['property.projectFeature'] = projFeatureView.toSaveDatas(projFeatureView.datas);
  1088. }
  1089. //清单工程量精度
  1090. let newBillsDecimalDatas = billsDecimalView.toBillsDecimalDatas(billsDecimalView.cache);
  1091. if(billsDecimalView.toUpdate(billsQuanDecimal.datas, newBillsDecimalDatas)){
  1092. billsQuanDecimal.datas = newBillsDecimalDatas;
  1093. reCalcBills = true;
  1094. properties['property.billsQuantityDecimal'] = newBillsDecimalDatas;
  1095. }
  1096. //小数位数
  1097. let updateDecimal = m_getDecimalData($('input', '#poj-settings-decimal'));
  1098. if(toUpdateDecimal(decimalObj, updateDecimal)) {
  1099. let frChanged = decimalObj.feeRate != updateDecimal.feeRate;
  1100. setDecimal(decimalObj, updateDecimal);
  1101. if (frChanged) {
  1102. project.calcProgram.compileAllTemps()
  1103. }
  1104. reCalcRations = true;
  1105. reCalcBills = true;
  1106. properties['property.decimal'] = updateDecimal;
  1107. }
  1108. // 呈现选项
  1109. projDisplayView.updateChecking(properties);
  1110. if(calcOptions.updateChecking(properties)){
  1111. reCalcRations = true;
  1112. }
  1113. // 人工系数
  1114. if (labourCoeView.needSave()){
  1115. let libID = $("#std_labour_coe_files").children("option:selected").val();
  1116. let libName = $("#std_labour_coe_files").children("option:selected").text();
  1117. labourCoes.updateData = {libID: libID, libName: libName, newItemArr: labourCoeView.needUpdateDatas};
  1118. project.labourCoe.refreshData(labourCoes.updateData); // 全编译所用到的人工系数来自project.labourCoe,所以必须先刷新project.labourCoe
  1119. project.calcProgram.compileAllTemps();
  1120. reCalcRations = true;
  1121. reCalcBills = true;
  1122. };
  1123. // 重新计算树节点
  1124. let changedNodes = [];
  1125. if (reCalcRations) // 定额动,全部计算。算完先不存储,和后面的数据一起提交,一次通讯。
  1126. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catAll)
  1127. else if (reCalcBills) // 清单动,可以只计算清单。
  1128. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catBills);
  1129. if (changedNodes.length > 0) {
  1130. for (let node of changedNodes){
  1131. let data = calcTools.cutNodeForSave(node);
  1132. if (node.sourceType == 'ration') rations.push(data)
  1133. else if (node.sourceType == 'bills') bills.push(data);
  1134. };
  1135. };
  1136. // for test.
  1137. /* console.log(mixDatas);
  1138. return; */
  1139. function hasMixData() {
  1140. return Object.keys(mixDatas.properties).length > 0 ||
  1141. mixDatas.labourCoes.updateData || mixDatas.rations.length > 0 || mixDatas.bills.length > 0;
  1142. }
  1143. if(hasMixData()){
  1144. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  1145. /* if (changedNodes.length > 0) {
  1146. for (let node of changedNodes){delete node.changed};
  1147. };
  1148. if (mixDatas.labourCoes.updateData) labourCoeView.refresh();*/
  1149. window.location.href = '/main?project=' + projectID;
  1150. });
  1151. }
  1152. });
  1153. $('#delete_row').on('shown.bs.modal', function (e) {
  1154. var controller = projectObj.mainController, project = projectObj.project;
  1155. var selected = controller.tree.selected, parent = selected.parent;
  1156. var showinfo = "确认要删除当前选中行吗?";
  1157. var showN = false;
  1158. var cancelText = "否";
  1159. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length>0){//选中的是分部,并且有子项
  1160. if(isSingleSelect()||selectionChecking()){
  1161. showinfo = "是否删除其下的子项?";
  1162. showN = true;
  1163. cancelText = "取消";
  1164. }
  1165. }
  1166. $('#delete_showinfo').text(showinfo);
  1167. showN==true? $('#deleteN').show():$('#deleteN').hide();
  1168. $('#deleteCancel').text(cancelText);
  1169. function selectionChecking() {
  1170. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  1171. let mainTreeMap = {};
  1172. for(let i =0;i<selection.rowCount;i++){
  1173. let tem_node = controller.tree.items[selection.row+i];
  1174. if(i==0){//第一个直接添加;
  1175. mainTreeMap[tem_node.getID()] = tem_node;
  1176. }else {
  1177. project.Bills.setNodeToMap(tem_node,mainTreeMap);
  1178. }
  1179. }
  1180. let nodes = changeMapToArray(mainTreeMap);
  1181. if(nodes.length==1){
  1182. return true
  1183. }
  1184. return false;
  1185. }
  1186. });
  1187. function changeMapToArray(map) {
  1188. let newArray = [];
  1189. for(let key in map){
  1190. newArray.push(map[key]);
  1191. }
  1192. return newArray;
  1193. }
  1194. $('#deleteY').click(function () { //正常删除,级联删除子项
  1195. let project = projectObj.project;
  1196. if(isSingleSelect()){
  1197. project.Bills.deleteSelectedNode();
  1198. }else {
  1199. project.Bills.deleteSelectedNodes();
  1200. }
  1201. });
  1202. $('#deleteN').click(function () {//不删除子项
  1203. let controller = projectObj.mainController, project = projectObj.project;
  1204. let selected = controller.tree.selected, parent = selected.parent;
  1205. if(selected){
  1206. let preNode = selected.preSibling;
  1207. let nextNode = selected.nextSibling;
  1208. if(preNode){//有前兄弟
  1209. if(preNode.children.length>0&&preNode.children[0].data.type != selected.children[0].data.type){//并且前兄弟子项和焦点行子项类别不同。
  1210. alert("删除分部会导致分部和分项同级,不允许该操作!");
  1211. return;
  1212. }
  1213. }else if(nextNode){
  1214. if(nextNode.data.type != selected.children[0].data.type){
  1215. alert("删除分部会导致分部和分项同级,不允许该操作! ");
  1216. return;
  1217. }
  1218. }
  1219. project.Bills.singleDeleteBills(selected,controller);
  1220. }
  1221. });
  1222. function isSingleSelect() {//是否选中造价书中的单行
  1223. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  1224. if (selections[0].rowCount == 1) {
  1225. return true;
  1226. }
  1227. return false;
  1228. }
  1229. function ifCanDelete() {
  1230. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  1231. let tree = projectObj.project.mainTree;
  1232. let selected = projectObj.project.mainTree.selected;
  1233. if(selections[0].rowCount==1){//选中单行
  1234. return canDelete(selected);
  1235. }else {
  1236. return canDelete_m(selections[0]);
  1237. }
  1238. function canDelete(node,m_selection) {
  1239. if (node) {
  1240. if (node.sourceType === projectObj.project.Bills.getSourceType()) {
  1241. if(node.data.type == billType.DXFY&&node.data.isAdd!=1){
  1242. return false;
  1243. }
  1244. }
  1245. if(m_selection!=true&&node.sourceType === projectObj.project.ration_glj.getSourceType()){//多选的时候不做这一项判断
  1246. return false;
  1247. }
  1248. return true;
  1249. } else {
  1250. return false;
  1251. }
  1252. };
  1253. function canDelete_m(selection) {
  1254. for(let i =0;i<selection.rowCount;i++){
  1255. if(tree.items[selection.row+i]==undefined||tree.items[selection.row+i]==null){
  1256. return false;
  1257. }
  1258. if(i==0&&tree.items[selection.row].sourceType === projectObj.project.ration_glj.getSourceType()){
  1259. return false
  1260. }
  1261. if(canDelete(tree.items[selection.row+i],true)==false){
  1262. return false
  1263. }
  1264. }
  1265. return true
  1266. };
  1267. }