project_view.js 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  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 (pre) {
  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. if($('#linkComments').hasClass('active')){
  35. subViewObj.loadComments(node);
  36. }
  37. gljOprObj.mainTreeSelectedChange = gljOprObj.selectedNodeId != node.getID();
  38. gljOprObj.showDataIfRationSelect(node);
  39. if (activeSubSheetIsCalcProgram())
  40. calcProgramObj.refreshCalcProgram(node, 3);
  41. //zhong 2017-9-1 特征及内容
  42. if(pageCCOprObj.active){
  43. pageCCOprObj.mainActiveCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];//mainSpread焦点单元格
  44. pageCCOprObj.setCacheAndShow(node);
  45. }
  46. },
  47. refreshBaseActn: function (tree) {
  48. let setButtonValid = function (valid, btn) {
  49. if (valid) {
  50. btn.removeClass('disabled');
  51. } else {
  52. btn.addClass('disabled');
  53. }
  54. };
  55. let selected = tree.selected, that = projectObj;
  56. let canUpLevel = function (node) {
  57. if(!node){
  58. return false;
  59. }
  60. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(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 || node.data.type == billType.BX){//是分项,或者补项灰显。
  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 || node.children[0].data.type==billType.BX){ //焦点行子项是分项
  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(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  93. return false;
  94. }
  95. if(node.depth()==0){//焦点行是树结构的第一层节点,灰显。
  96. return false;
  97. }
  98. if(node.sourceType !== that.project.Bills.getSourceType()) {//焦点行是定额/量价/工料机,灰显。
  99. return false;
  100. }else {
  101. if(node.data.type == billType.FX || node.data.type == billType.BX){//是分项,灰显。
  102. return false;
  103. }
  104. if(!node.preSibling){//无前兄弟,灰显
  105. return false;
  106. }else if(node.preSibling.data.calcBase&&node.preSibling.data.calcBase!=""){//前兄弟有基数计算
  107. return false
  108. }
  109. if(node.preSibling.children.length>0){//前兄弟有子项,子项是分项,灰显。
  110. if(node.data.type==billType.FB&&(node.preSibling.children[0].data.type==billType.FX||node.preSibling.children[0].data.type==billType.BX)){//焦点行是分部前兄弟有子项,子项是分项,灰显。
  111. return false;
  112. }
  113. if(node.data.type==billType.BILL&&node.preSibling.children[0].sourceType !== that.project.Bills.getSourceType()){//焦点行是清单,子项不是清单
  114. return false
  115. }
  116. }
  117. }
  118. return true;
  119. };
  120. let canUpMove = function (node) {
  121. if(node&&node.preSibling){//有前兄弟
  122. if(node.sourceType==that.project.Bills.getSourceType()){
  123. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  124. return false;
  125. }
  126. if(node.data.type == billType.DXFY&&node.data.isAdd!==1){
  127. return false;
  128. }
  129. }
  130. return true
  131. }
  132. return false
  133. };
  134. let canDownMove = function (node) {
  135. if(node&&node.nextSibling){
  136. if(node.sourceType==that.project.Bills.getSourceType()){
  137. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  138. return false;
  139. }
  140. if(node.data.type == billType.DXFY&&node.data.isAdd!==1){
  141. return false;
  142. }
  143. }
  144. return true;
  145. }
  146. return false
  147. };
  148. setButtonValid(projectObj.project.Ration.canAdd(selected), $('#insertRation'));
  149. setButtonValid(ifCanDelete(), $('#delete'));
  150. setButtonValid(canUpLevel(selected), $('#upLevel'));
  151. setButtonValid(canDownLevel(selected), $('#downLevel'));
  152. setButtonValid(canUpMove(selected) , $('#upMove'));
  153. setButtonValid(canDownMove(selected), $('#downMove'));
  154. setButtonValid(!projectObj.project.isBillsLocked(), $('#ZLFB_btn'));
  155. },
  156. checkCommonField: function (editingText, colSetting) {
  157. let value;
  158. if (colSetting.data.decimal) {
  159. value = Number(editingText);
  160. if (number_util.isNumber(value)) {
  161. if (colSetting.data.decimal) {
  162. value = value.toDecimal(colSetting.data.decimal);
  163. }
  164. } else {
  165. value = null;
  166. alert('当前输入的数据类型不正确,请重新输入。');
  167. }
  168. } else {
  169. value = editingText;
  170. }
  171. return value;
  172. },
  173. checkFormulaValidField: function (editingText, colSetting) {
  174. let value = Number(editingText);
  175. if (!value) {
  176. try {
  177. let exp = new Expression('');
  178. exp.Expression(editingText);
  179. value = Number(exp.Evaluate());
  180. } catch (error) {
  181. value = null;
  182. }
  183. }
  184. if (value!=undefined||value!=null) {
  185. if (colSetting.data.decimal) {
  186. value = value.toDecimal(colSetting.data.decimal);
  187. }
  188. } else if (editingText && editingText !== '') {
  189. value = null;
  190. alert('当前输入的数据类型不正确,请重新输入。');
  191. }
  192. return value;
  193. },
  194. checkSpreadEditingText: function (editingText, colSetting) {
  195. if (colSetting.data.field === 'contain') {//colSetting.data.field === 'quantity'
  196. return this.checkFormulaValidField(editingText, colSetting);
  197. }
  198. else if (colSetting.data.field === 'programID') {
  199. return this.project.calcProgram.compiledTemplateMaps[editingText];
  200. }
  201. else if (colSetting.data.field === 'subType') {
  202. if (typeof(editingText) !== "number")
  203. return volumePriceMaps[editingText]
  204. else
  205. return editingText;
  206. }
  207. else {
  208. return this.checkCommonField(editingText, colSetting);
  209. }
  210. },
  211. getVisibleRows: function (sRow, count) {
  212. let rst = [];
  213. let nodes = projectObj.project.mainTree.items;
  214. for(let i = sRow, len = nodes.length; i < len; i++){
  215. if(count <= 0){
  216. break;
  217. }
  218. if(nodes[i].visible){
  219. rst.push(i);
  220. count--;
  221. }
  222. }
  223. return rst;
  224. },
  225. //根据列标段设置焦点单元格
  226. setActiveCell(field, moveScroll){
  227. projectObj.mainSpread.focus(true);
  228. let mainSheet = projectObj.mainSpread.getActiveSheet();
  229. let fieldCol = colSettingObj.getColByField(field);
  230. if(fieldCol){
  231. if(moveScroll){
  232. mainSheet.showColumn(fieldCol, GC.Spread.Sheets.HorizontalPosition.left);
  233. }
  234. mainSheet.setActiveCell(projectObj.project.mainTree.selected.serialNo(), fieldCol);
  235. }
  236. },
  237. //获取粘贴更改的单元格(粘贴时,跳过隐藏行)
  238. checkSpreadChangedCells: function (info) {
  239. let rst = {refreshRows: [], changedCells: []};
  240. //获取显示行号
  241. let vRows = projectObj.getVisibleRows(info.row, info.rowCount);
  242. let vCount = vRows.length;
  243. let lastRow = null, count = 0;
  244. for(let cell of info.changedCells){
  245. cell.text = info.sheet.getCell(cell.row, cell.col).text();
  246. if(cell.row !== lastRow){
  247. count++;
  248. lastRow = cell.row;
  249. }
  250. if(count <= vCount){
  251. if(vRows[count - 1] !== cell.row){
  252. rst.refreshRows.push(cell.row);
  253. }
  254. rst.changedCells.push({row: vRows[count - 1], col: cell.col, text: cell.text});
  255. }
  256. else {
  257. rst.refreshRows.push(cell.row);
  258. }
  259. }
  260. rst.refreshRows = Array.from(new Set(rst.refreshRows));
  261. return rst;
  262. },
  263. updateBillsCode: function (node, value) {
  264. let project = projectObj.project,me = this;
  265. let stdMatchCode, formatCode, matchs;
  266. let searchStdBillsAndUpdate = function (stdCode, formatCode) {
  267. let orgCode = node.data.code?node.data.code.substr(0, 9):"";
  268. if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length === 0) {
  269. normalUpdate(node,value,stdCode === orgCode);
  270. } else if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0) {
  271. let libId = projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id;
  272. CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
  273. if (data) {
  274. function sortItems(serialItems, items){
  275. for(let item of items){
  276. for(let serialItem of serialItems){
  277. if(item.id === serialItem.id){
  278. item.serialNo = serialItem.serialNo;
  279. }
  280. }
  281. }
  282. items.sort(function (a, b) {
  283. let rst = 0;
  284. if(a.serialNo > b.serialNo){
  285. rst = 1;
  286. }
  287. else if(a.serialNo < b.serialNo){
  288. rst = -1;
  289. }
  290. return rst;
  291. });
  292. }
  293. function updateBeforeInsert(node, data) {
  294. node.data.name = data.name;
  295. if(node.data.type == billType.BX){//从清单库中找到标准清单的话,要把补项改成分项
  296. node.data.type = billType.FX;
  297. }
  298. sortItems(data.items, data.itemCharacter);
  299. sortItems(data.jobs, data.jobContent);
  300. pageCCOprObj.setItemContentNode(node, data.jobContent, data.itemCharacter, node.data.name);
  301. pageCCOprObj.setCacheAndShow(node);
  302. }
  303. if (/\//.test(data.unit)) {
  304. let existB = projectObj.project.Bills.sameStdCodeBillsData(data.code);
  305. if (existB) {
  306. updateBeforeInsert(node, data);
  307. data.unit = existB.unit;
  308. project.Bills.replaceBills(node.source, data, formatCode);
  309. projectObj.mainController.refreshTreeNode([node], false);
  310. } else {
  311. ConfirmModal.stdBillsUnit.check(data, function (std) {
  312. updateBeforeInsert(node, data);
  313. project.Bills.replaceBills(node.source, std, formatCode);
  314. projectObj.mainController.refreshTreeNode([node], false);
  315. }, function () {
  316. projectObj.mainController.refreshTreeNode([node], false);
  317. });
  318. }
  319. } else {
  320. updateBeforeInsert(node, data);
  321. project.Bills.replaceBills(node.source, data, formatCode);
  322. projectObj.mainController.refreshTreeNode([node], false);
  323. }
  324. } else {
  325. normalUpdate(node,value);
  326. }
  327. });
  328. }
  329. }
  330. //分部分项、措施项目才匹配
  331. let withinValidFixed = false;
  332. let matchFixedFlags = [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE];
  333. let rootNode = getRootFixedNode(node);
  334. if(rootNode && rootNode.data.flagsIndex && rootNode.data.flagsIndex.fixed && matchFixedFlags.includes(rootNode.data.flagsIndex.fixed.flag)){
  335. withinValidFixed = true;
  336. }
  337. if(withinValidFixed && (node.data.type==billType.FX||node.data.type==billType.BX||(node.data.type==billType.BILL&&node.source.children.length==0))){//是分项、补项或者叶子清单的情况下才需要查找替换
  338. if (value&&value.length === 9) {//&& /^[\d]+$/.test(value) 去掉全数字判断 07-31 zhang
  339. stdMatchCode = value;
  340. formatCode = project.Bills.newFormatCode(stdMatchCode);
  341. searchStdBillsAndUpdate(stdMatchCode, formatCode);
  342. return;
  343. } else if (value&&value.length === 12 ) {//&& /^[\d]+$/.test(value) 去掉全数字判断 07-31 zhang
  344. stdMatchCode = value.substr(0, 9);
  345. matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
  346. if (matchs.indexOf(value) === -1) {
  347. searchStdBillsAndUpdate(stdMatchCode, value);
  348. return;
  349. } else {
  350. hintBox.infoBox("系统提示","已存在该编码的清单,是否继续?",2,function () {
  351. searchStdBillsAndUpdate(stdMatchCode, value);
  352. },function () {
  353. me.mainController.refreshTreeNode([node], false);
  354. },['确定','取消']);
  355. return;
  356. }
  357. }
  358. }
  359. normalUpdate(node,value);
  360. function normalUpdate(billnode,codeValue,onNeedCheck) {//在标准库中没有找到清单时改分项为补项再更新
  361. let toBX = false;
  362. if(onNeedCheck!==true && billnode.data.type == billType.FX){
  363. billnode.data.type = billType.BX;
  364. toBX = true;
  365. }
  366. project.Bills.updateField(billnode.source, 'code', codeValue, toBX);
  367. me.mainController.refreshTreeNode([billnode], false);
  368. }
  369. },
  370. updateRationCode: function (node, value) {
  371. if(!isDef(node.data.code) && (!isDef(value) || value.toString().trim() == '')){
  372. return;
  373. }
  374. if (projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0) {
  375. alert('当前项目无定额库,请添加定额库。');
  376. this.mainController.refreshTreeNode([node], false);
  377. } else {
  378. let libId = parseInt($('#stdRationLibSelect').val());
  379. CommonAjax.post('/complementaryRation/api/getRationItem', {user_id: userID, rationRepId: libId, code: value}, function (data) {
  380. if (data) {
  381. projectObj.project.Ration.replaceRation(node.source, data);
  382. projectObj.project.ration_glj.addRationGLJ(node.source, data);
  383. } else {
  384. alert('当前库中找不到定额"' + value + '"');
  385. }
  386. projectObj.mainController.refreshTreeNode([node], false);
  387. });
  388. }
  389. },
  390. updateCode: function (node, value) {
  391. let project = projectObj.project;
  392. if (node.sourceType === project.Bills.getSourceType()) {
  393. this.updateBillsCode(node, value); // 新清单不适合实时计算,下面套什么还不能确定,无数量计算也无意义
  394. } else if (node.sourceType === project.Ration.getSourceType()) {
  395. if(value && typeof(value) == 'string'){//小写转换成大写
  396. value = value.toUpperCase();
  397. }
  398. project.Ration.updateRationCodes([{'node':node,value:value}]);
  399. // this.updateRationCode(node, value); // 新套定额适合实时计算
  400. // 这里因异步问题暂时缺少工料机价格。该过程移到:ration_glj.js的refreshAfterSave方法中。
  401. }
  402. },
  403. updateNodeField : function (node,value,filedID,callback) {
  404. if(node.data[filedID] == value){
  405. return;
  406. }
  407. let data = {
  408. type:node.sourceType,
  409. data:{
  410. ID:node.data.ID
  411. }
  412. };
  413. data.data[filedID] = value;
  414. $.bootstrapLoading.start();
  415. projectObj.project.updateNodes([data],function () {
  416. node.data[filedID] = value;
  417. if(callback){
  418. callback();
  419. }
  420. $.bootstrapLoading.end();
  421. })
  422. },
  423. updateCellValue: function (node, value, colSetting,editingText) {
  424. let project = projectObj.project, fieldName = colSetting.data.field;
  425. if(node.sourceType==project.ration_glj.getSourceType()){
  426. project.ration_glj.updateFromMainSpread(value,node,fieldName);
  427. }
  428. else if(fieldName === 'remark'){
  429. projectObj.updateNodeField(node,value,'remark');
  430. }
  431. else if(calcTools.isGljRation(node)){
  432. gljOprObj.updateRationTypeGLJ(value,node,fieldName,editingText);
  433. }
  434. else if (value !== calcFees.getFee(node.data, fieldName)||fieldName == 'quantity') {//工程量需要进行转换,所以做特殊处理
  435. if (fieldName === 'code' && value != '' && !calcTools.isVolumePrice(node)) {
  436. projectObj.updateCode(node, value);
  437. }
  438. else if(fieldName ==='feeRate'){
  439. project.FeeRate.updateFeeRateFromBills(value,node,fieldName);
  440. }
  441. else if(fieldName ==='contain'){//编辑含量
  442. project.Ration.updateContain(value,node);
  443. }
  444. else if (fieldName === 'quantity' || fieldName === 'marketUnitFee' || fieldName === 'feesIndex.common.unitFee' || fieldName === 'programID' ||
  445. fieldName === 'subType' || fieldName === 'calcBase' || fieldName === 'isSubcontract'){
  446. if (fieldName === 'quantity') {
  447. quantityEditObj.checkingAndUpdate(editingText,node);
  448. // project.quantity_detail.editMainTreeNodeQuantity(value,node,fieldName,editingText);
  449. return;
  450. }
  451. else if (fieldName === 'marketUnitFee' || fieldName === 'feesIndex.common.unitFee') {
  452. if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("unitPrice", node))};
  453. }
  454. else if (fieldName === 'calcBase') {
  455. //zhong
  456. if(value === undefined ||value === null || value.toString().trim() === ''){
  457. value = '';
  458. }
  459. if(value === node.data.calcBase){
  460. return;
  461. }
  462. node.data.userCalcBase = value;
  463. project.calcBase.calculate(node);
  464. if(!project.calcBase.success){
  465. let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  466. projectObj.mainController.refreshTreeNode([node]);
  467. return;
  468. }
  469. // if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("totalPrice", node))};
  470. };
  471. //计算基数赋值要经过解析和标准化,已在calculate里赋值
  472. if(fieldName !== 'calcBase'){
  473. calcTools.setFieldValue(node, fieldName, value);
  474. };
  475. project.calcProgram.calcAndSave(node);
  476. gljOprObj.showRationGLJSheetData();
  477. }
  478. else if (node.sourceType === project.Bills.getSourceType()&&fieldName === 'unit'){//修改清单单位的时候清单工程量要重新4舍5入
  479. node.data[fieldName] = value;
  480. node.changed = true;
  481. if(node.data.quantity){
  482. node.data.quantity =scMathUtil.roundForObj(node.data.quantity,getDecimal("quantity",node));
  483. }
  484. project.calcProgram.calcAndSave(node);
  485. }
  486. else {
  487. if (node.sourceType === project.Bills.getSourceType()) {
  488. project.Bills.updateField(node.source, fieldName, value, false);
  489. }
  490. else if (node.sourceType === project.Ration.getSourceType()) {
  491. project.Ration.updateField(node.source, fieldName, value);
  492. }
  493. if (colSetting.data.wordWrap) {
  494. this.mainSpread.getActiveSheet().autoFitRow(node.serialNo());
  495. }
  496. projectObj.mainController.refreshTreeNode([node]);
  497. }
  498. }
  499. else if(value==null && fieldName ==='feeRate'){
  500. project.FeeRate.cleanFeeRateID(node);
  501. }
  502. else {
  503. projectObj.mainController.refreshTreeNode([node], false);
  504. }
  505. },
  506. mainSpreadLeaveCell: function (sender, info) {
  507. let colSetting = projectObj.mainController.setting.cols[info.col];
  508. projectObj.lastCol = colSetting;
  509. projectObj.lastCell = {row: info.row, col: info.col};
  510. },
  511. //repaint 动态下拉框
  512. mainSpreadEnterCell: function (sender, info) {
  513. let colSetting = projectObj.mainController.setting.cols[info.col];
  514. if(colSetting.data.field === 'unit' || (projectObj.lastCol&&projectObj.lastCol.data.field === 'unit')||colSetting.data.field ==='subType'
  515. || (projectObj.lastCol&&projectObj.lastCol.data.field === 'subType') || colSetting.data.field === 'programID' ||(projectObj.lastCol&&projectObj.lastCol.data.field === 'programID')){
  516. let rects = [];
  517. rects.push(info.sheet.getCellRect(info.row, info.col));
  518. if(projectObj.lastCell){
  519. rects.push(info.sheet.getCellRect(projectObj.lastCell.row, projectObj.lastCell.col));
  520. }
  521. for(let rect of rects){
  522. info.sheet.repaint(rect);
  523. }
  524. }
  525. },
  526. mainSpreadEditStarting: function (sender, info) {
  527. let project = projectObj.project;
  528. let node = project.mainTree.items[info.row];
  529. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  530. let value = info.sheet.getValue(info.row, info.col);
  531. if(fieldName === 'code' && node && calcTools.isRationItem(node) && isDef(node.data.code)&&isDef(value)){
  532. if (isDef(node.data.prefix) && node.data.prefix !== rationPrefix.none){
  533. value = value.replace(new RegExp(node.data.prefix), '');
  534. };
  535. info.sheet.setValue(info.row, info.col, value);
  536. }
  537. if(node&&fieldName =='quantity'&&(node.data.quantityEXP !==null||node.data.quantityEXP !==undefined)){
  538. info.sheet.setValue(info.row, info.col, node.data.quantityEXP);
  539. }
  540. },
  541. onCellDoubleClick: function (sender, info){
  542. let project = projectObj.project;
  543. if(info.row && info.col){
  544. let node = project.mainTree.items[info.row];
  545. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  546. if(fieldName == 'marketUnitFee'){
  547. if(gljOprObj.hasComposition(node.data,true)){
  548. alert("当前人材机的市场价由组成物计算得出,不可直接修改。");
  549. return;
  550. }
  551. }
  552. if(fieldName == 'code' && node){
  553. projectObj.showBillOrRationLib(node)
  554. }
  555. }
  556. },
  557. showBillOrRationLib(node){
  558. let BILLS = projectObj.project.Bills;
  559. let code = node.data.code ? node.data.code : '';
  560. if(node.sourceType == ModuleNames.bills){//当清单是“分部分项工程”、“措施项目工程”时,要展开清单规则节点
  561. if(BILLS.isFXorBX(node)||(node.data.type == billType.BILL && BILLS.isMeasure(node))){//是分项或补项,是清单并且属于措施项目节点
  562. if(billsLibObj.stdBillsTree === null){
  563. billsLibObj.doAfterLoadBills = function () {
  564. this.locateAtBills(code);
  565. this.doAfterLoadBills = null;
  566. };
  567. }
  568. else {
  569. billsLibObj.locateAtBills(code);
  570. }
  571. if(!$("#qd").is(":visible")) $('#stdBillsTab').click();
  572. }
  573. }
  574. if(node.sourceType == ModuleNames.ration){ //在定额编码中双击,如果右侧定额库没有展开,则自动展开。
  575. if(!rationLibObj.tree){
  576. rationLibObj.doAfterGetRationTree = function () {
  577. this.locateAtRation(code);
  578. this.doAfterGetRationTree = null;
  579. };
  580. }
  581. else {
  582. rationLibObj.locateAtRation(code);
  583. }
  584. if(!$("#de").is(":visible")) $('#stdRationTab').click();
  585. }
  586. },
  587. onColumnWidthChanged: function (sender, info) { // CSL,2018.07.25
  588. if (info.colList.includes(4) || info.colList.includes(5)){
  589. let items = projectObj.project.mainTree.items;
  590. let sheet = projectObj.mainSpread.getActiveSheet();
  591. for (let i = 0; i < items.length; i++) {
  592. let need = false;
  593. if (items[i].data.itemCharacterText){
  594. sheet.getCell(i, 4).wordWrap(true);
  595. need = true;
  596. }
  597. if (items[i].data.jobContentText){
  598. sheet.getCell(i, 5).wordWrap(true);
  599. need = true;
  600. }
  601. if (need) sheet.autoFitRow(i);
  602. }
  603. }
  604. },
  605. onClipboardPasting: function (sender, info){
  606. let rIdx = info.sheet.getActiveRowIndex();
  607. let node = projectObj.project.mainTree.items[rIdx];
  608. if (!node.parent){
  609. info.cancel = true;
  610. hintBox.infoBox('系统提示','大项费用不允许粘贴!', 1);
  611. return false;
  612. };
  613. let colName = projectObj.project.projSetting.main_tree_col.cols[info.cellRange.col].data.field;
  614. if (colName == 'code'){
  615. info.cancel = true;
  616. function getNodeType(node) {
  617. let t = null;
  618. if (calcTools.isRationItem(node))
  619. t = 1
  620. else if (calcTools.isBill(node)){
  621. if (calcTools.isBill_FB(node))
  622. t = 2
  623. else if (calcTools.isBill_FX(node) || calcTools.isBill_BX(node))
  624. t = 3
  625. else if (calcTools.isBill_BILL(node))
  626. t = 4;
  627. };
  628. return t;
  629. };
  630. function getPasteTextArr(info) {
  631. let copyText = info.pasteData.text.trim();
  632. if (!copyText) return null;
  633. let rows = copyText.split('\r\n');
  634. let rstArr = [];
  635. for (let row of rows) {
  636. row = row.trim();
  637. row = row.split('\t');
  638. rstArr.push(row);
  639. }
  640. return rstArr;
  641. };
  642. function getPasteNodes(node, nodeType, count) {
  643. let nodesArr = [];
  644. let curNode = null;
  645. for (let i = rIdx; i < rIdx + count; i++) {
  646. curNode = projectObj.project.mainTree.items[i];
  647. if (curNode && calcTools.isSameTypeNode(curNode, node)){
  648. nodesArr.push(curNode);
  649. }
  650. else{
  651. curNode = projectObj.project.mainTree.items[i - 1];
  652. break;
  653. }
  654. };
  655. if (nodesArr.length < count){
  656. if (projectObj.project.mainTree.selected != curNode)
  657. projectObj.project.mainTree.selected = curNode;
  658. let add = count - nodesArr.length;
  659. for (let i = 0; i < add; i++) {
  660. switch (nodeType) {
  661. case 1:
  662. curNode = projectObj.project.Ration.addNewRationFast(rationType.ration);
  663. break;
  664. case 2:
  665. curNode = ProjectController.addFB(projectObj.project, projectObj.mainController);
  666. break;
  667. case 3:
  668. curNode = ProjectController.addFX(projectObj.project, projectObj.mainController);
  669. break;
  670. case 4:
  671. curNode = ProjectController.addBills(projectObj.project, projectObj.mainController);
  672. break;
  673. }
  674. if (!curNode){
  675. hintBox.infoBox('系统提示','插入新结点出错,粘贴失败!', 1);
  676. return nodesArr;
  677. }
  678. else{
  679. nodesArr.push(curNode);
  680. if (projectObj.project.mainTree.selected != curNode)
  681. projectObj.project.mainTree.selected = curNode;
  682. }
  683. }
  684. };
  685. return nodesArr;
  686. };
  687. function doPaste(nodes, nodeType, datas) {
  688. if (nodeType == 1){ // 批量粘贴定额有严重的异步问题,这里要和清单分开处理
  689. let updateRationCodes = [];
  690. for (let i = 0; i < datas.length; i++) {
  691. let ptNode = nodes[i];
  692. let code = datas[i][0];
  693. // 编号去掉“换、借、补”等多余的字
  694. code = code.replace(new RegExp(rationPrefix.complementary), '');
  695. code = code.replace(new RegExp(rationPrefix.borrow), '');
  696. // code = code.replace(new RegExp(rationPrefix.replace), '');
  697. updateRationCodes.push({'node':ptNode, value:code});
  698. }
  699. projectObj.project.Ration.updateRationCodes(updateRationCodes);
  700. }
  701. else {
  702. for (let i = 0; i < datas.length; i++) {
  703. let ptNode = nodes[i];
  704. let code = datas[i][0];
  705. if (!(ptNode.data && ptNode.data.code && ptNode.data.code.sameText(code))){
  706. projectObj.updateCode(ptNode, code);
  707. };
  708. }
  709. }
  710. projectObj.mainController.refreshTreeNode(nodes);
  711. };
  712. let tagType = getNodeType(node);
  713. if (!tagType){
  714. hintBox.infoBox('系统提示', '该树结点类型不支持从项目编码列粘贴!', 1);
  715. return false;
  716. };
  717. let datas = getPasteTextArr(info);
  718. if (!datas) return;
  719. let pasteNodes = getPasteNodes(node, tagType, datas.length);
  720. doPaste(pasteNodes, tagType, datas);
  721. };
  722. },
  723. mainSpreadEditEnded: function (sender, info) {
  724. console.log('enterEDEnd');
  725. let project = projectObj.project;
  726. let node = project.mainTree.items[info.row];
  727. project.withinBillsLocked(node);
  728. let colSetting = projectObj.mainController.setting.cols[info.col];
  729. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  730. // 检查输入类型等
  731. let value = projectObj.checkSpreadEditingText(info.editingText, colSetting);
  732. projectObj.updateCellValue(node, value, colSetting,info.editingText);
  733. // 自动行高
  734. const autoHeight = project.property.displaySetting.autoHeight;
  735. if (autoHeight) {
  736. projectObj.mainSpread.getActiveSheet().autoFitRow(info.row);
  737. }
  738. },
  739. msClipboardChanged: function (sender, info) {
  740. let colSettings = projectObj.mainController.setting.cols;
  741. let cDatas = sheetCommonObj.getTableData(info.sheet, colSettings);
  742. sheetCommonObj.copyTextToClipboard(cDatas);
  743. return;
  744. },
  745. mainSpreadRangeChanged: function (sender, info) {
  746. let project = projectObj.project, setting = projectObj.mainController.setting;
  747. let changedObj = projectObj.checkSpreadChangedCells(info);
  748. let refreshNodes = [];
  749. for(let row of changedObj.refreshRows){
  750. refreshNodes.push(project.mainTree.items[row]);
  751. }
  752. let updateRationCodes = [];//更新定额编码时要用同步的方式
  753. if(changedObj.changedCells.length > 0){
  754. for (let changedCell of changedObj.changedCells) {
  755. let node = project.mainTree.items[changedCell.row];
  756. let colSetting = setting.cols[changedCell.col];
  757. let value = projectObj.checkSpreadEditingText(changedCell.text, colSetting)
  758. if(colSetting.data.field=='code' && node.sourceType == project.Ration.getSourceType()&&node.data.type==rationType.ration){//如果是更新定额的编码
  759. updateRationCodes.push({'node':node,value:value});
  760. }else {
  761. projectObj.updateCellValue(node, value, colSetting,changedCell.text);
  762. }
  763. }
  764. }
  765. if(updateRationCodes.length>0){
  766. project.Ration.updateRationCodes(updateRationCodes);
  767. }
  768. if(refreshNodes.length > 0){
  769. projectObj.mainController.refreshTreeNode(refreshNodes);
  770. }
  771. },
  772. checkMainSpread: function () {
  773. if (!this.mainSpread) {
  774. this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
  775. sheetCommonObj.spreadDefaultStyle(this.mainSpread);
  776. this.mainSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.muliRange);
  777. this.mainSpread.getActiveSheet().name('mainSheet');
  778. this.mainSpread.getActiveSheet().options.isProtected = true;
  779. }
  780. },
  781. refreshMainSpread: function () {
  782. if (this.mainSpread) {
  783. this.mainSpread.refresh();
  784. }
  785. },
  786. loadProjectData: function () {
  787. var that = this;
  788. this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
  789. let startTime = +new Date();
  790. console.log("开始加载-----"+startTime);
  791. $.bootstrapLoading.start();
  792. this.project.loadDatas(function (err) {
  793. let mTime = +new Date();
  794. console.log(`get data时间——${mTime - startTime}`);
  795. //快速列设置
  796. if(!colSettingObj.getVisible('itemCharacterText')){
  797. switchTznrHtml(true);
  798. }
  799. if(colSettingObj.getVisible('itemCharacterText')){
  800. switchTznrHtml(false);
  801. }
  802. if (!err) {
  803. that.project.projectGLJ.calcQuantity(true);//计算分部分项和技术措施项目消耗量;
  804. gljCol.initGljCol(that.project.projSetting.glj_col?that.project.projSetting.glj_col.showAdjustPrice:false);
  805. subObj.initSubSpread();//初始化主界面下方的表格
  806. let quantityTime = +new Date();
  807. console.log(`计算quantity时间——${quantityTime - mTime}`);
  808. that.project.property = projectInfoObj.projectInfo.property;
  809. //that.project.calcProgram.compileAllTemps();
  810. that.project.calcBase.init(that.project);
  811. // that.project.calcFields = JSON.parse(JSON.stringify(cpFeeTypes));
  812. // that.project.initCalcFields();
  813. let str = JSON.stringify(that.project.projSetting.main_tree_col);
  814. that.project.projSetting.mainGridSetting = JSON.parse(str);
  815. that.project.projSetting.mainGridSetting.frozenCols = 4;
  816. TREE_SHEET_HELPER.initSetting($('#billsSpread')[0], that.project.projSetting.mainGridSetting);
  817. that.project.projSetting.mainGridSetting.setAutoFitRow = MainTreeCol.getEvent("setAutoFitRow");
  818. that.project.projSetting.mainGridSetting.cols.forEach(function (col) {
  819. col.data.splitFields = col.data.field.split('.');
  820. if (col.data.getText && Object.prototype.toString.apply(col.data.getText) === "[object String]") {
  821. col.data.getText = MainTreeCol.getEvent(col.data.getText);
  822. }
  823. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  824. col.readOnly = MainTreeCol.getEvent(col.readOnly);
  825. }
  826. if (col.data.cellType && Object.prototype.toString.apply(col.data.cellType) === "[object String]") {
  827. let getCellType = MainTreeCol.getEvent(col.data.cellType);
  828. col.data.cellType = getCellType;
  829. }
  830. // if (col.data.digit && Object.prototype.toString.apply(col.data.digit) === "[object String]") {
  831. // col.data.decimal = that.project.getDecimal(col.data.digit);
  832. // col.data.formatter = MainTreeCol.getNumberFormatter(col.data.decimal);
  833. // }
  834. if (col.data.field === 'code') {
  835. col.data.formatter = '@';
  836. }
  837. col.setAutoHeight = MainTreeCol.getEvent("setAutoHeight");
  838. col.editChecking = MainTreeCol.getEvent("editChecking");
  839. // 根据配置设置自动行高,在这里先做个标记,然后对每个单元格单独配置
  840. if (col.data.field === 'name' || col.data.field === 'itemCharacterText' ||
  841. col.data.field === 'jobContentText' || col.data.field === 'adjustState') {
  842. col.data.autoHeight = true;
  843. col.showHint = true;
  844. }
  845. if(col.data.field ==='quantity' || col.data.field ==='remark'){
  846. col.showHint = true;
  847. }
  848. // 综合单价、综合合价,小数部分应补0对齐。 CSL
  849. // if (col.data.field.hasSubStr("common")){
  850. if (col.data.field.hasSubStr(".totalFee"))
  851. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.totalPrice, true);
  852. else if (col.data.field.hasSubStr(".unitFee"))
  853. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.unitPrice, true);
  854. // }
  855. });
  856. let startShowTime = +new Date();
  857. that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), that.project.projSetting.mainGridSetting);
  858. that.mainController.showTreeData();
  859. let endShowTime = +new Date();
  860. console.log(`show data时间——${endShowTime - startShowTime}`);
  861. that.mainController.bind('refreshBaseActn', that.refreshBaseActn);
  862. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.beforeTreeSelectedChange, that.beforeMainTreeSelectedChange);
  863. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, that.treeSelectedChanged);
  864. if(!projectReadOnly){
  865. that.mainSpreadEscKey(that.mainSpread, that.mainSpreadEditStarting, that.mainSpreadEditEnded);
  866. sheetCommonObj.bindEnterKey(that.mainSpread, that.mainSpreadEnterKey);
  867. }
  868. setTimeout(function () {
  869. that.mainSpread.getActiveSheet().startEdit();//这两句需要挺多时间,而又需要在editend 事件前触发,而这些又不影响计算,所以这里用异步的方法
  870. that.mainSpread.getActiveSheet().endEdit();
  871. that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
  872. that.mainSpread.bind(GC.Spread.Sheets.Events.EditStarting, that.mainSpreadEditStarting);
  873. },100);
  874. that.mainSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, that.amountAreaNumber);//选中统计专用,节点相关操作在treeSelectedChanged里些
  875. that.mainSpread.bind(GC.Spread.Sheets.Events.LeaveCell, that.mainSpreadLeaveCell);
  876. that.mainSpread.bind(GC.Spread.Sheets.Events.EnterCell, that.mainSpreadEnterCell);
  877. that.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, that.mainSpreadRangeChanged);
  878. that.mainSpread.bind(GC.Spread.Sheets.Events.ClipboardChanged, that.msClipboardChanged);
  879. that.mainSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, that.onButtonClick);
  880. that.mainSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, that.onCellDoubleClick);
  881. that.mainSpread.bind(GC.Spread.Sheets.Events.ColumnWidthChanged, that.onColumnWidthChanged);
  882. that.mainSpread.bind(GC.Spread.Sheets.Events.ClipboardPasting, that.onClipboardPasting);
  883. //let loadOtherStartTime = +new Date();
  884. if(!projectReadOnly){
  885. that.loadMainSpreadContextMenu();
  886. }
  887. that.loadFocusLocation();
  888. socketObject.connect();//连接socket服务器
  889. let endTime = +new Date();
  890. console.log(`其它时间——${endTime - endShowTime}`);
  891. console.log("加载完成-----"+endTime);
  892. console.log(`时间——${endTime - startTime}`);
  893. that.project.projectMarkChecking();//是否需要重新进行造价计算
  894. installationFeeObj.engineeringTypeChecking();//检查是否安装工程
  895. autoFlashHeight();
  896. projectObj.refreshMainSpread();
  897. //定位到会话中的选项
  898. let mainTabFocus = sessionStorage.getItem('mainTab') ? sessionStorage.getItem('mainTab') : '#tab_zaojiashu';
  899. $(`${mainTabFocus}`).click();
  900. if(projectReadOnly){
  901. disableSpread(that.mainSpread);
  902. }
  903. $.bootstrapLoading.end();
  904. }
  905. else {
  906. }
  907. });
  908. },
  909. //mainSpread有一些单元格进入编辑状态后,会动态改变值,公用的bindEscKey方法不适用
  910. mainSpreadEscKey: function (workBook, editStarting = null, editEnded = null) {
  911. workBook.commandManager().register('myEsc', function () {
  912. let sheet = workBook.getActiveSheet();
  913. if(editStarting){
  914. sheet.unbind(GC.Spread.Sheets.Events.EditStarting);
  915. }
  916. if(editEnded){
  917. sheet.unbind(GC.Spread.Sheets.Events.EditEnded);
  918. }
  919. let row = sheet.getActiveRowIndex();
  920. let col = sheet.getActiveColumnIndex();
  921. let orgV = sheet.getValue(row, col);
  922. let node = projectObj.project.mainTree.items[row];
  923. let field = colSettingObj.getFieldByCol(col);
  924. //进入编辑状态后改变了单元格值的时候特殊处理
  925. if(isDef(field) && field === 'code'){
  926. if(node && node.sourceType === projectObj.project.Ration.getSourceType() && node.data.type === rationType.ration
  927. && isDef(node.data.code) && isDef(node.data.prefix) && node.data.prefix !== rationPrefix.none){
  928. orgV = node.data.prefix + orgV;
  929. }
  930. }
  931. else if(isDef(field) && field === 'quantity'){
  932. orgV = isDef(node) && isDef(node.data.quantity) ? node.data.quantity : '';
  933. }
  934. if(!isDef(orgV)){
  935. orgV = '';
  936. }
  937. if(sheet.isEditing()){
  938. sheet.endEdit();
  939. sheet.setValue(row, col, orgV);
  940. }
  941. if(editStarting){
  942. sheet.bind(GC.Spread.Sheets.Events.EditStarting, editStarting);
  943. }
  944. if(editEnded){
  945. sheet.bind(GC.Spread.Sheets.Events.EditEnded, editEnded);
  946. }
  947. });
  948. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.esc, false, false, false, false);
  949. workBook.commandManager().setShortcutKey('myEsc', GC.Spread.Commands.Key.esc, false, false, false, false);
  950. },
  951. mainSpreadEnterKey: function () {
  952. let me = projectObj;
  953. let sheet = me.mainSpread.getActiveSheet();
  954. let orgRow = sheet.getActiveRowIndex();
  955. let orgCol = sheet.getActiveColumnIndex();
  956. let orgField = colSettingObj.getFieldByCol(orgCol);
  957. let selected = me.project.mainTree.items[orgRow];
  958. if(sheet.isEditing()){
  959. sheet.endEdit();
  960. }
  961. //正常情况,焦点应该是在下一行的同一列
  962. let newRow = orgRow + 1, newCol = orgCol;
  963. //getColByField getVisible都不提出来,减少调用次数
  964. if(selected){
  965. //在分项/补项的编码单元格回车,焦点应跳动至本行的工程量单元格
  966. if(orgField && orgField === 'code' && selected.sourceType === me.project.Bills.getSourceType() && [billType.FX, billType.BX].includes(selected.data.type)){
  967. let quantityCol = colSettingObj.getColByField('quantity');
  968. let quantityVisible = colSettingObj.getVisible('quantity');
  969. if(quantityCol !== null && quantityVisible !== false){
  970. newRow = orgRow;
  971. newCol = quantityCol;
  972. }
  973. }
  974. else if(orgField && orgField === 'quantity' && selected.sourceType === me.project.Bills.getSourceType() && [billType.FX, billType.BX].includes(selected.data.type)){
  975. //在分项/补项的工程量单元格回车,如果其下有定额/量价/人材机,焦点应跳动至其下第一条定额/量价/人材机的工程量,如果是空行,则跳到至第一条定额xx的编码;
  976. if(selected.children.length !== 0 && !(isDef(selected.children[0].data.code) && selected.children[0].data.code.toString().trim() !== '')){
  977. let codeCol = colSettingObj.getColByField('code');
  978. let codeVisible = colSettingObj.getVisible('code');
  979. newRow = orgRow + 1;
  980. if(codeCol !== null && codeVisible !== false){
  981. newCol = codeCol;
  982. }
  983. }
  984. //如果其下没有定额/量价/人材机,则自动在其下插入一条定额空行,在其后自动插入一条分项空行,焦点跳动至定额空行的编码单元格。
  985. else if(selected.children.length === 0){
  986. //分项没有后兄弟,且没有锁定清单时在其后插入分项
  987. if(!selected.nextSibling && !(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected))){
  988. ProjectController.addFX(me.project, me.mainController);
  989. //将焦点行设置成原本的行,以插入定额
  990. me.mainController.setTreeSelected(me.project.mainTree.items[orgRow]);
  991. }
  992. //插入定额
  993. me.project.Ration.addNewRation(null, rationType.ration, function () {
  994. newRow = sheet.getActiveRowIndex();
  995. let codeCol = colSettingObj.getColByField('code');
  996. let codeVisible = colSettingObj.getVisible('code');
  997. if(codeCol !== null && codeVisible !== false){
  998. newCol = codeCol;
  999. }
  1000. sheet.setActiveCell(newRow, newCol);
  1001. },true);
  1002. }
  1003. }
  1004. //在定额/量价/人材机的编码单元格回车,焦点应跳动至本行的工程量单元格
  1005. else if(orgField && orgField === 'code' && selected.sourceType === me.project.Ration.getSourceType()){
  1006. let quantityCol = colSettingObj.getColByField('quantity');
  1007. let quantityVisible = colSettingObj.getVisible('quantity');
  1008. if(quantityCol !== null && quantityVisible !== false){
  1009. newRow = orgRow;
  1010. newCol = quantityCol;
  1011. }
  1012. }
  1013. //在定额/量价/人材机的工程量单元格回车
  1014. else if(orgField && orgField === 'quantity' && selected.sourceType === me.project.Ration.getSourceType()){
  1015. let nextSibling = selected.nextSibling;
  1016. //如果其后有定额/量价/人材机(空行:编码为空不算),焦点应跳动至下一行定额/量价/人材机的工程量,不需处理
  1017. //如果其后没有定额/量价/人材机(空行也没有),则自动在其后插入一行定额空行,焦点跳动至定额空行的编码单元格
  1018. if(!nextSibling){
  1019. let codeCol = colSettingObj.getColByField('code');
  1020. let codeVisible = colSettingObj.getVisible('code');
  1021. me.project.Ration.addNewRation(null, rationType.ration, function () {
  1022. newRow = sheet.getActiveRowIndex();
  1023. if(codeCol !== null && codeVisible !== false){
  1024. newCol = codeCol;
  1025. }
  1026. sheet.setActiveCell(newRow, newCol);
  1027. }, true);
  1028. }
  1029. //如果其后有定额空行,焦点跳动至定额空行的编码单元格
  1030. else if(nextSibling && !(isDef(nextSibling.data.code) && nextSibling.data.code.toString().trim() !== '')) {
  1031. let codeCol = colSettingObj.getColByField('code');
  1032. let codeVisible = colSettingObj.getVisible('code');
  1033. if(codeCol !== null && codeVisible !== false){
  1034. newRow = orgRow + 1;
  1035. newCol = codeCol;
  1036. }
  1037. }
  1038. }
  1039. //在清单的编码单元格回车,如果清单是叶子节点,焦点跳动至本行的工程量单元格
  1040. else if(orgField && orgField === 'code' && selected.sourceType === me.project.Bills.getSourceType()
  1041. && selected.data.type === billType.BILL && selected.source.children.length === 0){
  1042. let quantityCol = colSettingObj.getColByField('quantity');
  1043. let quantityVisible = colSettingObj.getVisible('quantity');
  1044. if(quantityCol && quantityVisible){
  1045. newRow = orgRow;
  1046. newCol = quantityCol;
  1047. }
  1048. }
  1049. }
  1050. //设置焦点
  1051. sheet.setActiveCell(newRow, newCol);
  1052. //触发表格事件
  1053. me.mainController.setTreeSelected(me.project.mainTree.items[newRow]);//SelectionChanged
  1054. me.mainSpreadLeaveCell({type: 'LeaveCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: orgRow, col: orgCol});
  1055. me.mainSpreadEnterCell({type: 'EnterCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: newRow, col: newCol});
  1056. },
  1057. loadMainSpreadContextMenu: function () {
  1058. var project = this.project, spread = this.mainSpread, controller = this.mainController;
  1059. $.contextMenu({
  1060. selector: '#billsSpread',
  1061. build: function ($trigger, e) {
  1062. var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  1063. controller.setTreeSelected(controller.tree.items[target.row]);
  1064. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1065. },
  1066. items: {
  1067. "insertRootBill": {
  1068. name: "插入大项费用",
  1069. icon: 'fa-sign-in',
  1070. disabled: function () {
  1071. return projectObj.project.isBillsLocked() && project.withinBillsLocked(project.mainTree.selected);
  1072. //return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
  1073. },
  1074. callback: function (key, opt) {
  1075. ProjectController.addRootBill(project, controller);
  1076. },
  1077. visible: function(key, opt){
  1078. return project.mainTree.selected&&project.mainTree.selected.parent==null;
  1079. }
  1080. },
  1081. "insertFB": {
  1082. name: "插入分部",
  1083. icon: 'fa-sign-in',
  1084. disabled: function () {
  1085. let selected = project.mainTree.selected;
  1086. if(projectObj.project.isBillsLocked()== false&&selected&&selected.sourceType==project.Bills.getSourceType()){
  1087. if(selected.data.type==billType.FB){
  1088. return false;
  1089. }
  1090. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  1091. if(selected.children.length>0){
  1092. return selected.children[0].data.type==billType.FX ||selected.children[0].data.type==billType.BX;//焦点行是分部分项工程,且子项是分项或补项
  1093. }else {
  1094. return false
  1095. }
  1096. }
  1097. }
  1098. return true;//除了清单,其它类型都只读
  1099. },
  1100. callback: function (key, opt) {
  1101. ProjectController.addFB(project, controller);
  1102. },
  1103. visible: function(key, opt){
  1104. if(project.mainTree.selected){
  1105. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  1106. }else {
  1107. return false;
  1108. }
  1109. }
  1110. },
  1111. "insertFX": {
  1112. name: "插入分项",
  1113. icon: 'fa-sign-in',
  1114. disabled: function () {
  1115. let selected = project.mainTree.selected;
  1116. if(projectObj.project.isBillsLocked()== false&& selected&&selected.sourceType==project.Bills.getSourceType()){
  1117. if(selected.data.type==billType.FX||selected.data.type==billType.BX){//焦点行是分项,有效显示
  1118. return false
  1119. }
  1120. if(selected.data.type==billType.FB){//点行是分部,
  1121. if(selected.children.length>0){//且有子项,子项是分部,灰显。
  1122. return selected.children[0].data.type == billType.FB
  1123. }else {
  1124. return false;
  1125. }
  1126. }
  1127. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  1128. if(selected.children.length>0){
  1129. return selected.children[0].data.type==billType.FB;//焦点行是分部分项工程,且子项是分部时灰显
  1130. }else {
  1131. return false
  1132. }
  1133. }
  1134. }
  1135. return true;//除了清单,其它类型都只读
  1136. },
  1137. callback: function (key, opt) {
  1138. ProjectController.addFX(project, controller);
  1139. },
  1140. visible: function(key, opt){
  1141. if(project.mainTree.selected){
  1142. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  1143. }else {
  1144. return false;
  1145. }
  1146. }
  1147. },
  1148. "insertBills": {
  1149. name: "插入清单",
  1150. icon: 'fa-sign-in',
  1151. disabled: function () {
  1152. let selected = project.mainTree.selected;
  1153. if(!(projectObj.project.isBillsLocked()== true && project.withinBillsLocked(selected)) && selected && selected.sourceType === project.Bills.getSourceType()){
  1154. return false
  1155. }
  1156. return true;
  1157. },
  1158. callback: function (key, opt) {
  1159. if(project.mainTree.selected.data.type == billType.DXFY){
  1160. if(project.mainTree.selected.data.calcBase&&project.mainTree.selected.data.calcBase!=""){
  1161. alert("当前有基数计算不能插入子项。");
  1162. return;
  1163. }
  1164. }
  1165. ProjectController.addBills(project, controller);
  1166. },
  1167. visible: function(key, opt){
  1168. if(project.mainTree.selected){
  1169. return project.Bills.isFBFX(project.mainTree.selected)==true?false:true;
  1170. }else {
  1171. return false;
  1172. }
  1173. }
  1174. },
  1175. "spr1": '--------',
  1176. "insertRation": {
  1177. name: "插入定额",
  1178. icon: 'fa-sign-in',
  1179. disabled: function () {
  1180. // var selected = project.mainTree.selected;
  1181. // return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  1182. // 工具栏要加按钮,且不能隐藏。菜单可以隐藏,两者又必须统一,所以启用新规则。怕以后又要改回来,所以保留。 CSL, 2018-01-02
  1183. return !project.Ration.canAdd(project.mainTree.selected);
  1184. },
  1185. callback: function (key, opt) {
  1186. project.Ration.addNewRation(null,rationType.ration,projectObj.selectColAndFocus,true);
  1187. // ProjectController.addRation(project, controller, rationType.ration);
  1188. }/*,
  1189. visible: function(key, opt){
  1190. var selected = project.mainTree.selected;
  1191. return canInsertRationNode(selected);
  1192. }*/
  1193. },
  1194. "insertLJ": {
  1195. name: "插入量价",
  1196. icon: 'fa-sign-in',
  1197. disabled: function () {
  1198. // var selected = project.mainTree.selected;
  1199. // return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  1200. return !project.Ration.canAdd(project.mainTree.selected);
  1201. },
  1202. callback: function (key, opt) {
  1203. project.Ration.addNewRation(null,rationType.volumePrice,null,true);
  1204. // ProjectController.addRation(project, controller, rationType.volumePrice);
  1205. }/*,
  1206. visible: function(key, opt){
  1207. var selected = project.mainTree.selected;
  1208. if(selected){
  1209. return canInsertRationNode(selected);
  1210. }
  1211. return false;
  1212. }*/
  1213. },
  1214. "insertGLJ": {
  1215. name: "插入人材机",
  1216. icon: 'fa-sign-in',
  1217. disabled: function () {
  1218. // var selected = project.mainTree.selected;
  1219. // return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  1220. return !project.Ration.canAdd(project.mainTree.selected);
  1221. },
  1222. callback: function (key, opt) {
  1223. var selected = project.mainTree.selected;
  1224. if(selected.sourceType == ModuleNames.bills){
  1225. if(selected.data.type == billType.FX||selected.data.type ==billType.BILL){
  1226. if(selected.data.calcBase&&selected.data.calcBase!=""){
  1227. alert("当前有基数计算不能插入子项。");
  1228. return;
  1229. }
  1230. }
  1231. }
  1232. getGLJData('insert');// ProjectController.addRation(project, controller, rationType.volumePrice);
  1233. }/*,
  1234. visible: function(key, opt){
  1235. var selected = project.mainTree.selected;
  1236. if(selected){
  1237. return canInsertRationNode(selected);
  1238. }
  1239. return false;
  1240. }*/
  1241. },
  1242. "spr2": '--------',
  1243. "calc_installation_fee": {
  1244. name: "计取安装费用",
  1245. icon: 'fa-sign-in',
  1246. disabled: function () {
  1247. return false;
  1248. },
  1249. callback: function (key, opt) {
  1250. installationFeeObj.showCalcInstallSettingDiv();
  1251. },
  1252. visible: function(key, opt){
  1253. let engineering = projectInfoObj.projectInfo.property.engineering;
  1254. return engineering==engineeringType.BUILD_IN;
  1255. }
  1256. },
  1257. "delete": {
  1258. name: '删除',
  1259. icon: 'fa-remove',
  1260. disabled: function () {
  1261. return !ifCanDelete();
  1262. },
  1263. callback: function () {
  1264. var selected = project.mainTree.selected;
  1265. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length<=0){//选中的是分部,并且没有子项,直接删除
  1266. project.Bills.deleteSelectedNode();
  1267. }else {
  1268. $("#delete_row").modal({show:true});//弹出删除提示框;
  1269. }
  1270. }
  1271. },
  1272. "calculateAll_RationContent": {
  1273. name: '造价计算',
  1274. icon: 'fa-calculator',
  1275. callback: function () {
  1276. project.calcProgram.calcAllNodesAndSave();
  1277. }
  1278. },
  1279. "spr4":'--------',
  1280. "copyBlock": {
  1281. name: '复制整块',
  1282. icon: 'fa-copy',
  1283. disabled: function () {
  1284. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  1285. let firstNode = projectObj.project.mainTree.items[selection.row];//当多选的情况,用mainTree.selected判断不正确,要用第一个选中的节点
  1286. for(let i = 0;i< selection.rowCount;i++){ //多选的时候判断所有与第一个节点同级的节点
  1287. let temNode = projectObj.project.mainTree.items[selection.row + i];
  1288. if(firstNode.getParentID() == temNode.getParentID()){
  1289. if(BlockController.copyBtnDisable(temNode) == true){
  1290. return true;
  1291. }
  1292. }
  1293. }
  1294. return false;
  1295. },
  1296. callback: function () {
  1297. $.bootstrapLoading.start();
  1298. //let selected = project.mainTree.selected;
  1299. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  1300. setTimeout(function () {
  1301. BlockController.copyBlock(selections[0]);
  1302. $.bootstrapLoading.end();
  1303. },100)
  1304. }
  1305. },
  1306. "pasteBlock": {
  1307. name: '粘贴整块',
  1308. icon: 'fa-paste',
  1309. disabled: function (){
  1310. return BlockController.pasteBtnDisable(project.mainTree.selected);
  1311. },
  1312. callback: function () {
  1313. BlockController.pasteBlock(project.mainTree.selected);
  1314. }
  1315. },
  1316. "editEngineer": {
  1317. name: '编辑工程内容',
  1318. icon: 'fa-edit',
  1319. visible: function(key, opt){
  1320. let selected = project.mainTree.selected;
  1321. return selected.sourceType==ModuleNames.bills&&project.Bills.isEngineerEst(selected);//当焦点行是“专业工程暂估价”时,右键可见并有效。
  1322. },
  1323. callback: function () {
  1324. let node = project.mainTree.selected;//project.Bills.getNodeByFlag(project.mainTree.selected,fixedFlag.ENGINEERING_ESITIMATE);
  1325. if(node){
  1326. projectObj.editContent(node,'engineeringContent');
  1327. }
  1328. }
  1329. },
  1330. "editService": {
  1331. name: '编辑服务内容',
  1332. icon: 'fa-edit',
  1333. visible: function(key, opt){
  1334. let selected = project.mainTree.selected;
  1335. return selected.sourceType==ModuleNames.bills&&project.Bills.isTotalService(selected);//当焦点行是“总承包服务费”时,右键可见并有效。
  1336. },
  1337. callback: function () {
  1338. let node = project.mainTree.selected;//project.Bills.getNodeByFlag(project.mainTree.selected,fixedFlag.TURN_KEY_CONTRACT);
  1339. if(node){
  1340. projectObj.editContent(node,'serviceContent');
  1341. }
  1342. }
  1343. },
  1344. "editAccording": {
  1345. name: '编辑签证及索赔依据',
  1346. icon: 'fa-edit',
  1347. visible: function(key, opt){
  1348. let selected = project.mainTree.selected;
  1349. return selected.sourceType==ModuleNames.bills&&project.Bills.isClaimVisa(selected);//当焦点行是“签证及索赔计价”时,右键可见并有效。
  1350. },
  1351. callback: function () {
  1352. let node = project.mainTree.selected;//project.Bills.getNodeByFlag(project.mainTree.selected,fixedFlag.CLAIM_VISA);
  1353. if(node){
  1354. projectObj.editContent(node,'claimVisa');
  1355. }
  1356. }
  1357. }
  1358. }
  1359. });
  1360. },
  1361. // 计算node及node的所有父项
  1362. converseCalculateBills: function (node) {
  1363. projectObj.project.calcProgram.calcAndSave(node);
  1364. },
  1365. // 获取上次退出时的焦点位置
  1366. loadFocusLocation: function() {
  1367. const projectId = scUrlUtil.GetQueryString('project');
  1368. let row = getLocalCache('lastRow:' + projectId);
  1369. let col = getLocalCache('lastCol:' + projectId);
  1370. if(row == null || col == null){
  1371. row = 0;
  1372. col = 0;
  1373. }
  1374. row = parseInt(row);
  1375. col = parseInt(col);
  1376. const sheet = this.mainSpread.getActiveSheet();
  1377. sheet.setSelection(row, col, 1, 1);
  1378. this.mainController.setTreeSelected(this.mainController.tree.items[row]);//触发树节点选中事件
  1379. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  1380. },
  1381. // 选中区域合计数字
  1382. amountAreaNumber: function(e, info) {
  1383. if (info.newSelections === undefined || info.newSelections.length <= 0) {
  1384. return false;
  1385. }
  1386. const selectedArea = info.newSelections[0];
  1387. const sheet = info.sheet;
  1388. if (selectedArea.colCount <= 1 && selectedArea.rowCount <= 1) {
  1389. return false;
  1390. }
  1391. //获取最左最右坐标
  1392. let maxCell = {row: selectedArea.row, col: selectedArea.col + selectedArea.colCount};
  1393. let maxCellX = sheet.getCellRect(maxCell.row, maxCell.col).x ? sheet.getCellRect(maxCell.row, maxCell.col).x : sheet.getCellRect(maxCell.row, maxCell.col - 1).x;
  1394. let minCell = {row: selectedArea.row, col: selectedArea.col};
  1395. let minCellX = sheet.getCellRect(minCell.row, minCell.col).x ? sheet.getCellRect(minCell.row, minCell.col).x : sheet.getCellRect(minCell.row, minCell.col + 1).x;
  1396. // 获取鼠标位置
  1397. let x = window.event.clientX;
  1398. let y = window.event.clientY;
  1399. // 匹配数字或小数
  1400. const regular = /^([0-9]+[.]{1}[0-9]+)$|^([1-9]{1}\d*)$/;
  1401. // 小数点最高位数
  1402. let max = 0;
  1403. let total = 0;
  1404. let counter = 0;
  1405. for (let col = selectedArea.col; col < (selectedArea.colCount + selectedArea.col); col++) {
  1406. for (let row = selectedArea.row; row < (selectedArea.rowCount + selectedArea.row); row++) {
  1407. const value = sheet.getCell(row, col).text();
  1408. if (!regular.test(value)) {
  1409. continue;
  1410. }
  1411. counter++;
  1412. // 获取当前数据小数位数
  1413. let pointPosition = value.toString().indexOf(".");
  1414. pointPosition = pointPosition < 0 ? pointPosition : pointPosition + 1;
  1415. const current = pointPosition > 0 ? value.toString().substring(pointPosition, value.toString().length).length : 0;
  1416. max = current > max ? current : max;
  1417. total += parseFloat(value);
  1418. }
  1419. }
  1420. // 如果不为0则悬浮显示
  1421. if (total > 0 && counter > 1) {
  1422. 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>');
  1423. div.css({
  1424. position: "absolute",
  1425. border: "1px #C0C0C0 solid",
  1426. background: "#fff",
  1427. boxShadow: "1px 2px 5px rgba(0,0,0,0.4)",
  1428. });
  1429. div.children("p").css({
  1430. textAlign: "center",
  1431. padding: 8,
  1432. marginBottom: 2,
  1433. });
  1434. div.children("p").first().css({
  1435. borderBottom: "1px #C0C0C0 solid"
  1436. });
  1437. const totalString = total.toFixed(max);
  1438. // input长度
  1439. const inputWidth = totalString.length * 8;
  1440. // 计算是否会超出显示范围
  1441. const baseWidth = 48;
  1442. const baseHeight = 81;
  1443. const canvasWidth = $("#billsSpreadvp_vp").width();
  1444. const canvasHeight = $("#billsSpreadvp_vp").height();
  1445. //x = x + baseWidth + inputWidth > canvasWidth ? x - baseWidth - inputWidth : x;
  1446. x = maxCellX + baseWidth + inputWidth > canvasWidth ? minCellX - baseWidth - inputWidth : maxCellX + baseWidth;
  1447. y = y + baseHeight > canvasHeight ? y - baseHeight : y;
  1448. //test
  1449. let testT = sheet.getParent().hitTest(x, y);
  1450. //test
  1451. div.css({
  1452. left: x,
  1453. top: y,
  1454. });
  1455. div.children().children("#total").width(inputWidth).val(totalString);
  1456. $("body").append(div);
  1457. // 用于判断是否要关闭窗体
  1458. setTimeout(function() {
  1459. isTotalShowing = true;
  1460. }, 200);
  1461. };
  1462. },
  1463. onButtonClick: function (e, info) {
  1464. let colSetting = projectObj.mainController.setting.cols[info.col];
  1465. let node = projectObj.project.mainTree.items[info.row];
  1466. let fieldName = colSetting.data.field;
  1467. if(fieldName == "isSubcontract"){
  1468. projectObj.onSubcontractClick(node);
  1469. }else if(fieldName == "isEstimate"){
  1470. projectObj.onIsEstimateClick(node,info);
  1471. }
  1472. },
  1473. onIsEstimateClick: function(node,info){
  1474. let checkboxValue = info.sheet.getCell(info.row, info.col).value();
  1475. let cell = info.sheet.getCell(info.row, info.col), newval = 0;
  1476. if (checkboxValue) {
  1477. newval = 0;
  1478. cell.value(newval);
  1479. } else {
  1480. newval = 1;
  1481. cell.value(newval);
  1482. }
  1483. if(MainTreeCol.readOnly.bills(node)){
  1484. projectObj.updateNodeField(node,newval,'isEstimate');
  1485. }else if(node.data.projectGLJID){//更新的是定额类型的工料机或者是显示在造价书页面的主材、设备
  1486. console.log(node);
  1487. let updateData = {id: node.data.projectGLJID, field: 'is_evaluate', value: newval};
  1488. projectObj.project.projectGLJ.pGljUpdate(updateData);
  1489. }
  1490. },
  1491. onSubcontractClick:function (node) {//点击分包费checkbox
  1492. if (node.data.isSubcontract) node.data.isSubcontract = false;
  1493. else node.data.isSubcontract = true;
  1494. node.changed = true;
  1495. projectObj.project.calcProgram.calcAndSave(node);
  1496. },
  1497. //根据节点获取行style(颜色、字体加粗)
  1498. getNodeColorStyle: function (sheet, node, tree) {
  1499. let colorSetting = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
  1500. let mapping = {DEFAULT: 'DEFAULT', SELECTED: 'SELECTED', DXFY: 'DXFY', FB: 'FB', UNLEAFBILL: 'UNLEAFBILL',
  1501. FX: 'FX', BX: 'BX', UNCBBILL: 'UNCBBILL', CBBILL: 'CBBILL', ZCSB: 'ZCSB'};
  1502. let styleMap = null;
  1503. tree?'':tree = this.project.mainTree;
  1504. //中文字段名,由于同一节点中,中文字体大小和数字字体大小不同
  1505. if(colorSetting == null){
  1506. return null;
  1507. }
  1508. let stringFields = [
  1509. 'code',
  1510. 'subType',
  1511. 'name',
  1512. 'unit',
  1513. 'itemCharacterText',
  1514. 'jobContentText',
  1515. 'adjustState',
  1516. 'calcBase',
  1517. 'programID',
  1518. 'ruleText'
  1519. ];
  1520. if(!isDef(node)){
  1521. return null;
  1522. }
  1523. //清单大类
  1524. if(node.sourceType === this.project.Bills.getSourceType()){
  1525. //大项费用
  1526. if(node.data.type === billType.DXFY){
  1527. styleMap = mapping.DXFY;
  1528. }
  1529. //分部
  1530. if(node.data.type === billType.FB){
  1531. styleMap = mapping.FB;
  1532. }
  1533. //分项
  1534. else if(node.data.type === billType.FX){
  1535. styleMap = mapping.FX;
  1536. }
  1537. //补项
  1538. else if(node.data.type === billType.BX){
  1539. styleMap = mapping.BX;
  1540. }
  1541. //清单
  1542. else if(node.data.type === billType.BILL){
  1543. //非叶子节点的清单
  1544. if(node.source.children.length > 0){
  1545. styleMap = mapping.UNLEAFBILL;
  1546. }
  1547. //未使用基数计算的叶子节点的清单
  1548. else if(node.source.children.length === 0 && (!isDef(node.data.calcBase) || node.data.calcBase === '')){
  1549. styleMap = mapping.UNCBBILL;
  1550. }
  1551. //使用基数计算的叶子节点的清单
  1552. else if(node.source.children.length === 0 && isDef(node.data.calcBase && node.data.calcBaseValue !== '')){
  1553. styleMap = mapping.CBBILL;
  1554. }
  1555. }
  1556. }
  1557. //定额下的主材、设备
  1558. else if(node.sourceType === this.project.ration_glj.getSourceType()){
  1559. styleMap = mapping.ZCSB;
  1560. }
  1561. else {
  1562. styleMap = mapping.DEFAULT;
  1563. }
  1564. let styleSetting = colorSetting[styleMap];
  1565. let defaultSetting = colorSetting[mapping.DEFAULT];
  1566. if(!isDef(styleSetting)){
  1567. return null;
  1568. }
  1569. let style = new GC.Spread.Sheets.Style();
  1570. //设置style属性
  1571. for(let attr in styleSetting){
  1572. if(attr !== 'stringFont' && attr !== 'numFont'){
  1573. style[attr] = styleSetting[attr] === 'default' || !isDef(styleSetting[attr]) ? defaultSetting[attr] : styleSetting[attr];
  1574. }
  1575. //暂时不开放字体设置,开放的话只能每个单元格进入此方法
  1576. /* else {
  1577. if(stringFields.indexOf(colSetting.data.field) > 0){
  1578. style.font = styleSetting.stringFont === 'default' || !isDef(styleSetting.stringFont) ? defaultSetting.stringFont : styleSetting.stringFont;
  1579. }
  1580. else {
  1581. style.font = styleSetting.numFont === 'default' || !isDef(styleSetting.numFont) ? defaultSetting.numFont : styleSetting.numFont;
  1582. }
  1583. }*/
  1584. }
  1585. //选中行-替换底色
  1586. if(node === tree.selected){
  1587. style.backColor = colorSetting[mapping.SELECTED]['backColor'];
  1588. }
  1589. //大项费用加粗(数字与中文字符大小不一问题由字体造成,暂时不考虑分别设置大小)
  1590. /* if(node.sourceType === this.project.Bills.getSourceType() && node.data.type === billType.DXFY){
  1591. style.font = 'bold 0.9rem Arial';
  1592. }*/
  1593. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1594. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1595. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1596. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  1597. return style;
  1598. },
  1599. //大项费用则字体加粗,String 15px, Number 13px
  1600. getBoldFontStyle: function (node, colSetting) {
  1601. let style = new GC.Spread.Sheets.Style();
  1602. if(node.sourceType !== this.project.Bills.getSourceType() || node.data.type !== billType.DXFY){
  1603. return null;
  1604. }
  1605. //备注暂无字段
  1606. let stringFields = [
  1607. 'code',
  1608. 'subType',
  1609. 'name',
  1610. 'unit',
  1611. 'itemCharacterText',
  1612. 'jobContentText',
  1613. 'adjustState',
  1614. 'calcBase',
  1615. 'programID',
  1616. 'ruleText'
  1617. ];
  1618. style.font = 'bold 0.9rem Arial';
  1619. return style;
  1620. },
  1621. //设置节点style
  1622. setNodesStyle: function (sheet, nodes,tree) {
  1623. let me = this;
  1624. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  1625. for(let node of nodes){
  1626. if(node && node.serialNo()!= -1){
  1627. sheet.getRange(node.serialNo(), -1, 1, -1).backColor(me.getNodeColorStyle(sheet, node,tree).backColor);
  1628. }
  1629. }
  1630. });
  1631. },
  1632. loadLockBillsButton:function () {
  1633. if(projectInfoObj.projectInfo.property.lockBills == true){
  1634. //$("a[name='lockBills']").attr("data-original-title","解锁清单");
  1635. $("a[name='lockBills']").html('<i class="fa fa-unlock-alt" aria-hidden="true"></i> 解锁清单');
  1636. }else {
  1637. //$("a[name='lockBills']").attr("data-original-title","锁定清单");
  1638. $("a[name='lockBills']").html('<i class="fa fa-lock" aria-hidden="true"></i> 锁定清单');
  1639. }
  1640. },
  1641. editContent:function (node,fieldID) {//右键编辑工程内容、服务内容、签证及索赔依据
  1642. let infoText = "请输入";
  1643. switch (fieldID){
  1644. case "engineeringContent":
  1645. infoText +='工程内容:';
  1646. break;
  1647. case "serviceContent":
  1648. infoText +='服务内容:';
  1649. break;
  1650. case "claimVisa":
  1651. infoText +='签证及索赔依据:';
  1652. break;
  1653. }
  1654. hintBox.valueBox(infoText, node.data[fieldID], function () {
  1655. let newValue = hintBox.value;
  1656. projectObj.updateNodeField(node,newValue,fieldID);
  1657. });
  1658. },
  1659. ifItemCharHiden:function (setting) {//项目特征及内容列是否隐藏
  1660. let col = _.find(setting.cols,function (item) {
  1661. return item.data.field == "itemCharacterText";
  1662. })
  1663. return !col.visible;
  1664. },
  1665. //综合合价cellType
  1666. getCommonTotalFeeCellType:function () {
  1667. let type = 'bills';
  1668. var ns = GC.Spread.Sheets;
  1669. function CommonTotalFeeCellType() {
  1670. var init=false;
  1671. }
  1672. CommonTotalFeeCellType.prototype = new ns.CellTypes.Text();
  1673. CommonTotalFeeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1674. // if(value!=null){
  1675. // ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3);
  1676. // ctx.fillText(value,x+w-3,y+h-3);
  1677. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1678. // }
  1679. if(calcBaseView.editingCell && !projectReadOnly && calcBaseView.ifEdit(type, options.row)){
  1680. if(calcBaseView.editingCell.row==options.row&&calcBaseView.editingCell.col==options.col){
  1681. var image = document.getElementById('f_btn'),imageMagin = 3;
  1682. var imageHeight = h-2*imageMagin;
  1683. var imageWidth = w*2/(type=='bills'?7:20);
  1684. var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
  1685. ctx.save();
  1686. ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
  1687. ctx.beginPath();
  1688. ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
  1689. ctx.arc(imageX+imageWidth/2-4,imageY+imageHeight/2,1,0,360,false);
  1690. ctx.arc(imageX+imageWidth/2+4,imageY+imageHeight/2,1,0,360,false);
  1691. ctx.fillStyle="black";//填充颜色,默认是黑色
  1692. ctx.fill();//画实心圆
  1693. ctx.closePath();
  1694. ctx.restore();
  1695. }
  1696. }
  1697. };
  1698. CommonTotalFeeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1699. return {
  1700. x: x,
  1701. y: y,
  1702. row: context.row,
  1703. col: context.col,
  1704. cellStyle: cellStyle,
  1705. cellRect: cellRect,
  1706. sheetArea: context.sheetArea
  1707. };
  1708. };
  1709. CommonTotalFeeCellType.prototype.processMouseDown = function (hitinfo) {
  1710. let me=calcBaseView;
  1711. me.pmLeave = false;
  1712. if(me.editingCell==null){
  1713. var showSelectBtn = true;
  1714. if(hitinfo.sheet.name()!='calc_detail'){
  1715. showSelectBtn=me.ifEdit(type, hitinfo.row);
  1716. }
  1717. if(showSelectBtn){
  1718. me.editingCell={
  1719. row:hitinfo.row,
  1720. col:hitinfo.col
  1721. }
  1722. hitinfo.sheet.invalidateLayout();
  1723. hitinfo.sheet.repaint();
  1724. }
  1725. }else if(hitinfo.row==me.editingCell.row){
  1726. var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
  1727. var imageMagin=3;
  1728. var imageHeight = hitinfo.cellRect.height-2*imageMagin;
  1729. var imageWidth = hitinfo.cellRect.width*2/7;
  1730. if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
  1731. if(!projectReadOnly && me.ifEdit(type, hitinfo.row)){
  1732. calcBaseView.confirmBtn.attr('toggle', 'commonTotalFee');
  1733. changeCalcBaseFeeRate('commonTotalFee');
  1734. $('#tabCalcBase').tab('show');
  1735. calcBaseView.initCalctor(type);
  1736. feeRateObject.showSelectModal(hitinfo);
  1737. }
  1738. }
  1739. }
  1740. };
  1741. CommonTotalFeeCellType.prototype.processMouseLeave = function (hitinfo) {
  1742. if(!calcBaseView.pmLeave){
  1743. calcBaseView.editingCell=null;
  1744. hitinfo.sheet.invalidateLayout();
  1745. hitinfo.sheet.repaint();
  1746. calcBaseView.pmLeave = true;
  1747. }
  1748. }
  1749. return new CommonTotalFeeCellType();
  1750. },
  1751. selectColAndFocus :function (newNode,field = 'code') {//选中单元格并设置焦点
  1752. if(newNode){
  1753. projectObj.mainController.sheet.setSelection(newNode.serialNo(), colSettingObj.getColByField(field), 1, 1); //
  1754. projectObj.mainSpread.focus();
  1755. }
  1756. }
  1757. };
  1758. // 点击合计框中的复制
  1759. $("body").on("click", "#total-tips a", function() {
  1760. const totalElement = $(this).parent().siblings("p").find("#total");
  1761. totalElement.select();
  1762. document.execCommand("Copy");
  1763. $(this).text("已复制");
  1764. });
  1765. // 合计框点击其他位置关闭
  1766. let isTotalShowing = false;
  1767. $("body").on("click", function(e) {
  1768. if (isTotalShowing && !$(e.target).is("#total-tips") && !$(e.target).is("#total-tips p") && !$(e.target).is("#total-tips p a")) {
  1769. $("#total-tips").remove();
  1770. isTotalShowing = false;
  1771. }
  1772. });
  1773. $('#insert').click(function () {
  1774. var controller = projectObj.mainController, project = projectObj.project;
  1775. var selected = controller.tree.selected;
  1776. if (!selected || selected.sourceType === project.Bills.getSourceType()) {
  1777. ProjectController.addBills(project, controller);
  1778. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1779. ProjectController.addRation(project, controller, selected.data.type);
  1780. };
  1781. });
  1782. $('#delete').click(function () {
  1783. let project = projectObj.project;
  1784. let selected = project.mainTree.selected;
  1785. if(isSingleSelect()&&selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length<=0){//选中的是分部,并且没有子项,直接删除
  1786. project.Bills.deleteSelectedNode();
  1787. }else {
  1788. $("#delete_row").modal({show:true});//弹出删除提示框;
  1789. }
  1790. });
  1791. $('#upLevel').click(function () {
  1792. var controller = projectObj.mainController, project = projectObj.project;
  1793. var selected = controller.tree.selected, orgParent = selected.parent;
  1794. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  1795. project.Bills.upLevelBills(selected.source);
  1796. controller.upLevel();
  1797. controller.refreshTreeNode([orgParent]);
  1798. projectObj.project.calcProgram.calcNodesAndSave([selected,orgParent]);
  1799. }
  1800. });
  1801. $('#downLevel').click(function () {
  1802. var controller = projectObj.mainController, project = projectObj.project;
  1803. var selected = controller.tree.selected;
  1804. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  1805. project.Bills.downLevelBills(selected.source);
  1806. controller.downLevel();
  1807. controller.refreshTreeNode([selected.parent]);
  1808. projectObj.converseCalculateBills(selected.parent);
  1809. }
  1810. });
  1811. $('#insertRation').click(function () {
  1812. // projectObj.project.Ration.addNewRation(null,rationType.ration);
  1813. // 连续点工具栏的插入定额按钮,显示树结构画线有问题。
  1814. projectObj.project.Ration.addNewRationFast(rationType.ration,projectObj.selectColAndFocus);
  1815. });
  1816. $('#upMove').click(function () {
  1817. var controller = projectObj.mainController, project = projectObj.project;
  1818. var selected = controller.tree.selected, pre = selected.preSibling, preSerialNo;
  1819. if (selected.sourceType === project.Bills.getSourceType()) {
  1820. project.Bills.upMoveBills(selected.source);
  1821. controller.upMove();
  1822. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1823. project.Ration.changePos(selected.source, selected.preSibling.source);
  1824. controller.upMove();
  1825. };
  1826. });
  1827. $('#downMove').click(function () {
  1828. var controller = projectObj.mainController, project = projectObj.project;
  1829. var selected = controller.tree.selected, next, nextSerialNo;
  1830. if (selected) {
  1831. if (selected.sourceType === project.Bills.getSourceType()) {
  1832. project.Bills.downMoveBills(selected.source);
  1833. controller.downMove();
  1834. } else if (selected.sourceType === project.Ration.getSourceType()) {
  1835. project.Ration.changePos(selected.source, selected.nextSibling.source);
  1836. controller.downMove();
  1837. };
  1838. }
  1839. });
  1840. $("a[name='lockBills']").click(function () {//点击锁定/解锁清单
  1841. let lockBills = projectInfoObj.projectInfo.property.lockBills;
  1842. lockBills = !lockBills;
  1843. projectObj.project.updateLockBills(lockBills,function () {
  1844. var controller = projectObj.mainController, project = projectObj.project;
  1845. var selected = controller.tree.selected;
  1846. let nodes = _.filter(project.mainTree.items,{'sourceType':ModuleNames.bills});
  1847. controller.refreshTreeNode(nodes);
  1848. projectObj.mainController.setTreeSelected(selected);//触发树节点选中事件
  1849. projectObj.loadLockBillsButton();
  1850. if(!projectReadOnly){
  1851. pageCCOprObj.refreshRuleTools(lockBills);
  1852. }
  1853. //$("[data-toggle='tooltip']").tooltip('hide'); bs 与 jqueryUI冲突
  1854. });
  1855. });
  1856. $('#ZLFB_btn').click(function () {
  1857. zlfb_object.getSectionInfo();
  1858. });
  1859. //显示至..
  1860. let displayLevel = function(nodes, depth, type){
  1861. let refreshNodes = [];
  1862. function getExpandedController(){
  1863. if(type === 'DXFY' || type === 'FB'){
  1864. if(type === 'FB'){
  1865. projectObj.project.mainTree.items[0].setExpanded(true);
  1866. refreshNodes.push(projectObj.project.mainTree.items[0]);
  1867. }
  1868. return function expandedControl(nodes, depth){
  1869. let bType = type === 'FB' ? billType.FB : billType.DXFY;
  1870. for(let node of nodes){
  1871. let nodeDepth = node.depth();
  1872. if(nodeDepth <= depth){
  1873. let expanded = nodeDepth === depth && !node.children[0] || nodeDepth < depth && node.children[0] && node.children[0].data.type === bType ? true : false;
  1874. node.setExpanded(expanded);
  1875. refreshNodes.push(node);
  1876. if(nodeDepth < depth){
  1877. expandedControl(node.children, depth);
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. else if(type === 'FX' || type === 'ZM' || type === 'ZD'){
  1884. return function expandedControl(nodes){
  1885. for(let node of nodes){
  1886. if(type !== 'FX' || node.sourceType === projectObj.project.Bills.getSourceType()){
  1887. let expanded = true;
  1888. if(type === 'FX'){
  1889. expanded = !node.children[0] || node.children[0] && node.children[0].sourceType === projectObj.project.Bills.getSourceType() ? true : false;
  1890. }
  1891. else if(type === 'ZM'){
  1892. expanded = !node.children[0] || node.children[0] && node.children[0].sourceType !== projectObj.project.ration_glj.getSourceType() ? true : false;
  1893. }
  1894. node.setExpanded(expanded);
  1895. refreshNodes.push(node);
  1896. expandedControl(node.children);
  1897. }
  1898. }
  1899. }
  1900. }
  1901. }
  1902. getExpandedController()(nodes, depth);
  1903. let sheet = projectObj.mainSpread.getActiveSheet();
  1904. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  1905. TREE_SHEET_HELPER.refreshNodesVisible(refreshNodes, projectObj.mainSpread.getActiveSheet(), true)
  1906. });
  1907. };
  1908. $('#displayDXFY').click(function () {
  1909. displayLevel(projectObj.project.mainTree.items, 0, 'DXFY')
  1910. });
  1911. //显示至一级分部
  1912. $('#displayFB1').click(function () {
  1913. displayLevel(projectObj.project.mainTree.items[0].children, 1, 'FB');
  1914. });
  1915. //二级分部
  1916. $('#displayFB2').click(function () {
  1917. displayLevel(projectObj.project.mainTree.items[0].children, 2, 'FB');
  1918. });
  1919. //三级分部
  1920. $('#displayFB3').click(function () {
  1921. displayLevel(projectObj.project.mainTree.items[0].children, 3, 'FB');
  1922. });
  1923. //四级分部
  1924. $('#displayFB4').click(function () {
  1925. displayLevel(projectObj.project.mainTree.items[0].children, 4, 'FB');
  1926. });
  1927. //分项
  1928. $('#displayFX').click(function () {
  1929. displayLevel(projectObj.project.mainTree.items, null, 'FX');
  1930. });
  1931. //子目
  1932. $('#displayZM').click(function () {
  1933. displayLevel(projectObj.project.mainTree.items, null, 'ZM');
  1934. });
  1935. //最底层
  1936. $('#displayZD').click(function () {
  1937. displayLevel(projectObj.project.mainTree.roots, null, 'ZD');
  1938. });
  1939. $('#poj-set').on('show.bs.modal', function () {
  1940. let setCalcFlag = function (obj, val, curFlag) {
  1941. obj.val(val);
  1942. if (val === curFlag) {
  1943. obj.prop('checked', true);
  1944. } else {
  1945. obj.prop('checked', false);
  1946. }
  1947. }
  1948. if (projectObj.project) {
  1949. let ft = projectObj.project.property.billsCalcMode ? projectObj.project.property.billsCalcMode : leafBillGetFeeType.rationContent;
  1950. let zg = projectObj.project.property.zanguCalcMode ? projectObj.project.property.zanguCalcMode : zanguCalcType.common;
  1951. setCalcFlag($('#rationContent'), leafBillGetFeeType.rationContent, ft);
  1952. setCalcFlag($('#rationPriceConverse'), leafBillGetFeeType.rationPriceConverse, ft);
  1953. setCalcFlag($('#rationPrice'), leafBillGetFeeType.rationPrice, ft);
  1954. setCalcFlag($('#billsPrice'), leafBillGetFeeType.billsPrice, ft);
  1955. setCalcFlag($('#zangu_common'), zanguCalcType.common, zg);
  1956. setCalcFlag($('#zangu_gatherMaterial'), zanguCalcType.gatherMaterial, zg);
  1957. let showAdjustPrice = projectObj.project.projSetting.glj_col?projectObj.project.projSetting.glj_col.showAdjustPrice:false;
  1958. showAdjustPrice === true ? $("#tab_poj-settings-6").show():$("#tab_poj-settings-6").hide();
  1959. projDisplayView.init();
  1960. calcOptions.init();
  1961. }
  1962. });
  1963. //恢复默认列设置
  1964. $('#recColSetting').click(function () {
  1965. let libID = projectObj.project.property.colLibID ? projectObj.project.property.colLibID : null;
  1966. if(!libID){
  1967. alert('项目没有绑定标准列设置');
  1968. return;
  1969. }
  1970. $(this).addClass('disabled');
  1971. CommonAjax.post('/project/getDefaultColSetting', {libID: libID}, function (rstData) {
  1972. if(!rstData || rstData.length === 0){
  1973. alert('标准列设置没有数据');
  1974. $('#recColSetting').removeClass('disabled');
  1975. return;
  1976. }
  1977. let sheet = colSettingObj.settingSpread.getActiveSheet();
  1978. SheetDataHelper.massOperationSheet(sheet, function () {
  1979. for(let row = 0; row < sheet.getRowCount(); row++){
  1980. sheet.setValue(row, 0, rstData.main_tree_col.cols[row].visible);
  1981. }
  1982. });
  1983. $('#recColSetting').removeClass('disabled');
  1984. }, function () {
  1985. $('#recColSetting').removeClass('disabled');
  1986. });
  1987. });
  1988. $('#property_ok').click(function () {
  1989. let project = projectObj.project,
  1990. projectID = project.ID(),
  1991. properties = {},
  1992. options = {},
  1993. labourCoes = {},
  1994. rations = [],
  1995. bills = [],
  1996. mixDatas = {
  1997. projectID: projectID,
  1998. updateType: 'update',
  1999. properties: properties,
  2000. options: options,
  2001. labourCoes: labourCoes,
  2002. rations: rations,
  2003. bills: bills
  2004. },
  2005. reCalcBills = false,
  2006. reCalcRations = false;
  2007. let b = parseInt($("input[name='calcFlag']:checked").val());
  2008. if (b !== project.property.billsCalcMode) {
  2009. properties['property.billsCalcMode'] = b;
  2010. project.property.billsCalcMode = b;
  2011. reCalcBills = true;
  2012. };
  2013. let zg = parseInt($("input[name='zangu']:checked").val());
  2014. if (zg !== project.property.zanguCalcMode) {
  2015. properties['property.zanguCalcMode'] = zg;
  2016. project.property.zanguCalcMode = zg;
  2017. reCalcRations = true;
  2018. };
  2019. //基本信息
  2020. if(basicInfoView.toUpdate(basicInfoView.orgDatas, basicInfoView.datas)){
  2021. let saveData = basicInfoView.toSaveDatas(basicInfoView.datas);
  2022. projectObj.project.property.basicInformation = saveData;
  2023. properties['property.basicInformation'] = saveData;
  2024. }
  2025. //工程特征
  2026. if(projFeatureView.toUpdate(projFeatureView.orgDatas, projFeatureView.datas)){
  2027. let saveData = projFeatureView.toSaveDatas(projFeatureView.datas);
  2028. projectObj.project.property.projectFeature = saveData;
  2029. properties['property.projectFeature'] = saveData;
  2030. }
  2031. //清单工程量精度
  2032. let newBillsDecimalDatas = billsDecimalView.toBillsDecimalDatas(billsDecimalView.cache);
  2033. if(billsDecimalView.toUpdate(billsQuanDecimal.datas, newBillsDecimalDatas)){
  2034. billsQuanDecimal.datas = newBillsDecimalDatas;
  2035. reCalcBills = true;
  2036. properties['property.billsQuantityDecimal'] = newBillsDecimalDatas;
  2037. }
  2038. //小数位数
  2039. let updateDecimal = m_getDecimalData($('input', '#poj-settings-decimal'));
  2040. if(toUpdateDecimal(decimalObj, updateDecimal)) {
  2041. let frChanged = decimalObj.feeRate != updateDecimal.feeRate;
  2042. setDecimal(decimalObj, updateDecimal);
  2043. if (frChanged) {
  2044. project.calcProgram.compileAllTemps()
  2045. }
  2046. reCalcRations = true;
  2047. reCalcBills = true;
  2048. properties['property.decimal'] = updateDecimal;
  2049. }
  2050. // 呈现选项
  2051. projDisplayView.updateChecking(properties);
  2052. //列设置(独立逻辑,只是通过项目属性确定按钮触发)
  2053. if(colSettingObj.dataChanged()){
  2054. colSettingObj.updateColSetting();
  2055. }
  2056. //系统选项
  2057. if(optionsOprObj.needToSaveGeneralOpts()){
  2058. let v1 = optionsOprObj.rationQuanACToBillsQuan.prop('checked'),
  2059. v2 = optionsOprObj.rationQuanACToRationUnit.prop('checked');
  2060. options.updateData = {
  2061. rationQuanACToBillsQuan: v1,
  2062. rationQuanACToRationUnit: v2
  2063. };
  2064. }
  2065. if(calcOptions.updateChecking(properties)){
  2066. reCalcRations = true;
  2067. }
  2068. // 人工系数
  2069. if (labourCoeView.needSave()){
  2070. let libID = $("#std_labour_coe_files").children("option:selected").val();
  2071. let libName = $("#std_labour_coe_files").children("option:selected").text();
  2072. labourCoes.updateData = {libID: libID, libName: libName, newItemArr: labourCoeView.needUpdateDatas};
  2073. project.labourCoe.refreshData(labourCoes.updateData); // 全编译所用到的人工系数来自project.labourCoe,所以必须先刷新project.labourCoe
  2074. project.calcProgram.compileAllTemps();
  2075. reCalcRations = true;
  2076. reCalcBills = true;
  2077. };
  2078. // 重新计算树节点
  2079. let changedNodes = [];
  2080. if (reCalcRations) // 定额动,全部计算。算完先不存储,和后面的数据一起提交,一次通讯。
  2081. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catAll)
  2082. else if (reCalcBills) // 清单动,可以只计算清单。
  2083. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catBills);
  2084. if (changedNodes.length > 0) {
  2085. for (let node of changedNodes){
  2086. let data = calcTools.cutNodeForSave(node);
  2087. if (node.sourceType == 'ration') rations.push(data)
  2088. else if (node.sourceType == 'bills') bills.push(data);
  2089. };
  2090. };
  2091. // for test.
  2092. /* console.log(mixDatas);
  2093. return; */
  2094. function hasMixData() {
  2095. return Object.keys(mixDatas.properties).length > 0 || mixDatas.options.updateData ||
  2096. mixDatas.labourCoes.updateData || mixDatas.rations.length > 0 || mixDatas.bills.length > 0;
  2097. }
  2098. function needToReload(mixDatas){
  2099. if(Object.keys(mixDatas.labourCoes).length > 0){
  2100. return true;
  2101. }
  2102. if(Object.keys(mixDatas.properties).length > 0){
  2103. if(mixDatas.properties.hasOwnProperty('property.billsCalcMode') ||
  2104. mixDatas.properties.hasOwnProperty('property.zanguCalcMode') ||
  2105. mixDatas.properties.hasOwnProperty('property.calcOptions')||
  2106. mixDatas.properties.hasOwnProperty('property.billsQuantityDecimal')||
  2107. mixDatas.properties.hasOwnProperty('property.decimal')||
  2108. mixDatas.properties.hasOwnProperty('property.displaySetting')){
  2109. return true;
  2110. }
  2111. }
  2112. return false;
  2113. }
  2114. if(hasMixData()){
  2115. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  2116. //需要重载页面
  2117. if(needToReload(mixDatas)){
  2118. window.location.href = '/main?project=' + projectID;
  2119. }
  2120. else{
  2121. if(mixDatas.properties.hasOwnProperty('property.basicInformation')){
  2122. basicInfoView.orgDatas = basicInfoView.toViewDatas(mixDatas.properties['property.basicInformation']);
  2123. }
  2124. if(mixDatas.properties.hasOwnProperty('property.projectFeature')){
  2125. projFeatureView.orgDatas = projFeatureView.toViewDatas(mixDatas.properties['property.projectFeature']);
  2126. }
  2127. if(mixDatas.options && mixDatas.options.updateData){
  2128. let v1 = mixDatas.options.updateData['rationQuanACToBillsQuan'],
  2129. v2 = mixDatas.options.updateData['rationQuanACToRationUnit'];
  2130. optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToBillsQuan', value: v1});
  2131. optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: v2});
  2132. }
  2133. }
  2134. });
  2135. }
  2136. });
  2137. function testShow() {
  2138. var controller = projectObj.mainController, project = projectObj.project;
  2139. var selected = controller.tree.selected, parent = selected.parent;
  2140. var showinfo = "<label>确认要删除当前选中行吗?</label>";
  2141. var showN = false;
  2142. var cancelText = "否";
  2143. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length>0){//选中的是分部,并且有子项
  2144. if(isSingleSelect()||selectionChecking()){
  2145. showinfo = "<label>是否删除其下的子项?</label><br><label>【是】则删除分部行及其下的所有子项,</label><br><label>【否】则仅删除当前分部行,子项保留,</label><br><label>【取消】则取消删除</label>";
  2146. showN = true;
  2147. cancelText = "取消";
  2148. }
  2149. }
  2150. $('#delete_showinfo').html(showinfo);
  2151. showN==true? $('#deleteN').show():$('#deleteN').hide();
  2152. $('#deleteCancel').text(cancelText);
  2153. function selectionChecking() {
  2154. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  2155. let mainTreeMap = {};
  2156. for(let i =0;i<selection.rowCount;i++){
  2157. let tem_node = controller.tree.items[selection.row+i];
  2158. if(i==0){//第一个直接添加;
  2159. mainTreeMap[tem_node.getID()] = tem_node;
  2160. }else {
  2161. project.Bills.setNodeToMap(tem_node,mainTreeMap);
  2162. }
  2163. }
  2164. let nodes = changeMapToArray(mainTreeMap);
  2165. if(nodes.length==1){
  2166. return true
  2167. }
  2168. return false;
  2169. }
  2170. }
  2171. $('#delete_row').on('show.bs.modal', function (e) {//这里用show,在shown之前调用,页面不会出现按钮闪现的情况
  2172. var controller = projectObj.mainController, project = projectObj.project;
  2173. var selected = controller.tree.selected, parent = selected.parent;
  2174. var showinfo = "<label>确认要删除当前选中行吗?</label>";
  2175. var showN = false;
  2176. var cancelText = "否";
  2177. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length>0){//选中的是分部,并且有子项
  2178. if(isSingleSelect()||selectionChecking()){
  2179. showinfo = "<label>是否删除其下的子项?</label><br><label>【是】则删除分部行及其下的所有子项,</label><br><label>【否】则仅删除当前分部行,子项保留,</label><br><label>【取消】则取消删除</label>";
  2180. showN = true;
  2181. cancelText = "取消";
  2182. }
  2183. }
  2184. $('#delete_showinfo').html(showinfo);
  2185. showN==true? $('#deleteN').show():$('#deleteN').hide();
  2186. $('#deleteCancel').text(cancelText);
  2187. function selectionChecking() {
  2188. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  2189. let mainTreeMap = {}, nodes = [];
  2190. for(let i =0;i<selection.rowCount;i++){
  2191. let tem_node = controller.tree.items[selection.row+i];
  2192. if(i==0){//第一个直接添加;
  2193. mainTreeMap[tem_node.getID()] = tem_node;
  2194. }else {
  2195. project.Bills.setNodeToMapAndArray(tem_node,mainTreeMap,nodes);
  2196. }
  2197. }
  2198. if(nodes.length==1){
  2199. return true
  2200. }
  2201. return false;
  2202. }
  2203. });
  2204. function changeMapToArray(map) {
  2205. let newArray = [];
  2206. for(let key in map){
  2207. newArray.push(map[key]);
  2208. }
  2209. return newArray;
  2210. }
  2211. $('#deleteY').click(function () { //正常删除,级联删除子项
  2212. let project = projectObj.project;
  2213. project.Bills.deleteSelectedNodes();
  2214. });
  2215. $('#deleteN').click(function () {//不删除子项
  2216. let controller = projectObj.mainController, project = projectObj.project;
  2217. let selected = controller.tree.selected, parent = selected.parent;
  2218. if(selected){
  2219. let preNode = selected.preSibling;
  2220. let nextNode = selected.nextSibling;
  2221. if(preNode){//有前兄弟
  2222. if(preNode.children.length>0&&preNode.children[0].data.type != selected.children[0].data.type){//并且前兄弟子项和焦点行子项类别不同。
  2223. alert("删除分部会导致分部和分项同级,不允许该操作!");
  2224. return;
  2225. }
  2226. }else if(nextNode){
  2227. if(nextNode.data.type != selected.children[0].data.type){
  2228. alert("删除分部会导致分部和分项同级,不允许该操作! ");
  2229. return;
  2230. }
  2231. }
  2232. project.Bills.singleDeleteBills(selected,controller);
  2233. }
  2234. });
  2235. function isSingleSelect() {//是否选中造价书中的单行
  2236. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  2237. if (selections[0].rowCount == 1) {
  2238. return true;
  2239. }
  2240. return false;
  2241. }
  2242. function ifCanDelete() {
  2243. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  2244. let tree = projectObj.project.mainTree;
  2245. let selected = projectObj.project.mainTree.selected;
  2246. if(selections[0].rowCount==1){//选中单行
  2247. return canDelete(selected);
  2248. }else {
  2249. return canDelete_m(selections[0]);
  2250. }
  2251. function canDelete(node,m_selection) {
  2252. if (node) {
  2253. if (node.sourceType === projectObj.project.Bills.getSourceType()) {
  2254. if(node.data.type == billType.DXFY&&node.data.isAdd!=1){
  2255. return false;
  2256. }
  2257. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  2258. return false;
  2259. }
  2260. if(projectObj.project.Bills.hasFlags(node)){
  2261. return false;
  2262. }
  2263. }
  2264. if(m_selection!=true&&node.sourceType === projectObj.project.ration_glj.getSourceType()){//多选的时候不做这一项判断
  2265. return false;
  2266. }
  2267. return true;
  2268. } else {
  2269. return false;
  2270. }
  2271. };
  2272. function canDelete_m(selection) {
  2273. for(let i =0;i<selection.rowCount;i++){
  2274. if(tree.items[selection.row+i]==undefined||tree.items[selection.row+i]==null){
  2275. return false;
  2276. }
  2277. if(i==0&&tree.items[selection.row].sourceType === projectObj.project.ration_glj.getSourceType()){
  2278. return false
  2279. }
  2280. if(canDelete(tree.items[selection.row+i],true)==false){
  2281. return false
  2282. }
  2283. }
  2284. return true
  2285. };
  2286. }
  2287. function canInsertRationNode(selected) {//判断是否能插入定额、量价、定额类型工料机, false 不能,true能
  2288. if(!selected)
  2289. return false;
  2290. let project = projectObj.project;
  2291. if(selected.sourceType == ModuleNames.bills && selected.data.type == billType.DXFY){
  2292. return false
  2293. }else if(!(project.Bills.isMeasure(selected)||project.Bills.isFBFX(selected))){
  2294. return false
  2295. }else if(selected.sourceType == ModuleNames.bills && selected.source.children.length > 0){
  2296. return false
  2297. }
  2298. else {
  2299. return true
  2300. }
  2301. }
  2302. //导入类型(09表、广联达)
  2303. const uploadType = {lj: 'lj', gld: 'gld'};
  2304. let fileType = uploadType.lj;
  2305. $('#uploadLj').click(function () {
  2306. fileType = uploadType.lj;
  2307. });
  2308. $('#uploadGld').click(function () {
  2309. fileType = uploadType.gld;
  2310. });
  2311. let importJson = null;
  2312. //选择导入的excel文件
  2313. $('#customFile').change(function () {
  2314. let file = $(this)[0];
  2315. let excelFile = file.files[0];
  2316. $('#uploadAlert').hide();
  2317. if(excelFile) {
  2318. let xlsReg = /xls$/g;
  2319. if(excelFile.name && xlsReg.test(excelFile.name)){
  2320. showUploadAlert(false, '请选择xlsx文件');
  2321. $(this).val('');
  2322. return;
  2323. }
  2324. $('.custom-file-label').text(`${file.files[0].name}`);
  2325. $('#uploadAlert').hide();
  2326. $.bootstrapLoading.start();
  2327. $('#loadingPage').css('z-index', '2000');
  2328. //前端解析excel数据
  2329. if(importJson){
  2330. importJson = null;
  2331. }
  2332. let excelIo = new GC.Spread.Excel.IO();
  2333. let sDate = +new Date();
  2334. excelIo.open(excelFile, function (json) {
  2335. importJson = json;
  2336. console.log(json);
  2337. //读取各个表及表名
  2338. importBills.setImportSheetsInfo(importJson.sheets);
  2339. console.log(`解析Excel文件时间:${+new Date() - sDate}`);
  2340. $.bootstrapLoading.end();
  2341. }, function (e) {
  2342. $.bootstrapLoading.end();
  2343. alert(e.errorMessage);
  2344. });
  2345. }
  2346. });
  2347. //线上nginx请求体最大设置为100m
  2348. //从excel导入清单
  2349. $('#importConfirm').click(function () {
  2350. let me = this;
  2351. $(me).addClass('disabled');
  2352. try{
  2353. $.bootstrapLoading.start();
  2354. $('#loadingPage').css('z-index', '2000');
  2355. let formData = new FormData();
  2356. let file = $('#customFile')[0];
  2357. if(file.files.length <= 0){
  2358. throw '未选择文件';
  2359. }
  2360. let projectID = scUrlUtil.GetQueryString('project');
  2361. if(!projectID || projectID <= 0){
  2362. throw '项目数据出错';
  2363. }
  2364. let sDate = +new Date();
  2365. formData.append('projectID', projectID);
  2366. //要去匹配的清单库(第一个)
  2367. let matchBillLibId = projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0 ? projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id : null;
  2368. formData.append('billsLibId', matchBillLibId);
  2369. //选择的表及导入位置
  2370. let importSheetsInfo = importBills.getImportSheetsInfo();
  2371. if(importSheetsInfo.length === 0){
  2372. throw '请选择要导入的表';
  2373. }
  2374. let importSheets = importBills.getImportSheets(importJson.sheets, importSheetsInfo, fileType);
  2375. console.log(`importSheets`);
  2376. console.log(importSheets);
  2377. let invalidSheetsInfo = importSheets.invalidSheets.join('、');
  2378. //获取同类表的有效数据
  2379. let importBillsData = importBills.getImportData(importSheets.validSheets, projectID);
  2380. if(!importBills.excelHasValidBills(importBillsData)){
  2381. throw 'excel无有效数据'
  2382. }
  2383. let compressData = LZString.compressToUTF16(JSON.stringify(importBillsData));
  2384. formData.append('compressData', compressData);
  2385. let eDate = +new Date();
  2386. console.log(`解析excel数据时间:${eDate - sDate}`);
  2387. $.ajax({
  2388. url: '/bills/import',
  2389. type: 'POST',
  2390. data: formData,
  2391. cache: false,
  2392. contentType: false,
  2393. processData: false,
  2394. success: function(response){
  2395. if (response.err === 0) {
  2396. if(invalidSheetsInfo !== ''){
  2397. alert(`${invalidSheetsInfo},导入失败。`);
  2398. }
  2399. // 成功则关闭窗体
  2400. $('#import').modal("hide");
  2401. //更新前端
  2402. doAfterImport(response.data);
  2403. if($.bootstrapLoading.isLoading()){
  2404. $.bootstrapLoading.end();
  2405. }
  2406. } else {
  2407. const message = response.msg !== undefined ? response.msg : '上传失败!';
  2408. $.bootstrapLoading.end();
  2409. alert(message);
  2410. }
  2411. $(me).removeClass('disabled');
  2412. },
  2413. error: function(jqXHR){
  2414. alert(`与服务器通信发生错误${jqXHR.status} ${jqXHR.statusText}`);
  2415. $.bootstrapLoading.end();
  2416. $(me).removeClass('disabled');
  2417. }
  2418. });
  2419. }
  2420. catch (err){
  2421. showUploadAlert(false, err);
  2422. $(me).removeClass('disabled');
  2423. if($.bootstrapLoading.isLoading()){
  2424. $.bootstrapLoading.end();
  2425. }
  2426. }
  2427. });
  2428. function showUploadAlert(success, msg){
  2429. if(!success){
  2430. $('#uploadAlert').removeClass('alert-success');
  2431. $('#uploadAlert').addClass('alert-danger');
  2432. }
  2433. else{
  2434. $('#uploadAlert').removeClass('alert-danger');
  2435. $('#uploadAlert').addClass('alert-success');
  2436. }
  2437. $('#uploadAlert').text(msg);
  2438. $('#uploadAlert').show();
  2439. }
  2440. //导入清单到一个固定行位置后,更新数据
  2441. function doAfterImportPosition(positionData){
  2442. let nodes = projectObj.project.mainTree.nodes;
  2443. let bills_datas = projectObj.project.Bills.datas;
  2444. let ration_datas = projectObj.project.Ration.datas;
  2445. let quantity_detail_datas = projectObj.project.quantity_detail.datas;
  2446. let ration_glj_datas = projectObj.project.ration_glj.datas;
  2447. let ration_coe_datas = projectObj.project.ration_coe.datas;
  2448. let ration_install_datas = projectObj.project.ration_installation.datas;
  2449. let delNodes = [];
  2450. for(let billID of positionData.remove.bill){
  2451. if(nodes['id_' + billID]){
  2452. delNodes.push(nodes['id_' + billID]);
  2453. }
  2454. //清除清单数据
  2455. _.remove(bills_datas, {ID: billID});
  2456. //清除清单工程量明细数据
  2457. _.remove(quantity_detail_datas, {billID: billID});
  2458. }
  2459. for(let rationID of positionData.remove.ration){
  2460. //清除定额数据
  2461. _.remove(ration_datas, {ID: rationID});
  2462. //清除定额下的相关数据
  2463. _.remove(ration_glj_datas, {rationID: rationID});
  2464. _.remove(ration_coe_datas, {rationID: rationID});
  2465. _.remove(ration_install_datas, {rationID: rationID});
  2466. _.remove(quantity_detail_datas, {rationID: rationID});
  2467. }
  2468. //删除节点
  2469. if(delNodes.length > 0){
  2470. //通过固定清单获得删除节点的起始行索引
  2471. let beginRow = null;
  2472. if(positionData.fixedBill){
  2473. let fixedNode = nodes['id_' + positionData.fixedBill.ID];
  2474. if(fixedNode){
  2475. beginRow = projectObj.project.mainTree.items.indexOf(fixedNode) + 1;
  2476. }
  2477. }
  2478. //删除主树节点
  2479. projectObj.mainController.m_delete(delNodes, beginRow);
  2480. //删除清单树节点
  2481. let delIdNodes = [];
  2482. for(let delNode of delNodes){
  2483. delIdNodes.push(delNode.source);
  2484. }
  2485. projectObj.project.Bills.tree.m_delete(delIdNodes);
  2486. }
  2487. if(positionData.insert.bill.length > 0){
  2488. //设置flagsIndex
  2489. for(let insertBill of positionData.insert.bill){
  2490. insertBill.flagsIndex = {};
  2491. if (insertBill.flags) {
  2492. insertBill.flags.forEach(function (flag) {
  2493. insertBill.flagsIndex[flag.fieldName] = flag;
  2494. });
  2495. }
  2496. }
  2497. //插入清单节点
  2498. projectObj.project.Bills.tree.insertByDatas(positionData.insert.bill);
  2499. //插入主树节点
  2500. let newNodes = projectObj.project.mainTree.insertByDatas(positionData.insert.bill);
  2501. for(let node of newNodes){
  2502. node.source = projectObj.project.Bills.tree.nodes['id_' + node.getID()];
  2503. node.data = node.source.data;
  2504. node.sourceType = projectObj.project.Bills.getSourceType();
  2505. }
  2506. ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes);
  2507. }
  2508. }
  2509. //导入后更新操作
  2510. function doAfterImport(resData){
  2511. if(resData && resData.length > 0){
  2512. for(let positionData of resData){
  2513. doAfterImportPosition(positionData);
  2514. }
  2515. //如果清单未锁定,导入后锁定清单
  2516. if(!projectInfoObj.projectInfo.property.lockBills){
  2517. $("a[name='lockBills']").click();
  2518. }
  2519. $.bootstrapLoading.end();
  2520. //重算
  2521. projectObj.project.calcProgram.calcAllNodesAndSave(calcAllType.catAll, function () {
  2522. projectObj.project.projectGLJ.loadData(function () {
  2523. $.bootstrapLoading.end();
  2524. });
  2525. });
  2526. }
  2527. }
  2528. //下载导入清单示例文件
  2529. $('#uploadExample').click(function () {
  2530. window.location.href = '/bills/downloadExamp';
  2531. });
  2532. $(function () {
  2533. //清空导入清单选择文件
  2534. $('#import').on('show.bs.modal', function(){
  2535. $('#customFile').val('');
  2536. $('#uploadAlert').hide();
  2537. $('.custom-file-label').text(`请选择上传文件`);
  2538. });
  2539. $('#import').on('hidden.bs.modal', function () {
  2540. //恢复选择表高度
  2541. $('#uploadSheets').height('');
  2542. $('#uploadSheets').hide();
  2543. $('#uploadSheetsHead').hide();
  2544. });
  2545. /* $("#billsSpread").mouseover(function(){
  2546. spreadAutoFocus(projectObj.mainSpread,subSpread);
  2547. });
  2548. $("#subSpread").mouseover(function(){
  2549. spreadAutoFocus(subSpread,projectObj.mainSpread);
  2550. });
  2551. */
  2552. $("#paste_confirm").click(function (){
  2553. let selected = projectObj.project.mainTree.selected;
  2554. let blockData = BlockController.getBlockData();
  2555. let position = $("input[name='pastePositionRadio']:checked").val();
  2556. BlockController.confirmPaste(blockData,selected,position);
  2557. $("#pastePosition").modal("hide");
  2558. });
  2559. function spreadAutoFocus(spread,relateSpread) {
  2560. if(relateSpread&&relateSpread.getActiveSheet().isEditing()){//关联的spread不在编辑状态的情况下,才自动获得焦点;
  2561. return;
  2562. }else {
  2563. spread?spread.focus():'';
  2564. }
  2565. }
  2566. //项目为只读
  2567. if(projectReadOnly){
  2568. disableTools();
  2569. }
  2570. });
  2571. //项目只读,处理不可操作的工具栏
  2572. function disableTools(){
  2573. //造价书按钮
  2574. $('#insertRation').remove();
  2575. $('#delete').remove();
  2576. $('#upLevel').remove();
  2577. $('#downLevel').remove();
  2578. $('#upMove').remove();
  2579. $('#downMove').remove();
  2580. $('#ZLFB_btn').remove();
  2581. $('#switchTznr').remove();
  2582. $('#importSpan').remove();
  2583. $('a[name="lockBills"]').remove();
  2584. //关于计算
  2585. $('#poj-settings-4').find('input').prop('disabled', 'disabled');
  2586. //小数位数
  2587. $('#poj-settings-decimal').find('input').prop('disabled', 'disabled');
  2588. //人工单价调整
  2589. $('#std_labour_coe_files').prop('disabled', 'disabled');
  2590. //呈现选项
  2591. $('#display-setting').find('input').prop('disabled', 'disabled');
  2592. $('#recColSetting').remove();
  2593. //项目属性确定
  2594. $('#property_ok').addClass('disabled');
  2595. //特征及内容
  2596. $('#add-rule').find('select').prop('disabled', 'disabled');
  2597. $('#use-to-current').addClass('disabled');
  2598. $('#use-to-all').addClass('disabled');
  2599. $('.bottom-tools').remove();
  2600. //导入
  2601. $('#importConfirm').addClass('disabled');
  2602. //选项
  2603. $('#generalOpts1').prop('disabled', 'disabled');
  2604. $('#generalOpts2').prop('disabled', 'disabled');
  2605. //补充库编辑器
  2606. $('#compleRationLib').addClass('disabled');
  2607. $('#compleGljLib').addClass('disabled')
  2608. //库
  2609. $('#stdBillsGuidanceTab').addClass('disabled');
  2610. $('#stdBillsTab').addClass('disabled');
  2611. $('#stdRationTab').addClass('disabled');
  2612. //人材机汇总,选择其他、另存使用
  2613. $('a[data-target="#change-unitFile"]').remove();
  2614. $('a[data-target="#unitFile-save-as"]').remove();
  2615. //费率,选择其他、另存使用、重选标准、统一设置相同参数
  2616. $('a[data-target="#change-lv"]').remove();
  2617. $('a[data-target="#copy-lv"]').remove();
  2618. $('#standardSelect').prop('disabled', 'disabled');
  2619. $('#cascadeSet').prop('disabled', 'disabled');
  2620. //计算程序标准
  2621. $('#calcProgramFileSelect').prop('disabled', 'disabled');
  2622. //调价
  2623. $('#calcPriceOption').prop('disabled', 'disabled');
  2624. $('#gljPriceTenderCoe').prop('disabled', 'disabled');
  2625. $('#tenderGLJQuantity').prop('disabled', 'disabled');
  2626. $('#tenderRationQuantity').prop('disabled', 'disabled');
  2627. $('#tenderPrice').prop('disabled', 'disabled');
  2628. $('#cleanTender').prop('disabled', 'disabled');
  2629. }
  2630. //项目只读,表格只读
  2631. function disableSpread(spread){
  2632. spread.unbind(GC.Spread.Sheets.Events.ButtonClicked);
  2633. let sheetCount = spread.getSheetCount();
  2634. for(let i = 0; i < sheetCount; i++){
  2635. let sheet = spread.getSheet(i);
  2636. sheet.unbind(GC.Spread.Sheets.Events.ButtonClicked);
  2637. sheet.unbind(GC.Spread.Sheets.Events.EditStarting);
  2638. sheet.unbind(GC.Spread.Sheets.Events.EditEnded);
  2639. sheet.unbind(GC.Spread.Sheets.Events.RangeChanged);
  2640. sheet.unbind(GC.Spread.Sheets.Events.ClipboardChanging);
  2641. sheet.unbind(GC.Spread.Sheets.Events.ClipboardChanged);
  2642. sheet.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  2643. sheet.unbind(GC.Spread.Sheets.Events.CellClick);
  2644. sheet.unbind(GC.Spread.Sheets.Events.ValueChanged);
  2645. sheet.suspendPaint();
  2646. sheet.suspendEvent();
  2647. sheet.options.isProtected = true;
  2648. let rowCount = sheet.getRowCount();
  2649. let colCount = sheet.getColumnCount();
  2650. for(let row = 0; row < rowCount; row++){
  2651. for(let col = 0; col < colCount; col++){
  2652. sheet.getCell(row, col).locked(true);
  2653. }
  2654. }
  2655. sheet.resumePaint();
  2656. sheet.resumeEvent();
  2657. }
  2658. }
  2659. //根据触发改变计算基数、费率弹出框
  2660. function changeCalcBaseFeeRate(toggle) {
  2661. if(toggle === 'calcBase'){
  2662. $('#calcBaseFeeRate').find('.modal-header').show();
  2663. $('#calcBaseFeeRate').find('.modal-title').text('计算基数选择').show();
  2664. $('#calcBaseFeeRate').find('.modal-body').find('button:first').hide();
  2665. $('#calcBaseFeeRate').find('.modal-body').find('ul:first').hide();
  2666. }
  2667. else if(toggle === 'feeRate'){
  2668. $('#calcBaseFeeRate').find('.modal-header').show();
  2669. $('#calcBaseFeeRate').find('.modal-title').text('费率选择').show();
  2670. $('#calcBaseFeeRate').find('.modal-body').find('button:first').hide();
  2671. $('#calcBaseFeeRate').find('.modal-body').find('ul:first').hide();
  2672. }
  2673. else if(toggle === 'commonTotalFee') {
  2674. $('#calcBaseFeeRate').find('.modal-header').hide();
  2675. $('#calcBaseFeeRate').find('.modal-body').find('button:first').show();
  2676. $('#calcBaseFeeRate').find('.modal-body').find('ul:first').show();
  2677. }
  2678. }
  2679. //综合合价弹出计算基数费率确认
  2680. $('#calcBaseFeeRateConf').click(function () {
  2681. let toggle = $(this).attr('toggle');
  2682. if(!toggle || toggle !== 'commonTotalFee'){
  2683. return
  2684. }
  2685. let needToSave = false;
  2686. let validateFeeRate = feeRateObject.checkSelectedFeeRate();
  2687. let calcBaseValue = calcBaseView.getInputExpr() ? calcBaseView.getInputExpr() : '';
  2688. let selected = projectObj.project.mainTree.selected;
  2689. if(calcBaseValue !== selected.data.calcBase){
  2690. needToSave = true;
  2691. selected.data.userCalcBase = calcBaseValue;
  2692. projectObj.project.calcBase.calculate(selected);
  2693. }
  2694. if(!projectObj.project.calcBase.success){
  2695. return;
  2696. }
  2697. if(validateFeeRate){
  2698. feeRateObject.submitFeeRateFromBill();
  2699. }
  2700. else if(!validateFeeRate && needToSave) {
  2701. projectObj.project.calcProgram.calcAndSave(selected);
  2702. }
  2703. });