project_view.js 130 KB

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