project_view.js 63 KB

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