project_view.js 174 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805
  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. selectedChangeNowTime: 0,
  22. selectedChangeDelayTime: 20,
  23. treeSelectedChanged: function (node) {
  24. let me = this;
  25. let project = projectObj.project;
  26. let mainSheet = projectObj.mainController.sheet;
  27. let init = true;
  28. locateToCache(node);
  29. //设置选中行底色和恢复前选中行底色
  30. let refreshNodes = [node];
  31. if(!project.mainTree.preSelected){
  32. refreshNodes.push(project.mainTree.items[0]);
  33. }
  34. else {
  35. refreshNodes.push(project.mainTree.preSelected);
  36. init = !(project.mainTree.preSelected == node)
  37. }
  38. mbzm_obj.nodeChanged = init;
  39. project.mainTree.preSelected = node;
  40. projectObj.setNodesStyle(projectObj.mainController.sheet, refreshNodes);
  41. function delayOpr(callback) {
  42. let nowTime = Date.now();
  43. me.selectedChangeNowTime = nowTime;
  44. setTimeout(function () {
  45. if (nowTime - me.selectedChangeNowTime == 0) {
  46. callback();
  47. }
  48. }, me.selectedChangeDelayTime);
  49. }
  50. delayOpr(function () {
  51. if($('#linkComments').hasClass('active')){
  52. subViewObj.loadComments(node);
  53. }
  54. let nodeID = node ? node.getID() : null;
  55. gljOprObj.mainTreeSelectedChange = gljOprObj.selectedNodeId != nodeID;
  56. if(init) subObj.initNavItem(node);
  57. /*
  58. 2018-11-9 在NavItem里设置了默认显示的item,在里执行了click这个操作所以这两个操作不用重复执行了
  59. gljOprObj.showDataIfRationSelect(node);
  60. if (activeSubSheetIsCalcProgram())
  61. calcProgramObj.refreshCalcProgram(node, 3);*/
  62. //zhong 2017-9-1 特征及内容
  63. if(pageCCOprObj.active){
  64. pageCCOprObj.mainActiveCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];//mainSpread焦点单元格
  65. pageCCOprObj.setCacheAndShow(node);
  66. }
  67. });
  68. },
  69. refreshBaseActn: function (tree) {
  70. let setButtonValid = function (valid, btn) {
  71. if (!projectReadOnly && valid) {
  72. btn.removeClass('disabled');
  73. } else {
  74. btn.addClass('disabled');
  75. }
  76. };
  77. let selected = tree.selected, that = projectObj;
  78. let canUpLevel = function (node) {
  79. if(!node){
  80. return false;
  81. }
  82. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  83. return false;
  84. }
  85. if(node.depth()<=1){//焦点行是树结构的第一/二层节点,灰显。
  86. return false;
  87. }
  88. if(node.sourceType !== that.project.Bills.getSourceType()){//焦点行是定额/量价/工料机,灰显。
  89. return false;
  90. }else {
  91. if(node.data.type == billType.FX || node.data.type == billType.BX){//是分项,或者补项灰显。
  92. return false;
  93. }
  94. if(node.data.type == billType.FB&&node.nextSibling&&node.children.length>0){//焦点行是分部有后兄弟,有子项.
  95. if(node.children[0].data.type==billType.FX || node.children[0].data.type==billType.BX){ //焦点行子项是分项
  96. return false;
  97. }
  98. }
  99. if(node.data.type == billType.BILL &&node.nextSibling){//焦点行是清单有后兄弟
  100. if(node.data.calcBase&&node.data.calcBase!=""){//有基数计算
  101. return false;
  102. }
  103. if(node.children.length>0&&node.children[0].sourceType !== that.project.Bills.getSourceType()){//有子项,并且子项不是清单
  104. return false;
  105. }
  106. }
  107. }
  108. return true;
  109. };
  110. let canDownLevel = function (node) {
  111. if(!node){
  112. return false;
  113. }
  114. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  115. return false;
  116. }
  117. if(node.depth()==0){//焦点行是树结构的第一层节点,灰显。
  118. return false;
  119. }
  120. if(node.sourceType !== that.project.Bills.getSourceType()) {//焦点行是定额/量价/工料机,灰显。
  121. return false;
  122. }else {
  123. if(node.data.type == billType.FX || node.data.type == billType.BX){//是分项,灰显。
  124. return false;
  125. }
  126. if(!node.preSibling){//无前兄弟,灰显
  127. return false;
  128. }else if(node.preSibling.data.calcBase&&node.preSibling.data.calcBase!=""){//前兄弟有基数计算
  129. return false
  130. }
  131. if(node.preSibling.children.length>0){//前兄弟有子项,子项是分项,灰显。
  132. if(node.data.type==billType.FB&&(node.preSibling.children[0].data.type==billType.FX||node.preSibling.children[0].data.type==billType.BX)){//焦点行是分部前兄弟有子项,子项是分项,灰显。
  133. return false;
  134. }
  135. if(node.data.type==billType.BILL&&node.preSibling.children[0].sourceType !== that.project.Bills.getSourceType()){//焦点行是清单,子项不是清单
  136. return false
  137. }
  138. }
  139. }
  140. return true;
  141. };
  142. let canUpMove = function (node) {
  143. if(node&&node.sourceType!= ModuleNames.ration_glj &&node.preSibling){//有前兄弟 并且不是定额工料机
  144. if(node.sourceType==that.project.Bills.getSourceType()){
  145. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  146. return false;
  147. }
  148. if(node.data.type == billType.DXFY&&node.data.isAdd!==1){
  149. return false;
  150. }
  151. }
  152. return true
  153. }
  154. return false
  155. };
  156. let canDownMove = function (node) {
  157. if(node&& node.sourceType!= ModuleNames.ration_glj &&node.nextSibling){//并且不是定额工料机
  158. if(node.sourceType==that.project.Bills.getSourceType()){
  159. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  160. return false;
  161. }
  162. if(node.data.type == billType.DXFY&&node.data.isAdd!==1){
  163. return false;
  164. }
  165. }
  166. return true;
  167. }
  168. return false
  169. };
  170. setButtonValid(projectObj.project.Ration.canAdd(selected), $('#insertRation'));
  171. setButtonValid(ifCanDelete(), $('#delete'));
  172. setButtonValid(canUpLevel(selected), $('#upLevel'));
  173. setButtonValid(canDownLevel(selected), $('#downLevel'));
  174. setButtonValid(canUpMove(selected) , $('#upMove'));
  175. setButtonValid(canDownMove(selected), $('#downMove'));
  176. setButtonValid(!projectObj.project.isBillsLocked(), $('#ZLFB_btn'));
  177. setButtonValid(!projectObj.project.isBillsLocked(), $('#ZLQD_btn'));
  178. },
  179. checkCommonField: function (editingText, colSetting) {
  180. let value;
  181. if (colSetting.data.decimal) {
  182. value = Number(editingText);
  183. if (number_util.isNumber(value)) {
  184. if (colSetting.data.decimal) {
  185. value = value.toDecimal(colSetting.data.decimal);
  186. }
  187. } else {
  188. value = null;
  189. alert('当前输入的数据类型不正确,请重新输入。');
  190. }
  191. } else {
  192. value = editingText;
  193. }
  194. return value;
  195. },
  196. checkFormulaValidField: function (editingText, colSetting) {
  197. let value = Number(editingText);
  198. if(isNaN(value)) return value;
  199. if (!value) {
  200. try {
  201. let exp = new Expression('');
  202. exp.Expression(editingText);
  203. value = Number(exp.Evaluate());
  204. } catch (error) {
  205. value = null;
  206. }
  207. }
  208. if (value!=undefined||value!=null) {
  209. if (colSetting.data.decimal) {
  210. value = value.toDecimal(colSetting.data.decimal);
  211. }
  212. } else if (editingText && editingText !== '') {
  213. value = null;
  214. alert('当前输入的数据类型不正确,请重新输入。');
  215. }
  216. return value;
  217. },
  218. checkSpreadEditingText: function (editingText, colSetting) {
  219. if (colSetting.data.field === 'contain'||colSetting.data.field === 'feesIndex.common.unitFee'|| colSetting.data.field === 'feesIndex.common.totalFee') {//colSetting.data.field === 'quantity'
  220. return this.checkFormulaValidField(editingText, colSetting);
  221. }
  222. else if (colSetting.data.field === 'programID') {
  223. return this.project.calcProgram.compiledTemplateMaps[editingText];
  224. }
  225. else if (colSetting.data.field === 'subType') {
  226. if (typeof(editingText) !== "number")
  227. return volumePriceMaps[editingText]
  228. else
  229. return editingText;
  230. }
  231. else {
  232. return this.checkCommonField(editingText, colSetting);
  233. }
  234. },
  235. getVisibleRows: function (sRow, count) {
  236. let rst = [];
  237. let nodes = projectObj.project.mainTree.items;
  238. for(let i = sRow, len = nodes.length; i < len; i++){
  239. if(count <= 0){
  240. break;
  241. }
  242. if(nodes[i].visible){
  243. rst.push(i);
  244. count--;
  245. }
  246. }
  247. return rst;
  248. },
  249. //根据列标段设置焦点单元格
  250. setActiveCell(field, moveScroll){
  251. projectObj.mainSpread.focus(true);
  252. let mainSheet = projectObj.mainSpread.getActiveSheet();
  253. TREE_SHEET_HELPER.massOperationSheet(mainSheet,function(){
  254. let fieldCol = colSettingObj.getColByField(field);
  255. if(fieldCol){
  256. if(moveScroll){
  257. mainSheet.showColumn(fieldCol, GC.Spread.Sheets.HorizontalPosition.center);
  258. }
  259. mainSheet.setActiveCell(projectObj.project.mainTree.selected.serialNo(), fieldCol);
  260. }
  261. });
  262. },
  263. //获取粘贴更改的单元格(粘贴时,跳过隐藏行)
  264. checkSpreadChangedCells: function (info) {
  265. let rst = {refreshRows: [], changedCells: []};
  266. //获取显示行号
  267. let vRows = projectObj.getVisibleRows(info.row, info.rowCount);
  268. let vCount = vRows.length;
  269. let lastRow = null, count = 0;
  270. for(let cell of info.changedCells){
  271. cell.text = info.sheet.getCell(cell.row, cell.col).text();
  272. if(cell.row !== lastRow){
  273. count++;
  274. lastRow = cell.row;
  275. }
  276. if(count <= vCount){
  277. if(vRows[count - 1] !== cell.row){
  278. rst.refreshRows.push(cell.row);
  279. }
  280. rst.changedCells.push({row: vRows[count - 1], col: cell.col, text: cell.text});
  281. }
  282. else {
  283. rst.refreshRows.push(cell.row);
  284. }
  285. }
  286. rst.refreshRows = Array.from(new Set(rst.refreshRows));
  287. return rst;
  288. },
  289. updateBillsCode: function (node, value) {
  290. let project = projectObj.project,me = this;
  291. let stdMatchCode, formatCode, matchs;
  292. let searchStdBillsAndUpdate = function (stdCode, formatCode) {
  293. let orgCode = node.data.code?node.data.code.substr(0, 9):"";
  294. if (projectObj.project.projectInfo.engineeringInfo.bill_lib.length === 0 || updateCodeCheck(value,stdCode === orgCode)) {
  295. normalUpdate(node,value,stdCode === orgCode);
  296. } else if (projectObj.project.projectInfo.engineeringInfo.bill_lib.length > 0) {
  297. let libId = projectObj.project.projectInfo.engineeringInfo.bill_lib[0].id;
  298. CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
  299. if (data) {
  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);//2018-12-03 这里改成在后端获取
  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. BillsSub.billsSelSub(node.data.code);
  318. } else {
  319. ConfirmModal.stdBillsUnit.check(data, function (std) {
  320. updateBeforeInsert(node, data);
  321. project.Bills.replaceBills(node.source, std, formatCode);
  322. projectObj.mainController.refreshTreeNode([node], false);
  323. BillsSub.billsSelSub(node.data.code);
  324. }, function () {
  325. projectObj.mainController.refreshTreeNode([node], false);
  326. });
  327. }
  328. } else {
  329. updateBeforeInsert(node, data);
  330. project.Bills.replaceBills(node.source, data, formatCode);
  331. projectObj.mainController.refreshTreeNode([node], false);
  332. BillsSub.billsSelSub(node.data.code);
  333. }
  334. } else {
  335. normalUpdate(node,value);
  336. }
  337. });
  338. }
  339. };
  340. //分部分项、措施项目才匹配
  341. let withinValidFixed = false;
  342. let matchFixedFlags = [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE];
  343. let rootNode = getRootFixedNode(node);
  344. if(rootNode && rootNode.data.flagsIndex && rootNode.data.flagsIndex.fixed && matchFixedFlags.includes(rootNode.data.flagsIndex.fixed.flag)){
  345. withinValidFixed = true;
  346. }
  347. if(withinValidFixed && (node.data.type==billType.FX||node.data.type==billType.BX||(node.data.type==billType.BILL&&node.source.children.length==0))){//是分项、补项或者叶子清单的情况下才需要查找替换
  348. if (value&&value.length === 9) {//&& /^[\d]+$/.test(value) 去掉全数字判断 07-31 zhang
  349. stdMatchCode = value;
  350. formatCode = project.Bills.newFormatCode(stdMatchCode);
  351. searchStdBillsAndUpdate(stdMatchCode, formatCode);
  352. return;
  353. } else if (value&&value.length === 12 ) {//&& /^[\d]+$/.test(value) 去掉全数字判断 07-31 zhang
  354. stdMatchCode = value.substr(0, 9);
  355. matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
  356. if (matchs.indexOf(value) === -1) {
  357. searchStdBillsAndUpdate(stdMatchCode, value);
  358. return;
  359. } else {
  360. hintBox.infoBox("系统提示","已存在该编码的清单,将自动修改编码后3位,是否继续?",2,function () {
  361. let newFormatCode = project.Bills.newFormatCode(stdMatchCode);
  362. searchStdBillsAndUpdate(stdMatchCode, newFormatCode);
  363. },function () {
  364. me.mainController.refreshTreeNode([node], false);
  365. },['确定','取消']);
  366. return;
  367. }
  368. }
  369. }
  370. normalUpdate(node,value);
  371. function normalUpdate(billnode,codeValue,no_Need_Check) {//在标准库中没有找到清单时改分项为补项再更新
  372. let toBX = false;
  373. if(no_Need_Check!==true && billnode.data.type == billType.FX){
  374. billnode.data.type = billType.BX;
  375. toBX = true;
  376. }
  377. project.Bills.updateField(billnode.source, 'code', codeValue, toBX);
  378. me.mainController.refreshTreeNode([billnode], false);
  379. }
  380. function updateCodeCheck(value,sameStdCode) {//如果前9位相同,只改前三位,则只更新编号就行了,不用做其它处理
  381. return sameStdCode && value && value.length == 12
  382. }
  383. },
  384. updateRationCode: function (node, value) {
  385. if(!isDef(node.data.code) && (!isDef(value) || value.toString().trim() == '')){
  386. return;
  387. }
  388. if (projectObj.project.projectInfo.engineeringInfo.ration_lib.length === 0) {
  389. alert('当前项目无定额库,请添加定额库。');
  390. this.mainController.refreshTreeNode([node], false);
  391. } else {
  392. let libId = parseInt($('#stdRationLibSelect').val());
  393. CommonAjax.post('/complementaryRation/api/getRationItem', {user_id: userID, rationRepId: libId, code: value}, function (data) {
  394. if (data) {
  395. projectObj.project.Ration.replaceRation(node.source, data);
  396. projectObj.project.ration_glj.addRationGLJ(node.source, data);
  397. } else {
  398. alert('当前库中找不到定额"' + value + '"');
  399. }
  400. projectObj.mainController.refreshTreeNode([node], false);
  401. });
  402. }
  403. },
  404. updateCode: function (node, value) {
  405. let project = projectObj.project;
  406. if (node.sourceType === project.Bills.getSourceType()) {
  407. this.updateBillsCode(node, value); // 新清单不适合实时计算,下面套什么还不能确定,无数量计算也无意义
  408. } else if (node.sourceType === project.Ration.getSourceType()) {
  409. if(value && typeof(value) == 'string'){//小写转换成大写
  410. value = value.toUpperCase();
  411. }
  412. project.Ration.updateRationCodes([{'node':node,value:value}]);
  413. // this.updateRationCode(node, value); // 新套定额适合实时计算
  414. // 这里因异步问题暂时缺少工料机价格。该过程移到:ration_glj.js的refreshAfterSave方法中。
  415. }
  416. },
  417. updateNodeField : function (node,value,filedID,callback) {
  418. if(node.data[filedID] == value){
  419. return;
  420. }
  421. let data = {
  422. type:node.sourceType,
  423. data:{
  424. ID:node.data.ID
  425. }
  426. };
  427. data.data[filedID] = value;
  428. $.bootstrapLoading.start();
  429. projectObj.project.updateNodes([data],function () {
  430. node.data[filedID] = value;
  431. if(callback){
  432. callback();
  433. }
  434. $.bootstrapLoading.end();
  435. })
  436. },
  437. updateCellValue: function (node, value, colSetting,editingText) {
  438. let project = projectObj.project, fieldName = colSetting.data.field;
  439. if(node.sourceType==project.ration_glj.getSourceType()){
  440. project.ration_glj.updateFromMainSpread(value,node,fieldName);
  441. }
  442. else if (fieldName === 'overHeight') {
  443. OVER_HEIGHT.handleValueChanged([{ node, value }]);
  444. return;
  445. }
  446. else if(fieldName === 'remark'){
  447. projectObj.updateNodeField(node,value,'remark');
  448. }
  449. else if(calcTools.isGljRation(node)){
  450. gljOprObj.updateRationTypeGLJ(value,node,fieldName,editingText);
  451. }
  452. else if (value !== calcFees.getFee(node.data, fieldName)||fieldName == 'quantity') {//工程量需要进行转换,所以做特殊处理
  453. if (fieldName === 'code' && value != '' && !calcTools.isVolumePrice(node)) {
  454. projectObj.updateCode(node, value);
  455. }
  456. else if(fieldName ==='feeRate'){
  457. project.FeeRate.updateFeeRateFromBills(value,node,fieldName);
  458. }
  459. else if(fieldName ==='contain'){//编辑含量
  460. project.Ration.updateContain(value,node);
  461. }
  462. else if (fieldName === 'quantity' || fieldName === 'marketUnitFee' || fieldName === 'feesIndex.common.unitFee'||fieldName === 'feesIndex.common.totalFee' || fieldName === 'programID' ||
  463. fieldName === 'subType' || fieldName === 'calcBase' || fieldName === 'isSubcontract'){
  464. if (fieldName === 'quantity') {
  465. quantityEditObj.checkingAndUpdate(editingText,node);
  466. // project.quantity_detail.editMainTreeNodeQuantity(value,node,fieldName,editingText);
  467. return;
  468. } else if (fieldName === 'marketUnitFee' || fieldName === 'feesIndex.common.unitFee'||fieldName === 'feesIndex.common.totalFee') {
  469. if(isNaN(value)){//说明输入的是无效的字符
  470. //value == null && editingText!=null && editingText!=""
  471. alert("当前输入的数据类型不正确,请重新输入。");
  472. projectObj.mainController.refreshTreeNode([node]);
  473. return
  474. }
  475. if (value) {
  476. if(fieldName === 'feesIndex.common.unitFee') {
  477. value = parseFloat(value).toDecimal(decimalObj.decimal("unitPrice", node));
  478. //当前是量价/人材机,综合单价可输入,输入的值读取到市场单价,重算综合单价。
  479. if(node.sourceType == ModuleNames.ration && node.data.type != rationType.ration){
  480. fieldName = 'marketUnitFee';
  481. }
  482. }
  483. if(fieldName === 'feesIndex.common.totalFee'){//修改了综合合价后,反算综合单价,然后再由计算程序算个综合合价出来
  484. let unitfee = 0;
  485. if(node.data.quantity){//如果工程量为0或空,综合合单直接填到综合单价
  486. let t_quantity = scMathUtil.roundForObj(node.data.quantity,getDecimal("quantity",node));
  487. value = scMathUtil.roundForObj(value,getDecimal("unitPrice", node));
  488. unitfee = scMathUtil.roundForObj(value/t_quantity,getDecimal("totalPrice", node));
  489. }else {
  490. unitfee = scMathUtil.roundForObj(value,getDecimal("totalPrice", node));
  491. }
  492. calcTools.setFieldValue(node, 'feesIndex.common.unitFee', unitfee);
  493. }
  494. }
  495. } else if (fieldName === 'calcBase') {
  496. //zhong
  497. if(value === undefined ||value === null || value.toString().trim() === ''){
  498. value = '';
  499. }
  500. if(value === node.data.calcBase){
  501. return;
  502. }
  503. node.data.userCalcBase = value;
  504. project.calcBase.calculate(node);
  505. if(!project.calcBase.success){
  506. let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  507. projectObj.mainController.refreshTreeNode([node]);
  508. return;
  509. } else if (value === '') {//删除清单基数,单价要清空
  510. calcTools.setFieldValue(node, 'feesIndex.common.unitFee', 0);
  511. }
  512. };
  513. //计算基数赋值要经过解析和标准化,已在calculate里赋值
  514. if(fieldName !== 'calcBase'){
  515. calcTools.setFieldValue(node, fieldName, value);
  516. };
  517. project.calcProgram.calcAndSave(node);
  518. gljOprObj.showRationGLJSheetData();
  519. } else if (node.sourceType === project.Bills.getSourceType()&&fieldName === 'unit'){//修改清单单位的时候清单工程量要重新4舍5入
  520. node.data[fieldName] = value;
  521. node.changed = true;
  522. if(node.data.quantity){
  523. node.data.quantity =scMathUtil.roundForObj(node.data.quantity,getDecimal("quantity",node));
  524. }
  525. project.calcProgram.calcAndSave(node);
  526. } else {
  527. if (node.sourceType === project.Bills.getSourceType()) {
  528. if(fieldName === "maxPrice" || fieldName === 'minPrice'){
  529. if(value == null){
  530. value = "";
  531. }else {
  532. value = scMathUtil.roundToString(value,getDecimal("unitPrice", node))
  533. }
  534. }
  535. project.Bills.updateField(node.source, fieldName, value, false);
  536. } else if (node.sourceType === project.Ration.getSourceType()) {
  537. project.Ration.updateField(node.source, fieldName, value);
  538. }
  539. if (colSetting.data.wordWrap) {
  540. this.mainSpread.getActiveSheet().autoFitRow(node.serialNo());
  541. }
  542. projectObj.mainController.refreshTreeNode([node]);
  543. }
  544. } else if(value==null && fieldName ==='feeRate'){
  545. project.FeeRate.cleanFeeRateID(node);
  546. } else {
  547. projectObj.mainController.refreshTreeNode([node], false);
  548. }
  549. },
  550. mainSpreadLeaveCell: function (sender, info) {
  551. let colSetting = projectObj.mainController.setting.cols[info.col];
  552. projectObj.lastCol = colSetting;
  553. projectObj.lastCell = {row: info.row, col: info.col};
  554. if(colSetting.data.field === 'quantity'){
  555. SheetDataHelper.hideMoreButton()
  556. }
  557. },
  558. //滚动造价书鼠标时,工程量的更多按钮跟着移动
  559. TopRowChanged:function(type,info){
  560. let colSetting = projectObj.mainController.setting.cols[info.sheet.getActiveColumnIndex()];
  561. if(colSetting.data.field === 'quantity'){
  562. SheetDataHelper.moveMoreButton(info.sheet)
  563. }
  564. },
  565. //repaint 动态下拉框
  566. mainSpreadEnterCell: function (sender, info) {
  567. let colSetting = projectObj.mainController.setting.cols[info.col];
  568. if(colSetting.data.field === 'unit' || (projectObj.lastCol&&projectObj.lastCol.data.field === 'unit')||colSetting.data.field ==='subType'
  569. || (projectObj.lastCol&&projectObj.lastCol.data.field === 'subType') || colSetting.data.field === 'programID' ||(projectObj.lastCol&&projectObj.lastCol.data.field === 'programID')){
  570. let rects = [];
  571. rects.push(info.sheet.getCellRect(info.row, info.col));
  572. if(projectObj.lastCell){
  573. rects.push(info.sheet.getCellRect(projectObj.lastCell.row, projectObj.lastCell.col));
  574. }
  575. for(let rect of rects){
  576. info.sheet.repaint(rect);
  577. }
  578. }
  579. },
  580. mainSpreadEditStarting: function (sender, info) {
  581. let project = projectObj.project;
  582. let node = project.mainTree.items[info.row];
  583. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  584. let value = info.sheet.getValue(info.row, info.col);
  585. if(fieldName === 'code' && node && calcTools.isRationItem(node) && isDef(node.data.code)&&isDef(value)){
  586. if (isDef(node.data.prefix) && node.data.prefix !== rationPrefix.none){
  587. value = value.replace(new RegExp(node.data.prefix), '');
  588. };
  589. value = value.replace(new RegExp(rationPrefix.replace), '');
  590. info.sheet.setValue(info.row, info.col, value);
  591. }
  592. if(node&&fieldName =='quantity'&&(node.data.quantityEXP !==null||node.data.quantityEXP !==undefined)){
  593. info.sheet.setValue(info.row, info.col, node.data.quantityEXP);
  594. }
  595. },
  596. onCellDoubleClick: function (sender, info){
  597. let project = projectObj.project;
  598. if(info.row && info.col){
  599. let node = project.mainTree.items[info.row];
  600. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  601. if(fieldName == 'marketUnitFee'){
  602. if(gljOprObj.hasComposition(node.data,true)){
  603. alert("当前人材机的市场价由组成物计算得出,不可直接修改。");
  604. return;
  605. }
  606. }
  607. if(fieldName == 'code' && node){
  608. projectObj.showBillOrRationLib(node)
  609. }
  610. }
  611. },
  612. showBillOrRationLib(node){
  613. let BILLS = projectObj.project.Bills;
  614. let code = node.data.code ? node.data.code : '';
  615. if(node.sourceType == ModuleNames.bills){//当清单是“分部分项工程”、“措施项目工程”时,要展开清单规则节点
  616. if(BILLS.isFXorBX(node)||(node.data.type == billType.BILL && BILLS.isMeasure(node))){//是分项或补项,是清单并且属于措施项目节点
  617. if(!billsGuidance.bills.tree){
  618. doAfterLoadGuidance = function () {
  619. billsGuidance.locateAtBills(code);
  620. doAfterLoadGuidance = null;
  621. }
  622. } else {
  623. billsGuidance.locateAtBills(code);
  624. }
  625. if(!$("#zy").is(":visible")) {
  626. $('#stdBillsGuidanceTab').click();
  627. }
  628. }
  629. }
  630. if(node.sourceType == ModuleNames.ration){ //在定额编码中双击,如果右侧定额库没有展开,则自动展开。
  631. if(node.data.type != rationType.ration) return ;//只有定额类型才需要自动展开,其它都不用
  632. let libID = node.data.libID;
  633. if (node.data.from === 'cpt') {
  634. libID = node.data.fromUser ? `${rationLibObj.compleRationLibId}*${node.data.fromUser}` : rationLibObj.compleRationLibId;
  635. }
  636. if(!rationLibObj.tree){
  637. if(isDef(libID)) sessionStorage.setItem('stdRationLib', libID);
  638. rationLibObj.doAfterGetRationTree = function () {
  639. this.locateAtRation(libID, code);
  640. this.doAfterGetRationTree = null;
  641. };
  642. } else {
  643. if($('#stdRationLibSelect').select().val() != libID){
  644. let libOpts = $('#stdRationLibSelect').find('option');
  645. for(let libOpt of libOpts){
  646. if($(libOpt).val() == libID){
  647. $(libOpt).prop('selected', 'selected');
  648. break;
  649. }
  650. }
  651. $('#stdRationLibSelect').change();
  652. rationLibObj.doAfterGetRationTree = function () {
  653. this.locateAtRation(libID, code);
  654. this.doAfterGetRationTree = null;
  655. };
  656. } else {
  657. rationLibObj.locateAtRation(node.data.libID, code);
  658. }
  659. }
  660. if(!$("#de").is(":visible")) $('#stdRationTab').click();
  661. }
  662. },
  663. onColumnWidthChanged: function (sender, info) { // CSL,2018.07.25
  664. if (info.colList.includes(4) || info.colList.includes(5)){
  665. let items = projectObj.project.mainTree.items;
  666. let sheet = projectObj.mainSpread.getActiveSheet();
  667. for (let i = 0; i < items.length; i++) {
  668. let need = false;
  669. if (items[i].data.itemCharacterText){
  670. sheet.getCell(i, 4).wordWrap(true);
  671. need = true;
  672. }
  673. if (items[i].data.jobContentText){
  674. sheet.getCell(i, 5).wordWrap(true);
  675. need = true;
  676. }
  677. if (need) sheet.autoFitRow(i);
  678. }
  679. }
  680. },
  681. onClipboardPasting: function (sender, info){
  682. let rIdx = info.sheet.getActiveRowIndex();
  683. let node = projectObj.project.mainTree.items[rIdx];
  684. if (!node.parent){
  685. info.cancel = true;
  686. hintBox.infoBox('系统提示','大项费用不允许粘贴!', 1);
  687. return false;
  688. };
  689. let colName = projectObj.project.projSetting.main_tree_col.cols[info.cellRange.col].data.field;
  690. if (colName == 'code'){
  691. info.cancel = true;
  692. function getNodeType(node) {
  693. let t = null;
  694. if (calcTools.isRationItem(node))
  695. t = 1
  696. else if (calcTools.isBill(node)){
  697. if (calcTools.isBill_FB(node))
  698. t = 2
  699. else if (calcTools.isBill_FX(node) || calcTools.isBill_BX(node))
  700. t = 3
  701. else if (calcTools.isBill_BILL(node))
  702. t = 4;
  703. };
  704. return t;
  705. };
  706. function getPasteTextArr(info) {
  707. let copyText = info.pasteData.text.trim();
  708. if (!copyText) return null;
  709. let spliter = '';
  710. if (copyText.includes('\r\n')){
  711. spliter = '\r\n'
  712. }
  713. else if (copyText.includes('\n')){ // 兼容Unix、Mac 等系统回车换行符
  714. spliter = '\n'
  715. }
  716. else{
  717. spliter = '\r'
  718. };
  719. let rows = copyText.split(spliter);
  720. let rstArr = [];
  721. for (let row of rows) {
  722. row = row.trim();
  723. row = row.split('\t');
  724. rstArr.push(row);
  725. }
  726. return rstArr;
  727. };
  728. function getPasteNodes(node, nodeType, count) {
  729. let nodesArr = [];
  730. let curNode = null;
  731. for (let i = rIdx; i < rIdx + count; i++) {
  732. curNode = projectObj.project.mainTree.items[i];
  733. if (curNode && calcTools.isSameTypeNode(curNode, node)){
  734. nodesArr.push(curNode);
  735. }
  736. else{
  737. curNode = projectObj.project.mainTree.items[i - 1];
  738. break;
  739. }
  740. }
  741. if (nodesArr.length < count){
  742. if (projectObj.project.mainTree.selected != curNode)
  743. projectObj.project.mainTree.selected = curNode;
  744. let add = count - nodesArr.length;
  745. for (let i = 0; i < add; i++) {
  746. switch (nodeType) {
  747. case 1:
  748. curNode = projectObj.project.Ration.addNewRationFast(rationType.ration);
  749. break;
  750. case 2:
  751. curNode = ProjectController.addFB(projectObj.project, projectObj.mainController);
  752. break;
  753. case 3:
  754. curNode = ProjectController.addFX(projectObj.project, projectObj.mainController);
  755. break;
  756. case 4:
  757. curNode = ProjectController.addBills(projectObj.project, projectObj.mainController);
  758. break;
  759. }
  760. if (!curNode){
  761. hintBox.infoBox('系统提示','插入新结点出错,粘贴失败!', 1);
  762. return nodesArr;
  763. }
  764. else{
  765. nodesArr.push(curNode);
  766. if (projectObj.project.mainTree.selected != curNode)
  767. projectObj.project.mainTree.selected = curNode;
  768. }
  769. }
  770. };
  771. return nodesArr;
  772. };
  773. function doPaste(nodes, nodeType, datas) {
  774. if (nodeType == 1){ // 批量粘贴定额有严重的异步问题,这里要和清单分开处理
  775. let updateRationCodes = [];
  776. for (let i = 0; i < datas.length; i++) {
  777. let ptNode = nodes[i];
  778. let code = datas[i][0];
  779. // 编号去掉“换、借、补”等多余的字
  780. code = code.replace(new RegExp(rationPrefix.complementary), '');
  781. code = code.replace(new RegExp(rationPrefix.borrow), '');
  782. code = code.replace(new RegExp(rationPrefix.replace), '');
  783. updateRationCodes.push({'node':ptNode, value:code});
  784. }
  785. projectObj.project.Ration.updateRationCodes(updateRationCodes);
  786. }
  787. else {
  788. for (let i = 0; i < datas.length; i++) {
  789. let ptNode = nodes[i];
  790. let code = datas[i][0];
  791. if (!(ptNode.data && ptNode.data.code && ptNode.data.code.sameText(code))){
  792. projectObj.updateCode(ptNode, code);
  793. };
  794. }
  795. }
  796. projectObj.mainController.refreshTreeNode(nodes);
  797. };
  798. let tagType = getNodeType(node);
  799. if (!tagType){
  800. hintBox.infoBox('系统提示', '该树结点类型不支持从项目编码列粘贴!', 1);
  801. return false;
  802. };
  803. let datas = getPasteTextArr(info);
  804. if (!datas) return;
  805. let pasteNodes = getPasteNodes(node, tagType, datas.length);
  806. doPaste(pasteNodes, tagType, datas);
  807. };
  808. },
  809. mainSpreadEditEnded: function (sender, info) {
  810. let project = projectObj.project;
  811. let node = project.mainTree.items[info.row];
  812. project.withinBillsLocked(node);
  813. let colSetting = projectObj.mainController.setting.cols[info.col];
  814. let fieldName = projectObj.mainController.setting.cols[info.col].data.field;
  815. //提前处理
  816. if (fieldName === 'code' || fieldName === 'name' || fieldName === 'unit') {
  817. info.editingText = info.editingText ? info.editingText.toString().replace(new RegExp(/[\r\n]/g), '') : info.editingText;
  818. }
  819. // 检查输入类型等
  820. let value = projectObj.checkSpreadEditingText(info.editingText, colSetting);
  821. projectObj.updateCellValue(node, value, colSetting,info.editingText);
  822. // 自动行高
  823. const autoHeight = project.property.displaySetting.autoHeight;
  824. if (autoHeight) {
  825. projectObj.mainSpread.getActiveSheet().autoFitRow(info.row);
  826. }
  827. },
  828. msClipboardChanged: function (sender, info) {
  829. let colSettings = projectObj.mainController.setting.cols;
  830. let cDatas = sheetCommonObj.getTableData(info.sheet, colSettings);
  831. sheetCommonObj.copyTextToClipboard(cDatas);
  832. return;
  833. },
  834. mainSpreadRangeChanged: function (sender, info) {
  835. let project = projectObj.project, setting = projectObj.mainController.setting;
  836. let changedObj = projectObj.checkSpreadChangedCells(info);
  837. let refreshNodes = [];
  838. for(let row of changedObj.refreshRows){
  839. refreshNodes.push(project.mainTree.items[row]);
  840. }
  841. let updateRationCodes = [];//更新定额编码时要用同步的方式
  842. // 超高降效的操作比较耗时,需要减少触发
  843. const overHeightChangedData = [];
  844. if(changedObj.changedCells.length > 0){
  845. console.log(changedObj.changedCells);
  846. for (let changedCell of changedObj.changedCells) {
  847. let node = project.mainTree.items[changedCell.row];
  848. let colSetting = setting.cols[changedCell.col];
  849. let value = projectObj.checkSpreadEditingText(changedCell.text, colSetting);
  850. if(colSetting.data.field=='code' && node.sourceType == project.Ration.getSourceType()&&node.data.type==rationType.ration){//如果是更新定额的编码
  851. updateRationCodes.push({'node':node,value:value});
  852. } else if (colSetting.data.field === 'overHeight') {
  853. overHeightChangedData.push({ node, value });
  854. } else {
  855. projectObj.updateCellValue(node, value, colSetting,changedCell.text);
  856. }
  857. }
  858. }
  859. if (overHeightChangedData.length) {
  860. OVER_HEIGHT.handleValueChanged(overHeightChangedData);
  861. }
  862. if(updateRationCodes.length>0){
  863. project.Ration.updateRationCodes(updateRationCodes);
  864. }
  865. if(refreshNodes.length > 0){
  866. projectObj.mainController.refreshTreeNode(refreshNodes);
  867. }
  868. },
  869. checkMainSpread: function () {
  870. if (!this.mainSpread) {
  871. this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
  872. sheetCommonObj.spreadDefaultStyle(this.mainSpread);
  873. this.mainSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.muliRange);
  874. this.mainSpread.getActiveSheet().name('mainSheet');
  875. this.mainSpread.getActiveSheet().options.isProtected = true;
  876. this.mainSpread.getActiveSheet().options.frozenlineColor = '#ababab';
  877. }
  878. },
  879. refreshMainSpread: function () {
  880. if (this.mainSpread) {
  881. this.mainSpread.refresh();
  882. }
  883. },
  884. loadProjectData: function () {
  885. var that = this;
  886. this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
  887. let startTime = +new Date();
  888. console.log("开始加载-----"+startTime);
  889. $.bootstrapLoading.start();
  890. this.project.loadDatas(function (err) {
  891. let mTime = +new Date();
  892. console.log(`get data时间——${mTime - startTime}`);
  893. //快速列设置
  894. if(!colSettingObj.getVisible('itemCharacterText')){
  895. switchTznrHtml(true);
  896. }
  897. if(colSettingObj.getVisible('itemCharacterText')){
  898. switchTznrHtml(false);
  899. }
  900. if (!err) {
  901. that.project.projectGLJ.calcQuantity(true);//计算分部分项和技术措施项目消耗量;
  902. let quantityTime = +new Date();
  903. console.log(`计算quantity时间——${quantityTime - mTime}`);
  904. //that.project.property = projectObj.project.projectInfo.property; 改在doAfterLoad的时候设置
  905. if (typeof overwriteRationCalcBases === 'function')
  906. overwriteRationCalcBases(that.project.property.taxType);
  907. //that.project.calcProgram.compileAllTemps();
  908. if (typeof dynamicLoadCalcBase !== 'undefined') {
  909. dynamicLoadCalcBase();
  910. }
  911. that.project.calcBase.init(that.project);
  912. // that.project.calcFields = JSON.parse(JSON.stringify(cpFeeTypes));
  913. // that.project.initCalcFields();
  914. let str = JSON.stringify(that.project.projSetting.main_tree_col);
  915. that.project.projSetting.mainGridSetting = JSON.parse(str);
  916. that.project.projSetting.mainGridSetting.frozenCols = 4;
  917. TREE_SHEET_HELPER.initSetting($('#billsSpread')[0], that.project.projSetting.mainGridSetting);
  918. that.project.projSetting.mainGridSetting.setAutoFitRow = MainTreeCol.getEvent("setAutoFitRow");
  919. that.project.projSetting.mainGridSetting.cols.forEach(function (col) {
  920. col.data.splitFields = col.data.field.split('.');
  921. if (col.data.getText && Object.prototype.toString.apply(col.data.getText) === "[object String]") {
  922. col.data.getText = MainTreeCol.getEvent(col.data.getText);
  923. }
  924. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  925. col.readOnly = MainTreeCol.getEvent(col.readOnly);
  926. }
  927. if (col.data.cellType && Object.prototype.toString.apply(col.data.cellType) === "[object String]") {
  928. let getCellType = MainTreeCol.getEvent(col.data.cellType);
  929. col.data.cellType = getCellType;
  930. }
  931. // if (col.data.digit && Object.prototype.toString.apply(col.data.digit) === "[object String]") {
  932. // col.data.decimal = that.project.getDecimal(col.data.digit);
  933. // col.data.formatter = MainTreeCol.getNumberFormatter(col.data.decimal);
  934. // }
  935. if (col.data.field === 'code') {
  936. col.data.formatter = '@';
  937. }
  938. col.setAutoHeight = MainTreeCol.getEvent("setAutoHeight");
  939. col.editChecking = MainTreeCol.getEvent("editChecking");
  940. // 根据配置设置自动行高,在这里先做个标记,然后对每个单元格单独配置
  941. if (col.data.field === 'name' || col.data.field === 'itemCharacterText' ||
  942. col.data.field === 'jobContentText' || col.data.field === 'adjustState') {
  943. col.data.autoHeight = true;
  944. col.showHint = true;
  945. }
  946. if(col.data.field ==='quantity' || col.data.field ==='remark'){
  947. col.showHint = true;
  948. }
  949. // 综合单价、综合合价,小数部分应补0对齐。 CSL
  950. // if (col.data.field.hasSubStr("common")){
  951. if (col.data.field.hasSubStr(".totalFee"))
  952. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.totalPrice, true);
  953. else if (col.data.field.hasSubStr(".unitFee")||col.data.field.hasSubStr("maxPrice"))
  954. col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.unitPrice, true);
  955. // }
  956. });
  957. let startShowTime = +new Date();
  958. that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), that.project.projSetting.mainGridSetting);
  959. let endShowTime = +new Date();
  960. console.log(`show data时间——${endShowTime - startShowTime}`);
  961. that.mainController.bind('refreshBaseActn', that.refreshBaseActn);
  962. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.beforeTreeSelectedChange, that.beforeMainTreeSelectedChange);
  963. that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, that.treeSelectedChanged);
  964. gljCol.initGljCol(that.project.projSetting.glj_col?that.project.projSetting.glj_col.showAdjustPrice:false,
  965. that.project.property.tenderSetting.showTenderFields?that.project.property.tenderSetting.showTenderFields:false,true);
  966. that.mainController.showTreeData();
  967. subObj.initSubSpread();//初始化主界面下方的表格
  968. if(!projectReadOnly){
  969. that.mainSpreadEscKey(that.mainSpread, that.mainSpreadEditStarting, that.mainSpreadEditEnded);
  970. sheetCommonObj.bindEnterKey(that.mainSpread, that.mainSpreadEnterKey);
  971. that.bindPaseBlockKey(that.mainSpread);
  972. }
  973. setTimeout(function () {
  974. that.mainSpread.getActiveSheet().startEdit();//这两句需要挺多时间,而又需要在editend 事件前触发,而这些又不影响计算,所以这里用异步的方法
  975. that.mainSpread.getActiveSheet().endEdit();
  976. that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
  977. that.mainSpread.bind(GC.Spread.Sheets.Events.EditStarting, that.mainSpreadEditStarting);
  978. },100);
  979. that.mainSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, that.amountAreaNumber);//选中统计专用,节点相关操作在treeSelectedChanged里些
  980. that.mainSpread.bind(GC.Spread.Sheets.Events.LeaveCell, that.mainSpreadLeaveCell);
  981. that.mainSpread.bind(GC.Spread.Sheets.Events.EnterCell, that.mainSpreadEnterCell);
  982. that.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, that.mainSpreadRangeChanged);
  983. that.mainSpread.bind(GC.Spread.Sheets.Events.ClipboardChanged, that.msClipboardChanged);
  984. that.mainSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, that.onButtonClick);
  985. that.mainSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, that.onCellDoubleClick);
  986. that.mainSpread.bind(GC.Spread.Sheets.Events.ColumnWidthChanged, that.onColumnWidthChanged);
  987. that.mainSpread.bind(GC.Spread.Sheets.Events.ClipboardPasting, that.onClipboardPasting);
  988. //工程量悬浮窗移动事件
  989. that.mainSpread.bind(GC.Spread.Sheets.Events.TopRowChanged, that.TopRowChanged);
  990. //let loadOtherStartTime = +new Date();
  991. //if(!projectReadOnly){
  992. that.loadMainSpreadContextMenu();
  993. //}
  994. socketObject.connect('main', { projectReadOnly: !!projectReadOnly, user: { ...projectObj.project.projectInfo.opener } });//连接socket服务器
  995. let endTime = +new Date();
  996. console.log(`其它时间——${endTime - endShowTime}`);
  997. console.log("加载完成-----"+endTime);
  998. console.log(`时间——${endTime - startTime}`);
  999. that.project.projectMarkChecking();//是否需要重新进行造价计算
  1000. autoFlashHeight();
  1001. that.loadFocusLocation();
  1002. projectObj.refreshMainSpread();
  1003. //定位到会话中的选项
  1004. let mainTabFocus = sessionStorage.getItem('mainTab') ? sessionStorage.getItem('mainTab') : '#tab_zaojiashu';
  1005. $(`${mainTabFocus}`).click();
  1006. if(projectReadOnly){
  1007. sheetCommonObj.disableSpread(that.mainSpread);
  1008. }
  1009. // 检查旧项目是否有调价数据,没有则自动生成 ----- 有种情况不行,如下:
  1010. // 未知情况:有调价数据,但调价算的不对,所以这里无论什么情况,打开时都要全局算一遍,牺牲速度体验,换来数据稳定。
  1011. // let node = projectObj.project.mainTree.firstNode();
  1012. // if (node.data.feesIndex && node.data.feesIndex.common && node.data.feesIndex.common.totalFee
  1013. // && node.data.feesIndex.common.totalFee != 0){
  1014. // if (node.data.feesIndex.common.tenderTotalFee == undefined || node.data.feesIndex.common.tenderTotalFee == 0)
  1015. // };
  1016. if (projectObj.project.projectInfo.lastFileVer != VERSION){
  1017. projectObj.project.calcProgram.doTenderCalc();
  1018. // console.log('旧项目,打开前进行了全局调价计算。')
  1019. }
  1020. $.bootstrapLoading.end();
  1021. }
  1022. else {
  1023. }
  1024. const onceAlert = getLocalCache(commonConstants.StorageKey.ONCE_MAIN_LOADED);
  1025. if (onceAlert) {
  1026. alert(onceAlert);
  1027. removeLocalCache(commonConstants.StorageKey.ONCE_MAIN_LOADED);
  1028. }
  1029. });
  1030. },
  1031. //绑定复制整块,粘贴整块快捷键
  1032. bindPaseBlockKey:function(workBook){
  1033. workBook.commandManager().register('paseBlock', function () {
  1034. // console.log("teest Z")
  1035. // BlockController.copyRightClickCallback();
  1036. })
  1037. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.z, true, false, false, false);
  1038. workBook.commandManager().setShortcutKey('paseBlock', GC.Spread.Commands.Key.z, true, false, false, false);
  1039. },
  1040. //mainSpread有一些单元格进入编辑状态后,会动态改变值,公用的bindEscKey方法不适用
  1041. mainSpreadEscKey: function (workBook, editStarting = null, editEnded = null) {
  1042. workBook.commandManager().register('myEsc', function () {
  1043. let sheet = workBook.getActiveSheet();
  1044. if(editStarting){
  1045. sheet.unbind(GC.Spread.Sheets.Events.EditStarting);
  1046. }
  1047. if(editEnded){
  1048. sheet.unbind(GC.Spread.Sheets.Events.EditEnded);
  1049. }
  1050. let row = sheet.getActiveRowIndex();
  1051. let col = sheet.getActiveColumnIndex();
  1052. let orgV = sheet.getValue(row, col);
  1053. let node = projectObj.project.mainTree.items[row];
  1054. let field = colSettingObj.getFieldByCol(col);
  1055. //进入编辑状态后改变了单元格值的时候特殊处理
  1056. if(isDef(field) && field === 'code'){
  1057. if(node && node.sourceType === projectObj.project.Ration.getSourceType() && node.data.type === rationType.ration
  1058. && isDef(node.data.code) && isDef(node.data.prefix) && node.data.prefix !== rationPrefix.none){
  1059. orgV = node.data.prefix + orgV;
  1060. }
  1061. }
  1062. else if(isDef(field) && field === 'quantity'){
  1063. orgV = isDef(node) && isDef(node.data.quantity) ? node.data.quantity : '';
  1064. }
  1065. if(!isDef(orgV)){
  1066. orgV = '';
  1067. }
  1068. if(sheet.isEditing()){
  1069. sheet.endEdit();
  1070. sheet.setValue(row, col, orgV);
  1071. }
  1072. if(editStarting){
  1073. sheet.bind(GC.Spread.Sheets.Events.EditStarting, editStarting);
  1074. }
  1075. if(editEnded){
  1076. sheet.bind(GC.Spread.Sheets.Events.EditEnded, editEnded);
  1077. }
  1078. });
  1079. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.esc, false, false, false, false);
  1080. workBook.commandManager().setShortcutKey('myEsc', GC.Spread.Commands.Key.esc, false, false, false, false);
  1081. },
  1082. mainSpreadEnterKey: function () {
  1083. let me = projectObj;
  1084. let sheet = me.mainSpread.getActiveSheet();
  1085. let orgRow = sheet.getActiveRowIndex();
  1086. let orgCol = sheet.getActiveColumnIndex();
  1087. let orgField = colSettingObj.getFieldByCol(orgCol);
  1088. let selected = me.project.mainTree.items[orgRow];
  1089. if(sheet.isEditing()){
  1090. sheet.endEdit();
  1091. }
  1092. //正常情况,焦点应该是在下一行的同一列
  1093. let newRow = orgRow + 1, newCol = orgCol;
  1094. //getColByField getVisible都不提出来,减少调用次数
  1095. if(selected){
  1096. //在分项/补项的编码单元格回车,焦点应跳动至本行的工程量单元格
  1097. if(orgField && orgField === 'code' && selected.sourceType === me.project.Bills.getSourceType() && [billType.FX, billType.BX].includes(selected.data.type)){
  1098. let quantityCol = colSettingObj.getColByField('quantity');
  1099. let quantityVisible = colSettingObj.getVisible('quantity');
  1100. if(quantityCol !== null && quantityVisible !== false){
  1101. newRow = orgRow;
  1102. newCol = quantityCol;
  1103. }
  1104. }
  1105. else if(orgField && orgField === 'quantity' && selected.sourceType === me.project.Bills.getSourceType() && [billType.FX, billType.BX].includes(selected.data.type)){
  1106. //在分项/补项的工程量单元格回车,如果其下有定额/量价/人材机,焦点应跳动至其下第一条定额/量价/人材机的工程量,如果是空行,则跳到至第一条定额xx的编码;
  1107. if(selected.children.length !== 0 && !(isDef(selected.children[0].data.code) && selected.children[0].data.code.toString().trim() !== '')){
  1108. let codeCol = colSettingObj.getColByField('code');
  1109. let codeVisible = colSettingObj.getVisible('code');
  1110. newRow = orgRow + 1;
  1111. if(codeCol !== null && codeVisible !== false){
  1112. newCol = codeCol;
  1113. }
  1114. }
  1115. //如果其下没有定额/量价/人材机,则自动在其下插入一条定额空行,在其后自动插入一条分项空行,焦点跳动至定额空行的编码单元格。
  1116. else if(selected.children.length === 0){
  1117. //分项没有后兄弟,且没有锁定清单时在其后插入分项
  1118. if(!selected.nextSibling && !(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected))){
  1119. ProjectController.addFX(me.project, me.mainController);
  1120. //将焦点行设置成原本的行,以插入定额
  1121. me.mainController.setTreeSelected(me.project.mainTree.items[orgRow]);
  1122. }
  1123. /* 2021-04-26 只插入清单不插入定额
  1124. //插入定额
  1125. me.project.Ration.addNewRation(null, rationType.ration, function () {
  1126. newRow = sheet.getActiveRowIndex();
  1127. let codeCol = colSettingObj.getColByField('code');
  1128. let codeVisible = colSettingObj.getVisible('code');
  1129. if(codeCol !== null && codeVisible !== false){
  1130. newCol = codeCol;
  1131. }
  1132. sheet.setActiveCell(newRow, newCol);
  1133. },true); */
  1134. }
  1135. }
  1136. //在定额/量价/人材机的编码单元格回车,焦点应跳动至本行的工程量单元格
  1137. else if(orgField && orgField === 'code' && selected.sourceType === me.project.Ration.getSourceType()){
  1138. let quantityCol = colSettingObj.getColByField('quantity');
  1139. let quantityVisible = colSettingObj.getVisible('quantity');
  1140. if(quantityCol !== null && quantityVisible !== false){
  1141. newRow = orgRow;
  1142. newCol = quantityCol;
  1143. }
  1144. }
  1145. //在定额/量价/人材机的工程量单元格回车
  1146. else if(orgField && orgField === 'quantity' && selected.sourceType === me.project.Ration.getSourceType()){
  1147. let nextSibling = selected.nextSibling;
  1148. //如果其后有定额/量价/人材机(空行:编码为空不算),焦点应跳动至下一行定额/量价/人材机的工程量,不需处理
  1149. //如果其后没有定额/量价/人材机(空行也没有),则自动在其后插入一行定额空行,焦点跳动至定额空行的编码单元格
  1150. if(!nextSibling){
  1151. let codeCol = colSettingObj.getColByField('code');
  1152. let codeVisible = colSettingObj.getVisible('code');
  1153. me.project.Ration.addNewRation(null, rationType.ration, function () {
  1154. newRow = sheet.getActiveRowIndex();
  1155. if(codeCol !== null && codeVisible !== false){
  1156. newCol = codeCol;
  1157. }
  1158. sheet.setActiveCell(newRow, newCol);
  1159. }, true);
  1160. }
  1161. //如果其后有定额空行,焦点跳动至定额空行的编码单元格
  1162. else if(nextSibling && !(isDef(nextSibling.data.code) && nextSibling.data.code.toString().trim() !== '')) {
  1163. let codeCol = colSettingObj.getColByField('code');
  1164. let codeVisible = colSettingObj.getVisible('code');
  1165. if(codeCol !== null && codeVisible !== false){
  1166. newRow = orgRow + 1;
  1167. newCol = codeCol;
  1168. }
  1169. }
  1170. }
  1171. //在清单的编码单元格回车,如果清单是叶子节点,焦点跳动至本行的工程量单元格
  1172. else if(orgField && orgField === 'code' && selected.sourceType === me.project.Bills.getSourceType()
  1173. && selected.data.type === billType.BILL && selected.source.children.length === 0){
  1174. let quantityCol = colSettingObj.getColByField('quantity');
  1175. let quantityVisible = colSettingObj.getVisible('quantity');
  1176. if(quantityCol && quantityVisible){
  1177. newRow = orgRow;
  1178. newCol = quantityCol;
  1179. }
  1180. }
  1181. }
  1182. //设置焦点
  1183. sheet.setActiveCell(newRow, newCol);
  1184. //触发表格事件
  1185. me.mainController.setTreeSelected(me.project.mainTree.items[newRow]);//SelectionChanged
  1186. me.mainSpreadLeaveCell({type: 'LeaveCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: orgRow, col: orgCol});
  1187. me.mainSpreadEnterCell({type: 'EnterCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: newRow, col: newCol});
  1188. },
  1189. // 注册自定义插入清单数量
  1190. registerFlexibleInsertBillMenu: function (type) {
  1191. const project = projectObj.project;
  1192. const name = `插入${billText[type]}`;
  1193. const inputID = `insert-bills-number${type}`;
  1194. const insertBillsHtml = `<span>${name}&nbsp;&nbsp;<input id=${inputID} class="menu-input" type="text" value="1" onfocus="this.select()">&nbsp;&nbsp;行</span>`;
  1195. return sheetCommonObj.registerInputContextMenuItem(`insertBills${type}`, insertBillsHtml, 'fa-sign-in', async function () {
  1196. if (project.mainTree.selected.data.type == billType.DXFY) {
  1197. if (project.mainTree.selected.data.calcBase && project.mainTree.selected.data.calcBase != "") {
  1198. alert("当前有基数计算,不能插入子项。");
  1199. return;
  1200. }
  1201. }
  1202. try {
  1203. const number = +$(`#${inputID}`).val();
  1204. if (!number) {
  1205. return;
  1206. }
  1207. $.bootstrapLoading.start();
  1208. const postData = ProjectController.getBillsPostData(number, type);
  1209. const newNodes = await ProjectController.addBillsByData(postData, true);
  1210. if (newNodes.length) {
  1211. projectObj.mainController.setTreeSelected(newNodes[0]);
  1212. projectObj.selectColAndFocus(project.mainTree.selected);
  1213. }
  1214. } catch (err) {
  1215. console.log(err);
  1216. if (!$('hintBox_form').is(':visible')) {
  1217. alert(err);
  1218. }
  1219. } finally {
  1220. $.bootstrapLoading.end();
  1221. }
  1222. });
  1223. },
  1224. // 注册自定义插入定额数量
  1225. registerFlexibleInsertRatoinMenu: function () {
  1226. const project = projectObj.project;
  1227. const insertRationHtml = `<span>插入定额&nbsp;&nbsp;<input id='insert-ration-number' class="menu-input" type="text" value="1" onfocus="this.select()">&nbsp;&nbsp;行</span>`;
  1228. return sheetCommonObj.registerInputContextMenuItem('insertRation', insertRationHtml, 'fa-sign-in', async function () {
  1229. try {
  1230. const number = +$('#insert-ration-number').val();
  1231. if (!number) {
  1232. return;
  1233. }
  1234. $.bootstrapLoading.start();
  1235. const newData = [];
  1236. for (let i = 0; i < number; i++) {
  1237. newData.push({ itemQuery: null, rationType: rationType.ration });
  1238. }
  1239. await project.Ration.addMultiRation(newData);
  1240. projectObj.setActiveCell('code', true);
  1241. } catch (err) {
  1242. console.log(err);
  1243. if (!$('hintBox_form').is(':visible')) {
  1244. alert(err);
  1245. }
  1246. } finally {
  1247. $.bootstrapLoading.end();
  1248. }
  1249. });
  1250. },
  1251. loadMainSpreadContextMenu: function () {
  1252. var project = this.project, spread = this.mainSpread, controller = this.mainController;
  1253. $.contextMenu({
  1254. selector: '#billsSpread',
  1255. selectableSubMenu: true,
  1256. build: function ($trigger, e) {
  1257. projectObj.cusRationCombCheck(spread.getActiveSheet());
  1258. var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  1259. controller.setTreeSelected(controller.tree.items[target.row]);
  1260. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1261. },
  1262. items: {
  1263. "insertRootBill": {
  1264. name: "插入大项费用",
  1265. icon: 'fa-sign-in',
  1266. disabled: function () {
  1267. return projectReadOnly || (projectObj.project.isBillsLocked() && project.withinBillsLocked(project.mainTree.selected));
  1268. //return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
  1269. },
  1270. callback: function (key, opt) {
  1271. ProjectController.addRootBill(project, controller);
  1272. },
  1273. visible: function(key, opt){
  1274. return project.mainTree.selected&&project.mainTree.selected.parent==null;
  1275. }
  1276. },
  1277. "insertFB": {
  1278. name: "插入分部",
  1279. icon: 'fa-sign-in',
  1280. disabled: function () {
  1281. if (projectReadOnly) {
  1282. return true;
  1283. }
  1284. let selected = project.mainTree.selected;
  1285. if(projectObj.project.isBillsLocked()== false&&selected&&selected.sourceType==project.Bills.getSourceType()){
  1286. if(selected.data.type==billType.FB){
  1287. return false;
  1288. }
  1289. if(selected.data.type==billType.FX || selected.data.type==billType.BX){// 当前定位在分项(包括补项),
  1290. if(selected.preSibling){//判断分项有无前兄弟?
  1291. //有,则判断父项的类型是什么,是分部,右键有效显示,点击则按②执行。
  1292. return selected.parent.data.type!==billType.FB
  1293. }
  1294. return false;// 无,右键有效显示,
  1295. }
  1296. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  1297. if(selected.children.length>0){
  1298. return selected.children[0].data.type==billType.FX ||selected.children[0].data.type==billType.BX;//焦点行是分部分项工程,且子项是分项或补项
  1299. }else {
  1300. return false
  1301. }
  1302. }
  1303. }
  1304. return true;//除了清单,其它类型都只读
  1305. },
  1306. callback: function (key, opt) {
  1307. /* 2020-12-28 插入前先弹窗选择
  1308. let selected = project.mainTree.selected;
  1309. if(selected.data.type==billType.FX || selected.data.type==billType.BX){
  1310. //添加成分项的父亲
  1311. ProjectController.addFXParent(selected);
  1312. }else{//正常添加分部
  1313. ProjectController.addFB(project, controller);
  1314. projectObj.selectColAndFocus(project.mainTree.selected);
  1315. } */
  1316. $("#selectFBFor").val("add");
  1317. $('#selectFBDiv').modal('show');
  1318. },
  1319. visible: function(key, opt){
  1320. if(project.mainTree.selected){
  1321. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  1322. }else {
  1323. return false;
  1324. }
  1325. }
  1326. },
  1327. "insertFX": {
  1328. type: projectObj.registerFlexibleInsertBillMenu(billType.FX), // 插入分项
  1329. disabled: function () {
  1330. if (projectReadOnly) {
  1331. return true;
  1332. }
  1333. let selected = project.mainTree.selected;
  1334. if(projectObj.project.isBillsLocked()== false&& selected&&selected.sourceType==project.Bills.getSourceType()){
  1335. if(selected.data.type==billType.FX||selected.data.type==billType.BX){//焦点行是分项,有效显示
  1336. return false
  1337. }
  1338. if(selected.data.type==billType.FB){//点行是分部,
  1339. if(selected.children.length>0){//且有子项,子项是分部,灰显。
  1340. return selected.children[0].data.type == billType.FB
  1341. }else {
  1342. return false;
  1343. }
  1344. }
  1345. if(isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//焦点行是分部分项工程
  1346. if(selected.children.length>0){
  1347. return selected.children[0].data.type==billType.FB;//焦点行是分部分项工程,且子项是分部时灰显
  1348. }else {
  1349. return false
  1350. }
  1351. }
  1352. }
  1353. return true;//除了清单,其它类型都只读
  1354. },
  1355. visible: function(key, opt){
  1356. if(project.mainTree.selected){
  1357. return project.Bills.isFBFX(project.mainTree.selected );//不属于分部分项的话隐藏
  1358. }else {
  1359. return false;
  1360. }
  1361. }
  1362. },
  1363. "insertBills": {
  1364. type: projectObj.registerFlexibleInsertBillMenu(billType.BILL), // 插入清单
  1365. disabled: function () {
  1366. if (projectReadOnly) {
  1367. return true;
  1368. }
  1369. let selected = project.mainTree.selected;
  1370. if(!(projectObj.project.isBillsLocked()== true && project.withinBillsLocked(selected)) && selected && selected.sourceType === project.Bills.getSourceType()){
  1371. return false
  1372. }
  1373. return true;
  1374. },
  1375. visible: function(key, opt){
  1376. if(project.mainTree.selected){
  1377. return project.Bills.isFBFX(project.mainTree.selected)==true?false:true;
  1378. }else {
  1379. return false;
  1380. }
  1381. }
  1382. },
  1383. "spr1": '--------',
  1384. "insertRation": {
  1385. type: projectObj.registerFlexibleInsertRatoinMenu(), // 插入定额
  1386. disabled: function () {
  1387. if (projectReadOnly) {
  1388. return true;
  1389. }
  1390. // var selected = project.mainTree.selected;
  1391. // return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  1392. // 工具栏要加按钮,且不能隐藏。菜单可以隐藏,两者又必须统一,所以启用新规则。怕以后又要改回来,所以保留。 CSL, 2018-01-02
  1393. return !project.Ration.canAdd(project.mainTree.selected);
  1394. },
  1395. },
  1396. "insertLJ": {
  1397. name: "插入量价",//插入量价不需要自动定位到编号列
  1398. icon: 'fa-sign-in',
  1399. disabled: function () {
  1400. if (projectReadOnly) {
  1401. return true;
  1402. }
  1403. return !project.Ration.canAdd(project.mainTree.selected);
  1404. },
  1405. callback: function (key, opt) {
  1406. /* project.Ration.addNewRation(null,rationType.volumePrice,function (newNode) {
  1407. projectObj.selectColAndFocus(newNode,null);
  1408. },true);*/
  1409. },
  1410. items:{
  1411. insertLabour:{
  1412. name: "人工",
  1413. icon: 'fa-sign-in',
  1414. callback:function(key){
  1415. project.Ration.insertVolumePrice(gljType.LABOUR);
  1416. }
  1417. },
  1418. insertMaterial:{
  1419. name:"材料" ,
  1420. icon: 'fa-sign-in',
  1421. callback:function(key){
  1422. project.Ration.insertVolumePrice(gljType.GENERAL_MATERIAL);
  1423. }
  1424. },
  1425. insertMachine:{
  1426. name:"机械" ,
  1427. icon: 'fa-sign-in',
  1428. callback:function(key){
  1429. project.Ration.insertVolumePrice(gljType.GENERAL_MACHINE);
  1430. }
  1431. },
  1432. insertMainMaterial:{
  1433. name:"主材" ,
  1434. icon: 'fa-sign-in',
  1435. callback:function(key){
  1436. project.Ration.insertVolumePrice(gljType.MAIN_MATERIAL);
  1437. }
  1438. },
  1439. insertEquipment:{
  1440. name:"设备" ,
  1441. icon: 'fa-sign-in',
  1442. visible: function () {
  1443. if (typeof isCQ2018 != 'undefined') {
  1444. return false;
  1445. }else{
  1446. return true;
  1447. }
  1448. },
  1449. callback:function(key){
  1450. project.Ration.insertVolumePrice(gljType.EQUIPMENT);
  1451. }
  1452. }
  1453. }
  1454. },
  1455. "insertGLJ": {
  1456. name: "插入人材机",
  1457. icon: 'fa-sign-in',
  1458. disabled: function () {
  1459. if (projectReadOnly) {
  1460. return true;
  1461. }
  1462. // var selected = project.mainTree.selected;
  1463. // return project.Ration.addRationChecking(selected); // Vincent, 2018-01-02
  1464. return !project.Ration.canAdd(project.mainTree.selected);
  1465. },
  1466. callback: function (key, opt) {
  1467. var selected = project.mainTree.selected;
  1468. if(selected.sourceType == ModuleNames.bills){
  1469. if(selected.data.type == billType.FX||selected.data.type ==billType.BILL){
  1470. if(selected.data.calcBase&&selected.data.calcBase!=""){
  1471. alert("当前有基数计算,不能插入定额/量价/人材机。");
  1472. return;
  1473. }
  1474. }
  1475. }
  1476. getGLJData('insert', null, true, null);// ProjectController.addRation(project, controller, rationType.volumePrice);
  1477. },
  1478. visible: function(key, opt){//2018-11-08 新需求,这个按钮先隐藏,有需要再放开
  1479. return true;
  1480. }
  1481. },
  1482. "insertMainMaterial": {
  1483. name: "按清单名称插入主材",//插入量价不需要自动定位到编号列
  1484. icon: 'fa-sign-in',
  1485. disabled: function () {
  1486. if (projectReadOnly) {
  1487. return true;
  1488. }
  1489. return !project.Ration.canAdd(project.mainTree.selected);
  1490. },
  1491. callback: function (key, opt) {
  1492. //名称取清单名称,单位取清单单位
  1493. let selected = project.mainTree.selected;
  1494. let billNode = selected;
  1495. if(selected.sourceType==project.Ration.getSourceType()) billNode = selected.parent;
  1496. let ext = {name:billNode.data.name,unit:billNode.data.unit};
  1497. project.Ration.insertVolumePrice(gljType.MAIN_MATERIAL,ext);
  1498. },
  1499. },
  1500. "spr2": '--------',
  1501. "calc_installation_fee": {
  1502. name: "计取安装费用",
  1503. icon: 'fa-sign-in',
  1504. disabled: function () {
  1505. if (projectReadOnly) {
  1506. return true;
  1507. }
  1508. return false;
  1509. },
  1510. callback: function (key, opt) {
  1511. installationFeeObj.showCalcInstallSettingDiv();
  1512. },
  1513. visible: function(key, opt){
  1514. return projectObj.project.isInstall();
  1515. }
  1516. },
  1517. "calcOverHeightFee": {
  1518. name: '超高降效费用',
  1519. icon: 'fa-sign-in',
  1520. visible: function () {
  1521. return projectObj.project.isOverHeightProject();
  1522. },
  1523. items: {
  1524. 'calcOverHeight': {
  1525. name: '计取超高降效',
  1526. icon: 'fa-sign-in',
  1527. disabled: function () {
  1528. return projectReadOnly;
  1529. },
  1530. callback: function (key, opt) {
  1531. OVER_HEIGHT.switchVisible(true);
  1532. }
  1533. },
  1534. 'setOption': {
  1535. name: '设置子目生成方式',
  1536. icon: 'fa-sign-in',
  1537. disabled: function () {
  1538. return projectReadOnly;
  1539. },
  1540. callback: function (key, opt) {
  1541. $('#overHeightOpt').modal('show');
  1542. }
  1543. },
  1544. 'cancelOverHeight': {
  1545. name: '取消超高降效',
  1546. icon: 'fa-sign-in',
  1547. disabled: function () {
  1548. return projectReadOnly;
  1549. },
  1550. callback: function (key, opt) {
  1551. OVER_HEIGHT.cancelCalc();
  1552. }
  1553. },
  1554. }
  1555. },
  1556. "cleanzmhs":{
  1557. name:'清空子目换算',
  1558. icon: 'fa-remove',
  1559. callback: function (key, opt) {
  1560. let selected = project.mainTree.selected;
  1561. projectObj.project.Ration.updateRationCodes([{'node':selected, value:selected.data.code}],true);
  1562. },
  1563. visible: function(key, opt){
  1564. let selected = project.mainTree.selected;
  1565. if (selected && selected.sourceType == ModuleNames.ration) {
  1566. return true;
  1567. }
  1568. return false;
  1569. },
  1570. disabled: function () {
  1571. let selected = project.mainTree.selected;
  1572. if (projectReadOnly) {
  1573. return true;
  1574. }
  1575. if(selected && selected.data.type != rationType.ration){
  1576. return true;
  1577. }
  1578. return false;
  1579. },
  1580. },
  1581. "areaIncreaseFee":{
  1582. name:"面积增加费",
  1583. icon: 'fa-sign-in',
  1584. visible:function () {
  1585. return projectObj.project.property.isAreaIncrease == true;
  1586. },
  1587. items:{
  1588. "calcAreaIncreaseFee":{
  1589. name:"计取面积增加费",
  1590. icon: 'fa-sign-in',
  1591. callback:function () {
  1592. areaIncreaseFeeObj.setDefaultSetting();
  1593. colSettingObj.setVisible('areaIncreaseFee', true);
  1594. colSettingObj.updateColSetting(true);
  1595. }
  1596. },
  1597. "setArea":{
  1598. name:"设置调整系数",
  1599. icon: 'fa-sign-in',
  1600. callback:function(){
  1601. $("#areaIncreaseFeeDiv").modal('show');
  1602. }
  1603. },
  1604. "cancelAreaIncreaseFee":{
  1605. name:"取消面积增加费",
  1606. icon: 'fa-sign-in',
  1607. callback:function(){
  1608. colSettingObj.setVisible('areaIncreaseFee', false);
  1609. colSettingObj.updateColSetting(true);
  1610. areaIncreaseFeeObj.cancelAreaIncreaseFee();
  1611. }
  1612. }
  1613. }
  1614. },
  1615. "itemIncreaseFee":{
  1616. name:"子目增加费",
  1617. icon: 'fa-sign-in',
  1618. visible:function () {
  1619. return projectObj.project.property.isItemIncrease == true;
  1620. },
  1621. items:{
  1622. "setItem":{
  1623. name:"设置范围",
  1624. icon: 'fa-sign-in',
  1625. callback:function(){
  1626. $("#itemIncreaseFeeDiv").modal('show');
  1627. }
  1628. },
  1629. "cancelAreaIncreaseFee":{
  1630. name:"取消子目增加费",
  1631. icon: 'fa-sign-in',
  1632. callback:function(){
  1633. itemIncreaseFeeObj.cancelItemIncreaseFee();
  1634. }
  1635. }
  1636. }
  1637. },
  1638. "setBookMark": {
  1639. name: '设置书签批注',
  1640. icon: 'fa-flag',
  1641. disabled: function () {
  1642. if (projectReadOnly || !project.mainTree.selected || project.mainTree.selected.sourceType == ModuleNames.ration_glj) {
  1643. return true;
  1644. }
  1645. return false
  1646. },
  1647. items: {
  1648. cancelMark: {
  1649. name: '取消书签批注',
  1650. icon: 'fa-remove',
  1651. disabled: function () {
  1652. const selected = project.mainTree.selected;
  1653. return !(selected && selected.data.bookmarkBackground);
  1654. },
  1655. callback: function () {
  1656. locateObject.setOrCancelBookmark(project.mainTree.selected, null);
  1657. }
  1658. },
  1659. markE2F2C5: {
  1660. name: function () {
  1661. return locateObject.getDescribeByColor('E2F2C5');
  1662. },
  1663. icon: 'fa-square annotate-color-1',
  1664. callback: function () {
  1665. locateObject.setOrCancelBookmark(project.mainTree.selected, 'E2F2C5');
  1666. }
  1667. },
  1668. markF9E2CF: {
  1669. name: function () {
  1670. return locateObject.getDescribeByColor('F9E2CF');
  1671. },
  1672. icon: 'fa-square annotate-color-2',
  1673. callback: function () {
  1674. locateObject.setOrCancelBookmark(project.mainTree.selected, 'F9E2CF');
  1675. }
  1676. },
  1677. markF2EFD9: {
  1678. name: function () {
  1679. return locateObject.getDescribeByColor('F2EFD9');
  1680. },
  1681. icon: 'fa-square annotate-color-3',
  1682. callback: function () {
  1683. locateObject.setOrCancelBookmark(project.mainTree.selected, 'F2EFD9');
  1684. }
  1685. },
  1686. markF5D1DA: {
  1687. name: function () {
  1688. return locateObject.getDescribeByColor('F5D1DA');
  1689. },
  1690. icon: 'fa-square annotate-color-4',
  1691. callback: function () {
  1692. locateObject.setOrCancelBookmark(project.mainTree.selected, 'F5D1DA');
  1693. }
  1694. },
  1695. markE3E3E3: {
  1696. name: function () {
  1697. return locateObject.getDescribeByColor('E3E3E3');
  1698. },
  1699. icon: 'fa-square annotate-color-5',
  1700. callback: function () {
  1701. locateObject.setOrCancelBookmark(project.mainTree.selected, 'E3E3E3');
  1702. }
  1703. },
  1704. markB6F3F2: {
  1705. name: function () {
  1706. return locateObject.getDescribeByColor('B6F3F2');
  1707. },
  1708. icon: 'fa-square annotate-color-6',
  1709. callback: function () {
  1710. locateObject.setOrCancelBookmark(project.mainTree.selected, 'B6F3F2');
  1711. }
  1712. },
  1713. markECE0F5: {
  1714. name: function () {
  1715. return locateObject.getDescribeByColor('ECE0F5');
  1716. },
  1717. icon: 'fa-square annotate-color-7',
  1718. callback: function () {
  1719. locateObject.setOrCancelBookmark(project.mainTree.selected, 'ECE0F5');
  1720. }
  1721. },
  1722. }
  1723. },
  1724. "delete": {
  1725. name: '删除',
  1726. icon: 'fa-remove',
  1727. disabled: function () {
  1728. return !ifCanDelete();
  1729. },
  1730. callback: function () {
  1731. var selected = project.mainTree.selected;
  1732. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length<=0){//选中的是分部,并且没有子项,直接删除
  1733. project.Bills.deleteSelectedNodes();//project.Bills.deleteSelectedNode();
  1734. }else {
  1735. $("#delete_row").modal({show:true});//弹出删除提示框;
  1736. }
  1737. }
  1738. },
  1739. "calculateAll_RationContent": {
  1740. name: '造价计算',
  1741. icon: 'fa-calculator',
  1742. callback: function () {
  1743. $.bootstrapLoading.start();
  1744. setTimeout(function(){
  1745. project.calcProgram.calcAllNodesAndSave();
  1746. $.bootstrapLoading.end();
  1747. },100)
  1748. },
  1749. disabled: function () {
  1750. if (projectReadOnly) {
  1751. return true;
  1752. }
  1753. },
  1754. visible:function(key, opt){//2018-11-15 新需求隐藏右键“造价计算”。
  1755. return true;
  1756. }
  1757. },
  1758. "spr4":'--------',
  1759. "copyBlock": {
  1760. name: '复制整块',
  1761. icon: 'fa-copy',
  1762. disabled: function () {
  1763. /* if (projectReadOnly) {
  1764. return true;
  1765. }
  1766. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  1767. let firstNode = projectObj.project.mainTree.items[selection.row];//当多选的情况,用mainTree.selected判断不正确,要用第一个选中的节点
  1768. for(let i = 0;i< selection.rowCount;i++){ //多选的时候判断所有与第一个节点同级的节点
  1769. let temNode = projectObj.project.mainTree.items[selection.row + i];
  1770. if(firstNode.getParentID() == temNode.getParentID()){
  1771. if(BlockController.copyBtnDisable(temNode) == true){
  1772. return true;
  1773. }
  1774. }
  1775. }
  1776. return false; */
  1777. return BlockController.disabelCopyRightClick();
  1778. },
  1779. callback: function () {
  1780. $.bootstrapLoading.start();
  1781. //let selected = project.mainTree.selected;
  1782. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  1783. setTimeout(function () {
  1784. BlockController.copyBlock(selections[0]);
  1785. $.bootstrapLoading.end();
  1786. },100)
  1787. }
  1788. },
  1789. "pasteBlock": {
  1790. name: '粘贴整块',
  1791. icon: 'fa-paste',
  1792. disabled: function (){
  1793. if (projectReadOnly) {
  1794. return true;
  1795. }
  1796. return BlockController.pasteBtnDisable(project.mainTree.selected);
  1797. },
  1798. callback: function () {
  1799. BlockController.pasteBlock(project.mainTree.selected);
  1800. }
  1801. },
  1802. "recoverDeletedNodes": {
  1803. name: '恢复删除节点',
  1804. icon: 'fa-undo',
  1805. disabled: function (){
  1806. return BlockController.recoverBlockDisabled();
  1807. },
  1808. callback: function () {
  1809. BlockController.recoverBlock();
  1810. }
  1811. },
  1812. "editEngineer": {
  1813. name: '编辑工程内容',
  1814. icon: 'fa-edit',
  1815. disabled: function () {
  1816. return projectReadOnly;
  1817. },
  1818. visible: function(key, opt){
  1819. let selected = project.mainTree.selected;
  1820. return selected.sourceType==ModuleNames.bills&&project.Bills.isEngineerEst(selected);//当焦点行是“专业工程暂估价”时,右键可见并有效。
  1821. },
  1822. callback: function () {
  1823. let node = project.mainTree.selected;//project.Bills.getNodeByFlag(project.mainTree.selected,fixedFlag.ENGINEERING_ESITIMATE);
  1824. if(node){
  1825. projectObj.editContent(node,'engineeringContent');
  1826. }
  1827. }
  1828. },
  1829. "editService": {
  1830. name: '编辑服务内容',
  1831. icon: 'fa-edit',
  1832. disabled: function () {
  1833. return projectReadOnly;
  1834. },
  1835. visible: function(key, opt){
  1836. let selected = project.mainTree.selected;
  1837. return selected.sourceType==ModuleNames.bills&&project.Bills.isTotalService(selected);//当焦点行是“总承包服务费”时,右键可见并有效。
  1838. },
  1839. callback: function () {
  1840. let node = project.mainTree.selected;//project.Bills.getNodeByFlag(project.mainTree.selected,fixedFlag.TURN_KEY_CONTRACT);
  1841. if(node){
  1842. projectObj.editContent(node,'serviceContent');
  1843. }
  1844. }
  1845. },
  1846. "editAccording": {
  1847. name: '编辑签证及索赔依据',
  1848. icon: 'fa-edit',
  1849. disabled: function () {
  1850. return projectReadOnly;
  1851. },
  1852. visible: function(key, opt){
  1853. let selected = project.mainTree.selected;
  1854. return selected.sourceType==ModuleNames.bills&&project.Bills.isClaimVisa(selected);//当焦点行是“签证及索赔计价”时,右键可见并有效。
  1855. },
  1856. callback: function () {
  1857. let node = project.mainTree.selected;//project.Bills.getNodeByFlag(project.mainTree.selected,fixedFlag.CLAIM_VISA);
  1858. if(node){
  1859. projectObj.editContent(node,'claimVisa');
  1860. }
  1861. }
  1862. },
  1863. "replaceMaterial":{
  1864. name:'智能材料替换',
  1865. icon: 'fa-edit',
  1866. disabled:function (key,opt) {
  1867. if (projectReadOnly) {
  1868. return true;
  1869. }
  1870. let selected = project.mainTree.selected;
  1871. return selected.sourceType==ModuleNames.bills ?!(project.Bills.isFXorBX(selected)||selected.source.children.length ==0):true//是分项、补项或叶子清单才有效;
  1872. },
  1873. callback:function(){
  1874. MaterialController.replaceMaterial([project.mainTree.selected]);
  1875. },
  1876. visible: function(key, opt){//2018-11-15 暂时隐藏
  1877. return false
  1878. }
  1879. },
  1880. "createBlocks":{
  1881. name:'生成组价模板',
  1882. icon: 'fa-puzzle-piece',
  1883. disabled:function (key,opt) {
  1884. if (projectReadOnly) {
  1885. return true;
  1886. }
  1887. let selected = project.mainTree.selected;
  1888. return selected.sourceType != ModuleNames.bills;
  1889. },
  1890. callback: function(){
  1891. blockLibObj.checkShow();
  1892. },
  1893. visible: function(key, opt){
  1894. return G_SHOW_BLOCK_LIB;
  1895. }
  1896. }
  1897. }
  1898. });
  1899. },
  1900. // 计算node及node的所有父项
  1901. converseCalculateBills: function (node) {
  1902. projectObj.project.calcProgram.calcAndSave(node);
  1903. },
  1904. // 获取上次退出时的焦点位置
  1905. loadFocusLocation: function(orow,ocol) {
  1906. const projectId = scUrlUtil.GetQueryString('project');
  1907. let row = gljUtil.isDef(orow)?orow:getLocalCache('lastRow:' + projectId);
  1908. let col = gljUtil.isDef(ocol)?ocol:getLocalCache('lastCol:' + projectId);
  1909. if(row == null || col == null){
  1910. //默认焦点定位到造价书的第一行“分项”。
  1911. col = 1;
  1912. row = 0;
  1913. for(let i =0;i<this.mainController.tree.items.length;i++){
  1914. let node = this.mainController.tree.items[i];
  1915. if(node && node.sourceType == ModuleNames.bills && (node.data.type === billType.FX ||node.data.type === billType.BX )){//默认字位到第一条分项或补项
  1916. row = i;
  1917. break;
  1918. }
  1919. }
  1920. }
  1921. row = parseInt(row);
  1922. col = parseInt(col);
  1923. const sheet = this.mainSpread.getActiveSheet();
  1924. sheet.setSelection(row, col, 1, 1);
  1925. row=row<this.mainController.tree.items.length?row:0;
  1926. this.mainController.setTreeSelected(this.mainController.tree.items[row]);//触发树节点选中事件
  1927. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  1928. },
  1929. // 选中区域合计数字
  1930. amountAreaNumber: function(e, info) {
  1931. if (info.newSelections === undefined || info.newSelections.length <= 0) {
  1932. return false;
  1933. }
  1934. const selectedArea = info.newSelections[0];
  1935. const sheet = info.sheet;
  1936. if (selectedArea.colCount <= 1 && selectedArea.rowCount <= 1) {
  1937. return false;
  1938. }
  1939. //获取最左最右坐标
  1940. let maxCell = {row: selectedArea.row, col: selectedArea.col + selectedArea.colCount};
  1941. let maxCellX = sheet.getCellRect(maxCell.row, maxCell.col).x ? sheet.getCellRect(maxCell.row, maxCell.col).x : sheet.getCellRect(maxCell.row, maxCell.col - 1).x;
  1942. let minCell = {row: selectedArea.row, col: selectedArea.col};
  1943. let minCellX = sheet.getCellRect(minCell.row, minCell.col).x ? sheet.getCellRect(minCell.row, minCell.col).x : sheet.getCellRect(minCell.row, minCell.col + 1).x;
  1944. // 获取鼠标位置
  1945. let x = window.event.clientX;
  1946. let y = window.event.clientY;
  1947. // 匹配数字或小数
  1948. const regular = /^([0-9]+[.]{1}[0-9]+)$|^([1-9]{1}\d*)$/;
  1949. // 小数点最高位数
  1950. let max = 0;
  1951. let total = 0;
  1952. let counter = 0;
  1953. let notNumber = false; //如果有非数字,则不显示
  1954. for (let col = selectedArea.col; col < (selectedArea.colCount + selectedArea.col); col++) {
  1955. for (let row = selectedArea.row; row < (selectedArea.rowCount + selectedArea.row); row++) {
  1956. const value = sheet.getCell(row, col).text();
  1957. if (!regular.test(value)) {
  1958. if(value) notNumber = true;
  1959. continue;
  1960. }
  1961. counter++;
  1962. // 获取当前数据小数位数
  1963. let pointPosition = value.toString().indexOf(".");
  1964. pointPosition = pointPosition < 0 ? pointPosition : pointPosition + 1;
  1965. const current = pointPosition > 0 ? value.toString().substring(pointPosition, value.toString().length).length : 0;
  1966. max = current > max ? current : max;
  1967. total += parseFloat(value);
  1968. }
  1969. }
  1970. //选中的都是数字, 如果不为0则悬浮显示
  1971. if (notNumber === false && total > 0 && counter > 1) {
  1972. 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>');
  1973. div.css({
  1974. position: "absolute",
  1975. border: "1px #C0C0C0 solid",
  1976. background: "#fff",
  1977. boxShadow: "1px 2px 5px rgba(0,0,0,0.4)",
  1978. });
  1979. div.children("p").css({
  1980. textAlign: "center",
  1981. padding: 8,
  1982. marginBottom: 2,
  1983. });
  1984. div.children("p").first().css({
  1985. borderBottom: "1px #C0C0C0 solid"
  1986. });
  1987. const totalString = total.toFixed(max);
  1988. // input长度
  1989. const inputWidth = totalString.length * 8;
  1990. // 计算是否会超出显示范围
  1991. const baseWidth = 48;
  1992. const baseHeight = 81;
  1993. const canvasWidth = $("#billsSpreadvp_vp").width();
  1994. const canvasHeight = $("#billsSpreadvp_vp").height();
  1995. //x = x + baseWidth + inputWidth > canvasWidth ? x - baseWidth - inputWidth : x;
  1996. x = maxCellX + baseWidth + inputWidth > canvasWidth ? minCellX - baseWidth - inputWidth : maxCellX + baseWidth;
  1997. y = y + baseHeight > canvasHeight ? y - baseHeight : y;
  1998. //test
  1999. let testT = sheet.getParent().hitTest(x, y);
  2000. //test
  2001. div.css({
  2002. left: x,
  2003. top: y,
  2004. });
  2005. div.children().children("#total").width(inputWidth).val(totalString);
  2006. $("body").append(div);
  2007. // 用于判断是否要关闭窗体
  2008. setTimeout(function() {
  2009. isTotalShowing = true;
  2010. }, 200);
  2011. };
  2012. },
  2013. onButtonClick: function (e, info) {
  2014. let colSetting = projectObj.mainController.setting.cols[info.col];
  2015. let node = projectObj.project.mainTree.items[info.row];
  2016. let fieldName = colSetting.data.field;
  2017. if(fieldName == "isSubcontract"){
  2018. projectObj.onSubcontractClick(node);
  2019. }else if(fieldName == "isEstimate"){
  2020. projectObj.onIsEstimateClick(node,info);
  2021. }else if(fieldName == "evaluationProject"){
  2022. projectObj.onEvaluationProjectClic(node,info);
  2023. }else if(fieldName == "mainBills"||fieldName == "outPutMaxPrice"||fieldName=="outPutLimitPrice"||fieldName=="areaIncreaseFee"||fieldName == "lockUnitPrice"){
  2024. projectObj.onCasCadeButtonClick(node,info,fieldName);
  2025. }
  2026. },
  2027. onEvaluationProjectClic:function (node,info) {
  2028. let checkboxValue = info.sheet.getCell(info.row, info.col).value();
  2029. let newval = checkboxValue?0:1;
  2030. projectObj.project.updateEvalproject(newval,node.data,function (programID) {
  2031. node.data.evaluationProject = newval;
  2032. node.data.programID = programID;
  2033. node.changed=true;
  2034. projectObj.project.calcProgram.calcAndSave(node);
  2035. })
  2036. },
  2037. onIsEstimateClick: function(node,info){
  2038. let checkboxValue = info.sheet.getCell(info.row, info.col).value();
  2039. let cell = info.sheet.getCell(info.row, info.col), newval = 0;
  2040. if (checkboxValue) {
  2041. newval = 0;
  2042. cell.value(newval);
  2043. } else {
  2044. newval = 1;
  2045. cell.value(newval);
  2046. }
  2047. if(MainTreeCol.readOnly.bills(node)){
  2048. projectObj.updateNodeField(node,newval,'isEstimate');
  2049. }else if(node.data.projectGLJID){//更新的是定额类型的工料机或者是显示在造价书页面的主材、设备
  2050. console.log(node);
  2051. let updateData = {id: node.data.projectGLJID, field: 'is_evaluate', value: newval};
  2052. projectObj.project.projectGLJ.pGljUpdate(updateData);
  2053. }
  2054. },
  2055. /* onMainBillsClick:function (node,info) {//清单有三种状态,true,false,null。 打勾:true, 不打勾 false 子项有打勾和不打勾的情况 null
  2056. let checkboxValue = info.sheet.getCell(info.row, info.col).value();
  2057. let cell = info.sheet.getCell(info.row, info.col), newval = true;
  2058. if (checkboxValue == true) {
  2059. newval = false;
  2060. } else {
  2061. newval = true;
  2062. }
  2063. projectObj.project.updateMainBills(node,newval);
  2064. },*/
  2065. onCasCadeButtonClick:function (node,info,fieldName) {
  2066. let checkboxValue = info.sheet.getCell(info.row, info.col).value();
  2067. let cell = info.sheet.getCell(info.row, info.col), newval = true;
  2068. if (checkboxValue == true) {
  2069. newval = false;
  2070. } else {
  2071. newval = true;
  2072. }
  2073. if(fieldName == "areaIncreaseFee"){
  2074. areaIncreaseFeeObj.casCadeUpdate(node,newval,fieldName);
  2075. } else {
  2076. projectObj.project.updateCasCadeBills(node,newval,fieldName,fieldName != "lockUnitPrice");
  2077. }
  2078. },
  2079. onSubcontractClick:function (node) {//点击分包费checkbox
  2080. if (node.data.isSubcontract) node.data.isSubcontract = false;
  2081. else node.data.isSubcontract = true;
  2082. node.changed = true;
  2083. projectObj.project.calcProgram.calcAndSave(node);
  2084. },
  2085. //根据节点获取行style(颜色、字体加粗)
  2086. getNodeColorStyle: function (sheet, node, tree) {
  2087. let colorSetting = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
  2088. let mapping = {DEFAULT: 'DEFAULT', SELECTED: 'SELECTED', DXFY: 'DXFY', FB: 'FB', UNLEAFBILL: 'UNLEAFBILL',
  2089. FX: 'FX', BX: 'BX', UNCBBILL: 'UNCBBILL', CBBILL: 'CBBILL', ZCSB: 'ZCSB'};
  2090. let styleMap = null;
  2091. tree?'':tree = this.project.mainTree;
  2092. //中文字段名,由于同一节点中,中文字体大小和数字字体大小不同
  2093. if(colorSetting == null){
  2094. return null;
  2095. }
  2096. let stringFields = [
  2097. 'code',
  2098. 'subType',
  2099. 'name',
  2100. 'unit',
  2101. 'itemCharacterText',
  2102. 'jobContentText',
  2103. 'adjustState',
  2104. 'calcBase',
  2105. 'programID',
  2106. 'ruleText'
  2107. ];
  2108. if(!isDef(node)){
  2109. return null;
  2110. }
  2111. //清单大类
  2112. if(node.sourceType === this.project.Bills.getSourceType()){
  2113. //大项费用
  2114. if(node.data.type === billType.DXFY){
  2115. styleMap = mapping.DXFY;
  2116. }
  2117. //分部
  2118. if(node.data.type === billType.FB){
  2119. styleMap = mapping.FX;
  2120. }
  2121. //分项
  2122. else if(node.data.type === billType.FX){
  2123. styleMap = mapping.FB;
  2124. }
  2125. //补项
  2126. else if(node.data.type === billType.BX){
  2127. styleMap = mapping.BX;
  2128. }
  2129. //清单
  2130. else if(node.data.type === billType.BILL){
  2131. //非叶子节点的清单
  2132. if(node.source.children.length > 0){
  2133. styleMap = mapping.UNCBBILL;
  2134. // styleMap = mapping.UNLEAFBILL;
  2135. }
  2136. //未使用基数计算的叶子节点的清单
  2137. else if(node.source.children.length === 0 && (!isDef(node.data.calcBase) || node.data.calcBase === '')){
  2138. // styleMap = mapping.UNCBBILL;
  2139. styleMap = mapping.UNLEAFBILL;
  2140. }
  2141. //使用基数计算的叶子节点的清单
  2142. else if(node.source.children.length === 0 && isDef(node.data.calcBase && node.data.calcBaseValue !== '')){
  2143. // styleMap = mapping.CBBILL;
  2144. styleMap = mapping.UNLEAFBILL;
  2145. }
  2146. }
  2147. }
  2148. //定额下的主材、设备
  2149. else if(node.sourceType === this.project.ration_glj.getSourceType()){
  2150. styleMap = mapping.ZCSB;
  2151. }
  2152. else {
  2153. styleMap = mapping.DEFAULT;
  2154. }
  2155. let styleSetting = colorSetting[styleMap];
  2156. let defaultSetting = colorSetting[mapping.DEFAULT];
  2157. if(!isDef(styleSetting)){
  2158. return null;
  2159. }
  2160. let style = new GC.Spread.Sheets.Style();
  2161. //设置style属性
  2162. for(let attr in styleSetting){
  2163. if(attr !== 'stringFont' && attr !== 'numFont'){
  2164. style[attr] = styleSetting[attr] === 'default' || !isDef(styleSetting[attr]) ? defaultSetting[attr] : styleSetting[attr];
  2165. }
  2166. //暂时不开放字体设置,开放的话只能每个单元格进入此方法
  2167. /* else {
  2168. if(stringFields.indexOf(colSetting.data.field) > 0){
  2169. style.font = styleSetting.stringFont === 'default' || !isDef(styleSetting.stringFont) ? defaultSetting.stringFont : styleSetting.stringFont;
  2170. }
  2171. else {
  2172. style.font = styleSetting.numFont === 'default' || !isDef(styleSetting.numFont) ? defaultSetting.numFont : styleSetting.numFont;
  2173. }
  2174. }*/
  2175. }
  2176. //选中行-替换底色
  2177. if(node === tree.selected){
  2178. style.backColor = colorSetting[mapping.SELECTED]['backColor'];
  2179. }
  2180. if(_ && !_.isEmpty(node.data.bookmarkBackground)) style.backColor = "#"+ node.data.bookmarkBackground;//设置书签和批注背景色
  2181. //大项费用加粗(数字与中文字符大小不一问题由字体造成,暂时不考虑分别设置大小)
  2182. /* if(node.sourceType === this.project.Bills.getSourceType() && node.data.type === billType.DXFY){
  2183. style.font = 'bold 14px Arial';
  2184. }*/
  2185. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  2186. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  2187. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  2188. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  2189. return style;
  2190. },
  2191. //大项费用则字体加粗,String 15px, Number 13px
  2192. getBoldFontStyle: function (node, colSetting) {
  2193. let style = new GC.Spread.Sheets.Style();
  2194. if(node.sourceType !== this.project.Bills.getSourceType() || node.data.type !== billType.DXFY){
  2195. return null;
  2196. }
  2197. //备注暂无字段
  2198. let stringFields = [
  2199. 'code',
  2200. 'subType',
  2201. 'name',
  2202. 'unit',
  2203. 'itemCharacterText',
  2204. 'jobContentText',
  2205. 'adjustState',
  2206. 'calcBase',
  2207. 'programID',
  2208. 'ruleText'
  2209. ];
  2210. style.font = 'bold 14px Arial';
  2211. return style;
  2212. },
  2213. //设置节点style
  2214. setNodesStyle: function (sheet, nodes,tree) {
  2215. let me = this;
  2216. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  2217. for(let node of nodes){
  2218. if(node && node.serialNo()!= -1){
  2219. sheet.getRange(node.serialNo(), -1, 1, -1).backColor(me.getNodeColorStyle(sheet, node,tree)?me.getNodeColorStyle(sheet, node,tree).backColor:null);
  2220. }
  2221. }
  2222. });
  2223. },
  2224. loadLockBillsButton:function () {
  2225. if(projectObj.project.projectInfo.property.lockBills == true){
  2226. //$("a[name='lockBills']").attr("data-original-title","解锁清单");
  2227. $("a[name='lockBills']").html('<i class="fa fa-unlock-alt" aria-hidden="true"></i> 解锁清单');
  2228. }else {
  2229. //$("a[name='lockBills']").attr("data-original-title","锁定清单");
  2230. $("a[name='lockBills']").html('<i class="fa fa-lock" aria-hidden="true"></i> 锁定清单');
  2231. }
  2232. },
  2233. editContent:function (node,fieldID) {//右键编辑工程内容、服务内容、签证及索赔依据
  2234. let infoText = "请输入";
  2235. switch (fieldID){
  2236. case "engineeringContent":
  2237. infoText +='工程内容:';
  2238. break;
  2239. case "serviceContent":
  2240. infoText +='服务内容:';
  2241. break;
  2242. case "claimVisa":
  2243. infoText +='签证及索赔依据:';
  2244. break;
  2245. }
  2246. hintBox.valueBox(infoText, node.data[fieldID], function () {
  2247. let newValue = hintBox.value;
  2248. projectObj.updateNodeField(node,newValue,fieldID);
  2249. },3);
  2250. },
  2251. ifItemCharHiden:function (setting) {//项目特征及内容列是否隐藏
  2252. if(this.itemCol == null||this.itemCol == undefined){
  2253. this.itemCol = _.find(setting.cols,function (item) {
  2254. return item.data.field == "itemCharacterText";
  2255. })
  2256. }
  2257. return !this.itemCol.visible;
  2258. },
  2259. onCommonTotalFeeButtonClick:function(hitinfo) {
  2260. let me = calcBaseView;
  2261. if(hitinfo.sheet.getParent() === projectObj.mainSpread){
  2262. let node = projectObj.project.mainTree.items[hitinfo.row] ? projectObj.project.mainTree.items[hitinfo.row] : null;
  2263. projectObj.mainController.setTreeSelected(node);
  2264. }
  2265. hitinfo.sheet.setActiveCell(hitinfo.row, hitinfo.col);
  2266. calcBaseView.confirmBtn.attr('toggle', 'commonTotalFee');
  2267. changeCalcBaseFeeRate('commonTotalFee');
  2268. $('#tabCalcBase').tab('show');
  2269. let field = projectObj.mainController.setting.cols[hitinfo.col].data.field;
  2270. calcBaseView.initCalctor('bills',field);
  2271. feeRateObject.showSelectModal(hitinfo);
  2272. },
  2273. selectColAndFocus :function (newNode,field = 'code') {//选中单元格并设置焦点
  2274. if(newNode){
  2275. if(field != null) projectObj.mainController.sheet.setSelection(newNode.serialNo(), colSettingObj.getColByField(field), 1, 1); //自动定位到编号单元格
  2276. projectObj.mainSpread.focus();
  2277. }
  2278. },
  2279. cusRationCombCheck:function (sheet) {//检查自定义定额编号下拉框,右键的时候不自动消失,现手动结束编辑,并删除元素
  2280. if(sheet.isEditing()){
  2281. sheet.endEdit()
  2282. }
  2283. if($("#rationCheckBox").is(':visible')) $("#rationCheckBox").parent().parent().remove();
  2284. }
  2285. };
  2286. // 点击合计框中的复制
  2287. $("body").on("click", "#total-tips a", function() {
  2288. const totalElement = $(this).parent().siblings("p").find("#total");
  2289. totalElement.select();
  2290. document.execCommand("Copy");
  2291. $(this).text("已复制");
  2292. });
  2293. // 合计框点击其他位置关闭
  2294. let isTotalShowing = false;
  2295. $("body").on("click", function(e) {
  2296. if (isTotalShowing && !$(e.target).is("#total-tips") && !$(e.target).is("#total-tips p") && !$(e.target).is("#total-tips p a")) {
  2297. $("#total-tips").remove();
  2298. isTotalShowing = false;
  2299. }
  2300. });
  2301. $('#insert').click(function () {
  2302. var controller = projectObj.mainController, project = projectObj.project;
  2303. var selected = controller.tree.selected;
  2304. if (!selected || selected.sourceType === project.Bills.getSourceType()) {
  2305. ProjectController.addBills(project, controller);
  2306. } else if (selected.sourceType === project.Ration.getSourceType()) {
  2307. ProjectController.addRation(project, controller, selected.data.type);
  2308. };
  2309. });
  2310. $('#delete').click(function () {
  2311. let project = projectObj.project;
  2312. let selected = project.mainTree.selected;
  2313. if(isSingleSelect()&&selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length<=0){//选中的是分部,并且没有子项,直接删除
  2314. project.Bills.deleteSelectedNode();
  2315. }else {
  2316. $("#delete_row").modal({show:true});//弹出删除提示框;
  2317. }
  2318. });
  2319. $('#upLevel').click(function () {
  2320. var controller = projectObj.mainController, project = projectObj.project;
  2321. var selected = controller.tree.selected, orgParent = selected.parent;
  2322. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  2323. project.Bills.upLevelBills(selected.source);
  2324. controller.upLevel();
  2325. controller.refreshTreeNode([orgParent]);
  2326. projectObj.project.calcProgram.calcNodesAndSave([selected,orgParent]);
  2327. }
  2328. });
  2329. $('#downLevel').click(function () {
  2330. var controller = projectObj.mainController, project = projectObj.project;
  2331. var selected = controller.tree.selected;
  2332. if (selected && selected.sourceType === project.Bills.getSourceType()) {
  2333. project.Bills.downLevelBills(selected.source);
  2334. controller.downLevel();
  2335. controller.refreshTreeNode([selected.parent]);
  2336. projectObj.converseCalculateBills(selected.parent);
  2337. }
  2338. });
  2339. $('#insertRation').click(function () {
  2340. // projectObj.project.Ration.addNewRation(null,rationType.ration);
  2341. // 连续点工具栏的插入定额按钮,显示树结构画线有问题。
  2342. //projectObj.project.Ration.addNewRationFast(rationType.ration,projectObj.selectColAndFocus);
  2343. //2020-01-08 要限制定额数量,所以还是要用等回传信息的方式插入定额
  2344. projectObj.project.Ration.addNewRation(null,rationType.ration,projectObj.selectColAndFocus,false);
  2345. });
  2346. $('#upMove').click(function () {
  2347. var controller = projectObj.mainController, project = projectObj.project;
  2348. var selected = controller.tree.selected, pre = selected.preSibling, preSerialNo;
  2349. if (selected.sourceType === project.Bills.getSourceType()) {
  2350. project.Bills.upMoveBills(selected.source);
  2351. controller.upMove();
  2352. } else if (selected.sourceType === project.Ration.getSourceType()) {
  2353. project.Ration.changePos(selected.source, selected.preSibling.source);
  2354. controller.upMove();
  2355. };
  2356. });
  2357. $('#downMove').click(function () {
  2358. var controller = projectObj.mainController, project = projectObj.project;
  2359. var selected = controller.tree.selected, next, nextSerialNo;
  2360. if (selected) {
  2361. if (selected.sourceType === project.Bills.getSourceType()) {
  2362. project.Bills.downMoveBills(selected.source);
  2363. controller.downMove();
  2364. } else if (selected.sourceType === project.Ration.getSourceType()) {
  2365. project.Ration.changePos(selected.source, selected.nextSibling.source);
  2366. controller.downMove();
  2367. };
  2368. }
  2369. });
  2370. $("a[name='lockBills']").click(function () {//点击锁定/解锁清单
  2371. let lockBills = projectObj.project.projectInfo.property.lockBills;
  2372. lockBills = !lockBills;
  2373. projectObj.project.updateLockBills(lockBills,function () {
  2374. var controller = projectObj.mainController, project = projectObj.project;
  2375. var selected = controller.tree.selected;
  2376. let nodes = _.filter(project.mainTree.items,{'sourceType':ModuleNames.bills});
  2377. controller.refreshTreeNode(nodes);
  2378. projectObj.mainController.setTreeSelected(selected);//触发树节点选中事件
  2379. projectObj.loadLockBillsButton();
  2380. $('#tzCharacterText').prop('readonly', lockBills);
  2381. if(!projectReadOnly){
  2382. pageCCOprObj.refreshRuleTools(lockBills);
  2383. }
  2384. //$("[data-toggle='tooltip']").tooltip('hide'); bs 与 jqueryUI冲突
  2385. });
  2386. });
  2387. $('#ZLFB_btn').click(function () {
  2388. zlfb_object.getSectionInfo();
  2389. });
  2390. //显示至..
  2391. let displayLevel = function(nodes, depth, type){
  2392. let refreshNodes = [];
  2393. function getExpandedController(){
  2394. if(type === 'DXFY' || type === 'FB'){
  2395. if(type === 'FB'){
  2396. projectObj.project.mainTree.items[0].setExpanded(true);
  2397. refreshNodes.push(projectObj.project.mainTree.items[0]);
  2398. }
  2399. return function expandedControl(nodes, depth){
  2400. let bType = type === 'FB' ? billType.FB : billType.DXFY;
  2401. for(let node of nodes){
  2402. let nodeDepth = node.depth();
  2403. if(nodeDepth <= depth){
  2404. let expanded = nodeDepth === depth && !node.children[0] || nodeDepth < depth && node.children[0] && node.children[0].data.type === bType ? true : false;
  2405. node.setExpanded(expanded);
  2406. refreshNodes.push(node);
  2407. if(nodeDepth < depth){
  2408. expandedControl(node.children, depth);
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. else if(type === 'FX' || type === 'ZM' || type === 'ZD'){
  2415. return function expandedControl(nodes){
  2416. for(let node of nodes){
  2417. if(type !== 'FX' || node.sourceType === projectObj.project.Bills.getSourceType()){
  2418. let expanded = true;
  2419. if(type === 'FX'){
  2420. expanded = !node.children[0] || node.children[0] && node.children[0].sourceType === projectObj.project.Bills.getSourceType() ? true : false;
  2421. }
  2422. else if(type === 'ZM'){
  2423. expanded = !node.children[0] || node.children[0] && node.children[0].sourceType !== projectObj.project.ration_glj.getSourceType() ? true : false;
  2424. }
  2425. node.setExpanded(expanded);
  2426. refreshNodes.push(node);
  2427. expandedControl(node.children);
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. getExpandedController()(nodes, depth);
  2434. let sheet = projectObj.mainSpread.getActiveSheet();
  2435. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  2436. TREE_SHEET_HELPER.refreshNodesVisible(refreshNodes, projectObj.mainSpread.getActiveSheet(), true)
  2437. });
  2438. };
  2439. //导入下拉
  2440. $('#importSpan').click(function () {
  2441. $('[data-toggle="tooltip"]').tooltip('hide');
  2442. let toggle = $('#importDropDown').attr('data-toggle');
  2443. if (toggle) {
  2444. $('#importDropDown').removeAttr('data-toggle');
  2445. }
  2446. $('#importDropDown').dropdown('toggle');
  2447. setTimeout(function () {
  2448. $('#importDropDown').attr('data-toggle', 'dropdown');
  2449. }, 100);
  2450. });
  2451. $('#importDropDown').click(function () {
  2452. $('[data-toggle="tooltip"]').tooltip('hide');
  2453. });
  2454. //导出接口下拉
  2455. $('#exportSpan').click(function () {
  2456. $('[data-toggle="tooltip"]').tooltip('hide');
  2457. let toggle = $('#exportSpan>a').attr('data-toggle');
  2458. if (toggle) {
  2459. $('#exportSpan>a').removeAttr('data-toggle');
  2460. }
  2461. $('#exportSpan>a').dropdown('toggle');
  2462. setTimeout(function () {
  2463. $('#exportSpan>a').attr('data-toggle', 'dropdown');
  2464. }, 100);
  2465. });
  2466. $('#exportSpan>a').click(function () {
  2467. $('[data-toggle="tooltip"]').tooltip('hide');
  2468. });
  2469. $('body').click(function () {
  2470. //点击完后隐藏子菜单
  2471. if ($('#subDisplay').is(':visible')) {
  2472. $('#subDisplay').removeClass('show');
  2473. }
  2474. });
  2475. let enterDisplayA = false;
  2476. //鼠标移到显示至,自动弹出子菜单
  2477. $('#displayA').click(function () {
  2478. return false;
  2479. });
  2480. $('#displayA').mouseenter(function (e) {
  2481. enterDisplayA = true;
  2482. $('#subDisplay').addClass('show');
  2483. });
  2484. $('#displayA').mouseleave(function () {
  2485. enterDisplayA = false;
  2486. });
  2487. let enterInterfaceDropdown = false;
  2488. $('#interface-dropdown').mouseenter(function () {
  2489. enterInterfaceDropdown = true;
  2490. $('#interface-dropdown-sub').addClass('show');
  2491. });
  2492. $('#interface-dropdown').mouseleave(function () {
  2493. enterInterfaceDropdown = false;
  2494. });
  2495. $('#interface-dropdown').click(function() {
  2496. return false;
  2497. });
  2498. let enterZLFB = false
  2499. $('#ZLFB_MENU').mouseenter(function () {
  2500. enterZLFB = true;
  2501. $('#ZLFB_MENU_sub').addClass('show');
  2502. });
  2503. $('#ZLFB_MENU').mouseleave(function () {
  2504. enterZLFB = false;
  2505. });
  2506. $('#ZLFB_MENU').click(function() {
  2507. return false;
  2508. });
  2509. $('#moreMenu > a').mouseenter(function () {
  2510. if (!enterDisplayA) {
  2511. $('#subDisplay').removeClass('show');
  2512. }
  2513. if (!enterInterfaceDropdown) {
  2514. $('#interface-dropdown-sub').removeClass('show');
  2515. }
  2516. if(!enterZLFB){
  2517. $('#ZLFB_MENU_sub').removeClass('show');
  2518. }
  2519. });
  2520. $('#displayDXFY').click(function () {
  2521. displayLevel(projectObj.project.mainTree.items, 0, 'DXFY')
  2522. });
  2523. //显示至一级分部
  2524. $('#displayFB1').click(function () {
  2525. displayLevel(projectObj.project.mainTree.items[0].children, 1, 'FB');
  2526. });
  2527. //二级分部
  2528. $('#displayFB2').click(function () {
  2529. displayLevel(projectObj.project.mainTree.items[0].children, 2, 'FB');
  2530. });
  2531. //三级分部
  2532. $('#displayFB3').click(function () {
  2533. displayLevel(projectObj.project.mainTree.items[0].children, 3, 'FB');
  2534. });
  2535. //四级分部
  2536. $('#displayFB4').click(function () {
  2537. displayLevel(projectObj.project.mainTree.items[0].children, 4, 'FB');
  2538. });
  2539. //分项
  2540. $('#displayFX').click(function () {
  2541. displayLevel(projectObj.project.mainTree.items, null, 'FX');
  2542. });
  2543. //子目
  2544. $('#displayZM').click(function () {
  2545. displayLevel(projectObj.project.mainTree.items, null, 'ZM');
  2546. });
  2547. //最底层
  2548. $('#displayZD').click(function () {
  2549. displayLevel(projectObj.project.mainTree.roots, null, 'ZD');
  2550. });
  2551. $('#poj-set').on('show.bs.modal', function () {
  2552. //建设项目-编制说明
  2553. let compilationIVP = projectObj.project.property.compilationIllustrationProject ? projectObj.project.property.compilationIllustrationProject : '';
  2554. $('#compilationIllustrationP textarea').val(compilationIVP);
  2555. //单位工程-编制说明
  2556. let compilationIV = projectObj.project.property.compilationIllustration ? projectObj.project.property.compilationIllustration : '';
  2557. $('#compilationIllustration textarea').val(compilationIV);
  2558. let setCalcFlag = function (obj, val, curFlag) {
  2559. obj.val(val);
  2560. if (val === curFlag) {
  2561. obj.prop('checked', true);
  2562. } else {
  2563. obj.prop('checked', false);
  2564. }
  2565. }
  2566. if (projectObj.project) {
  2567. //江西重定义了leafBillGetFeeType的内容
  2568. let ft = (projectObj.project.property.billsCalcMode !== undefined && projectObj.project.property.billsCalcMode !== null) ?
  2569. projectObj.project.property.billsCalcMode : leafBillGetFeeType.rationContent; // 广东默认取1不是0,但这里不动,防止这种情况:旧项目默认无值,按取0算的,你改成1了,计算结果会变。
  2570. let zg = projectObj.project.property.zanguCalcMode !== undefined &&
  2571. projectObj.project.property.zanguCalcMode !== null ? projectObj.project.property.zanguCalcMode : zanguCalcType.common;
  2572. setCalcFlag($('#rationContent'), leafBillGetFeeType.rationContent, ft);
  2573. setCalcFlag($('#rationPriceConverse'), leafBillGetFeeType.rationPriceConverse, ft);
  2574. setCalcFlag($('#rationPrice'), leafBillGetFeeType.rationPrice, ft);
  2575. setCalcFlag($('#billsPrice'), leafBillGetFeeType.billsPrice, ft);
  2576. setCalcFlag($('#zangu_common'), zanguCalcType.common, zg);
  2577. setCalcFlag($('#zangu_gatherMaterial'), zanguCalcType.gatherMaterial, zg);
  2578. let showAdjustPrice = projectObj.project.projSetting.glj_col?projectObj.project.projSetting.glj_col.showAdjustPrice:false;
  2579. showAdjustPrice === true ? $("#tab_poj-settings-6").show():$("#tab_poj-settings-6").hide();
  2580. projDisplayView.init();
  2581. calcOptions.init();
  2582. }
  2583. });
  2584. //恢复默认列设置
  2585. $('#recColSetting').click(function () {
  2586. let libID = projectObj.project.property.colLibID ? projectObj.project.property.colLibID : null;
  2587. if(!libID){
  2588. alert('项目没有绑定标准列设置');
  2589. return;
  2590. }
  2591. $(this).addClass('disabled');
  2592. CommonAjax.post('/project/getDefaultColSetting', {libID: libID}, function (rstData) {
  2593. if(!rstData || rstData.length === 0){
  2594. alert('标准列设置没有数据');
  2595. $('#recColSetting').removeClass('disabled');
  2596. return;
  2597. }
  2598. let sheet = colSettingObj.settingSpread.getActiveSheet();
  2599. SheetDataHelper.massOperationSheet(sheet, function () {
  2600. for(let row = 0; row < sheet.getRowCount(); row++){
  2601. sheet.setValue(row, 0, rstData.main_tree_col.cols[row].visible);
  2602. }
  2603. });
  2604. $('#recColSetting').removeClass('disabled');
  2605. }, function () {
  2606. $('#recColSetting').removeClass('disabled');
  2607. });
  2608. });
  2609. //恢复默认系统设置
  2610. $('#property_default').click(function () {
  2611. let project = projectObj.project,
  2612. projectID = project.ID();
  2613. /*
  2614. * 清除窗口比例缓存
  2615. * */
  2616. //清单精灵/指引窗口比例
  2617. removeLocalCache('stdBillsGuidanceTabmainWidth');
  2618. removeLocalCache('stdBillsGuidanceTabmainSideWidth');
  2619. // 清单展开状态
  2620. window.sessionStorage.removeItem('stdBillsGuidanceExpState');
  2621. //定额库窗口比例
  2622. removeLocalCache('stdRationTabmainWidth');
  2623. removeLocalCache('stdRationTabmainSideWidth');
  2624. removeLocalCache('dedeTopDivHeight');
  2625. removeLocalCache('dedeBottomDivHeight');
  2626. //查找定位窗口比例
  2627. removeLocalCache('locateTabmainWidth');
  2628. removeLocalCache('locateTabmainSideWidth');
  2629. removeLocalCache('locatelocateTopDivHeight');
  2630. removeLocalCache('locatelocateBottomDivHeight');
  2631. //块模板库窗口比例
  2632. removeLocalCache('kmbkkmbkTopDivHeight');
  2633. removeLocalCache('kmbkkmbkMidDivHeight');
  2634. removeLocalCache('kmbkkmbkBottomDivHeight');
  2635. //主界面窗口比例
  2636. removeLocalCache('mainVerticaltop_divHeight');
  2637. removeLocalCache('mainVerticalbottom_divHeight');
  2638. //造价书下方-人材机和项目特征文本
  2639. removeLocalCache('subRcjsubSpreadWidth');
  2640. removeLocalCache('subRcjitemTextDivWidth');
  2641. //造价书下方-子目换算下调整状态和辅助值
  2642. removeLocalCache('subRcjitemTextDivWidth');
  2643. removeLocalCache('subRcjitemTextDivWidth');
  2644. //造价书下方-特征及内容窗口比例
  2645. removeLocalCache('subZmhscoeSpreadWidth');
  2646. removeLocalCache('subZmhsassDivWidth');
  2647. //人材机汇总窗口比例
  2648. removeLocalCache('projectGljprojectGljTopHeight');
  2649. removeLocalCache('projectGljprojectGljBottomHeight');
  2650. //补充人材机库
  2651. removeLocalCache('compleGLjleftContentWidth');
  2652. removeLocalCache('compleGLjmidContentWidth');
  2653. removeLocalCache('compleGLjrightContentWidth');
  2654. //补充定额库
  2655. removeLocalCache('compleRationleftContentWidth');
  2656. removeLocalCache('compleRationmainContentWidth');
  2657. removeLocalCache('compleRationzmhsContentWidth');
  2658. removeLocalCache('compleRationrationItemsSheetHeight');
  2659. removeLocalCache('compleRationsubContentHeight');
  2660. removeLocalCache('compleRationmainSpreadHeight');
  2661. removeLocalCache('compleRationcontentSpreadHeight');
  2662. //在后台恢复一些设置
  2663. CommonAjax.post('/pm/api/defaultSettings', {user_id: userID, projectID: projectID}, function (rstData) {
  2664. window.location.href = `/main?project=${projectID}`;
  2665. });
  2666. });
  2667. $('#property_ok').click(function () {
  2668. let project = projectObj.project,
  2669. projectID = project.ID(),
  2670. properties = {},
  2671. options = {},
  2672. labourCoes = {},
  2673. rations = [],
  2674. bills = [],
  2675. mixDatas = {
  2676. projectID: projectID,
  2677. updateType: 'update',
  2678. properties: properties,
  2679. options: options,
  2680. labourCoes: labourCoes,
  2681. rations: rations,
  2682. bills: bills
  2683. },
  2684. reCalcBills = false,
  2685. reCalcRations = false;
  2686. let b = parseInt($("input[name='calcFlag']:checked").val());
  2687. if (b !== project.property.billsCalcMode) {
  2688. properties['property.billsCalcMode'] = b;
  2689. project.property.billsCalcMode = b;
  2690. reCalcBills = true;
  2691. };
  2692. let zg = parseInt($("input[name='zangu']:checked").val());
  2693. if (zg !== project.property.zanguCalcMode) {
  2694. properties['property.zanguCalcMode'] = zg;
  2695. project.property.zanguCalcMode = zg;
  2696. reCalcRations = true;
  2697. };
  2698. //基本信息
  2699. if(basicInfoView.toUpdate(basicInfoView.orgDatas, basicInfoView.datas)){
  2700. let saveData = basicInfoView.toSaveDatas(basicInfoView.datas);
  2701. projectObj.project.property.basicInformation = saveData;
  2702. properties['property.basicInformation'] = saveData;
  2703. }
  2704. //建设项目-编制说明
  2705. let compilationIllustrationP = $('#compilationIllustrationP textarea').val();
  2706. if (compilationIllustrationP !== project.property.compilationIllustrationProject) {
  2707. properties['property.compilationIllustrationProject'] = compilationIllustrationP;
  2708. project.property.compilationIllustrationProject = compilationIllustrationP;
  2709. }
  2710. //工程特征
  2711. if(projFeatureView.toUpdate(projFeatureView.orgDatas, projFeatureView.datas)){
  2712. let saveData = projFeatureView.toSaveDatas(projFeatureView.datas);
  2713. projectObj.project.property.projectFeature = saveData;
  2714. properties['property.projectFeature'] = saveData;
  2715. }
  2716. // 清单限价
  2717. const maxPriceRate = $('#max-price-rate') && +$('#max-price-rate').val();
  2718. if (commonUtil.isNumber(maxPriceRate) && maxPriceRate !== projectObj.project.property.maxPriceRate) {
  2719. properties['property.maxPriceRate'] = maxPriceRate;
  2720. }
  2721. const minPriceRate = $('#min-price-rate') && +$('#min-price-rate').val();
  2722. if (commonUtil.isNumber(minPriceRate) && minPriceRate !== projectObj.project.property.minPriceRate) {
  2723. properties['property.minPriceRate'] = minPriceRate;
  2724. }
  2725. //清单工程量精度
  2726. let newBillsDecimalDatas = billsDecimalView.toBillsDecimalDatas(billsDecimalView.cache);
  2727. if(billsDecimalView.toUpdate(billsQuanDecimal.datas, newBillsDecimalDatas)){
  2728. billsQuanDecimal.datas = newBillsDecimalDatas;
  2729. reCalcBills = true;
  2730. properties['property.billsQuantityDecimal'] = newBillsDecimalDatas;
  2731. }
  2732. //小数位数
  2733. let updateDecimal = m_getDecimalData($('input', '#poj-settings-decimal'));
  2734. if(toUpdateDecimal(decimalObj, updateDecimal)) {
  2735. let frChanged = decimalObj.feeRate != updateDecimal.feeRate;
  2736. setDecimal(decimalObj, updateDecimal);
  2737. if (frChanged) {
  2738. project.calcProgram.compileAllTemps()
  2739. }
  2740. reCalcRations = true;
  2741. reCalcBills = true;
  2742. properties['property.decimal'] = updateDecimal;
  2743. }
  2744. // 呈现选项
  2745. projDisplayView.updateChecking(properties);
  2746. //列设置(独立逻辑,只是通过项目属性确定按钮触发)
  2747. if(colSettingObj.dataChanged()){
  2748. colSettingObj.updateColSetting();
  2749. }
  2750. //单位工程-编制说明
  2751. let compilationIllustration = $('#compilationIllustration textarea').val();
  2752. if (compilationIllustration !== project.property.compilationIllustration) {
  2753. properties['property.compilationIllustration'] = compilationIllustration;
  2754. project.property.compilationIllustration = compilationIllustration;
  2755. }
  2756. //系统选项
  2757. if(optionsOprObj.needToSaveGeneralOpts()){
  2758. let v1 = optionsOprObj.rationQuanACToBillsQuan.prop('checked'),
  2759. v2 = optionsOprObj.rationQuanACToRationUnit.prop('checked');
  2760. options.updateData = {
  2761. rationQuanACToBillsQuan: v1,
  2762. rationQuanACToRationUnit: v2
  2763. };
  2764. }
  2765. if(calcOptions.updateChecking(properties)){
  2766. reCalcRations = true;
  2767. }
  2768. // 人工系数
  2769. if (labourCoeView.needSave()){
  2770. let libID = $("#std_labour_coe_files").children("option:selected").val();
  2771. let libName = $("#std_labour_coe_files").children("option:selected").text();
  2772. labourCoes.updateData = {libID: libID, libName: libName, newItemArr: labourCoeView.needUpdateDatas};
  2773. project.labourCoe.refreshData(labourCoes.updateData); // 全编译所用到的人工系数来自project.labourCoe,所以必须先刷新project.labourCoe
  2774. project.calcProgram.compileAllTemps();
  2775. reCalcRations = true;
  2776. reCalcBills = true;
  2777. };
  2778. // 重新计算树节点
  2779. let changedNodes = [];
  2780. if (reCalcRations) // 定额动,全部计算。算完先不存储,和后面的数据一起提交,一次通讯。
  2781. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catAll)
  2782. else if (reCalcBills) // 清单动,可以只计算清单。
  2783. changedNodes = project.calcProgram.calcAllNodes(calcAllType.catBills);
  2784. if (changedNodes.length > 0) {
  2785. for (let node of changedNodes){
  2786. let data = calcTools.cutNodeForSave(node);
  2787. if (node.sourceType == 'ration') rations.push(data)
  2788. else if (node.sourceType == 'bills') bills.push(data);
  2789. };
  2790. };
  2791. // for test.
  2792. /* console.log(mixDatas);
  2793. return; */
  2794. function hasMixData() {
  2795. return Object.keys(mixDatas.properties).length > 0 || mixDatas.options.updateData ||
  2796. mixDatas.labourCoes.updateData || mixDatas.rations.length > 0 || mixDatas.bills.length > 0;
  2797. }
  2798. function needToReload(mixDatas){
  2799. if(Object.keys(mixDatas.labourCoes).length > 0){
  2800. return true;
  2801. }
  2802. if(Object.keys(mixDatas.properties).length > 0){
  2803. if(mixDatas.properties.hasOwnProperty('property.billsCalcMode') ||
  2804. mixDatas.properties.hasOwnProperty('property.zanguCalcMode') ||
  2805. mixDatas.properties.hasOwnProperty('property.calcOptions')||
  2806. mixDatas.properties.hasOwnProperty('property.billsQuantityDecimal')||
  2807. mixDatas.properties.hasOwnProperty('property.decimal')||
  2808. mixDatas.properties.hasOwnProperty('property.displaySetting')){
  2809. return true;
  2810. }
  2811. }
  2812. return false;
  2813. }
  2814. if(hasMixData()){
  2815. CommonAjax.post('/pm/api/updateMixDatas', {user_id: userID, mixDataArr: mixDatas}, function (rstData) {
  2816. //需要重载页面
  2817. if(needToReload(mixDatas)){
  2818. window.location.href = '/main?project=' + projectID;
  2819. }
  2820. else{
  2821. if(mixDatas.properties.hasOwnProperty('property.maxPriceRate')){
  2822. projectObj.project.property.maxPriceRate = maxPriceRate;
  2823. }
  2824. if(mixDatas.properties.hasOwnProperty('property.minPriceRate')){
  2825. projectObj.project.property.minPriceRate = minPriceRate;
  2826. }
  2827. if(mixDatas.properties.hasOwnProperty('property.basicInformation')){
  2828. basicInfoView.orgDatas = basicInfoView.toViewDatas(mixDatas.properties['property.basicInformation']);
  2829. }
  2830. if(mixDatas.properties.hasOwnProperty('property.projectFeature')){
  2831. projFeatureView.orgDatas = projFeatureView.toViewDatas(mixDatas.properties['property.projectFeature']);
  2832. }
  2833. if(mixDatas.options && mixDatas.options.updateData){
  2834. let v1 = mixDatas.options.updateData['rationQuanACToBillsQuan'],
  2835. v2 = mixDatas.options.updateData['rationQuanACToRationUnit'];
  2836. optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToBillsQuan', value: v1});
  2837. optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: v2});
  2838. }
  2839. }
  2840. });
  2841. }
  2842. });
  2843. function testShow() {
  2844. var controller = projectObj.mainController, project = projectObj.project;
  2845. var selected = controller.tree.selected, parent = selected.parent;
  2846. var showinfo = "<label>确认要删除当前选中行吗?</label>";
  2847. var showN = false;
  2848. var cancelText = "否";
  2849. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length>0){//选中的是分部,并且有子项
  2850. if(isSingleSelect()||selectionChecking()){
  2851. showinfo = "<label>是否删除其下的子项?</label><br><label>【是】则删除分部行及其下的所有子项,</label><br><label>【否】则仅删除当前分部行,子项保留,</label><br><label>【取消】则取消删除</label>";
  2852. showN = true;
  2853. cancelText = "取消";
  2854. }
  2855. }
  2856. $('#delete_showinfo').html(showinfo);
  2857. showN==true? $('#deleteN').show():$('#deleteN').hide();
  2858. $('#deleteCancel').text(cancelText);
  2859. function selectionChecking() {
  2860. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  2861. let mainTreeMap = {};
  2862. for(let i =0;i<selection.rowCount;i++){
  2863. let tem_node = controller.tree.items[selection.row+i];
  2864. if(i==0){//第一个直接添加;
  2865. mainTreeMap[tem_node.getID()] = tem_node;
  2866. }else {
  2867. project.Bills.setNodeToMap(tem_node,mainTreeMap);
  2868. }
  2869. }
  2870. let nodes = changeMapToArray(mainTreeMap);
  2871. if(nodes.length==1){
  2872. return true
  2873. }
  2874. return false;
  2875. }
  2876. }
  2877. $('#delete_row').on('show.bs.modal', function (e) {//这里用show,在shown之前调用,页面不会出现按钮闪现的情况
  2878. var controller = projectObj.mainController, project = projectObj.project;
  2879. var selected = controller.tree.selected, parent = selected.parent;
  2880. var showinfo = "<label>确认要删除当前选中行吗?</label>";
  2881. var showN = false;
  2882. var cancelText = "否";
  2883. if(selected.sourceType == project.Bills.getSourceType()&&selected.data.type==billType.FB&&selected.children.length>0){//选中的是分部,并且有子项
  2884. if(isSingleSelect()||selectionChecking()){
  2885. showinfo = "<label>是否删除其下的子项?</label><br><label>【是】则删除分部行及其下的所有子项,</label><br><label>【否】则仅删除当前分部行,子项保留,</label><br><label>【取消】则取消删除</label>";
  2886. showN = true;
  2887. cancelText = "取消";
  2888. }
  2889. }else if(isSingleSelect()&&mbzm_obj.hasReferenceRation(selected)){//“有模板关联的定额”右键点击删除,弹窗提示“删除主子目时将删除对应的关联子目,是否继续? 是 否” (只有单选中一条定额并且是有模板关联的定额)
  2890. showinfo = "<label>删除主子目时将删除对应的关联子目,是否继续?</label>";
  2891. }
  2892. $('#delete_showinfo').html(showinfo);
  2893. showN==true? $('#deleteN').show():$('#deleteN').hide();
  2894. $('#deleteCancel').text(cancelText);
  2895. function selectionChecking() {
  2896. let selection = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  2897. let mainTreeMap = {}, nodes = [];
  2898. for(let i =0;i<selection.rowCount;i++){
  2899. let tem_node = controller.tree.items[selection.row+i];
  2900. if(i==0){//第一个直接添加;
  2901. mainTreeMap[tem_node.getID()] = tem_node;
  2902. }else {
  2903. project.Bills.setNodeToMapAndArray(tem_node,mainTreeMap,nodes);
  2904. }
  2905. }
  2906. if(nodes.length==1){
  2907. return true
  2908. }
  2909. return false;
  2910. }
  2911. });
  2912. function changeMapToArray(map) {
  2913. let newArray = [];
  2914. for(let key in map){
  2915. newArray.push(map[key]);
  2916. }
  2917. return newArray;
  2918. }
  2919. $('#deleteY').click(function () { //正常删除,级联删除子项
  2920. let project = projectObj.project;
  2921. project.Bills.deleteSelectedNodes();
  2922. });
  2923. $('#deleteN').click(function () {//不删除子项
  2924. let controller = projectObj.mainController, project = projectObj.project;
  2925. let selected = controller.tree.selected, parent = selected.parent;
  2926. if(selected){
  2927. let preNode = selected.preSibling;
  2928. let nextNode = selected.nextSibling;
  2929. if(preNode){//有前兄弟
  2930. if(preNode.children.length>0&&preNode.children[0].data.type != selected.children[0].data.type){//并且前兄弟子项和焦点行子项类别不同。
  2931. alert("删除分部会导致分部和分项同级,不允许该操作!");
  2932. return;
  2933. }
  2934. }else if(nextNode){
  2935. if(nextNode.data.type != selected.children[0].data.type){
  2936. alert("删除分部会导致分部和分项同级,不允许该操作! ");
  2937. return;
  2938. }
  2939. }
  2940. project.Bills.singleDeleteBills(selected,controller);
  2941. }
  2942. });
  2943. function isSingleSelect() {//是否选中造价书中的单行
  2944. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  2945. if (selections[0].rowCount == 1) {
  2946. return true;
  2947. }
  2948. return false;
  2949. }
  2950. function ifCanDelete() {
  2951. if (projectReadOnly) {
  2952. return false;
  2953. }
  2954. let selections = projectObj.mainSpread.getActiveSheet().getSelections();
  2955. let tree = projectObj.project.mainTree;
  2956. let selected = projectObj.project.mainTree.selected;
  2957. if(selections[0].rowCount==1){//选中单行
  2958. return canDelete(selected);
  2959. }else {
  2960. return canDelete_m(selections[0]);
  2961. }
  2962. function canDelete(node,m_selection) {
  2963. if (node) {
  2964. if (node.sourceType === projectObj.project.Bills.getSourceType()) {
  2965. if(node.data.type == billType.DXFY&&node.data.isAdd!=1){
  2966. return false;
  2967. }
  2968. if(projectObj.project.isBillsLocked()== true && projectObj.project.withinBillsLocked(node)){
  2969. return false;
  2970. }
  2971. if(projectObj.project.Bills.hasFlags(node)){
  2972. return false;
  2973. }
  2974. }
  2975. if(m_selection!=true&&node.sourceType === projectObj.project.ration_glj.getSourceType()){//多选的时候不做这一项判断
  2976. return false;
  2977. }
  2978. return true;
  2979. } else {
  2980. return false;
  2981. }
  2982. };
  2983. function canDelete_m(selection) {
  2984. for(let i =0;i<selection.rowCount;i++){
  2985. if(tree.items[selection.row+i]==undefined||tree.items[selection.row+i]==null){
  2986. return false;
  2987. }
  2988. if(i==0&&tree.items[selection.row].sourceType === projectObj.project.ration_glj.getSourceType()){
  2989. return false
  2990. }
  2991. if(canDelete(tree.items[selection.row+i],true)==false){
  2992. return false
  2993. }
  2994. }
  2995. return true
  2996. };
  2997. }
  2998. function canInsertRationNode(selected) {//判断是否能插入定额、量价、定额类型工料机, false 不能,true能
  2999. if(!selected)
  3000. return false;
  3001. let project = projectObj.project;
  3002. if(selected.sourceType == ModuleNames.bills && selected.data.type == billType.DXFY){
  3003. return false
  3004. }else if(!(project.Bills.isMeasure(selected)||project.Bills.isFBFX(selected))){
  3005. return false
  3006. }else if(selected.sourceType == ModuleNames.bills && selected.source.children.length > 0){
  3007. return false
  3008. }
  3009. else {
  3010. return true
  3011. }
  3012. }
  3013. //导入类型(09表、广联达)
  3014. const uploadType = {general: 'general', lj: 'lj', gld: 'gld'};
  3015. let fileType = uploadType.lj;
  3016. $('#uploadLj').click(function () {
  3017. $('#example-gld').hide();
  3018. $('#example-general').show();
  3019. fileType = uploadType.lj;
  3020. });
  3021. $('#uploadGld').click(function () {
  3022. $('#example-general').hide();
  3023. $('#example-gld').show();
  3024. fileType = uploadType.gld;
  3025. });
  3026. let importJson = null;
  3027. //选择导入的excel文件
  3028. $('#customFile').change(function () {
  3029. let file = $(this)[0];
  3030. let excelFile = file.files[0];
  3031. $('#uploadAlert').hide();
  3032. if(excelFile) {
  3033. let xlsReg = /xls$/g;
  3034. if(excelFile.name && xlsReg.test(excelFile.name)){
  3035. showUploadAlert(false, '请选择xlsx文件');
  3036. $(this).val('');
  3037. return;
  3038. }
  3039. $('.custom-file-label').text(`${file.files[0].name}`);
  3040. $('#uploadAlert').hide();
  3041. $.bootstrapLoading.start();
  3042. $('#loadingPage').css('z-index', '2000');
  3043. //前端解析excel数据
  3044. if(importJson){
  3045. importJson = null;
  3046. }
  3047. let excelIo = new GC.Spread.Excel.IO();
  3048. let sDate = +new Date();
  3049. excelIo.open(excelFile, function (json) {
  3050. importJson = json;
  3051. console.log(json);
  3052. //读取各个表及表名
  3053. importBills.setImportSheetsInfo(importJson.sheets);
  3054. console.log(`解析Excel文件时间:${+new Date() - sDate}`);
  3055. $.bootstrapLoading.end();
  3056. }, function (e) {
  3057. $.bootstrapLoading.end();
  3058. alert(e.errorMessage);
  3059. });
  3060. }
  3061. });
  3062. //线上nginx请求体最大设置为100m
  3063. //从excel导入清单
  3064. $('#importConfirm').click(function () {
  3065. let me = this;
  3066. $(me).addClass('disabled');
  3067. try{
  3068. $.bootstrapLoading.start();
  3069. $('#loadingPage').css('z-index', '2000');
  3070. let formData = new FormData();
  3071. let file = $('#customFile')[0];
  3072. if(file.files.length <= 0){
  3073. throw '未选择文件';
  3074. }
  3075. let projectID = scUrlUtil.GetQueryString('project');
  3076. if(!projectID || projectID <= 0){
  3077. throw '项目数据出错';
  3078. }
  3079. let sDate = +new Date();
  3080. formData.append('projectID', projectID);
  3081. //要去匹配的清单库(第一个)
  3082. let matchBillLibId = projectObj.project.projectInfo.engineeringInfo.bill_lib.length > 0 ? projectObj.project.projectInfo.engineeringInfo.bill_lib[0].id : null;
  3083. formData.append('billsLibId', matchBillLibId);
  3084. //选择的表及导入位置
  3085. let importSheetsInfo = importBills.getImportSheetsInfo();
  3086. if(importSheetsInfo.length === 0){
  3087. throw '请勾选要导入的表';
  3088. }
  3089. let importSheets = importBills.getImportSheets(importJson.sheets, importSheetsInfo, fileType);
  3090. console.log(`importSheets`);
  3091. console.log(importSheets);
  3092. let invalidSheetsInfo = importSheets.invalidSheets.join('、');
  3093. //获取同类表的有效数据
  3094. let importBillsData = importBills.getImportData(importSheets.validSheets, projectID);
  3095. if(!importBills.excelHasValidBills(importBillsData)){
  3096. throw 'excel无有效数据'
  3097. }
  3098. let compressData = LZString.compressToUTF16(JSON.stringify(importBillsData));
  3099. formData.append('compressData', compressData);
  3100. let eDate = +new Date();
  3101. console.log(`解析excel数据时间:${eDate - sDate}`);
  3102. $.ajax({
  3103. url: '/bills/import',
  3104. type: 'POST',
  3105. data: formData,
  3106. cache: false,
  3107. contentType: false,
  3108. processData: false,
  3109. success: function(response){
  3110. if (response.err === 0) {
  3111. if(invalidSheetsInfo !== ''){
  3112. alert(`${invalidSheetsInfo},导入失败。`);
  3113. }
  3114. // 成功则关闭窗体
  3115. $('#import').modal("hide");
  3116. //更新前端
  3117. doAfterImport(response.data);
  3118. if($.bootstrapLoading.isLoading()){
  3119. $.bootstrapLoading.end();
  3120. }
  3121. } else {
  3122. const message = response.msg !== undefined ? response.msg : '上传失败!';
  3123. $.bootstrapLoading.end();
  3124. alert(message);
  3125. }
  3126. $(me).removeClass('disabled');
  3127. },
  3128. error: function(jqXHR){
  3129. alert(`与服务器通信发生错误${jqXHR.status} ${jqXHR.statusText}`);
  3130. $.bootstrapLoading.end();
  3131. $(me).removeClass('disabled');
  3132. }
  3133. });
  3134. }
  3135. catch (err){
  3136. console.log(err);
  3137. showUploadAlert(false, err);
  3138. $(me).removeClass('disabled');
  3139. if($.bootstrapLoading.isLoading()){
  3140. $.bootstrapLoading.end();
  3141. }
  3142. }
  3143. });
  3144. function showUploadAlert(success, msg){
  3145. if(!success){
  3146. $('#uploadAlert').removeClass('alert-success');
  3147. $('#uploadAlert').addClass('alert-danger');
  3148. }
  3149. else{
  3150. $('#uploadAlert').removeClass('alert-danger');
  3151. $('#uploadAlert').addClass('alert-success');
  3152. }
  3153. $('#uploadAlert').text(msg);
  3154. $('#uploadAlert').show();
  3155. }
  3156. //导入清单到一个固定行位置后,更新数据
  3157. function doAfterImportPosition(positionData){
  3158. let nodes = projectObj.project.mainTree.nodes;
  3159. let bills_datas = projectObj.project.Bills.datas;
  3160. let ration_datas = projectObj.project.Ration.datas;
  3161. let quantity_detail_datas = projectObj.project.quantity_detail.datas;
  3162. let ration_glj_datas = projectObj.project.ration_glj.datas;
  3163. let ration_coe_datas = projectObj.project.ration_coe.datas;
  3164. let ration_install_datas = projectObj.project.ration_installation.datas;
  3165. let delNodes = [];
  3166. for(let billID of positionData.remove.bill){
  3167. if(nodes['id_' + billID]){
  3168. delNodes.push(nodes['id_' + billID]);
  3169. }
  3170. //清除清单数据
  3171. _.remove(bills_datas, {ID: billID});
  3172. //清除清单工程量明细数据
  3173. _.remove(quantity_detail_datas, {billID: billID});
  3174. }
  3175. for(let rationID of positionData.remove.ration){
  3176. //清除定额数据
  3177. _.remove(ration_datas, {ID: rationID});
  3178. //清除定额下的相关数据
  3179. _.remove(ration_glj_datas, {rationID: rationID});
  3180. _.remove(ration_coe_datas, {rationID: rationID});
  3181. _.remove(ration_install_datas, {rationID: rationID});
  3182. _.remove(quantity_detail_datas, {rationID: rationID});
  3183. }
  3184. //删除节点
  3185. if(delNodes.length > 0){
  3186. //通过固定清单获得删除节点的起始行索引
  3187. let beginRow = null;
  3188. if(positionData.fixedBill){
  3189. let fixedNode = nodes['id_' + positionData.fixedBill.ID];
  3190. if(fixedNode){
  3191. beginRow = projectObj.project.mainTree.items.indexOf(fixedNode) + 1;
  3192. }
  3193. }
  3194. //删除主树节点
  3195. projectObj.mainController.m_delete(delNodes, beginRow);
  3196. //删除清单树节点
  3197. let delIdNodes = [];
  3198. for(let delNode of delNodes){
  3199. delIdNodes.push(delNode.source);
  3200. }
  3201. projectObj.project.Bills.tree.m_delete(delIdNodes);
  3202. }
  3203. if(positionData.insert.bill.length > 0){
  3204. //设置flagsIndex
  3205. for(let insertBill of positionData.insert.bill){
  3206. insertBill.flagsIndex = {};
  3207. if (insertBill.flags) {
  3208. insertBill.flags.forEach(function (flag) {
  3209. insertBill.flagsIndex[flag.fieldName] = flag;
  3210. });
  3211. }
  3212. }
  3213. //插入清单节点
  3214. projectObj.project.Bills.tree.insertByDatas(positionData.insert.bill);
  3215. //插入主树节点
  3216. let newNodes = projectObj.project.mainTree.insertByDatas(positionData.insert.bill);
  3217. for(let node of newNodes){
  3218. node.source = projectObj.project.Bills.tree.nodes['id_' + node.getID()];
  3219. node.data = node.source.data;
  3220. node.sourceType = projectObj.project.Bills.getSourceType();
  3221. }
  3222. ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes);
  3223. }
  3224. if (positionData.insert.ration.length) {
  3225. const rationNodes = [];
  3226. positionData.insert.ration.forEach(ration => {
  3227. projectObj.project.Ration.datas.push(ration);
  3228. const rationNode = projectObj.project.mainTree.insert(ration.billsItemID, -1, ration.ID);
  3229. rationNode.source = ration;
  3230. rationNode.sourceType = projectObj.project.Ration.getSourceType();
  3231. rationNode.data = ration;
  3232. rationNodes.push(rationNode);
  3233. });
  3234. ProjectController.syncDisplayNewNodes(projectObj.mainController, rationNodes);
  3235. }
  3236. }
  3237. //导入后更新操作
  3238. function doAfterImport(resData){
  3239. if(resData && resData.length > 0){
  3240. for(let positionData of resData){
  3241. doAfterImportPosition(positionData);
  3242. }
  3243. //如果清单未锁定,导入后锁定清单
  3244. /*if(!projectObj.project.projectInfo.property.lockBills){
  3245. $("a[name='lockBills']").click();
  3246. }*/
  3247. $.bootstrapLoading.end();
  3248. //重算
  3249. projectObj.project.calcProgram.calcAllNodesAndSave(calcAllType.catAll, function () {
  3250. projectObj.project.projectGLJ.loadData(function () {
  3251. $.bootstrapLoading.end();
  3252. });
  3253. });
  3254. }
  3255. }
  3256. //下载导入清单示例文件
  3257. $('#uploadExample-general').click(function () {
  3258. window.location.href = `/bills/downloadExamp?type=${uploadType.general}`;
  3259. });
  3260. $('#uploadExample').click(function () {
  3261. window.location.href = `/bills/downloadExamp?type=${fileType === uploadType.lj ? uploadType.lj : uploadType.gld}`;
  3262. });
  3263. $('#uploadExample-lj').click(function () {
  3264. window.location.href = `/bills/downloadExamp?type=${uploadType.lj}`;
  3265. });
  3266. $('#uploadExample-gld').click(function () {
  3267. window.location.href = `/bills/downloadExamp?type=${uploadType.gld}`;
  3268. });
  3269. $(function () {
  3270. //清空导入清单选择文件
  3271. $('#import').on('show.bs.modal', function(){
  3272. $('#customFile').val('');
  3273. $('#uploadAlert').hide();
  3274. $('.custom-file-label').text(`请选择上传文件`);
  3275. });
  3276. $('#import').on('hidden.bs.modal', function () {
  3277. //恢复选择表高度
  3278. $('#uploadSheets').height('');
  3279. $('#uploadSheets').hide();
  3280. $('#uploadSheetsHead').hide();
  3281. });
  3282. /* $("#billsSpread").mouseover(function(){
  3283. spreadAutoFocus(projectObj.mainSpread,subSpread);
  3284. });
  3285. $("#subSpread").mouseover(function(){
  3286. spreadAutoFocus(subSpread,projectObj.mainSpread);
  3287. });
  3288. */
  3289. $("#paste_confirm").click(function (){
  3290. let selected = projectObj.project.mainTree.selected;
  3291. let blockData = BlockController.getBlockData();
  3292. let position = $("input[name='pastePositionRadio']:checked").val();
  3293. BlockController.confirmPaste(blockData,selected,position);
  3294. $("#pastePosition").modal("hide");
  3295. });
  3296. $("#div_createBlocks").on('show.bs.modal', function(){
  3297. function getBlockCategoriesHtml(Categories) {
  3298. let result = '';
  3299. if (Categories.length <= 0) return result;
  3300. for (let c of Categories){
  3301. result += '<option value="'+ c.data.ID +'">'+ c.data.nodeName +'</option>';
  3302. };
  3303. return result;
  3304. };
  3305. let sHtml = getBlockCategoriesHtml(blockLibObj.getCategories());
  3306. $("#select_block_category").html(sHtml);
  3307. $("#select_block_category")[0].selectedIndex = 0;
  3308. $('#ckb_block_exist_cover').prop("checked", false);
  3309. });
  3310. $("#div_cloneOptions").on('show.bs.modal', function(){
  3311. let s = '';
  3312. switch (blockLibObj.cloneType) {
  3313. case 1:
  3314. s = '一对一克隆';
  3315. break;
  3316. case 2:
  3317. s = '一对多克隆';
  3318. break;
  3319. case 3:
  3320. s = '多对多克隆';
  3321. break;
  3322. }
  3323. s = `<span style='color:red;'>${s}</span>`;
  3324. $('#clone_option_title').html(`快速组价 (${s})`);
  3325. $('#clone_option_code').prop("checked", true);
  3326. $('#clone_option_name').prop("checked", false);
  3327. $('#clone_option_unit').prop("checked", true);
  3328. $('#clone_option_quantity').prop("checked", true);
  3329. $('#clone_option_cover').prop("checked", true);
  3330. });
  3331. $("#btn_block_createBlocks").click(async function () {
  3332. if ($("#select_block_category")[0].options.length < 1) return;
  3333. let cID = $("#select_block_category").val();
  3334. let selected = projectObj.project.mainTree.selected;
  3335. let cover = $('#ckb_block_exist_cover').prop("checked");
  3336. async function createBlocks(aNode, categoryID){
  3337. async function createBlock(node) {
  3338. if (node.data.name == undefined || node.data.name == '') return; // 清单名称为空,不生成块模板文件
  3339. if (node.children.length == 0) return;
  3340. // 封装成伟城的块文件格式,直接调用伟城接口(定额这里的业务太多太庞杂,不要再重做一遍,尽量共用,维护代价小)
  3341. // 块文件要构建自己的树结构,所以也有自己的一部分数据。两种结构揉合在一起,显得有点杂乱,但利大于弊。
  3342. let vBlock_WC = {
  3343. compilationID: projectObj.project.projectInfo.compilation,
  3344. firstNodeType: node.data.type,
  3345. isFBFX: projectObj.project.Bills.isFBFX(node),
  3346. copyTime: +new Date(),
  3347. datas: []
  3348. };
  3349. let ration_glj_Map = _.groupBy(projectObj.project.ration_glj.datas, 'rationID');
  3350. vBlock_WC.datas.push(BlockController.getNodeDatas(node, ration_glj_Map));
  3351. vBlock_WC = JSON.parse(JSON.stringify(vBlock_WC));
  3352. const unitFee = (node.data.feesIndex && node.data.feesIndex.common) ? node.data.feesIndex.common.unitFee : 0;
  3353. let fileName = node.data.code + ' ' + node.data.name + ' ' + node.data.unit + ' ' + unitFee;
  3354. fileName = fileName.replace(/^\s+|\s+$/g, ""); // 只去两头空格
  3355. let extN = blockLibObj.getSameNameNode(fileName);
  3356. if (extN){
  3357. if (cover) blockLibObj.assignData(extN, vBlock_WC);
  3358. }
  3359. else
  3360. await blockLibObj.newNode(2, fileName, categoryID, vBlock_WC);
  3361. };
  3362. async function createRecursion(node){
  3363. if (!node) return;
  3364. if (calcTools.isLeafBill(node)) await createBlock(node);
  3365. if (node.firstChild()) await createRecursion(node.firstChild());
  3366. if (node.nextSibling) await createRecursion(node.nextSibling);
  3367. };
  3368. if (calcTools.isLeafBill(aNode))
  3369. await createBlock(aNode)
  3370. else
  3371. await createRecursion(aNode.firstChild());
  3372. };
  3373. await createBlocks(selected, cID);
  3374. blockLibObj.loadDetailDatas(blockLibObj.mainTree.selected);
  3375. $("#div_createBlocks").modal("hide");
  3376. });
  3377. $("#btn_block_clone_ok").click(async function () {
  3378. let projectNode = projectObj.project.mainTree.selected;
  3379. let block = blockLibObj.mainTree.selected;
  3380. let options = {};
  3381. if ($('#clone_option_code').prop("checked")) options.checkCode = true;
  3382. if ($('#clone_option_name').prop("checked")) options.checkName = true;
  3383. if ($('#clone_option_unit').prop("checked")) options.checkUnit = true;
  3384. if ($('#clone_option_zeroQuantity').prop("checked")) options.zeroQuantity = true;
  3385. if ($('#clone_option_cover').prop("checked")) options.overwriteRations = true;
  3386. let nodes = [];
  3387. let calcNodes = [];
  3388. switch (blockLibObj.cloneType) {
  3389. case 1:
  3390. nodes = await blockLibObj.oneToOneClone(projectNode, block, options);
  3391. calcNodes = calcNodes.concat(nodes[1]);
  3392. break;
  3393. case 2:
  3394. let bills = calcTools.getLeafBills(projectNode);
  3395. for (let bill of bills){
  3396. calcTools.forceSelect(bill);
  3397. nodes = await blockLibObj.oneToOneClone(bill, block, options);
  3398. calcNodes = calcNodes.concat(nodes[1]);
  3399. };
  3400. break;
  3401. case 3:
  3402. let mtmBills = calcTools.getLeafBills(projectNode);
  3403. let mtmBlocks = blockLibObj.mainTree.selected.children;
  3404. for (let mtmBill of mtmBills){
  3405. for (let mtmBlock of mtmBlocks){
  3406. calcTools.forceSelect(mtmBill);
  3407. nodes = await blockLibObj.oneToOneClone(mtmBill, mtmBlock, options);
  3408. calcNodes = calcNodes.concat(nodes[1]);
  3409. };
  3410. };
  3411. break;
  3412. }
  3413. if(calcNodes.length > 0){
  3414. // projectObj.project.calcProgram.calcNodesAndSave(calcNodes, function () {
  3415. // installationFeeObj.calcInstallationFee();
  3416. // });
  3417. projectObj.project.calcProgram.calcNodesAndSave(calcNodes, async function () {
  3418. installationFeeObj.calcInstallationFee();
  3419. await OVER_HEIGHT.reCalcOverHeightFee();
  3420. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(nodes[0]);
  3421. });
  3422. }
  3423. });
  3424. function spreadAutoFocus(spread,relateSpread) {
  3425. if(relateSpread&&relateSpread.getActiveSheet().isEditing()){//关联的spread不在编辑状态的情况下,才自动获得焦点;
  3426. return;
  3427. }else {
  3428. spread?spread.focus():'';
  3429. }
  3430. }
  3431. //项目为只读
  3432. if(projectReadOnly){
  3433. disableTools();
  3434. }
  3435. });
  3436. //项目只读,处理不可操作的工具栏
  3437. function disableTools(){
  3438. //造价书按钮
  3439. $('#insertRation').addClass('disabled');
  3440. $('#delete').addClass('disabled');
  3441. $('#upLevel').addClass('disabled');
  3442. $('#downLevel').addClass('disabled');
  3443. $('#upMove').addClass('disabled');
  3444. $('#downMove').addClass('disabled');
  3445. $('#ZLFB_btn').addClass('disabled');
  3446. //$('#switchTznr').addClass('disabled');
  3447. $('#uploadLj').addClass('disabled');
  3448. $('#uploadGld').addClass('disabled');
  3449. $('a[name="lockBills"]').addClass('disabled');
  3450. //关于计算
  3451. $('#poj-settings-4').find('input').prop('disabled', 'disabled');
  3452. //小数位数
  3453. $('#poj-settings-decimal').find('input').prop('disabled', 'disabled');
  3454. // 清单限价
  3455. $('.limit-price-input').prop('disabled', 'disabled');
  3456. //人工单价调整
  3457. $('#std_labour_coe_files').prop('disabled', 'disabled');
  3458. //呈现选项
  3459. $('#display-setting').find('input').prop('disabled', 'disabled');
  3460. $('#recColSetting').remove();
  3461. //建设项目-编制说明
  3462. $('#compilationIllustrationP textarea').prop('readOnly', true);
  3463. //单位工程-编制说明
  3464. $('#compilationIllustration textarea').prop('readOnly', true);
  3465. //项目属性恢复默认系统设置
  3466. $('#property_default').addClass('disabled');
  3467. //项目属性确定
  3468. $('#property_ok').addClass('disabled');
  3469. // 清单指引
  3470. $('#guidanceInsertRation').addClass('disabled');
  3471. //清单精灵
  3472. $('#elfInsertRation').addClass('disabled');
  3473. $('#elfInsertSingle').addClass('disabled');
  3474. //模板子目:应用、下一条
  3475. $('#apply_mbzm').addClass('disabled');
  3476. $('#next_mbzm').addClass('disabled');
  3477. //特征及内容
  3478. $('#add-rule').find('select').prop('disabled', 'disabled');
  3479. $('#use-to-current').addClass('disabled');
  3480. $('#use-to-all').addClass('disabled');
  3481. $('.bottom-tools').remove();
  3482. //导入
  3483. $('#importConfirm').addClass('disabled');
  3484. //导出
  3485. $('#export-confirm').addClass('disabled');
  3486. $('#exportSpan .dropdown-item').addClass('disabled');
  3487. //选项
  3488. $('#generalOpts1').prop('disabled', 'disabled');
  3489. $('#generalOpts2').prop('disabled', 'disabled');
  3490. //补充库编辑器
  3491. $('.compleRationLib').addClass('disabled');
  3492. $('.compleGljLib').addClass('disabled')
  3493. //库
  3494. //$('#stdBillsGuidanceTab').addClass('disabled');
  3495. $('#stdBillsTab').addClass('disabled');
  3496. //$('#stdRationTab').addClass('disabled');
  3497. $('#blockLibTab').addClass('disabled');
  3498. // 组价模板分享
  3499. $('#btn_block_share').prop('disabled', true);
  3500. //人材机汇总,选择其他、另存使用
  3501. $('a[data-target="#change-unitFile"]').remove();
  3502. $('a[data-target="#unitFile-save-as"]').remove();
  3503. //费率,选择其他、另存使用、重选标准、统一设置相同参数
  3504. $('a[data-target="#change-lv"]').remove();
  3505. $('a[data-target="#copy-lv"]').remove();
  3506. $('#standardSelect').prop('disabled', 'disabled');
  3507. $('#cascadeSet').prop('disabled', 'disabled');
  3508. $('#changeConfirm').prop('disabled', 'disabled');
  3509. //计算程序标准
  3510. $('#calcProgramFileSelect').prop('disabled', 'disabled');
  3511. //调价
  3512. $('#calcPriceOption').prop('disabled', 'disabled');
  3513. $('#gljPriceTenderCoe').prop('readOnly', true);
  3514. $('#tenderGLJQuantity').prop('disabled', 'disabled');
  3515. $('#tenderRationQuantity').prop('disabled', 'disabled');
  3516. $('#cleanTender').prop('disabled', 'disabled');
  3517. $('#calcTender').prop('disabled', 'disabled');
  3518. }
  3519. //根据触发改变计算基数、费率弹出框
  3520. function changeCalcBaseFeeRate(toggle) {
  3521. if(toggle === 'calcBase'){
  3522. $('#mixedHeader').hide();
  3523. $('#normalHeader').show();
  3524. $('#calcBaseFeeRate').find('.modal-title').text('计算基数选择').show();
  3525. $('#calcBaseFeeRate').find('.modal-body').find('button:first').hide();
  3526. $('#calcBaseFeeRate').find('.modal-body').find('ul:first').show();
  3527. $('#calcBaseExp').remove();
  3528. let $textarea = $('<textarea>').attr('id', 'calcBaseExp').prop('rows', 2).addClass('form-control').css('resize', 'none');
  3529. $('#expArea').prepend($textarea);
  3530. }
  3531. else if(toggle === 'feeRate'){
  3532. $('#mixedHeader').hide();
  3533. $('#normalHeader').show();
  3534. $('#calcBaseFeeRate').find('.modal-title').text('费率选择').show();
  3535. $('#calcBaseFeeRate').find('.modal-body').find('button:first').hide();
  3536. $('#calcBaseFeeRate').find('.modal-body').find('ul:first').hide();
  3537. }
  3538. else if(toggle === 'commonTotalFee') {
  3539. $('#normalHeader').hide();
  3540. $('#mixedHeader').show();
  3541. $('#calcBaseFeeRate').find('.modal-body').find('button:first').show();
  3542. $('#calcBaseFeeRate').find('.modal-body').find('ul:first').show();
  3543. $('#calcBaseExp').remove();
  3544. let $textarea = $('<textarea>').attr('id', 'calcBaseExp').prop('rows', 2).addClass('form-control').css('resize', 'none');
  3545. $('#expArea').prepend($textarea);
  3546. }
  3547. }
  3548. //综合合价弹出计算基数费率确认
  3549. $('#calcBaseFeeRateConf').click(function () {
  3550. let toggle = $(this).attr('toggle');
  3551. if(!toggle || toggle !== 'commonTotalFee'){
  3552. return
  3553. }
  3554. let calcBaseValue = calcBaseView.getInputExpr() ? calcBaseView.getInputExpr() : '';
  3555. let selected = projectObj.project.mainTree.selected;
  3556. let needToSave = false,validateFeeRate=false,cusFeeRate = false;
  3557. if($("input[name='editFeeRateOptions']:checked").val() == "0"){ //等于”0“ 是自定义输入,删除费率关联ID,直接取值
  3558. let newVal = null;
  3559. if($("#customFeeRate").val() != ""){
  3560. newVal = number_util.checkNumberValue( $("#customFeeRate").val(),getDecimal("feeRate"));
  3561. if(newVal == null) return
  3562. }
  3563. selected.data.feeRateID = null;
  3564. selected.data.feeRate = newVal;
  3565. selected.changed = true;
  3566. needToSave = true;
  3567. cusFeeRate = true;
  3568. }else {
  3569. validateFeeRate = feeRateObject.checkSelectedFeeRate();
  3570. }
  3571. if(calcBaseValue !== selected.data.calcBase){
  3572. needToSave = true;
  3573. selected.data.userCalcBase = calcBaseValue;
  3574. selected.data.lockUnitPrice = null;
  3575. projectObj.project.calcBase.calculate(selected);
  3576. }
  3577. if(validateFeeRate){
  3578. feeRateObject.submitFeeRateFromBill();
  3579. } else {
  3580. if(calcBaseValue === calcBaseValue){
  3581. $('#calcBaseFeeRate').modal('hide');
  3582. }
  3583. }
  3584. //删除清单基数,要清空单价
  3585. if (projectObj.project.calcBase.success && calcBaseValue === '') {
  3586. calcTools.setFieldValue(selected, 'feesIndex.common.unitFee', 0);
  3587. }
  3588. if(!projectObj.project.calcBase.success && cusFeeRate==false){
  3589. return;
  3590. } else if((!validateFeeRate || selected.data.feeRateID === parseInt(feeRateObject.feeRateSelection.ID)) && needToSave) {
  3591. projectObj.project.calcProgram.calcAndSave(selected);
  3592. $('#calcBaseFeeRate').modal('hide');
  3593. }
  3594. });
  3595. $('#menu_calc_program_manage').click(function () {
  3596. $('#tab_calc_program_manage').click();
  3597. });
  3598. $('#menu_index_info').click(function () {
  3599. $('#tab_index').click();
  3600. });
  3601. // 快速定位
  3602. const FastLocateType = {
  3603. SUB_ENGINERRING: 'subEnginerring',
  3604. MEASURE: 'measure',
  3605. OTHER: 'other',
  3606. };
  3607. const locateCache = {
  3608. [FastLocateType.SUB_ENGINERRING]: null,
  3609. [FastLocateType.MEASURE]: null,
  3610. [FastLocateType.OTHER]: null,
  3611. };
  3612. // 变更焦点行时,将焦点节点存至对应部分的locateCache中,用于快速定位功能
  3613. function locateToCache(node) {
  3614. if (!node) {
  3615. return;
  3616. }
  3617. if (node.isBelongToFlags([fixedFlag.SUB_ENGINERRING])) {
  3618. locateCache[FastLocateType.SUB_ENGINERRING] = node;
  3619. } else if (node.isBelongToFlags([fixedFlag.MEASURE])) {
  3620. locateCache[FastLocateType.MEASURE] = node;
  3621. } else if (node.isBelongToFlags([fixedFlag.OTHER])) {
  3622. locateCache[FastLocateType.OTHER] = node;
  3623. }
  3624. }
  3625. // “分项”、“措施”、“其他”,用于快速定位至对应部分上次的焦点行
  3626. function fastLocate(type) {
  3627. let locatedNode;
  3628. if (type === FastLocateType.SUB_ENGINERRING) {
  3629. locatedNode = locateCache[type] || projectObj.project.mainTree.roots.find(node => node.getFlag() === fixedFlag.SUB_ENGINERRING);
  3630. } else if (type === FastLocateType.MEASURE) {
  3631. locatedNode = locateCache[type] || projectObj.project.mainTree.roots.find(node => node.getFlag() === fixedFlag.MEASURE);
  3632. } else {
  3633. locatedNode = locateCache[type] || projectObj.project.mainTree.roots.find(node => node.getFlag() === fixedFlag.OTHER);
  3634. }
  3635. if (locatedNode && locatedNode !== projectObj.project.mainTree.selected) {
  3636. const locateRow = locatedNode.serialNo();
  3637. const sheet = projectObj.mainController.sheet;
  3638. projectObj.loadFocusLocation(locateRow, sheet.getActiveColumnIndex());
  3639. }
  3640. }
  3641. $('#locate-sub').click(() => {
  3642. fastLocate(FastLocateType.SUB_ENGINERRING);
  3643. });
  3644. $('#locate-measure').click(() => {
  3645. fastLocate(FastLocateType.MEASURE);
  3646. });
  3647. $('#locate-other').click(() => {
  3648. fastLocate(FastLocateType.OTHER);
  3649. });
  3650. // 清单限价
  3651. $('.limit-price-input').bind('input', function () {
  3652. const limitType = $(this).data('limit');
  3653. const orgVal = limitType === 'max'
  3654. ? (projectObj.project.property.maxPriceRate || 0)
  3655. : (projectObj.project.property.minPriceRate || 0);
  3656. try {
  3657. const val = $(this).val();
  3658. if (isNaN(val)) {
  3659. throw '只能输入两位小数数值!';
  3660. }
  3661. const splits = val.split('.');
  3662. const decimalDigits = splits[1] && splits[1].length || 0;
  3663. if (decimalDigits > 2) {
  3664. const roundVal = scMathUtil.roundForObj(val, 2);
  3665. $(this).val(roundVal);
  3666. }
  3667. } catch (err) {
  3668. alert(err);
  3669. $(this).val(orgVal);
  3670. }
  3671. });
  3672. //导出接口
  3673. ExportView.exportListener();