project_view.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978
  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 c = '';
  17. if (caption) c = caption + ': ';
  18. let s = `          ${c}${value}`;
  19. $('#testDisplay').html(s);
  20. },
  21. treeSelectedChanged: function (node) {
  22. let project = projectObj.project;
  23. let mainSheet = projectObj.mainController.sheet;
  24. //设置选中行底色和恢复前选中行底色
  25. let refreshNodes = [node];
  26. if(!project.mainTree.preSelected){
  27. refreshNodes.push(project.mainTree.items[0]);
  28. }
  29. else {
  30. refreshNodes.push(project.mainTree.preSelected);
  31. }
  32. project.mainTree.preSelected = node;
  33. projectObj.setNodesStyle(projectObj.mainController.sheet, refreshNodes);
  34. subViewObj.loadComments(node);
  35. gljOprObj.showDataIfRationSelect(node);
  36. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  37. calcProgramObj.showData(node);
  38. }
  39. //zhong 2017-9-1 特征及内容
  40. if(pageCCOprObj.active){
  41. pageCCOprObj.mainActiveCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];//mainSpread焦点单元格
  42. if(node && node.sourceType === project.Bills.getSourceType()){
  43. pageCCOprObj.setCacheAndShow(node);
  44. }
  45. else{
  46. pageCCOprObj.clearData();
  47. }
  48. }
  49. // for test interface. CSLAAAAA
  50. // projectObj.testDisplay('前四项累计值排除当前选中项' + projectObj.project.calcProgram.getBeforeTaxTotalFee([node]));
  51. // 基数
  52. // node.data.isSubcontract = true;
  53. // node.data.gljList = project.ration_glj.getGljArrByRation(node.data);
  54. // let bname = '甲供定额基价材料费';
  55. // projectObj.testDisplay(bname, rationCalcBases[bname](node));
  56. },
  57. refreshBaseActn: function (tree) {
  58. let setButtonValid = function (valid, btn) {
  59. if (valid) {
  60. btn.removeClass('disabled');
  61. } else {
  62. btn.addClass('disabled');
  63. }
  64. };
  65. let selected = tree.selected, that = projectObj;
  66. let canUpLevel = function (node) {
  67. if(!node){
  68. return false;
  69. }
  70. if(projectObj.project.isBillsLocked()== true){
  71. return false;
  72. }
  73. if(node.depth()<=1){//焦点行是树结构的第一/二层节点,灰显。
  74. return false;
  75. }
  76. if(node.sourceType !== that.project.Bills.getSourceType()){//焦点行是定额/量价/工料机,灰显。
  77. return false;
  78. }else {
  79. if(node.data.type == billType.FX){//是分项,灰显。
  80. return false;
  81. }
  82. if(node.data.type == billType.FB&&node.nextSibling&&node.children.length>0){//焦点行是分部有后兄弟,有子项.
  83. if(node.children[0].data.type==billType.FX){ //焦点行子项是分项
  84. return false;
  85. }
  86. }
  87. if(node.data.type == billType.BILL &&node.nextSibling){//焦点行是清单有后兄弟
  88. if(node.data.calcBase&&node.data.calcBase!=""){//有基数计算
  89. return false;
  90. }
  91. if(node.children.length>0&&node.children[0].sourceType !== that.project.Bills.getSourceType()){//有子项,并且子项不是清单
  92. return false;
  93. }
  94. }
  95. }
  96. return true;
  97. };
  98. let canDownLevel = function (node) {
  99. if(!node){
  100. return false;
  101. }
  102. if(projectObj.project.isBillsLocked()== true){
  103. return false;
  104. }
  105. if(node.depth()==0){//焦点行是树结构的第一层节点,灰显。
  106. return false;
  107. }
  108. if(node.sourceType !== that.project.Bills.getSourceType()) {//焦点行是定额/量价/工料机,灰显。
  109. return false;
  110. }else {
  111. if(node.data.type == billType.FX){//是分项,灰显。
  112. return false;
  113. }
  114. if(!node.preSibling){//无前兄弟,灰显
  115. return false;
  116. }else if(node.preSibling.data.calcBase&&node.preSibling.data.calcBase!=""){//前兄弟有基数计算
  117. return false
  118. }
  119. if(node.preSibling.children.length>0){//前兄弟有子项,子项是分项,灰显。
  120. if(node.data.type==billType.FB&&node.preSibling.children[0].data.type==billType.FX){//焦点行是分部前兄弟有子项,子项是分项,灰显。
  121. return false;
  122. }
  123. if(node.data.type==billType.BILL&&node.preSibling.children[0].sourceType !== that.project.Bills.getSourceType()){//焦点行是清单,子项不是清单
  124. return false
  125. }
  126. }
  127. }
  128. return true;
  129. };
  130. let canUpMove = function (node) {
  131. if(node&&node.preSibling){//有前兄弟
  132. if(node.sourceType==that.project.Bills.getSourceType()){
  133. if(projectObj.project.isBillsLocked()== true){
  134. return false;
  135. }
  136. if(node.data.type == billType.DXFY&&node.data.isAdd!==1){
  137. return false;
  138. }
  139. }
  140. return true
  141. }
  142. return false
  143. };
  144. let canDownMove = function (node) {
  145. if(node&&node.nextSibling){
  146. if(node.sourceType==that.project.Bills.getSourceType()){
  147. if(projectObj.project.isBillsLocked()== true){
  148. return false;
  149. }
  150. if(node.data.type == billType.DXFY&&node.data.isAdd!==1){
  151. return false;
  152. }
  153. }
  154. return true;
  155. }
  156. return false
  157. };
  158. setButtonValid(ifCanDelete(), $('#delete'));
  159. setButtonValid(canUpLevel(selected), $('#upLevel'));
  160. setButtonValid(canDownLevel(selected), $('#downLevel'));
  161. setButtonValid(canUpMove(selected) , $('#upMove'));
  162. setButtonValid(canDownMove(selected), $('#downMove'));
  163. },
  164. checkCommonField: function (editingText, colSetting) {
  165. let value;
  166. if (colSetting.data.decimal) {
  167. value = Number(editingText);
  168. if (number_util.isNumber(value)) {
  169. if (colSetting.data.decimal) {
  170. value = value.toDecimal(colSetting.data.decimal);
  171. }
  172. } else {
  173. value = null;
  174. alert('当前输入的数据类型不正确,请重新输入。');
  175. }
  176. } else {
  177. value = editingText;
  178. }
  179. return value;
  180. },
  181. checkFormulaValidField: function (editingText, colSetting) {
  182. let value = Number(editingText);
  183. if (!value) {
  184. try {
  185. let exp = new Expression('');
  186. exp.Expression(editingText);
  187. value = Number(exp.Evaluate());
  188. } catch (error) {
  189. value = null;
  190. }
  191. }
  192. if (value!=undefined||value!=null) {
  193. if (colSetting.data.decimal) {
  194. value = value.toDecimal(colSetting.data.decimal);
  195. }
  196. } else if (editingText && editingText !== '') {
  197. value = null;
  198. alert('当前输入的数据类型不正确,请重新输入。');
  199. }
  200. return value;
  201. },
  202. checkSpreadEditingText: function (editingText, colSetting) {
  203. if (colSetting.data.field === 'quantity'||colSetting.data.field === 'contain') {
  204. return this.checkFormulaValidField(editingText, colSetting);
  205. }
  206. else if (colSetting.data.field === 'programID') {
  207. return this.project.calcProgram.compiledTemplateMaps[editingText];
  208. }
  209. else if (colSetting.data.field === 'subType') {
  210. if (typeof(editingText) !== "number")
  211. return volumePriceMaps[editingText]
  212. else
  213. return editingText;
  214. }
  215. else {
  216. return this.checkCommonField(editingText, colSetting);
  217. }
  218. },
  219. getVisibleRows: function (sRow, count) {
  220. let rst = [];
  221. let nodes = projectObj.project.mainTree.items;
  222. for(let i = sRow, len = nodes.length; i < len; i++){
  223. if(count <= 0){
  224. break;
  225. }
  226. if(nodes[i].visible){
  227. rst.push(i);
  228. count--;
  229. }
  230. }
  231. return rst;
  232. },
  233. //获取粘贴更改的单元格(粘贴时,跳过隐藏行)
  234. checkSpreadChangedCells: function (info) {
  235. let rst = {refreshRows: [], changedCells: []};
  236. //获取显示行号
  237. let vRows = projectObj.getVisibleRows(info.row, info.rowCount);
  238. let vCount = vRows.length;
  239. let lastRow = null, count = 0;
  240. for(let cell of info.changedCells){
  241. cell.text = info.sheet.getCell(cell.row, cell.col).text();
  242. if(cell.row !== lastRow){
  243. count++;
  244. lastRow = cell.row;
  245. }
  246. if(count <= vCount){
  247. if(vRows[count - 1] !== cell.row){
  248. rst.refreshRows.push(cell.row);
  249. }
  250. rst.changedCells.push({row: vRows[count - 1], col: cell.col, text: cell.text});
  251. }
  252. else {
  253. rst.refreshRows.push(cell.row);
  254. }
  255. }
  256. rst.refreshRows = Array.from(new Set(rst.refreshRows));
  257. return rst;
  258. },
  259. updateBillsCode: function (node, value) {
  260. let project = projectObj.project,me = this;
  261. let stdMatchCode, formatCode, matchs;
  262. let searchStdBillsAndUpdate = function (stdCode, formatCode) {
  263. let orgCode = node.data.code?node.data.code.substr(0, 9):"";
  264. if (stdCode === orgCode || projectInfoObj.projectInfo.engineeringInfo.bill_lib.length === 0) {
  265. normalUpdate(node,value);
  266. } else if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0) {
  267. let libId = projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id;
  268. CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
  269. if (data) {
  270. //data.itemCharacter = pageCCOprObj.safeItemCharater(data.itemCharacter);
  271. node.data.name = data.name;
  272. if(node.data.type == billType.BX){//从清单库中找到标准清单的话,要把补项改成分项
  273. node.data.type = billType.FX;
  274. }
  275. pageCCOprObj.setItemContentNode(node, data.jobContent, data.itemCharacter, node.data.name);
  276. if (/\//.test(data.unit)) {
  277. let existB = projectObj.project.Bills.sameStdCodeBillsData(data.code);
  278. if (existB) {
  279. data.unit = existB.unit;
  280. //
  281. project.Bills.replaceBills(node.source, data, formatCode);
  282. projectObj.mainController.refreshTreeNode([node], false);
  283. } else {
  284. ConfirmModal.stdBillsUnit.check(data, function (std) {
  285. project.Bills.replaceBills(node.source, std, formatCode);
  286. projectObj.mainController.refreshTreeNode([node], false);
  287. }, function () {
  288. projectObj.mainController.refreshTreeNode([node], false);
  289. });
  290. }
  291. } else {
  292. project.Bills.replaceBills(node.source, data, formatCode);
  293. projectObj.mainController.refreshTreeNode([node], false);
  294. }
  295. } else {
  296. normalUpdate(node,value);
  297. }
  298. });
  299. }
  300. }
  301. if(node.data.type==billType.FX||node.data.type==billType.BX||(node.data.type==billType.BILL&&node.source.children.length==0)){//是分项、补项或者叶子清单的情况下才需要查找替换
  302. if (value&&value.length === 9 && /^[\d]+$/.test(value)) {
  303. stdMatchCode = value;
  304. formatCode = project.Bills.newFormatCode(stdMatchCode);
  305. searchStdBillsAndUpdate(stdMatchCode, formatCode);
  306. return;
  307. } else if (value&&value.length === 12 && /^[\d]+$/.test(value)) {
  308. stdMatchCode = value.substr(0, 9);
  309. matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
  310. if (matchs.indexOf(value) === -1) {
  311. searchStdBillsAndUpdate(stdMatchCode, value);
  312. return;
  313. } else {
  314. if (confirm('已存在该编码的清单,是否继续?')) {
  315. // formatCode = project.Bills.newFormatCode(stdMatchCode, node.data.code);
  316. searchStdBillsAndUpdate(stdMatchCode, value);
  317. return;
  318. }else {
  319. this.mainController.refreshTreeNode([node], false);
  320. return;
  321. }
  322. }
  323. }
  324. }
  325. normalUpdate(node,value);
  326. function normalUpdate(billnode,codeValue) {//在标准库中没有找到清单时改分项为补项再更新
  327. let toBX = false;
  328. if(billnode.data.type == billType.FX){
  329. billnode.data.type = billType.BX;
  330. toBX = true;
  331. }
  332. project.Bills.updateField(billnode.source, 'code', codeValue, toBX);
  333. me.mainController.refreshTreeNode([billnode], false);
  334. }
  335. },
  336. updateRationCode: function (node, value) {
  337. if(!isDef(node.data.code) && (!isDef(value) || value.toString().trim() == '')){
  338. return;
  339. }
  340. if (projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0) {
  341. alert('当前项目无定额库,请添加定额库。');
  342. this.mainController.refreshTreeNode([node], false);
  343. } else {
  344. let libId = parseInt($('#stdRationLibSelect').val());
  345. CommonAjax.post('/complementaryRation/api/getRationItem', {user_id: userID, rationRepId: libId, code: value}, function (data) {
  346. if (data) {
  347. projectObj.project.Ration.replaceRation(node.source, data);
  348. projectObj.project.ration_glj.addRationGLJ(node.source, data);
  349. } else {
  350. alert('当前库中找不到定额"' + value + '"');
  351. }
  352. projectObj.mainController.refreshTreeNode([node], false);
  353. });
  354. }
  355. },
  356. updateCode: function (node, value) {
  357. let project = projectObj.project;
  358. if (node.sourceType === project.Bills.getSourceType()) {
  359. this.updateBillsCode(node, value); // 新清单不适合实时计算,下面套什么还不能确定,无数量计算也无意义
  360. } else if (node.sourceType === project.Ration.getSourceType()) {
  361. if(value && typeof(value) == 'string'){//小写转换成大写
  362. value = value.toUpperCase();
  363. }
  364. project.Ration.updateRationCodes([{'node':node,value:value}]);
  365. // this.updateRationCode(node, value); // 新套定额适合实时计算
  366. // 这里因异步问题暂时缺少工料机价格。该过程移到:ration_glj.js的refreshAfterSave方法中。
  367. /*project.calcProgram.calcAndSave(node);
  368. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  369. calcProgramObj.showData(node, false);
  370. };*/
  371. }
  372. },
  373. updateNodeField : function (node,value,filedID,callback) {
  374. if(node.data[filedID] == value){
  375. return;
  376. }
  377. let data = {
  378. type:node.sourceType,
  379. data:{
  380. ID:node.data.ID
  381. }
  382. };
  383. data.data[filedID] = value;
  384. $.bootstrapLoading.start();
  385. projectObj.project.updateNodes([data],function () {
  386. node.data[filedID] = value;
  387. if(callback){
  388. callback();
  389. }
  390. $.bootstrapLoading.end();
  391. })
  392. },
  393. updateCellValue: function (node, value, colSetting,editingText) {
  394. let project = projectObj.project, fieldName = colSetting.data.field;
  395. if(node.sourceType==project.ration_glj.getSourceType()){
  396. project.ration_glj.updateFromMainSpread(value,node,fieldName);
  397. }else if(fieldName === 'remark'){
  398. projectObj.updateNodeField(node,value,'remark');
  399. } else if(calcTools.isGljRation(node)){
  400. gljOprObj.updateRationTypeGLJ(value,node,fieldName);
  401. } else if (value !== calcFees.getFee(node.data, fieldName)||fieldName == 'quantity') {//工程量需要进行转换,所以做特殊处理
  402. if (fieldName === 'code' && !calcTools.isVolumePrice(node)) {
  403. projectObj.updateCode(node, value);
  404. }
  405. else if(fieldName ==='feeRate'){
  406. project.FeeRate.updateFeeRateFromBills(value,node,fieldName);
  407. }
  408. else if(fieldName ==='contain'){//编辑含量
  409. project.Ration.updateContain(value,node);
  410. }
  411. else if (fieldName === 'quantity' || fieldName === 'marketUnitFee' || fieldName === 'programID' ||
  412. fieldName === 'subType' || fieldName === 'calcBase' || fieldName === 'isSubcontract'){
  413. if (fieldName === 'quantity') {
  414. project.quantity_detail.editMainTreeNodeQuantity(value,node,fieldName,editingText);
  415. return;
  416. }
  417. else if (fieldName === 'marketUnitFee') {
  418. if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("unitPrice", node))};
  419. }
  420. else if (fieldName === 'calcBase') {
  421. //zhong
  422. if(value === undefined ||value === null || value.toString().trim() === ''){
  423. value = '';
  424. }
  425. node.data.userCalcBase = value;
  426. project.calcBase.calculate(node);
  427. if(!project.calcBase.success){
  428. let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  429. projectObj.mainController.refreshTreeNode([node]);
  430. return;
  431. }
  432. // if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("totalPrice", node))};
  433. };
  434. //计算基数赋值要经过解析和标准化,已在calculate里赋值
  435. if(fieldName !== 'calcBase'){
  436. node.data[fieldName] = value;
  437. node.changed = true;
  438. }
  439. project.calcProgram.calcAndSave(node);
  440. gljOprObj.showRationGLJSheetData();
  441. }
  442. else if (node.sourceType === project.Bills.getSourceType()&&fieldName === 'unit'){//修改清单单位的时候清单工程量要重新4舍5入
  443. node.data[fieldName] = value;
  444. node.changed = true;
  445. if(node.data.quantity){
  446. node.data.quantity =scMathUtil.roundForObj(node.data.quantity,getDecimal("quantity",node));
  447. }
  448. project.calcProgram.calcAndSave(node);
  449. }
  450. else {
  451. if (node.sourceType === project.Bills.getSourceType()) {
  452. project.Bills.updateField(node.source, fieldName, value, false);
  453. }
  454. else if (node.sourceType === project.Ration.getSourceType()) {
  455. project.Ration.updateField(node.source, fieldName, value);
  456. };
  457. if (colSetting.data.wordWrap) {
  458. this.mainSpread.getActiveSheet().autoFitRow(node.serialNo());
  459. }
  460. projectObj.mainController.refreshTreeNode([node]);
  461. }
  462. }
  463. else if(value==null && fieldName ==='feeRate'){
  464. project.FeeRate.cleanFeeRateID(node);
  465. }
  466. else {
  467. projectObj.mainController.refreshTreeNode([node], false);
  468. }
  469. },
  470. mainSpreadLeaveCell: function (sender, info) {
  471. let colSetting = projectObj.mainController.setting.cols[info.col];
  472. projectObj.lastCol = colSetting;
  473. projectObj.lastCell = {row: info.row, col: info.col};
  474. },
  475. //repaint 动态下拉框
  476. mainSpreadEnterCell: function (sender, info) {
  477. console.log('enterCell');
  478. let colSetting = projectObj.mainController.setting.cols[info.col];
  479. if(colSetting.data.field === 'unit' || (projectObj.lastCol&&projectObj.lastCol.data.field === 'unit')||colSetting.data.field ==='subType'
  480. || (projectObj.lastCol&&projectObj.lastCol.data.field === 'subType') || colSetting.data.field === 'programID' ||(projectObj.lastCol&&projectObj.lastCol.data.field === 'programID')){
  481. let rects = [];
  482. rects.push(info.sheet.getCellRect(info.row, info.col));
  483. if(projectObj.lastCell){
  484. rects.push(info.sheet.getCellRect(projectObj.lastCell.row, projectObj.lastCell.col));
  485. }
  486. for(let rect of rects){
  487. info.sheet.repaint(rect);
  488. }
  489. }
  490. },
  491. mainSpreadEditStarting: function (sender, info) {
  492. let project = projectObj.project;
  493. let node = project.mainTree.items[info.row];
  494. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  495. let orgV = info.sheet.getValue(info.row, info.col);
  496. let newV;
  497. if(node && node.sourceType === projectObj.project.Ration.getSourceType() && node.data.type === rationType.ration
  498. && isDef(node.data.code) && isDef(node.data.prefix) && node.data.prefix !== rationPrefix.none && fieldName === 'code'){
  499. if(node.data.prefix === rationPrefix.complementary){
  500. newV = orgV.replace(new RegExp('补'), '');
  501. }
  502. if(node.data.prefix === rationPrefix.borrow){
  503. newV = orgV.replace(new RegExp('借'), '');
  504. }
  505. info.sheet.setValue(info.row, info.col, newV);
  506. }
  507. },
  508. onCellDoubleClick: function (sender, info){
  509. let project = projectObj.project;
  510. let node = project.mainTree.items[info.row];
  511. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  512. if(fieldName == 'marketUnitFee'){
  513. if(gljOprObj.hasComposition(node.data,true)){
  514. alert("当前人材机的市场价由组成物计算得出,不可直接修改。");
  515. return;
  516. }
  517. }
  518. },
  519. mainSpreadEditEnded: function (sender, info) {
  520. let project = projectObj.project;
  521. let node = project.mainTree.items[info.row];
  522. let colSetting = projectObj.mainController.setting.cols[info.col];
  523. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  524. // 检查输入类型等
  525. let value = projectObj.checkSpreadEditingText(info.editingText, colSetting);
  526. projectObj.updateCellValue(node, value, colSetting,info.editingText);
  527. // 自动行高
  528. const autoHeight = project.property.displaySetting.autoHeight;
  529. if (autoHeight) {
  530. projectObj.mainSpread.getActiveSheet().autoFitRow(info.row);
  531. }
  532. },
  533. msClipboardChanged: function (sender, info) {
  534. let colSettings = projectObj.mainController.setting.cols;
  535. let cDatas = sheetCommonObj.getTableData(info.sheet, colSettings);
  536. sheetCommonObj.copyTextToClipboard(cDatas);
  537. return;
  538. },
  539. mainSpreadRangeChanged: function (sender, info) {
  540. let project = projectObj.project, setting = projectObj.mainController.setting;
  541. let changedObj = projectObj.checkSpreadChangedCells(info);
  542. let refreshNodes = [];
  543. for(let row of changedObj.refreshRows){
  544. refreshNodes.push(project.mainTree.items[row]);
  545. }
  546. let updateRationCodes = [];//更新定额编码时要用同步的方式
  547. if(changedObj.changedCells.length > 0){
  548. for (let changedCell of changedObj.changedCells) {
  549. let node = project.mainTree.items[changedCell.row];
  550. let colSetting = setting.cols[changedCell.col];
  551. let value = projectObj.checkSpreadEditingText(changedCell.text, colSetting)
  552. if(colSetting.data.field=='code'&& node.sourceType == project.Ration.getSourceType()&&node.data.type==rationType.ration){//如果是更新定额的编码
  553. updateRationCodes.push({'node':node,value:value});
  554. }else {
  555. projectObj.updateCellValue(node, value, colSetting,changedCell.text);
  556. }
  557. }
  558. }
  559. if(updateRationCodes.length>0){
  560. project.Ration.updateRationCodes(updateRationCodes);
  561. }
  562. if(refreshNodes.length > 0){
  563. projectObj.mainController.refreshTreeNode(refreshNodes);
  564. }
  565. },
  566. checkMainSpread: function () {
  567. if (!this.mainSpread) {
  568. this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
  569. this.mainSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.muliRange);
  570. this.mainSpread.getActiveSheet().name('mainSheet');
  571. }
  572. },
  573. refreshMainSpread: function () {
  574. if (this.mainSpread) {
  575. this.mainSpread.refresh();
  576. }
  577. },
  578. loadProjectData: function () {
  579. var that = this;
  580. this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
  581. let startTime = +new Date();
  582. console.log("开始加载-----"+startTime);
  583. $.bootstrapLoading.start();
  584. this.project.loadDatas(function (err) {
  585. let mTime = +new Date();
  586. console.log(`get data时间——${mTime - startTime}`);
  587. if (!err) {
  588. that.project.projectGLJ.calcQuantity(true);//计算分部分项和技术措施项目消耗量;
  589. let quantityTime = +new Date();
  590. console.log(`计算quantity时间——${quantityTime - mTime}`);
  591. that.project.property = projectInfoObj.projectInfo.property;
  592. //that.project.calcProgram.compileAllTemps();
  593. that.project.calcBase.init(that.project);
  594. // that.project.calcFields = JSON.parse(JSON.stringify(cpFeeTypes));
  595. // that.project.initCalcFields();
  596. let str = JSON.stringify(that.project.projSetting.main_tree_col);
  597. that.project.projSetting.mainGridSetting = JSON.parse(str);
  598. that.project.projSetting.mainGridSetting.frozenCols = 4;
  599. TREE_SHEET_HELPER.initSetting($('#billsSpread')[0], that.project.projSetting.mainGridSetting);
  600. that.project.projSetting.mainGridSetting.setAutoFitRow = MainTreeCol.getEvent("setAutoFitRow");
  601. that.project.projSetting.mainGridSetting.cols.forEach(function (col) {
  602. col.data.splitFields = col.data.field.split('.');
  603. if (col.data.getText && Object.prototype.toString.apply(col.data.getText) === "[object String]") {
  604. col.data.getText = MainTreeCol.getEvent(col.data.getText);
  605. }
  606. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  607. col.readOnly = MainTreeCol.getEvent(col.readOnly);
  608. }
  609. if (col.data.cellType && Object.prototype.toString.apply(col.data.cellType) === "[object String]") {
  610. let getCellType = MainTreeCol.getEvent(col.data.cellType);
  611. col.data.cellType = getCellType;
  612. }
  613. // if (col.data.digit && Object.prototype.toString.apply(col.data.digit) === "[object String]") {
  614. // col.data.decimal = that.project.getDecimal(col.data.digit);
  615. // col.data.formatter = MainTreeCol.getNumberFormatter(col.data.decimal);
  616. // }
  617. if (col.data.field === 'code') {
  618. col.data.formatter = '@';
  619. }
  620. col.setAutoHeight = MainTreeCol.getEvent("setAutoHeight");
  621. col.editChecking = MainTreeCol.getEvent("editChecking");
  622. // 根据配置设置自动行高,在这里先做个标记,然后对每个单元格单独配置
  623. if (col.data.field === 'name' || col.data.field === 'itemCharacterText' ||
  624. col.data.field === 'jobContentText' || col.data.field === 'adjustState') {
  625. col.data.autoHeight = true;
  626. col.showHint = true;
  627. }
  628. if(col.data.field ==='quantity'){
  629. col.showHint = true;
  630. }
  631. // 综合单价、综合合价,小数部分应补0对齐。 CSLAAAAA
  632. // if (col.data.field.hasSubStr("common")){
  633. if (col.data.field.hasSubStr(".totalFee"))
  634. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.totalPrice, true)
  635. else if (col.data.field.hasSubStr(".unitFee"))
  636. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.unitPrice, true)
  637. // }
  638. });
  639. let startShowTime = +new Date();
  640. that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), that.project.projSetting.mainGridSetting);
  641. that.mainController.showTreeData();
  642. let endShowTime = +new Date();
  643. console.log(`show data时间——${endShowTime - startShowTime}`);
  644. that.mainController.bind('refreshBaseActn', that.refreshBaseActn);
  645. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.beforeTreeSelectedChange, that.beforeMainTreeSelectedChange);
  646. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, that.treeSelectedChanged);
  647. that.mainSpread.getActiveSheet().startEdit();
  648. that.mainSpread.getActiveSheet().endEdit();
  649. that.mainSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, that.amountAreaNumber);
  650. that.mainSpread.bind(GC.Spread.Sheets.Events.LeaveCell, that.mainSpreadLeaveCell);
  651. that.mainSpread.bind(GC.Spread.Sheets.Events.EnterCell, that.mainSpreadEnterCell);
  652. that.mainSpread.bind(GC.Spread.Sheets.Events.EditStarting, that.mainSpreadEditStarting);
  653. that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
  654. that.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, that.mainSpreadRangeChanged);
  655. that.mainSpread.bind(GC.Spread.Sheets.Events.ClipboardChanged, that.msClipboardChanged);
  656. that.mainSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, that.onButtonClick);
  657. that.mainSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, that.onCellDoubleClick);
  658. //let loadOtherStartTime = +new Date();
  659. that.loadMainSpreadContextMenu();
  660. that.loadFocusLocation();
  661. socketObject.connect();//连接socket服务器
  662. let endTime = +new Date();
  663. console.log(`其它时间——${endTime - endShowTime}`);
  664. console.log("加载完成-----"+endTime);
  665. console.log(`时间——${endTime - startTime}`);
  666. that.project.projectMarkChecking();//是否需要重新进行造价计算
  667. installationFeeObj.engineeringTypeChecking();//检查是否安装工程
  668. autoFlashHeight();
  669. projectObj.refreshMainSpread();
  670. //定位到会话中的选项
  671. let mainTabFocus = sessionStorage.getItem('mainTab') ? sessionStorage.getItem('mainTab') : '#tab_zaojiashu';
  672. $(`${mainTabFocus}`).click();
  673. $.bootstrapLoading.end();
  674. }
  675. else {
  676. }
  677. });
  678. },
  679. loadMainSpreadContextMenu: function () {
  680. var project = this.project, spread = this.mainSpread, controller = this.mainController;
  681. $.contextMenu({
  682. selector: '#billsSpread',
  683. build: function ($trigger, e) {
  684. var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  685. controller.setTreeSelected(controller.tree.items[target.row]);
  686. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  687. },
  688. items: {
  689. "insertRootBill": {
  690. name: "插入大项费用",
  691. icon: 'fa-sign-in',
  692. disabled: function () {
  693. return projectObj.project.isBillsLocked();
  694. //return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
  695. },
  696. callback: function (key, opt) {
  697. ProjectController.addRootBill(project, controller);
  698. },
  699. visible: function(key, opt){
  700. return project.mainTree.selected&&project.mainTree.selected.parent==null;
  701. }
  702. },
  703. "insertFB": {
  704. name: "插入分部",
  705. icon: 'fa-sign-in',
  706. disabled: function () {
  707. let selected = project.mainTree.selected;
  708. if(projectObj.project.isBillsLocked()== false&&selected&&selected.sourceType==project.Bills.getSourceType()){
  709. if(selected.data.type==billType.FB){
  710. return false;
  711. }
  712. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  713. if(selected.children.length>0){
  714. return selected.children[0].data.type==billType.FX;//焦点行是分部分项工程,且子项是分项
  715. }else {
  716. return false
  717. }
  718. }
  719. }
  720. return true;//除了清单,其它类型都只读
  721. },
  722. callback: function (key, opt) {
  723. ProjectController.addFB(project, controller);
  724. },
  725. visible: function(key, opt){
  726. if(project.mainTree.selected){
  727. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  728. }else {
  729. return false;
  730. }
  731. }
  732. },
  733. "insertFX": {
  734. name: "插入分项",
  735. icon: 'fa-sign-in',
  736. disabled: function () {
  737. let selected = project.mainTree.selected;
  738. if(projectObj.project.isBillsLocked()== false&& selected&&selected.sourceType==project.Bills.getSourceType()){
  739. if(selected.data.type==billType.FX||selected.data.type==billType.BX){//焦点行是分项,有效显示
  740. return false
  741. }
  742. if(selected.data.type==billType.FB){//点行是分部,
  743. if(selected.children.length>0){//且有子项,子项是分部,灰显。
  744. return selected.children[0].data.type == billType.FB
  745. }else {
  746. return false;
  747. }
  748. }
  749. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  750. if(selected.children.length>0){
  751. return selected.children[0].data.type==billType.FB;//焦点行是分部分项工程,且子项是分部时灰显
  752. }else {
  753. return false
  754. }
  755. }
  756. }
  757. return true;//除了清单,其它类型都只读
  758. },
  759. callback: function (key, opt) {
  760. ProjectController.addFX(project, controller);
  761. },
  762. visible: function(key, opt){
  763. if(project.mainTree.selected){
  764. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  765. }else {
  766. return false;
  767. }
  768. }
  769. },
  770. "insertBills": {
  771. name: "插入清单",
  772. icon: 'fa-sign-in',
  773. disabled: function () {
  774. let selected = project.mainTree.selected;
  775. if(projectObj.project.isBillsLocked()== false && selected && selected.sourceType === project.Bills.getSourceType()){
  776. return false
  777. }
  778. return true;
  779. },
  780. callback: function (key, opt) {
  781. if(project.mainTree.selected.data.type == billType.DXFY){
  782. if(project.mainTree.selected.data.calcBase&&project.mainTree.selected.data.calcBase!=""){
  783. alert("当前有基数计算不能插入子项。");
  784. return;
  785. }
  786. }
  787. ProjectController.addBills(project, controller);
  788. },
  789. visible: function(key, opt){
  790. if(project.mainTree.selected){
  791. return project.Bills.isFBFX(project.mainTree.selected)==true?false:true;
  792. }else {
  793. return false;
  794. }
  795. }
  796. },
  797. "insertRation": {
  798. name: "插入定额",
  799. icon: 'fa-sign-in',
  800. disabled: function () {
  801. var selected = project.mainTree.selected;
  802. return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  803. },
  804. callback: function (key, opt) {
  805. project.Ration.addNewRation(null,rationType.ration);
  806. // ProjectController.addRation(project, controller, rationType.ration);
  807. },
  808. visible: function(key, opt){
  809. var selected = project.mainTree.selected;
  810. if(selected){
  811. if(selected.sourceType == ModuleNames.bills&&selected.data.type == billType.DXFY){
  812. return false
  813. }else {
  814. return true
  815. }
  816. }
  817. return false;
  818. }
  819. },
  820. "insertLJ": {
  821. name: "插入量价",
  822. icon: 'fa-sign-in',
  823. disabled: function () {
  824. var selected = project.mainTree.selected;
  825. return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  826. },
  827. callback: function (key, opt) {
  828. project.Ration.addNewRation(null,rationType.volumePrice);
  829. // ProjectController.addRation(project, controller, rationType.volumePrice);
  830. },
  831. visible: function(key, opt){
  832. var selected = project.mainTree.selected;
  833. if(selected){
  834. if(selected.sourceType == ModuleNames.bills&&selected.data.type == billType.DXFY){
  835. return false
  836. }else {
  837. return true
  838. }
  839. }
  840. return false;
  841. }
  842. },
  843. "insertGLJ": {
  844. name: "插入人材机",
  845. icon: 'fa-sign-in',
  846. disabled: function () {
  847. var selected = project.mainTree.selected;
  848. return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  849. },
  850. callback: function (key, opt) {
  851. var selected = project.mainTree.selected;
  852. if(selected.sourceType == ModuleNames.bills){
  853. if(selected.data.type == billType.FX||selected.data.type ==billType.BILL){
  854. if(selected.data.calcBase&&selected.data.calcBase!=""){
  855. alert("当前有基数计算不能插入子项。");
  856. return;
  857. }
  858. }
  859. }
  860. getGLJData('insert');// ProjectController.addRation(project, controller, rationType.volumePrice);
  861. },
  862. visible: function(key, opt){
  863. var selected = project.mainTree.selected;
  864. if(selected){
  865. if(selected.sourceType == ModuleNames.bills&&selected.data.type == billType.DXFY){
  866. return false;
  867. }else {
  868. return true;
  869. }
  870. }
  871. return false;
  872. }
  873. },
  874. "ZLFB": {
  875. name: "整理分部",
  876. icon: 'fa-sign-in',
  877. disabled: function () {
  878. return projectObj.project.isBillsLocked();
  879. },
  880. callback: function (key, opt) {
  881. zlfb_object.getSectionInfo();
  882. },
  883. visible: function(key, opt){
  884. return true;
  885. }
  886. },
  887. "calc_installation_fee": {
  888. name: "计取安装费用",
  889. icon: 'fa-sign-in',
  890. disabled: function () {
  891. return false;
  892. },
  893. callback: function (key, opt) {
  894. installationFeeObj.showCalcInstallSettingDiv();
  895. },
  896. visible: function(key, opt){
  897. let engineering = projectInfoObj.projectInfo.property.engineering;
  898. return engineering==engineeringType.BUILD_IN;
  899. }
  900. },
  901. "spr1": '--------',
  902. "delete": {
  903. name: '删除',
  904. icon: 'fa-remove',
  905. disabled: function () {
  906. return !ifCanDelete();
  907. },
  908. callback: function () {
  909. var selected = project.mainTree.selected;
  910. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length<=0){//选中的是分部,并且没有子项,直接删除
  911. project.Bills.deleteSelectedNode();
  912. }else {
  913. $("#delete_row").modal({show:true});//弹出删除提示框;
  914. }
  915. }
  916. },
  917. "spr2":'--------',
  918. "calculateAll_RationContent": {
  919. name: '造价计算',
  920. callback: function () {
  921. project.calcProgram.calcAllNodesAndSave();
  922. }
  923. },
  924. "spr2":'--------',
  925. "copyBlock": {
  926. name: '复制整块',
  927. icon: 'fa-copy',
  928. disabled: function () {
  929. return BlockController.copyBtnDisable(project.mainTree.selected);
  930. },
  931. callback: function () {
  932. $.bootstrapLoading.start();
  933. let selected = project.mainTree.selected;
  934. setTimeout(function () {
  935. BlockController.copyBlock(selected);
  936. $.bootstrapLoading.end();
  937. },100)
  938. }
  939. },
  940. "spr2":'--------',
  941. "pasteBlock": {
  942. name: '粘贴整块',
  943. icon: 'fa-paste',
  944. disabled: function (){
  945. return BlockController.pasteBtnDisable(project.mainTree.selected);
  946. },
  947. callback: function () {
  948. BlockController.pasteBlock(project.mainTree.selected);
  949. }
  950. }
  951. }
  952. });
  953. },
  954. // 计算node及node的所有父项
  955. converseCalculateBills: function (node) {
  956. /* if (node) {
  957. let calc = new BillsCalcHelper(this.project);
  958. calc.calcNode(node, true);
  959. let cur = node, nodes = [];
  960. while (cur) {
  961. nodes.push(cur);
  962. cur = cur.parent;
  963. }
  964. this.mainController.refreshTreeNode(nodes, false);
  965. this.project.Bills.updateNodes(nodes, true);
  966. calc = null;
  967. }*/
  968. projectObj.project.calcProgram.calcAndSave(node);
  969. },
  970. // 计算全部清单
  971. /* calculateAll: function () {
  972. let calc = new BillsCalcHelper(this.project);
  973. calc.calcAll();
  974. this.mainController.showTreeData();
  975. this.project.Bills.updateAll();
  976. calc = null;
  977. }*/
  978. // 获取上次退出时的焦点位置
  979. loadFocusLocation: function() {
  980. const projectId = scUrlUtil.GetQueryString('project');
  981. let row = getLocalCache('lastRow:' + projectId);
  982. let col = getLocalCache('lastCol:' + projectId);
  983. if(row == null || col == null){
  984. row = 0;
  985. col = 0;
  986. }
  987. row = parseInt(row);
  988. col = parseInt(col);
  989. const sheet = this.mainSpread.getActiveSheet();
  990. sheet.setSelection(row, col, 1, 1);
  991. this.mainController.setTreeSelected(this.mainController.tree.items[row]);//触发树节点选中事件
  992. },
  993. // 选中区域合计数字
  994. amountAreaNumber: function(e, info) {
  995. if (info.newSelections === undefined || info.newSelections.length <= 0) {
  996. return false;
  997. }
  998. const selectedArea = info.newSelections[0];
  999. const sheet = info.sheet;
  1000. if (selectedArea.colCount <= 1 && selectedArea.rowCount <= 1) {
  1001. return false;
  1002. }
  1003. // 获取鼠标位置
  1004. let x = window.event.clientX;
  1005. let y = window.event.clientY;
  1006. // 匹配数字或小数
  1007. const regular = /^([0-9]+[.]{1}[0-9]+)$|^([1-9]{1}\d*)$/;
  1008. // 小数点最高位数
  1009. let max = 0;
  1010. let total = 0;
  1011. let counter = 0;
  1012. for (let col = selectedArea.col; col < (selectedArea.colCount + selectedArea.col); col++) {
  1013. for (let row = selectedArea.row; row < (selectedArea.rowCount + selectedArea.row); row++) {
  1014. const value = sheet.getCell(row, col).text();
  1015. if (!regular.test(value)) {
  1016. continue;
  1017. }
  1018. counter++;
  1019. // 获取当前数据小数位数
  1020. let pointPosition = value.toString().indexOf(".");
  1021. pointPosition = pointPosition < 0 ? pointPosition : pointPosition + 1;
  1022. const current = pointPosition > 0 ? value.toString().substring(pointPosition, value.toString().length).length : 0;
  1023. max = current > max ? current : max;
  1024. total += parseFloat(value);
  1025. }
  1026. }
  1027. // 如果不为0则悬浮显示
  1028. if (total > 0 && counter > 1) {
  1029. 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>');
  1030. div.css({
  1031. position: "absolute",
  1032. border: "1px #C0C0C0 solid",
  1033. background: "#fff",
  1034. boxShadow: "1px 2px 5px rgba(0,0,0,0.4)",
  1035. });
  1036. div.children("p").css({
  1037. textAlign: "center",
  1038. padding: 8,
  1039. marginBottom: 2,
  1040. });
  1041. div.children("p").first().css({
  1042. borderBottom: "1px #C0C0C0 solid"
  1043. });
  1044. const totalString = total.toFixed(max);
  1045. // input长度
  1046. const inputWidth = totalString.length * 8;
  1047. // 计算是否会超出显示范围
  1048. const baseWidth = 48;
  1049. const baseHeight = 81;
  1050. const canvasWidth = $("#billsSpreadvp_vp").width();
  1051. const canvasHeight = $("#billsSpreadvp_vp").height();
  1052. x = x + baseWidth + inputWidth > canvasWidth ? x - baseWidth - inputWidth : x;
  1053. y = y + baseHeight > canvasHeight ? y - baseHeight : y;
  1054. div.css({
  1055. left: x,
  1056. top: y,
  1057. });
  1058. div.children().children("#total").width(inputWidth).val(totalString);
  1059. $("body").append(div);
  1060. // 用于判断是否要关闭窗体
  1061. setTimeout(function() {
  1062. isTotalShowing = true;
  1063. }, 200);
  1064. };
  1065. },
  1066. onButtonClick: function (e, info) {
  1067. let colSetting = projectObj.mainController.setting.cols[info.col];
  1068. let node = projectObj.project.mainTree.items[info.row];
  1069. let fieldName = colSetting.data.field;
  1070. if(fieldName == "isSubcontract"){
  1071. projectObj.onSubcontractClick(node);
  1072. }else if(fieldName == "isEstimate"){
  1073. projectObj.onIsEstimateClick(node,info);
  1074. }
  1075. },
  1076. onIsEstimateClick: function(node,info){
  1077. let checkboxValue = info.sheet.getCell(info.row, info.col).value();
  1078. let cell = info.sheet.getCell(info.row, info.col), newval = 0;
  1079. if (checkboxValue) {
  1080. newval = 0;
  1081. cell.value(newval);
  1082. } else {
  1083. newval = 1;
  1084. cell.value(newval);
  1085. }
  1086. if(MainTreeCol.readOnly.bills(node)){
  1087. projectObj.updateNodeField(node,newval,'isEstimate');
  1088. }else if(node.data.projectGLJID){//更新的是定额类型的工料机或者是显示在造价书页面的主材、设备
  1089. console.log(node);
  1090. let updateData = {id: node.data.projectGLJID, field: 'is_evaluate', value: newval};
  1091. projectObj.project.projectGLJ.pGljUpdate(updateData);
  1092. }
  1093. },
  1094. onSubcontractClick:function (node) {//点击分包费checkbox
  1095. if (node.data.isSubcontract) node.data.isSubcontract = false;
  1096. else node.data.isSubcontract = true;
  1097. node.changed = true;
  1098. projectObj.project.calcProgram.calcAndSave(node);
  1099. },
  1100. //根据节点获取行style(颜色、字体加粗)
  1101. getNodeColorStyle: function (sheet, node, colSetting = null) {
  1102. let colorSetting = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
  1103. let mapping = {DEFAULT: 'DEFAULT', SELECTED: 'SELECTED', DXFY: 'DXFY', FB: 'FB', UNLEAFBILL: 'UNLEAFBILL',
  1104. FX: 'FX', BX: 'BX', UNCBBILL: 'UNCBBILL', CBBILL: 'CBBILL', ZCSB: 'ZCSB'};
  1105. let styleMap = null;
  1106. //中文字段名,由于同一节点中,中文字体大小和数字字体大小不同
  1107. if(colorSetting == null){
  1108. return null;
  1109. }
  1110. let stringFields = [
  1111. 'code',
  1112. 'subType',
  1113. 'name',
  1114. 'unit',
  1115. 'itemCharacterText',
  1116. 'jobContentText',
  1117. 'adjustState',
  1118. 'calcBase',
  1119. 'programID',
  1120. 'ruleText'
  1121. ];
  1122. if(!isDef(node)){
  1123. return null;
  1124. }
  1125. //选中行
  1126. if(node === this.project.mainTree.selected){
  1127. styleMap = mapping.SELECTED;
  1128. }
  1129. //非选中行
  1130. else {
  1131. //清单大类
  1132. if(node.sourceType === this.project.Bills.getSourceType()){
  1133. //大项费用
  1134. if(node.data.type === billType.DXFY){
  1135. styleMap = mapping.DXFY;
  1136. }
  1137. //分部
  1138. if(node.data.type === billType.FB){
  1139. styleMap = mapping.FB;
  1140. }
  1141. //分项
  1142. else if(node.data.type === billType.FX){
  1143. styleMap = mapping.FX;
  1144. }
  1145. //补项
  1146. else if(node.data.type === billType.BX){
  1147. styleMap = mapping.BX;
  1148. }
  1149. //清单
  1150. else if(node.data.type === billType.BILL){
  1151. //非叶子节点的清单
  1152. if(node.source.children.length > 0){
  1153. styleMap = mapping.UNLEAFBILL;
  1154. }
  1155. //未使用基数计算的叶子节点的清单
  1156. else if(node.source.children.length === 0 && (!isDef(node.data.calcBase) || node.data.calcBase === '')){
  1157. styleMap = mapping.UNCBBILL;
  1158. }
  1159. //使用基数计算的叶子节点的清单
  1160. else if(node.source.children.length === 0 && isDef(node.data.calcBase && node.data.calcBaseValue !== '')){
  1161. styleMap = mapping.CBBILL;
  1162. }
  1163. }
  1164. }
  1165. //定额下的主材、设备
  1166. else if(node.sourceType === this.project.ration_glj.getSourceType()){
  1167. styleMap = mapping.ZCSB;
  1168. }
  1169. else {
  1170. styleMap = mapping.DEFAULT;
  1171. }
  1172. }
  1173. let styleSetting = colorSetting[styleMap];
  1174. let defaultSetting = colorSetting[mapping.DEFAULT];
  1175. if(!isDef(styleSetting)){
  1176. return null;
  1177. }
  1178. let style = new GC.Spread.Sheets.Style();
  1179. //设置style属性
  1180. for(let attr in styleSetting){
  1181. if(attr !== 'stringFont' && attr !== 'numFont'){
  1182. style[attr] = styleSetting[attr] === 'default' || !isDef(styleSetting[attr]) ? defaultSetting[attr] : styleSetting[attr];
  1183. }
  1184. //暂时不开放字体设置,开放的话只能每个单元格进入此方法
  1185. /* else {
  1186. if(stringFields.indexOf(colSetting.data.field) > 0){
  1187. style.font = styleSetting.stringFont === 'default' || !isDef(styleSetting.stringFont) ? defaultSetting.stringFont : styleSetting.stringFont;
  1188. }
  1189. else {
  1190. style.font = styleSetting.numFont === 'default' || !isDef(styleSetting.numFont) ? defaultSetting.numFont : styleSetting.numFont;
  1191. }
  1192. }*/
  1193. }
  1194. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1195. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1196. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1197. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1198. return style;
  1199. },
  1200. //大项费用则字体加粗,String 15px, Number 13px
  1201. getBoldFontStyle: function (node, colSetting) {
  1202. let style = new GC.Spread.Sheets.Style();
  1203. if(node.sourceType !== this.project.Bills.getSourceType() || node.data.type !== billType.DXFY){
  1204. return null
  1205. }
  1206. //备注暂无字段
  1207. let stringFields = [
  1208. 'code',
  1209. 'subType',
  1210. 'name',
  1211. 'unit',
  1212. 'itemCharacterText',
  1213. 'jobContentText',
  1214. 'adjustState',
  1215. 'calcBase',
  1216. 'programID',
  1217. 'ruleText'
  1218. ];
  1219. if(stringFields.indexOf(colSetting.data.field) > 0){
  1220. style.font = 'bold 15px Arial';
  1221. }
  1222. else {
  1223. style.font = 'bold 13px Arial';
  1224. }
  1225. return style;
  1226. },
  1227. //设置节点style
  1228. setNodesStyle: function (sheet, nodes) {
  1229. let me = this;
  1230. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  1231. for(let node of nodes){
  1232. if(node && node.serialNo()!= -1){
  1233. sheet.getRange(node.serialNo(), -1, 1, -1).backColor(me.getNodeColorStyle(sheet, node).backColor);
  1234. }
  1235. }
  1236. });
  1237. },
  1238. loadLockBillsButton:function () {
  1239. if(projectInfoObj.projectInfo.property.lockBills == true){
  1240. $("a[name='lockBills']").prop("title","解锁清单");
  1241. $("a[name='lockBills']").html('<i class="fa fa-unlock-alt" aria-hidden="true"></i> 解锁清单');
  1242. }else {
  1243. $("a[name='lockBills']").prop("title","锁定清单");
  1244. $("a[name='lockBills']").html('<i class="fa fa-lock" aria-hidden="true"></i> 锁定清单');
  1245. }
  1246. }
  1247. };
  1248. // 点击合计框中的复制
  1249. $("body").on("click", "#total-tips a", function() {
  1250. const totalElement = $(this).parent().siblings("p").find("#total");
  1251. totalElement.select();
  1252. document.execCommand("Copy");
  1253. $(this).text("已复制");
  1254. });
  1255. // 合计框点击其他位置关闭
  1256. let isTotalShowing = false;
  1257. $("body").on("click", function(e) {
  1258. if (isTotalShowing && !$(e.target).is("#total-tips") && !$(e.target).is("#total-tips p") && !$(e.target).is("#total-tips p a")) {
  1259. $("#total-tips").remove();
  1260. isTotalShowing = false;
  1261. }
  1262. });
  1263. $('#insert').click(function () {
  1264. var controller = projectObj.mainController, project = projectObj.project;
  1265. var selected = controller.tree.selected;
  1266. if (!selected || selected.sourceType === project.Bills.getSourceType()) {
  1267. ProjectController.addBills(project, controller);
  1268. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1269. ProjectController.addRation(project, controller, selected.data.type);
  1270. };
  1271. });
  1272. $('#delete').click(function () {
  1273. let project = projectObj.project;
  1274. let selected = project.mainTree.selected;
  1275. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length<=0){//选中的是分部,并且没有子项,直接删除
  1276. project.Bills.deleteSelectedNode();
  1277. }else {
  1278. $("#delete_row").modal({show:true});//弹出删除提示框;
  1279. }
  1280. });
  1281. $('#upLevel').click(function () {
  1282. var controller = projectObj.mainController, project = projectObj.project;
  1283. var selected = controller.tree.selected, orgParent = selected.parent;
  1284. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  1285. project.Bills.upLevelBills(selected.source);
  1286. controller.upLevel();
  1287. controller.refreshTreeNode([orgParent]);
  1288. projectObj.project.calcProgram.calcBillsAndSave([selected,orgParent]);
  1289. }
  1290. });
  1291. $('#downLevel').click(function () {
  1292. var controller = projectObj.mainController, project = projectObj.project;
  1293. var selected = controller.tree.selected;
  1294. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  1295. project.Bills.downLevelBills(selected.source);
  1296. controller.downLevel();
  1297. controller.refreshTreeNode([selected.parent]);
  1298. projectObj.converseCalculateBills(selected.parent);
  1299. }
  1300. });
  1301. $('#upMove').click(function () {
  1302. var controller = projectObj.mainController, project = projectObj.project;
  1303. var selected = controller.tree.selected, pre = selected.preSibling, preSerialNo;
  1304. if (selected.sourceType === project.Bills.getSourceType()) {
  1305. project.Bills.upMoveBills(selected.source);
  1306. controller.upMove();
  1307. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1308. project.Ration.changePos(selected.source, selected.preSibling.source);
  1309. controller.upMove();
  1310. };
  1311. });
  1312. $('#downMove').click(function () {
  1313. var controller = projectObj.mainController, project = projectObj.project;
  1314. var selected = controller.tree.selected, next, nextSerialNo;
  1315. if (selected) {
  1316. if (selected.sourceType === project.Bills.getSourceType()) {
  1317. project.Bills.downMoveBills(selected.source);
  1318. controller.downMove();
  1319. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1320. project.Ration.changePos(selected.source, selected.nextSibling.source);
  1321. controller.downMove();
  1322. };
  1323. }
  1324. });
  1325. $("a[name='lockBills']").click(function () {
  1326. let lockBills = projectInfoObj.projectInfo.property.lockBills;
  1327. lockBills = !lockBills;
  1328. projectObj.project.updateLockBills(lockBills,function () {
  1329. var controller = projectObj.mainController, project = projectObj.project;
  1330. var selected = controller.tree.selected;
  1331. let nodes = _.filter(project.mainTree.items,{'sourceType':ModuleNames.bills});
  1332. controller.refreshTreeNode(nodes);
  1333. projectObj.mainController.setTreeSelected(selected);//触发树节点选中事件
  1334. projectObj.loadLockBillsButton();
  1335. pageCCOprObj.refreshRuleTools(lockBills);
  1336. });
  1337. });
  1338. //显示至..
  1339. let displayLevel = function(nodes, depth, type){
  1340. let refreshNodes = [];
  1341. function getExpandedController(){
  1342. if(type === 'DXFY' || type === 'FB'){
  1343. if(type === 'FB'){
  1344. projectObj.project.mainTree.items[0].setExpanded(true);
  1345. refreshNodes.push(projectObj.project.mainTree.items[0]);
  1346. }
  1347. return function expandedControl(nodes, depth){
  1348. let bType = type === 'FB' ? billType.FB : billType.DXFY;
  1349. for(let node of nodes){
  1350. let nodeDepth = node.depth();
  1351. if(nodeDepth <= depth){
  1352. let expanded = nodeDepth === depth && !node.children[0] || nodeDepth < depth && node.children[0] && node.children[0].data.type === bType ? true : false;
  1353. node.setExpanded(expanded);
  1354. refreshNodes.push(node);
  1355. if(nodeDepth < depth){
  1356. expandedControl(node.children, depth);
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. else if(type === 'FX' || type === 'ZM' || type === 'ZD'){
  1363. return function expandedControl(nodes){
  1364. for(let node of nodes){
  1365. if(type !== 'FX' || node.sourceType === projectObj.project.Bills.getSourceType()){
  1366. let expanded = true;
  1367. if(type === 'FX'){
  1368. expanded = !node.children[0] || node.children[0] && node.children[0].sourceType === projectObj.project.Bills.getSourceType() ? true : false;
  1369. }
  1370. else if(type === 'ZM'){
  1371. expanded = !node.children[0] || node.children[0] && node.children[0].sourceType !== projectObj.project.ration_glj.getSourceType() ? true : false;
  1372. }
  1373. node.setExpanded(expanded);
  1374. refreshNodes.push(node);
  1375. expandedControl(node.children);
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. getExpandedController()(nodes, depth);
  1382. let sheet = projectObj.mainSpread.getActiveSheet();
  1383. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  1384. TREE_SHEET_HELPER.refreshNodesVisible(refreshNodes, projectObj.mainSpread.getActiveSheet(), true)
  1385. });
  1386. };
  1387. $('#displayDXFY').click(function () {
  1388. displayLevel(projectObj.project.mainTree.items, 0, 'DXFY')
  1389. });
  1390. //显示至一级分部
  1391. $('#displayFB1').click(function () {
  1392. displayLevel(projectObj.project.mainTree.items[0].children, 1, 'FB');
  1393. });
  1394. //二级分部
  1395. $('#displayFB2').click(function () {
  1396. displayLevel(projectObj.project.mainTree.items[0].children, 2, 'FB');
  1397. });
  1398. //三级分部
  1399. $('#displayFB3').click(function () {
  1400. displayLevel(projectObj.project.mainTree.items[0].children, 3, 'FB');
  1401. });
  1402. //四级分部
  1403. $('#displayFB4').click(function () {
  1404. displayLevel(projectObj.project.mainTree.items[0].children, 4, 'FB');
  1405. });
  1406. //分项
  1407. $('#displayFX').click(function () {
  1408. displayLevel(projectObj.project.mainTree.items, null, 'FX');
  1409. });
  1410. //子目
  1411. $('#displayZM').click(function () {
  1412. displayLevel(projectObj.project.mainTree.items, null, 'ZM');
  1413. });
  1414. //最底层
  1415. $('#displayZD').click(function () {
  1416. displayLevel(projectObj.project.mainTree.roots, null, 'ZD');
  1417. });
  1418. $('#poj-set').on('show.bs.modal', function () {
  1419. let setCalcFlag = function (obj, val, curFlag) {
  1420. obj.val(val);
  1421. if (val === curFlag) {
  1422. obj.prop('checked', true);
  1423. } else {
  1424. obj.prop('checked', false);
  1425. }
  1426. }
  1427. if (projectObj.project) {
  1428. let ft = projectObj.project.property.billsCalcMode ? projectObj.project.property.billsCalcMode : leafBillGetFeeType.rationContent;
  1429. let zg = projectObj.project.property.zanguCalcMode ? projectObj.project.property.zanguCalcMode : zanguCalcType.common;
  1430. setCalcFlag($('#rationContent'), leafBillGetFeeType.rationContent, ft);
  1431. setCalcFlag($('#rationPriceConverse'), leafBillGetFeeType.rationPriceConverse, ft);
  1432. setCalcFlag($('#rationPrice'), leafBillGetFeeType.rationPrice, ft);
  1433. setCalcFlag($('#billsPrice'), leafBillGetFeeType.billsPrice, ft);
  1434. setCalcFlag($('#zangu_common'), zanguCalcType.common, zg);
  1435. setCalcFlag($('#zangu_gatherMaterial'), zanguCalcType.gatherMaterial, zg);
  1436. projDisplayView.init();
  1437. calcOptions.init();
  1438. }
  1439. });
  1440. $('#property_ok').click(function () {
  1441. let project = projectObj.project,
  1442. projectID = project.ID(),
  1443. properties = {},
  1444. labourCoes = {},
  1445. rations = [],
  1446. bills = [],
  1447. mixDatas = {
  1448. projectID: projectID,
  1449. updateType: 'update',
  1450. properties: properties,
  1451. labourCoes: labourCoes,
  1452. rations: rations,
  1453. bills: bills
  1454. },
  1455. reCalcBills = false,
  1456. reCalcRations = false;
  1457. let b = parseInt($("input[name='calcFlag']:checked").val());
  1458. if (b !== project.property.billsCalcMode) {
  1459. properties['property.billsCalcMode'] = b;
  1460. project.property.billsCalcMode = b;
  1461. reCalcBills = true;
  1462. };
  1463. let zg = parseInt($("input[name='zangu']:checked").val());
  1464. if (zg !== project.property.zanguCalcMode) {
  1465. properties['property.zanguCalcMode'] = zg;
  1466. project.property.zanguCalcMode = zg;
  1467. reCalcRations = true;
  1468. };
  1469. //基本信息
  1470. if(basicInfoView.toUpdate(basicInfoView.orgDatas, basicInfoView.datas)){
  1471. properties['property.basicInformation'] = basicInfoView.toSaveDatas(basicInfoView.datas);
  1472. }
  1473. //工程特征
  1474. if(projFeatureView.toUpdate(projFeatureView.orgDatas, projFeatureView.datas)){
  1475. properties['property.projectFeature'] = projFeatureView.toSaveDatas(projFeatureView.datas);
  1476. }
  1477. //清单工程量精度
  1478. let newBillsDecimalDatas = billsDecimalView.toBillsDecimalDatas(billsDecimalView.cache);
  1479. if(billsDecimalView.toUpdate(billsQuanDecimal.datas, newBillsDecimalDatas)){
  1480. billsQuanDecimal.datas = newBillsDecimalDatas;
  1481. reCalcBills = true;
  1482. properties['property.billsQuantityDecimal'] = newBillsDecimalDatas;
  1483. }
  1484. //小数位数
  1485. let updateDecimal = m_getDecimalData($('input', '#poj-settings-decimal'));
  1486. if(toUpdateDecimal(decimalObj, updateDecimal)) {
  1487. let frChanged = decimalObj.feeRate != updateDecimal.feeRate;
  1488. setDecimal(decimalObj, updateDecimal);
  1489. if (frChanged) {
  1490. project.calcProgram.compileAllTemps()
  1491. }
  1492. reCalcRations = true;
  1493. reCalcBills = true;
  1494. properties['property.decimal'] = updateDecimal;
  1495. }
  1496. // 呈现选项
  1497. projDisplayView.updateChecking(properties);
  1498. if(calcOptions.updateChecking(properties)){
  1499. reCalcRations = true;
  1500. }
  1501. // 人工系数
  1502. if (labourCoeView.needSave()){
  1503. let libID = $("#std_labour_coe_files").children("option:selected").val();
  1504. let libName = $("#std_labour_coe_files").children("option:selected").text();
  1505. labourCoes.updateData = {libID: libID, libName: libName, newItemArr: labourCoeView.needUpdateDatas};
  1506. project.labourCoe.refreshData(labourCoes.updateData); // 全编译所用到的人工系数来自project.labourCoe,所以必须先刷新project.labourCoe
  1507. project.calcProgram.compileAllTemps();
  1508. reCalcRations = true;
  1509. reCalcBills = true;
  1510. };
  1511. // 重新计算树节点
  1512. let changedNodes = [];
  1513. if (reCalcRations) // 定额动,全部计算。算完先不存储,和后面的数据一起提交,一次通讯。
  1514. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catAll)
  1515. else if (reCalcBills) // 清单动,可以只计算清单。
  1516. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catBills);
  1517. if (changedNodes.length > 0) {
  1518. for (let node of changedNodes){
  1519. let data = calcTools.cutNodeForSave(node);
  1520. if (node.sourceType == 'ration') rations.push(data)
  1521. else if (node.sourceType == 'bills') bills.push(data);
  1522. };
  1523. };
  1524. // for test.
  1525. /* console.log(mixDatas);
  1526. return; */
  1527. function hasMixData() {
  1528. return Object.keys(mixDatas.properties).length > 0 ||
  1529. mixDatas.labourCoes.updateData || mixDatas.rations.length > 0 || mixDatas.bills.length > 0;
  1530. }
  1531. function needToReload(mixDatas){
  1532. if(Object.keys(mixDatas.labourCoes).length > 0){
  1533. return true;
  1534. }
  1535. if(Object.keys(mixDatas.properties).length > 0){
  1536. if(mixDatas.properties.hasOwnProperty('property.billsCalcMode') ||
  1537. mixDatas.properties.hasOwnProperty('property.zanguCalcMode') ||
  1538. mixDatas.properties.hasOwnProperty('property.calcOptions')||
  1539. mixDatas.properties.hasOwnProperty('property.billsQuantityDecimal')||
  1540. mixDatas.properties.hasOwnProperty('property.decimal')||
  1541. mixDatas.properties.hasOwnProperty('property.displaySetting')){
  1542. return true;
  1543. }
  1544. }
  1545. return false;
  1546. }
  1547. if(hasMixData()){
  1548. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  1549. //需要重载页面
  1550. if(needToReload(mixDatas)){
  1551. window.location.href = '/main?project=' + projectID;
  1552. }
  1553. else{
  1554. if(mixDatas.properties.hasOwnProperty('property.basicInformation')){
  1555. basicInfoView.orgDatas = basicInfoView.toViewDatas(mixDatas.properties['property.basicInformation']);
  1556. }
  1557. if(mixDatas.properties.hasOwnProperty('property.projectFeature')){
  1558. projFeatureView.orgDatas = projFeatureView.toViewDatas(mixDatas.properties['property.projectFeature']);
  1559. }
  1560. }
  1561. });
  1562. }
  1563. });
  1564. function testShow() {
  1565. var controller = projectObj.mainController, project = projectObj.project;
  1566. var selected = controller.tree.selected, parent = selected.parent;
  1567. var showinfo = "<label>确认要删除当前选中行吗?</label>";
  1568. var showN = false;
  1569. var cancelText = "否";
  1570. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length>0){//选中的是分部,并且有子项
  1571. if(isSingleSelect()||selectionChecking()){
  1572. showinfo = "<label>是否删除其下的子项?</label><br><label>【是】则删除分部行及其下的所有子项,</label><br><label>【否】则仅删除当前分部行,子项保留,</label><br><label>【取消】则取消删除</label>";
  1573. showN = true;
  1574. cancelText = "取消";
  1575. }
  1576. }
  1577. $('#delete_showinfo').html(showinfo);
  1578. showN==true? $('#deleteN').show():$('#deleteN').hide();
  1579. $('#deleteCancel').text(cancelText);
  1580. function selectionChecking() {
  1581. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  1582. let mainTreeMap = {};
  1583. for(let i =0;i<selection.rowCount;i++){
  1584. let tem_node = controller.tree.items[selection.row+i];
  1585. if(i==0){//第一个直接添加;
  1586. mainTreeMap[tem_node.getID()] = tem_node;
  1587. }else {
  1588. project.Bills.setNodeToMap(tem_node,mainTreeMap);
  1589. }
  1590. }
  1591. let nodes = changeMapToArray(mainTreeMap);
  1592. if(nodes.length==1){
  1593. return true
  1594. }
  1595. return false;
  1596. }
  1597. }
  1598. $('#delete_row').on('shown.bs.modal', function (e) {
  1599. var controller = projectObj.mainController, project = projectObj.project;
  1600. var selected = controller.tree.selected, parent = selected.parent;
  1601. var showinfo = "<label>确认要删除当前选中行吗?</label>";
  1602. var showN = false;
  1603. var cancelText = "否";
  1604. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length>0){//选中的是分部,并且有子项
  1605. if(isSingleSelect()||selectionChecking()){
  1606. showinfo = "<label>是否删除其下的子项?</label><br><label>【是】则删除分部行及其下的所有子项,</label><br><label>【否】则仅删除当前分部行,子项保留,</label><br><label>【取消】则取消删除</label>";
  1607. showN = true;
  1608. cancelText = "取消";
  1609. }
  1610. }
  1611. $('#delete_showinfo').html(showinfo);
  1612. showN==true? $('#deleteN').show():$('#deleteN').hide();
  1613. $('#deleteCancel').text(cancelText);
  1614. function selectionChecking() {
  1615. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  1616. let mainTreeMap = {};
  1617. for(let i =0;i<selection.rowCount;i++){
  1618. let tem_node = controller.tree.items[selection.row+i];
  1619. if(i==0){//第一个直接添加;
  1620. mainTreeMap[tem_node.getID()] = tem_node;
  1621. }else {
  1622. project.Bills.setNodeToMap(tem_node,mainTreeMap);
  1623. }
  1624. }
  1625. let nodes = changeMapToArray(mainTreeMap);
  1626. if(nodes.length==1){
  1627. return true
  1628. }
  1629. return false;
  1630. }
  1631. });
  1632. function changeMapToArray(map) {
  1633. let newArray = [];
  1634. for(let key in map){
  1635. newArray.push(map[key]);
  1636. }
  1637. return newArray;
  1638. }
  1639. $('#deleteY').click(function () { //正常删除,级联删除子项
  1640. let project = projectObj.project;
  1641. project.Bills.deleteSelectedNodes();
  1642. /*if(isSingleSelect()){
  1643. project.Bills.deleteSelectedNode();//这个方法不用了,会出现异步删除干净的问题
  1644. }else {
  1645. project.Bills.deleteSelectedNodes();
  1646. }*/
  1647. });
  1648. $('#deleteN').click(function () {//不删除子项
  1649. let controller = projectObj.mainController, project = projectObj.project;
  1650. let selected = controller.tree.selected, parent = selected.parent;
  1651. if(selected){
  1652. let preNode = selected.preSibling;
  1653. let nextNode = selected.nextSibling;
  1654. if(preNode){//有前兄弟
  1655. if(preNode.children.length>0&&preNode.children[0].data.type != selected.children[0].data.type){//并且前兄弟子项和焦点行子项类别不同。
  1656. alert("删除分部会导致分部和分项同级,不允许该操作!");
  1657. return;
  1658. }
  1659. }else if(nextNode){
  1660. if(nextNode.data.type != selected.children[0].data.type){
  1661. alert("删除分部会导致分部和分项同级,不允许该操作! ");
  1662. return;
  1663. }
  1664. }
  1665. project.Bills.singleDeleteBills(selected,controller);
  1666. }
  1667. });
  1668. function isSingleSelect() {//是否选中造价书中的单行
  1669. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  1670. if (selections[0].rowCount == 1) {
  1671. return true;
  1672. }
  1673. return false;
  1674. }
  1675. function ifCanDelete() {
  1676. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  1677. let tree = projectObj.project.mainTree;
  1678. let selected = projectObj.project.mainTree.selected;
  1679. if(selections[0].rowCount==1){//选中单行
  1680. return canDelete(selected);
  1681. }else {
  1682. return canDelete_m(selections[0]);
  1683. }
  1684. function canDelete(node,m_selection) {
  1685. if (node) {
  1686. if (node.sourceType === projectObj.project.Bills.getSourceType()) {
  1687. if(node.data.type == billType.DXFY&&node.data.isAdd!=1){
  1688. return false;
  1689. }
  1690. if(projectObj.project.isBillsLocked()== true){
  1691. return false;
  1692. }
  1693. }
  1694. if(m_selection!=true&&node.sourceType === projectObj.project.ration_glj.getSourceType()){//多选的时候不做这一项判断
  1695. return false;
  1696. }
  1697. return true;
  1698. } else {
  1699. return false;
  1700. }
  1701. };
  1702. function canDelete_m(selection) {
  1703. for(let i =0;i<selection.rowCount;i++){
  1704. if(tree.items[selection.row+i]==undefined||tree.items[selection.row+i]==null){
  1705. return false;
  1706. }
  1707. if(i==0&&tree.items[selection.row].sourceType === projectObj.project.ration_glj.getSourceType()){
  1708. return false
  1709. }
  1710. if(canDelete(tree.items[selection.row+i],true)==false){
  1711. return false
  1712. }
  1713. }
  1714. return true
  1715. };
  1716. }
  1717. //选择要导入的excel文件
  1718. $('#customFile').change(function () {
  1719. let file = $(this)[0];
  1720. if(file.files.length > 0){
  1721. $('.custom-file-label').text(`${file.files[0].name} 准备导入上传`);
  1722. $('#uploadAlert').hide();
  1723. }
  1724. else{
  1725. $('.custom-file-label').text(`请选择上传文件`);
  1726. }
  1727. });
  1728. //从excel导入清单
  1729. $('#uploadConfirm').click(function () {
  1730. let me = this;
  1731. $(me).addClass('disabled');
  1732. try{
  1733. let formData = new FormData();
  1734. let file = $('#customFile')[0];
  1735. if(file.files.length <= 0){
  1736. throw '未选择文件';
  1737. }
  1738. formData.append('file', file.files[0]);
  1739. let projectID = scUrlUtil.GetQueryString('project');
  1740. if(!projectID || projectID <= 0){
  1741. throw '项目数据出错';
  1742. }
  1743. formData.append('projectID', projectID);
  1744. //要去匹配的清单库(第一个)
  1745. let matchBillLibId = projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0 ? projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id : null;
  1746. formData.append('billsLibId', matchBillLibId);
  1747. $.ajax({
  1748. url: '/bills/upload',
  1749. type: 'POST',
  1750. data: formData,
  1751. cache: false,
  1752. contentType: false,
  1753. processData: false,
  1754. beforeSend: function() {
  1755. $.bootstrapLoading.start();
  1756. },
  1757. success: function(response){
  1758. if (response.err === 0) {
  1759. const message = response.msg !== undefined ? response.msg : '';
  1760. if (message !== '') {
  1761. alert(message);
  1762. }
  1763. // 成功则关闭窗体
  1764. $('#import').modal("hide");
  1765. //更新前端
  1766. doAfterImport(response.data);
  1767. } else {
  1768. const message = response.msg !== undefined ? response.msg : '上传失败!';
  1769. $.bootstrapLoading.end();
  1770. alert(message);
  1771. }
  1772. $(me).removeClass('disabled');
  1773. },
  1774. error: function(){
  1775. alert("与服务器通信发生错误");
  1776. $.bootstrapLoading.end();
  1777. $(me).removeClass('disabled');
  1778. }
  1779. });
  1780. }
  1781. catch (err){
  1782. //alert(err);
  1783. showUploadAlert(false, err);
  1784. $(me).removeClass('disabled');
  1785. }
  1786. });
  1787. function showUploadAlert(success, msg){
  1788. if(!success){
  1789. $('#uploadAlert').removeClass('alert-success');
  1790. $('#uploadAlert').addClass('alert-danger');
  1791. }
  1792. else{
  1793. $('#uploadAlert').removeClass('alert-danger');
  1794. $('#uploadAlert').addClass('alert-success');
  1795. }
  1796. $('#uploadAlert').text(msg);
  1797. $('#uploadAlert').show();
  1798. }
  1799. //导入后更新操作
  1800. function doAfterImport(resData){
  1801. if(resData){
  1802. let nodes = projectObj.project.mainTree.nodes;
  1803. let bills_datas = projectObj.project.Bills.datas;
  1804. let ration_datas = projectObj.project.Ration.datas;
  1805. let quantity_detail_datas = projectObj.project.quantity_detail.datas;
  1806. let ration_glj_datas = projectObj.project.ration_glj.datas;
  1807. let ration_coe_datas = projectObj.project.ration_coe.datas;
  1808. let ration_install_datas = projectObj.project.ration_installation.datas;
  1809. let delNodes = [];
  1810. for(let billID of resData.remove.bill){
  1811. if(nodes['id_' + billID]){
  1812. delNodes.push(nodes['id_' + billID]);
  1813. }
  1814. //清除清单数据
  1815. _.remove(bills_datas, {ID: billID});
  1816. //清除清单工程量明细数据
  1817. _.remove(quantity_detail_datas, {billID: billID});
  1818. }
  1819. for(let rationID of resData.remove.ration){
  1820. //清除定额数据
  1821. _.remove(ration_datas, {ID: rationID});
  1822. //清除定额下的相关数据
  1823. _.remove(ration_glj_datas, {rationID: rationID});
  1824. _.remove(ration_coe_datas, {rationID: rationID});
  1825. _.remove(ration_install_datas, {rationID: rationID});
  1826. _.remove(quantity_detail_datas, {rationID: rationID});
  1827. }
  1828. //删除节点
  1829. if(delNodes.length > 0){
  1830. //通过固定清单获得删除节点的起始行索引
  1831. let beginRow = null;
  1832. if(resData.fixedBill){
  1833. let fixedNode = nodes['id_' + resData.fixedBill.ID];
  1834. if(fixedNode){
  1835. beginRow = projectObj.project.mainTree.items.indexOf(fixedNode) + 1;
  1836. }
  1837. }
  1838. //删除主树节点
  1839. projectObj.mainController.m_delete(delNodes, beginRow);
  1840. //删除清单树节点
  1841. let delIdNodes = [];
  1842. for(let delNode of delNodes){
  1843. delIdNodes.push(delNode.source);
  1844. }
  1845. projectObj.project.Bills.tree.m_delete(delIdNodes);
  1846. }
  1847. if(resData.insert.bill.length > 0){
  1848. //设置flagsIndex
  1849. for(let insertBill of resData.insert.bill){
  1850. insertBill.flagsIndex = {};
  1851. if (insertBill.flags) {
  1852. insertBill.flags.forEach(function (flag) {
  1853. insertBill.flagsIndex[flag.fieldName] = flag;
  1854. });
  1855. }
  1856. }
  1857. //插入清单节点
  1858. projectObj.project.Bills.tree.insertByDatas(resData.insert.bill);
  1859. //插入主树节点
  1860. let newNodes = projectObj.project.mainTree.insertByDatas(resData.insert.bill);
  1861. for(let node of newNodes){
  1862. node.source = projectObj.project.Bills.tree.nodes['id_' + node.getID()];
  1863. node.data = node.source.data;
  1864. node.sourceType = projectObj.project.Bills.getSourceType();
  1865. }
  1866. ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes);
  1867. }
  1868. //如果清单未锁定,导入后锁定清单
  1869. if(!projectInfoObj.projectInfo.property.lockBills){
  1870. $("a[name='lockBills']").click();
  1871. }
  1872. $.bootstrapLoading.end();
  1873. //重算
  1874. projectObj.project.calcProgram.calcAllNodesAndSave(calcAllType.catAll, function () {
  1875. projectObj.project.projectGLJ.loadData(function () {
  1876. $.bootstrapLoading.end();
  1877. });
  1878. });
  1879. }
  1880. }
  1881. $(function () {
  1882. //清空导入清单选择文件
  1883. $('#import').on('show.bs.modal', function(){
  1884. $('#customFile').val('');
  1885. $('#uploadAlert').hide();
  1886. $('.custom-file-label').text(`请选择上传文件`);
  1887. });
  1888. $("#billsSpread").mouseover(function(){
  1889. spreadAutoFocus(projectObj.mainSpread,subSpread);
  1890. });
  1891. $("#subSpread").mouseover(function(){
  1892. spreadAutoFocus(subSpread,projectObj.mainSpread);
  1893. });
  1894. $("#paste_confirm").click(function (){
  1895. let selected = projectObj.project.mainTree.selected;
  1896. let blockData = BlockController.getBlockData();
  1897. let position = $("input[name='pastePositionRadio']:checked").val();
  1898. BlockController.confirmPaste(blockData,selected,position);
  1899. $("#pastePosition").modal("hide");
  1900. });
  1901. function spreadAutoFocus(spread,relateSpread) {
  1902. if(relateSpread&&relateSpread.getActiveSheet().isEditing()){//关联的spread不在编辑状态的情况下,才自动获得焦点;
  1903. return;
  1904. }else {
  1905. spread?spread.focus():'';
  1906. }
  1907. }
  1908. });