change_revise.js 196 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, converse = false) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. };
  51. $(document).ready(() => {
  52. let stdXmj, stdGcl, searchLedger;
  53. autoFlashHeight();
  54. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  55. if (!billsSpreadSetting.readOnly) {
  56. for (const col of billsSpreadSetting.cols) {
  57. if (!col.readOnly || col.readOnly === false)
  58. col.readOnly = 'readOnly.isChangeAdd';
  59. }
  60. }
  61. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  62. if (!posSpreadSetting.readOnly) {
  63. for (const col of posSpreadSetting.cols) {
  64. if (!col.readOnly || col.readOnly === false)
  65. col.readOnly = 'readOnly.isChangeAdd';
  66. }
  67. }
  68. const billsCol = {
  69. readOnly: {
  70. isChangeAdd: function (data) {
  71. return !readOnly && !data.formc;
  72. },
  73. isChangeList: function (data) {
  74. if (!data) return true;
  75. let edit = !readOnly && !(data.is_leaf && data.b_code);
  76. if (!edit && data.id) {
  77. const lPos = pos.getLedgerPos(data.id);
  78. if (lPos && lPos.length > 0) {
  79. edit = true;
  80. }
  81. }
  82. return edit;
  83. }
  84. }
  85. };
  86. const posCol = {
  87. getValue: {
  88. isChange: function (data) {
  89. if (!data) return 0;
  90. if (!data.name) return 0;
  91. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  92. return cInfo ? 1 : 0;
  93. }
  94. },
  95. readOnly: {
  96. isChangeAdd: function (data) {
  97. return !readOnly && !data.formc && (data.settle_status && data.settle_status === settleStatus.finish);
  98. },
  99. isChangeList: function (data) {
  100. if (!data) return true;
  101. // console.log(data.name);
  102. return !readOnly && !data.name;
  103. }
  104. }
  105. };
  106. // 判断是否是已结算清单
  107. function checkIsSettle(data) {
  108. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  109. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  110. return true;
  111. }
  112. return false;
  113. }
  114. // 初始化spread
  115. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  116. const billsSheet = billsSpread.getActiveSheet();
  117. billsSpreadSetting.rowHeader = [
  118. {
  119. rowHeaderType: 'circle',
  120. setting: {
  121. size: 5,
  122. indent: 16,
  123. getColor: function (index, data) {
  124. if (!data) return;
  125. if(!data.formc && !data.cid) return;
  126. return '#dc3545';
  127. }
  128. },
  129. },
  130. ];
  131. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  132. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  133. return spreadColor.stage.settle;
  134. }
  135. if (data && data.is_change) {
  136. return '#c3e6cb';
  137. }
  138. return defaultColor;
  139. };
  140. billsSpreadSetting.localCache = {
  141. key: 'changes-ledger-spread',
  142. colWidth: true,
  143. };
  144. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  145. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  146. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  147. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  148. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  149. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  150. const posSheet = posSpread.getActiveSheet();
  151. posSpreadSetting.rowHeader = [
  152. {
  153. rowHeaderType: 'circle',
  154. setting: {
  155. size: 5,
  156. indent: 16,
  157. getColor: function (index, data) {
  158. if (!data) return;
  159. if(!data.formc) return;
  160. return '#dc3545';
  161. }
  162. },
  163. },
  164. ];
  165. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  166. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  167. return spreadColor.stage.settle;
  168. }
  169. return defaultColor;
  170. };
  171. posSpreadSetting.localCache = {
  172. key: 'changes-pos-spread',
  173. colWidth: true,
  174. };
  175. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  176. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  177. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  178. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  179. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  180. const errorList = $.cs_errorList({
  181. tabSelector: '#error-list-tab',
  182. selector: '#error-list',
  183. relaSpread: billsSpread,
  184. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  185. afterLocated: function () {
  186. posSpreadObj.loadCurPosData();
  187. },
  188. afterShow: function () {
  189. billsSpread.refresh();
  190. if (posSpread) posSpread.refresh();
  191. },
  192. });
  193. const checkList = $.ledger_checkList({
  194. id: 'check-list',
  195. tabSelector: '#check-list-tab',
  196. selector: '#check-list',
  197. relaSpread: billsSpread,
  198. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  199. checkType: getCheckType(checkOption),
  200. afterLocated: function () {
  201. posSpreadObj.loadCurPosData();
  202. },
  203. afterShow: function () {
  204. billsSpread.refresh();
  205. if (posSpread) posSpread.refresh();
  206. },
  207. });
  208. const sumLoadMiss = $.sumLoadMiss({
  209. tabSelector: '#sum-load-miss-tab',
  210. selector: '#sum-load-miss',
  211. relaSpread: billsSpread,
  212. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  213. id: 'revise-slm',
  214. afterLocated: function () {
  215. posSpreadObj.loadCurPosData();
  216. },
  217. afterShow: function () {
  218. billsSpread.refresh();
  219. if (posSpread) posSpread.refresh();
  220. },
  221. });
  222. // 初始化 节点树结构
  223. const treeSetting = {
  224. id: 'ledger_id',
  225. pid: 'ledger_pid',
  226. order: 'order',
  227. level: 'level',
  228. rootId: -1,
  229. keys: ['id', 'tender_id', 'ledger_id'],
  230. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  231. autoExpand: 3,
  232. markExpandKey: 'change-bills-expand',
  233. markExpandSubKey: window.location.pathname.split('/')[2],
  234. };
  235. if (!isTz) {
  236. treeSetting.calcFields.push('deal_tp');
  237. }
  238. treeSetting.calcFun = function (node) {
  239. if (node && node.b_code && isTz) {
  240. const posData = pos.getLedgerPos(node.id) || [];
  241. if (posData.length > 0) {
  242. let sgfh_qty = 0;
  243. let sjcl_qty = 0;
  244. let qtcl_qty = 0;
  245. for (const np of posData) {
  246. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  247. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  248. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  249. }
  250. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  251. node.sgfh_qty = sgfh_qty;
  252. node.sjcl_qty = sjcl_qty;
  253. node.qtcl_qty = qtcl_qty;
  254. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  255. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  256. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  257. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  258. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  259. }
  260. }
  261. }
  262. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  263. };
  264. const billsTree = createNewPathTree('revise', treeSetting);
  265. // 初始化 计量单元
  266. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  267. // 清单 相关方法&绑定spreadjs事件
  268. const billsTreeSpreadObj = {
  269. loadExprToInput(sheet) {
  270. const sel = sheet.getSelections()[0];
  271. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  272. if (col && col.type === 'Number') {
  273. const data = SpreadJsObj.getSelectObject(sheet);
  274. if (data) {
  275. const exprInfo = getExprInfo(col.field);
  276. if (exprInfo) {
  277. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  278. .attr('field', col.field).attr('org', data[col.field]);
  279. } else {
  280. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  281. }
  282. if (col.field.indexOf('dgn') >= 0) {
  283. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  284. } else if (col.field === 'unit_price') {
  285. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  286. } else {
  287. const nodePos = pos.getLedgerPos(data.id);
  288. if (nodePos && nodePos.length > 0) {
  289. $('#bills-expr').val('').attr('readOnly', true);
  290. $('#bills-expr').removeAttr('data-row');
  291. } else {
  292. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  293. }
  294. }
  295. $('#bills-expr').attr('data-row', sel.row);
  296. } else {
  297. $('#bills-expr').val('').attr('readOnly', true);
  298. $('#bills-expr').removeAttr('data-row');
  299. }
  300. } else {
  301. $('#bills-expr').val('').attr('readOnly', true);
  302. $('#bills-expr').removeAttr('data-row');
  303. }
  304. },
  305. getDefaultSelectInfo: function (sheet) {
  306. const tree = sheet.zh_tree;
  307. if (!tree) return;
  308. const sel = sheet.getSelections()[0];
  309. const node = sheet.zh_tree.nodes[sel.row];
  310. if (!node) return;
  311. let count = 1;
  312. if (sel.rowCount > 1) {
  313. for (let r = 1; r < sel.rowCount; r++) {
  314. const rNode = sheet.zh_tree.nodes[sel.row + r];
  315. if (rNode.level > node.level) continue;
  316. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  317. toastr.warning('请选择同一节点下的节点,进行该操作');
  318. return;
  319. }
  320. count += 1;
  321. }
  322. }
  323. return [tree, node, count];
  324. },
  325. /**
  326. * 刷新顶部按钮是否可用
  327. * @param sheet
  328. * @param selections
  329. */
  330. refreshOperationValid: function (sheet, selection) {
  331. const setObjEnable = function (obj, enable) {
  332. if (enable) {
  333. obj.removeClass('disabled');
  334. } else {
  335. obj.addClass('disabled');
  336. }
  337. };
  338. const invalidAll = function () {
  339. setObjEnable($('a[name=base-opr][type=add]'), false);
  340. setObjEnable($('a[name=base-opr][type=delete]'), false);
  341. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  342. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  343. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  344. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  345. };
  346. const sel = selection ? selection[0] : sheet.getSelections()[0];
  347. const row = sel ? sel.row : -1;
  348. const tree = sheet.zh_tree;
  349. if (!tree) {
  350. invalidAll();
  351. return;
  352. }
  353. const first = sheet.zh_tree.nodes[row];
  354. if (!first) {
  355. invalidAll();
  356. return;
  357. }
  358. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  359. if (sel.rowCount > 1 && first) {
  360. for (let r = 1; r < sel.rowCount; r++) {
  361. const rNode = tree.nodes[sel.row + r];
  362. if (!rNode) {
  363. sameParent = false;
  364. break;
  365. }
  366. if (!rNode.formc) {
  367. sameParent = false;
  368. break;
  369. }
  370. nodeUsed = nodeUsed || rNode.used;
  371. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  372. if (rNode.level > first.level) continue;
  373. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  374. sameParent = false;
  375. break;
  376. }
  377. last = rNode;
  378. }
  379. }
  380. const preNode = tree.getPreSiblingNode(first);
  381. const siblings = tree.getChildren(tree.getParent(first));
  382. let upPower = true;
  383. for (let order = last.order; order < siblings.length - 1; order ++) {
  384. if (!siblings[order].formc) {
  385. upPower = false;
  386. break;
  387. }
  388. }
  389. const valid = !sheet.zh_setting.readOnly;
  390. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  391. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  392. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  393. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  394. const posRange = last ? pos.getLedgerPos(last.id) : [];
  395. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  396. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  397. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  398. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  399. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  400. setObjEnable($('#cut'), valid);
  401. setObjEnable($('#paste'), valid);
  402. },
  403. /**
  404. *
  405. * @param sheet
  406. * @param data
  407. */
  408. refreshTree: function (sheet, data) {
  409. SpreadJsObj.massOperationSheet(sheet, function () {
  410. const tree = sheet.zh_tree;
  411. // 处理删除
  412. if (data.delete) {
  413. data.delete.sort(function (a, b) {
  414. return b.deleteIndex - a.deleteIndex;
  415. });
  416. for (const d of data.delete) {
  417. sheet.deleteRows(d.deleteIndex, 1);
  418. }
  419. }
  420. // 处理新增
  421. if (data.create) {
  422. const newNodes = data.create;
  423. if (newNodes) {
  424. newNodes.sort(function (a, b) {
  425. return a.index - b.index;
  426. });
  427. for (const node of newNodes) {
  428. sheet.addRows(node.index, 1);
  429. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  430. }
  431. }
  432. }
  433. // 处理更新
  434. if (data.update) {
  435. const rows = [];
  436. for (const u of data.update) {
  437. rows.push(tree.nodes.indexOf(u));
  438. }
  439. SpreadJsObj.reLoadRowsData(sheet, rows);
  440. }
  441. // 处理展开
  442. if (data.expand) {
  443. const expanded = [];
  444. for (const e of data.expand) {
  445. if (expanded.indexOf(e) === -1) {
  446. const posterity = tree.getPosterity(e);
  447. for (const p of posterity) {
  448. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  449. expanded.push(p);
  450. }
  451. }
  452. }
  453. }
  454. });
  455. },
  456. selectionChanged: function (e, info) {
  457. if (info.newSelections) {
  458. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  459. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  460. billsTreeSpreadObj.refreshPosData();
  461. }
  462. }
  463. billsTreeSpreadObj.loadExprToInput(info.sheet);
  464. },
  465. refreshPosData: function() {
  466. SpreadJsObj.resetTopAndSelect(posSheet);
  467. posSpreadObj.loadCurPosData();
  468. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  469. posSearch.search($('#pos-keyword').val());
  470. },
  471. /**
  472. * 新增节点
  473. * @param spread
  474. */
  475. baseOpr: function (sheet, type, addCount = 1) {
  476. const self = this;
  477. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  478. if (!tree || !node || !count) return;
  479. if (type === 'delete') {
  480. const parent = tree.getParent(node);
  481. const children = parent ? parent.children : tree.children;
  482. const index = children.indexOf(node);
  483. for (let i = 0; i < count; i++) {
  484. const child = children[i+index];
  485. if (tree.checkNodeUsed(child, pos)) {
  486. toastr.warning('选中的节点已计量,不可删除');
  487. return;
  488. }
  489. if (child.settle_status === settleStatus.finish) {
  490. toastr.warning('选中的节点已结算,不可删除');
  491. return;
  492. }
  493. }
  494. } else if (type === 'up-level') {
  495. const parent = tree.getParent(node);
  496. const children = parent ? parent.children : tree.children;
  497. const index = children.indexOf(node);
  498. const lastSelect = children[index + count - 1];
  499. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  500. toastr.warning('选中的节点已计量,不可升级');
  501. return;
  502. }
  503. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  504. toastr.warning('选中的节点已结算,不可升级');
  505. return;
  506. }
  507. // for (let i = index; i < children.length; i++) {
  508. // const child = children[index];
  509. // if (tree.checkNodeUsed(child, pos)) {
  510. // if (i >= index + count) {
  511. // toastr.warning('其后节点已计量,选中的节点不可升级');
  512. // } else {
  513. // toastr.warning('选中的节点已计量,不可升级');
  514. // }
  515. // return;
  516. // }
  517. // }
  518. } else if (type === 'down-level') {
  519. const parent = tree.getParent(node);
  520. const children = parent ? parent.children : tree.children;
  521. const index = children.indexOf(node);
  522. if (index > 0 && children[index-1].used) {
  523. toastr.warning('其前节点已计量,选中的节点不可降级');
  524. return;
  525. }
  526. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  527. toastr.warning('其前节点已结算,选中的节点不可降级');
  528. return;
  529. }
  530. for (let i = index; i < count; i++) {
  531. const child = children[i+index];
  532. if (tree.checkNodeUsed(child, pos)) {
  533. toastr.warning('选中的节点已计量,不可降级');
  534. return;
  535. }
  536. if (tree.settle_status === settleStatus.finish) {
  537. toastr.warning('选中的节点已结算,不可降级');
  538. return;
  539. }
  540. }
  541. } else if (type === 'add') {
  542. if (node.settle_status === settleStatus.finish) {
  543. toastr.warning('选中的节点已结算,不可新增子项');
  544. return;
  545. }
  546. }
  547. if (type === 'delete') {
  548. deleteAfterHint(function () {
  549. postData(window.location.pathname + '/update', {
  550. postType: type,
  551. postData: {
  552. id: node.ledger_id,
  553. count: type === 'add' ? addCount : count,
  554. }
  555. }, function (result) {
  556. changeList = result.changeList;
  557. const refreshData = tree.loadPostData(result);
  558. self.refreshTree(sheet, refreshData);
  559. const sel = sheet.getSelections()[0];
  560. if (sel) {
  561. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  562. billsTreeSpreadObj.refreshPosData();
  563. }
  564. self.refreshOperationValid(sheet);
  565. });
  566. });
  567. } else {
  568. postData(window.location.pathname + '/update', {
  569. postType: type,
  570. postData: {
  571. id: node.ledger_id,
  572. count: type === 'add' ? addCount : count,
  573. }
  574. }, function (result) {
  575. changeList = result.changeList;
  576. const refreshData = tree.loadPostData(result);
  577. self.refreshTree(sheet, refreshData);
  578. if (['up-move', 'down-move'].indexOf(type) > -1) {
  579. const sel = sheet.getSelections()[0];
  580. if (sel) {
  581. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  582. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  583. }
  584. } else if (type === 'add') {
  585. const sel = sheet.getSelections()[0];
  586. if (sel) {
  587. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  588. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  589. billsTreeSpreadObj.refreshPosData();
  590. }
  591. }
  592. self.refreshOperationValid(sheet);
  593. });
  594. }
  595. },
  596. buttonClicked: function (e, info, v) {
  597. if (info.sheet.zh_setting) {
  598. const select = SpreadJsObj.getSelectObject(info.sheet);
  599. const col = info.sheet.zh_setting.cols[info.col];
  600. if (col.field === 'is_change') {
  601. if (billsCol.readOnly.isChangeList(select)) {
  602. return
  603. }
  604. if (info.sheet.isEditing()) {
  605. info.sheet.endEdit(true);
  606. }
  607. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  608. if (is_change) {
  609. makeGclGatherData();
  610. const gclInfo = _.find(gclGatherData, function (item) {
  611. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  612. });
  613. const xmjInfo = gclInfo.leafXmjs[0];
  614. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  615. const data = {
  616. lid: select.id,
  617. code: gclInfo.b_code,
  618. name: gclInfo.name,
  619. unit: gclInfo.unit,
  620. unit_price: gclInfo.unit_price,
  621. oamount: xmjInfo.quantity,
  622. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  623. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  624. xmj_code: xmjInfo.code || '',
  625. xmj_jldy: xmjInfo.jldy || '',
  626. xmj_dwgc: xmjInfo.dwgc || '',
  627. xmj_fbgc: xmjInfo.fbgc || '',
  628. xmj_fxgc: xmjInfo.fxgc || '',
  629. gcl_id: select.id,
  630. mx_id: '',
  631. };
  632. if (oldCInfo) {
  633. data.detail = oldCInfo.detail;
  634. data.camount = oldCInfo.camount;
  635. data.spamount = oldCInfo.spamount;
  636. data.is_valuation = oldCInfo.is_valuation;
  637. data.delimit = oldCInfo.delimit;
  638. }
  639. // 更新至服务器
  640. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  641. changeList = result.changeList;
  642. select.is_change = 1;
  643. }, function () {
  644. info.sheet.setValue(info.row, info.col, 0);
  645. });
  646. console.log(data);
  647. } else {
  648. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  649. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  650. info.sheet.setValue(info.row, info.col, 1);
  651. return
  652. }
  653. const cInfo = _.find(changeList, { gcl_id: select.id });
  654. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  655. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  656. info.sheet.setValue(info.row, info.col, 1);
  657. return
  658. } else if (checkIsSettle(cInfo)) {
  659. toastr.warning('该清单计量单元已结算,无法取消勾选');
  660. info.sheet.setValue(info.row, info.col, 1);
  661. return
  662. } else {
  663. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  664. changeList = result.changeList;
  665. select.is_change = 0;
  666. }, function () {
  667. info.sheet.setValue(info.row, info.col, 1);
  668. });
  669. }
  670. }
  671. }
  672. }
  673. },
  674. /**
  675. * 编辑单元格响应事件
  676. * @param {Object} e
  677. * @param {Object} info
  678. */
  679. editEnded: function (e, info) {
  680. if (info.sheet.zh_setting) {
  681. const col = info.sheet.zh_setting.cols[info.col];
  682. if (col.field === 'is_change') {
  683. return;
  684. }
  685. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  686. const node = sortData[info.row];
  687. const data = {
  688. id: node.id,
  689. tender_id: node.tender_id,
  690. ledger_id: node.ledger_id
  691. };
  692. // 未改变值则不提交
  693. const orgValue = node[col.field];
  694. const newValue = trimInvalidChar(info.editingText);
  695. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  696. return;
  697. }
  698. // 台账模式,检查计量单元相关
  699. if (isTz) {
  700. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  701. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  702. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  703. if (!node.children || node.children.length ===0) {
  704. const lPos = pos.getLedgerPos(node.id);
  705. if (lPos && lPos.length > 0) {
  706. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  707. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  708. return;
  709. }
  710. }
  711. }
  712. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  713. const lPos = pos.getLedgerPos(node.id);
  714. if (lPos && lPos.length > 0) {
  715. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  716. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  717. return;
  718. }
  719. }
  720. }
  721. // 获取更新数据
  722. const exprInfo = getExprInfo(col.field);
  723. if (info.editingText) {
  724. const text = newValue;
  725. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  726. toastr.error('节点已计量,请勿删除编号');
  727. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  728. return;
  729. }
  730. if (col.type === 'Number') {
  731. const num = _.toNumber(text);
  732. if (_.isFinite(num)) {
  733. data[col.field] = num;
  734. if (exprInfo) {
  735. data[exprInfo.expr] = '';
  736. }
  737. } else {
  738. try {
  739. data[col.field] = math.evaluate(transExpr(text));
  740. if (exprInfo) {
  741. data[exprInfo.expr] = newValue;
  742. }
  743. } catch(err) {
  744. toastr.error('输入的表达式非法');
  745. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  746. return;
  747. }
  748. }
  749. } else {
  750. data[col.field] = text;
  751. }
  752. } else {
  753. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  754. toastr.error('节点已计量,请勿删除编号');
  755. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  756. return;
  757. }
  758. data[col.field] = null;
  759. if (exprInfo) {
  760. data[exprInfo.expr] = '';
  761. }
  762. }
  763. if (col.field === 'b_code' && newValue) {
  764. const ledgerData = _.filter(billsTree.nodes, function (item) {
  765. return item.b_code !== null && item.b_code !== '' && !item.formc;
  766. });
  767. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  768. if (ledgerOneData) {
  769. data.name = ledgerOneData.name;
  770. data.unit = ledgerOneData.unit;
  771. data.unit_price = ledgerOneData.unit_price;
  772. }
  773. }
  774. // 更新至服务器
  775. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  776. changeList = result.changeList;
  777. const refreshNode = billsTree.loadPostData(result);
  778. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  779. });
  780. }
  781. },
  782. clipboardPasting: function (e, info) {
  783. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  784. info.cancel = true;
  785. if (!setting || !tree) return;
  786. // const range = info.cellRange;
  787. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  788. // const node = tree.nodes[iRow];
  789. // if (tree.checkNodeUsed(node, pos)) {
  790. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  791. // return;
  792. // }
  793. // }
  794. const pasteData = info.pasteData.html
  795. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  796. : (info.pasteData.text === ''
  797. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  798. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  799. const hint = {
  800. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  801. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  802. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  803. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  804. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  805. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  806. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  807. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  808. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  809. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  810. };
  811. const datas = [], filterNodes = [];
  812. let pid, level, filterRow = 0;
  813. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  814. const curRow = info.cellRange.row + iRow;
  815. const node = tree.nodes[curRow];
  816. if (!node) continue;
  817. if (!pid) pid = node.ledger_pid;
  818. if (!level) level = node.level;
  819. // if (node.ledger_pid !== pid) {
  820. // toastMessageUniq(hint.sameParent);
  821. // filterRow+=1;
  822. // continue;
  823. // }
  824. if (node.level < level) break;
  825. let bPaste = false;
  826. const data = info.sheet.zh_tree.getNodeKeyData(node);
  827. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  828. const curCol = info.cellRange.col + iCol;
  829. const colSetting = info.sheet.zh_setting.cols[curCol];
  830. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  831. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  832. toastMessageUniq(hint.parent);
  833. continue;
  834. }
  835. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  836. toastMessageUniq(hint.gcl);
  837. continue;
  838. }
  839. const lPos = pos.getLedgerPos(node.id);
  840. if (lPos && lPos.length > 0) {
  841. if (value === '' && colSetting.field === 'b_code') {
  842. toastMessageUniq(hint.posCode);
  843. continue;
  844. }
  845. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  846. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  847. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  848. toastMessageUniq(hint.posQty);
  849. continue;
  850. }
  851. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  852. toastMessageUniq(hint.posXmj);
  853. continue;
  854. }
  855. }
  856. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  857. toastMessageUniq (hint.usedUp);
  858. continue;
  859. }
  860. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  861. toastMessageUniq(hint.settle);
  862. continue;
  863. }
  864. if (colSetting.type === 'Number') {
  865. const num = _.toNumber(value);
  866. if (num) {
  867. data[colSetting.field] = num;
  868. } else {
  869. try {
  870. data[colSetting.field] = math.evaluate(transExpr(value));
  871. const exprInfo = getExprInfo(colSetting.field);
  872. if (exprInfo) {
  873. data[exprInfo.expr] = value;
  874. }
  875. bPaste = true;
  876. } catch (err) {
  877. toastMessageUniq(hint.invalidExpr);
  878. continue;
  879. }
  880. }
  881. } else {
  882. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  883. && data[colSetting.field] !== '' && value === '') {
  884. toastMessageUniq(hint.usedCode);
  885. continue;
  886. }
  887. data[colSetting.field] = value;
  888. }
  889. if (colSetting.field === 'b_code' && value) {
  890. const ledgerData = _.filter(billsTree.nodes, function (item) {
  891. return item.b_code !== null && item.b_code !== '' && !item.formc;
  892. });
  893. const ledgerOneData = _.find(ledgerData, { b_code: value });
  894. if (ledgerOneData) {
  895. data.name = ledgerOneData.name;
  896. data.unit = ledgerOneData.unit;
  897. data.unit_price = ledgerOneData.unit_price;
  898. }
  899. }
  900. bPaste = true;
  901. }
  902. if (bPaste) {
  903. datas.push(data);
  904. } else {
  905. filterNodes.push(node);
  906. }
  907. }
  908. if (datas.length > 0) {
  909. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  910. changeList = result.changeList;
  911. const refreshNode = tree.loadPostData(result);
  912. if (refreshNode.update) {
  913. refreshNode.update = refreshNode.update.concat(filterNodes);
  914. }
  915. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  916. }, function () {
  917. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  918. });
  919. } else {
  920. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  921. }
  922. },
  923. clipboardPasted: function (e, info) {
  924. const hint = {
  925. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  926. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  927. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  928. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  929. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  930. };
  931. const tree = info.sheet.zh_tree;
  932. if (!tree) { return; }
  933. const sortData = info.sheet.zh_tree.nodes;
  934. const datas = [], filterNodes = [];
  935. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  936. let bPaste = false;
  937. const curRow = info.cellRange.row + iRow;
  938. const node = sortData[curRow];
  939. if (node) {
  940. const data = info.sheet.zh_tree.getNodeKeyData(node);
  941. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  942. const curCol = info.cellRange.col + iCol;
  943. const colSetting = info.sheet.zh_setting.cols[curCol];
  944. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  945. const lPos = pos.getLedgerPos(node.id);
  946. if (lPos && lPos.length > 0) {
  947. if (value === '' && colSetting.field === 'b_code') {
  948. toastMessageUniq(hint.posCode);
  949. continue;
  950. }
  951. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  952. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  953. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  954. toastMessageUniq(hint.posQty);
  955. continue;
  956. }
  957. }
  958. if (node.used && colSetting.field === 'unit_price') {
  959. toastMessageUniq (hint.usedUp);
  960. continue;
  961. }
  962. if (colSetting.type === 'Number') {
  963. const num = _.toNumber(value);
  964. if (num) {
  965. data[colSetting.field] = num;
  966. } else {
  967. try {
  968. data[colSetting.field] = math.evaluate(transExpr(value));
  969. } catch (err) {
  970. toastMessageUniq(hint.invalidExpr);
  971. continue;
  972. }
  973. }
  974. } else {
  975. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  976. && data[colSetting.field] !== '' && value === '') {
  977. toastMessageUniq(hint.usedCode);
  978. continue;
  979. }
  980. data[colSetting.field] = value;
  981. }
  982. if (colSetting.field === 'b_code' && value) {
  983. const ledgerData = _.filter(billsTree.nodes, function (item) {
  984. return item.b_code !== null && item.b_code !== '' && !item.formc;
  985. });
  986. const ledgerOneData = _.find(ledgerData, { b_code: value });
  987. if (ledgerOneData) {
  988. data.name = ledgerOneData.name;
  989. data.unit = ledgerOneData.unit;
  990. data.unit_price = ledgerOneData.unit_price;
  991. }
  992. }
  993. bPaste = true;
  994. }
  995. if (bPaste) {
  996. datas.push(data);
  997. } else {
  998. filterNodes.push(node);
  999. }
  1000. }
  1001. }
  1002. if (datas.length > 0) {
  1003. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1004. changeList = result.changeList;
  1005. const refreshNode = tree.loadPostData(result);
  1006. if (refreshNode.update) {
  1007. refreshNode.update = refreshNode.update.concat(filterNodes);
  1008. }
  1009. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1010. }, function () {
  1011. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1012. });
  1013. } else {
  1014. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1015. }
  1016. },
  1017. deletePress: function (sheet) {
  1018. if (!sheet.zh_setting) return;
  1019. const sel = sheet.getSelections()[0], datas = [];
  1020. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1021. let bDel = false;
  1022. const node = sheet.zh_tree.nodes[iRow];
  1023. const data = sheet.zh_tree.getNodeKeyData(node);
  1024. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1025. const col = sheet.zh_setting.cols[iCol];
  1026. const style = sheet.getStyle(iRow, iCol);
  1027. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1028. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1029. if (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1030. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1031. return;
  1032. }
  1033. data[col.field] = null;
  1034. const exprInfo = getExprInfo(col.field);
  1035. if (exprInfo) {
  1036. data[exprInfo.expr] = '';
  1037. }
  1038. bDel = true;
  1039. }
  1040. if (bDel) datas.push(data);
  1041. }
  1042. if (datas.length > 0) {
  1043. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1044. changeList = result.changeList;
  1045. const refreshNode = sheet.zh_tree.loadPostData(result);
  1046. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1047. billsTreeSpreadObj.loadExprToInput(sheet);
  1048. });
  1049. }
  1050. },
  1051. pasteBlock: function (spread, copyInfo) {
  1052. const self = this;
  1053. const sheet = spread.getActiveSheet();
  1054. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1055. if (node.settle_status === settleStatus.finish) {
  1056. toastr.warning('选中的节点已结算,不可粘贴整块');
  1057. return;
  1058. }
  1059. postData(window.location.pathname + '/update', {
  1060. postType: 'paste-block',
  1061. postData: {
  1062. id: tree.getNodeKey(node),
  1063. tid: copyInfo.tid,
  1064. block: copyInfo.block,
  1065. }
  1066. }, function (data) {
  1067. changeList = data.changeList;
  1068. pos.updateDatas(data.pos);
  1069. const result = tree.loadPostData(data.ledger);
  1070. self.refreshTree(sheet, result);
  1071. const sel = sheet.getSelections()[0];
  1072. if (sel) {
  1073. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1074. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1075. }
  1076. self.refreshOperationValid(sheet);
  1077. removeLocalCache(copyBlockTag);
  1078. }, null, true);
  1079. },
  1080. topRowChanged: function (e, info) {
  1081. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1082. },
  1083. editStarting(e, info) {
  1084. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1085. const col = info.sheet.zh_setting.cols[info.col];
  1086. const node = info.sheet.zh_tree.nodes[info.row];
  1087. if (!node) {
  1088. info.cancel = true;
  1089. return;
  1090. }
  1091. const exprInfo = getExprInfo(col.field);
  1092. if (exprInfo) {
  1093. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1094. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1095. }
  1096. }
  1097. switch (col.field) {
  1098. case 'code':
  1099. const posRange = pos.getLedgerPos(node.id);
  1100. info.cancel = posRange && posRange.length > 0;
  1101. break;
  1102. case 'unit_price':
  1103. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1104. break;
  1105. case 'sgfh_qty':
  1106. case 'sgfh_tp':
  1107. case 'sjcl_qty':
  1108. case 'sjcl_tp':
  1109. case 'qtcl_qty':
  1110. case 'qtcl_tp':
  1111. case 'deal_qty':
  1112. case 'deal_tp':
  1113. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1114. break;
  1115. case 'dgn_qty1':
  1116. case 'dgn_qty2':
  1117. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1118. break;
  1119. }
  1120. },
  1121. cut: function (sheet, sel, callback) {
  1122. if (!sheet || !sel) return;
  1123. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1124. toastr.warning('请勿选中整行剪切');
  1125. return;
  1126. }
  1127. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1128. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1129. const node = sortData[iRow];
  1130. if (node) {
  1131. const data = sheet.zh_tree.getNodeKeyData(node);
  1132. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1133. const col = sheet.zh_setting.cols[iCol];
  1134. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1135. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1136. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  1137. const lPos = pos.getLedgerPos(node.id);
  1138. if (lPos && lPos.length > 0) {
  1139. toastr.error('不可剪切');
  1140. return;
  1141. }
  1142. }
  1143. const style = sheet.getStyle(iRow, iCol);
  1144. if (style.locked) {
  1145. toastr.error('不可剪切');
  1146. return;
  1147. }
  1148. const colSetting = sheet.zh_setting.cols[iCol];
  1149. data[colSetting.field] = null;
  1150. const exprInfo = getExprInfo(colSetting.field);
  1151. if (exprInfo) {
  1152. data[exprInfo.expr] = '';
  1153. }
  1154. }
  1155. datas.push(data);
  1156. }
  1157. }
  1158. if (datas.length > 0) {
  1159. callback();
  1160. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1161. changeList = result.changeList;
  1162. const refreshNode = sheet.zh_tree.loadPostData(result);
  1163. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1164. });
  1165. }
  1166. },
  1167. sortCode: function (sheet) {
  1168. const tree = sheet.zh_tree;
  1169. if (!tree) return;
  1170. const select = SpreadJsObj.getSelectObject(sheet);
  1171. if (!select || !select.code || select.code === '') return;
  1172. const recursiveSortCode = function (data, parentCode, children) {
  1173. if (!children || children.length === 0) return;
  1174. for (const [i, child] of children.entries()) {
  1175. if (!child.b_code || child.b_code === '') {
  1176. const code = parentCode + '-' + (i + 1);
  1177. const cData = tree.getNodeKeyData(child);
  1178. cData.code = code;
  1179. data.push(cData);
  1180. if (!tree.isLeafXmj(child)) {
  1181. recursiveSortCode(data, code, child.children);
  1182. }
  1183. }
  1184. }
  1185. };
  1186. const data = [];
  1187. recursiveSortCode(data, select.code, select.children);
  1188. if (data.length > 0) {
  1189. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1190. changeList = result.changeList;
  1191. const refreshNode = tree.loadPostData(result);
  1192. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1193. })
  1194. }
  1195. }
  1196. };
  1197. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1198. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1199. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1200. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1201. if (!readOnly) {
  1202. // 增删上下移升降级
  1203. $('a[name="base-opr"]').click(function () {
  1204. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1205. });
  1206. $('a[name=cpc]').click(function () {
  1207. billsSpread.commandManager().execute({
  1208. cmd: this.getAttribute('type'),
  1209. sheetName: billsSheet.name()
  1210. });
  1211. });
  1212. $('#bills-expr').bind('change onblur', function () {
  1213. if (this.readOnly) return;
  1214. const expr = $(this);
  1215. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1216. const select = billsTree.getItemsByIndex(row);
  1217. if (!select) return;
  1218. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1219. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1220. const data = {
  1221. id: select.id,
  1222. tender_id: select.tender_id,
  1223. ledger_id: select.ledger_id
  1224. };
  1225. const exprInfo = getExprInfo(field);
  1226. if (newValue !== '') {
  1227. const num = _.toNumber(newValue);
  1228. if (num) {
  1229. data[field] = num;
  1230. if (exprInfo) {
  1231. data[exprInfo.expr] = '';
  1232. }
  1233. } else {
  1234. try {
  1235. data[field] = math.evaluate(transExpr(newValue));
  1236. if (exprInfo) {
  1237. data[exprInfo.expr] = newValue;
  1238. }
  1239. } catch (err) {
  1240. toastr.error('输入的表达式非法');
  1241. return;
  1242. }
  1243. }
  1244. } else {
  1245. data[field] = null;
  1246. if (exprInfo) {
  1247. data[exprInfo.expr] = '';
  1248. }
  1249. }
  1250. // 更新至服务器
  1251. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1252. changeList = result.changeList;
  1253. const refreshNode = billsTree.loadPostData(result);
  1254. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1255. });
  1256. });
  1257. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1258. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1259. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  1260. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1261. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1262. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1263. SpreadJsObj.Clipboard.setCopyData(copyText);
  1264. });
  1265. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1266. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1267. }
  1268. // 右键菜单
  1269. let batchInsertObj;
  1270. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1271. const self = this;
  1272. if ($.isFunction(item.icon)) {
  1273. item._icon = item.icon.call(this, this, $t, key, item);
  1274. } else {
  1275. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1276. // to enable font awesome
  1277. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1278. } else {
  1279. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1280. }
  1281. }
  1282. this.addClass(item._icon);
  1283. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  1284. .appendTo(this);
  1285. const $input = $obj.find('input');
  1286. const event = () => {
  1287. if (self.hasClass('context-menu-disabled')) return;
  1288. item.batchInsert($input[0], root);
  1289. };
  1290. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1291. $input.click((e) => {e.stopPropagation();})
  1292. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1293. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1294. };
  1295. const billsContextMenuOptions = {
  1296. selector: '#bills-spread',
  1297. build: function ($trigger, e) {
  1298. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1299. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1300. },
  1301. items: {}
  1302. };
  1303. if (!readOnly) {
  1304. billsContextMenuOptions.items.create = {
  1305. name: '新增',
  1306. icon: 'fa-sign-in',
  1307. callback: function (key, opt) {
  1308. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1309. },
  1310. disabled: function (key, opt) {
  1311. const sheet = billsSheet;
  1312. const selection = sheet.getSelections();
  1313. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1314. const row = sel ? sel.row : -1;
  1315. const tree = sheet.zh_tree;
  1316. if (!tree) return true;
  1317. const first = sheet.zh_tree.nodes[row];
  1318. const valid = !sheet.zh_setting.readOnly;
  1319. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1320. }
  1321. };
  1322. billsContextMenuOptions.items.delete = {
  1323. name: '删除',
  1324. icon: 'fa-remove',
  1325. callback: function (key, opt) {
  1326. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  1327. },
  1328. disabled: function (key, opt) {
  1329. const sheet = billsSheet;
  1330. const selection = sheet.getSelections();
  1331. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1332. const row = sel ? sel.row : -1;
  1333. const tree = sheet.zh_tree;
  1334. if (!tree) return true;
  1335. const first = sheet.zh_tree.nodes[row];
  1336. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  1337. if (sel.rowCount > 1 && first) {
  1338. for (let r = 1; r < sel.rowCount; r++) {
  1339. const rNode = tree.nodes[sel.row + r];
  1340. if (!rNode) {
  1341. sameParent = false;
  1342. break;
  1343. }
  1344. if (!rNode.formc) {
  1345. return true;
  1346. }
  1347. nodeUsed = nodeUsed || rNode.used;
  1348. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  1349. if (rNode.level > first.level) continue;
  1350. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1351. sameParent = false;
  1352. break;
  1353. }
  1354. last = rNode;
  1355. }
  1356. }
  1357. const valid = !sheet.zh_setting.readOnly;
  1358. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  1359. }
  1360. };
  1361. billsContextMenuOptions.items.sprBase = '----';
  1362. }
  1363. billsContextMenuOptions.items.copyBlock = {
  1364. name: '复制整块',
  1365. icon: 'fa-files-o',
  1366. callback: function (key, opt) {
  1367. const copyBlockList = [];
  1368. const sheet = billsSheet;
  1369. const sel = sheet.getSelections()[0];
  1370. let iRow = sel.row;
  1371. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1372. while (iRow < sel.row + sel.rowCount) {
  1373. const node = sheet.zh_tree.nodes[iRow];
  1374. if (node.ledger_pid !== pid) {
  1375. toastr.error('仅可同时选中同层节点');
  1376. return;
  1377. }
  1378. const posterity = sheet.zh_tree.getPosterity(node);
  1379. iRow += posterity.length + 1;
  1380. posterity.unshift(node);
  1381. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1382. }
  1383. for (const cbl of copyBlockList) {
  1384. for (const b of cbl) {
  1385. const posRange = pos.getLedgerPos(b.id);
  1386. if (posRange && posRange.length > 0) b.pos = posRange;
  1387. }
  1388. }
  1389. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1390. },
  1391. visible: function (key, opt) {
  1392. const sheet = billsSheet;
  1393. const selection = sheet.getSelections();
  1394. const row = selection[0].row;
  1395. const select = billsTree.nodes[row];
  1396. return select;
  1397. },
  1398. disabled: function (key, opt) {
  1399. const sheet = billsSheet;
  1400. const selection = sheet.getSelections();
  1401. const row = selection[0].row;
  1402. const select = billsTree.nodes[row];
  1403. return select && select.level <= 1;
  1404. }
  1405. };
  1406. billsContextMenuOptions.items.copyBlockXmj = {
  1407. name: '复制整块(只复制项目节)',
  1408. icon: 'fa-files-o',
  1409. callback: function (key, opt) {
  1410. const copyBlockList = [];
  1411. const sheet = billsSheet;
  1412. const sel = sheet.getSelections()[0];
  1413. let iRow = sel.row;
  1414. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1415. while (iRow < sel.row + sel.rowCount) {
  1416. const node = sheet.zh_tree.nodes[iRow];
  1417. if (node.ledger_pid !== pid) {
  1418. toastr.error('仅可同时选中同层节点');
  1419. return;
  1420. }
  1421. const posterity = sheet.zh_tree.getPosterity(node);
  1422. iRow += posterity.length + 1;
  1423. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1424. copyPosterity.unshift(node);
  1425. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1426. for (const p of copyData) {
  1427. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1428. p.is_leaf = children.length === 0;
  1429. }
  1430. copyBlockList.push(copyData);
  1431. }
  1432. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1433. },
  1434. visible: function (key, opt) {
  1435. const sheet = billsSheet;
  1436. const selection = sheet.getSelections();
  1437. const row = selection[0].row;
  1438. const select = billsTree.nodes[row];
  1439. return select;
  1440. },
  1441. disabled: function (key, opt) {
  1442. const sheet = billsSheet;
  1443. const selection = sheet.getSelections();
  1444. const row = selection[0].row;
  1445. const select = billsTree.nodes[row];
  1446. return select && select.level <= 1;
  1447. }
  1448. };
  1449. if (!readOnly) {
  1450. billsContextMenuOptions.items.pasteBlock = {
  1451. name: '粘贴整块',
  1452. icon: 'fa-clipboard',
  1453. disabled: function (key, opt) {
  1454. //const block = treeOperationObj.block || [];
  1455. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1456. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1457. },
  1458. callback: function (key, opt) {
  1459. //const block = treeOperationObj.block || [];
  1460. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1461. if (copyInfo.block.length > 0) {
  1462. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1463. } else {
  1464. document.execCommand('paste');
  1465. }
  1466. },
  1467. visible: function (key, opt) {
  1468. return !readOnly;
  1469. }
  1470. };
  1471. billsContextMenuOptions.items.sprBlock = '----';
  1472. }
  1473. if (!readOnly) {
  1474. billsContextMenuOptions.items.batchInsert = {
  1475. name: '批量插入',
  1476. type: 'batchInsert',
  1477. value: '2',
  1478. icon: 'fa-sign-in',
  1479. batchInsert: function (obj, root) {
  1480. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1481. obj.value = obj.max;
  1482. toastr.warning('批量插入不可多于' + obj.max);
  1483. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1484. obj.value = obj.min;
  1485. toastr.warning('批量插入不可少于' + obj.min);
  1486. } else {
  1487. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1488. root.$menu.trigger('contextmenu:hide');
  1489. }
  1490. },
  1491. disabled: function (key, opt) {
  1492. const sheet = billsSheet;
  1493. const selection = sheet.getSelections();
  1494. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1495. const row = sel ? sel.row : -1;
  1496. const tree = sheet.zh_tree;
  1497. if (!tree) return true;
  1498. const first = sheet.zh_tree.nodes[row];
  1499. const valid = !sheet.zh_setting.readOnly;
  1500. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1501. }
  1502. };
  1503. billsContextMenuOptions.items.batchInsertBillsPos = {
  1504. name: '批量插入清单-计量单元',
  1505. icon: 'fa-sign-in',
  1506. visible: function (key, opt) {
  1507. return false;
  1508. },
  1509. disabled: function (key, opt) {
  1510. if (!isTz) return true;
  1511. const select = SpreadJsObj.getSelectObject(billsSheet);
  1512. if (select) {
  1513. if (select.code && select.code !== '') {
  1514. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  1515. } else {
  1516. const parent = billsTree.getParent(select);
  1517. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  1518. }
  1519. } else {
  1520. return false;
  1521. }
  1522. },
  1523. callback: function (key, opt) {
  1524. if (!batchInsertObj) {
  1525. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1526. } else {
  1527. batchInsertObj.initView();
  1528. }
  1529. $('#batch').modal('show');
  1530. }
  1531. };
  1532. }
  1533. billsContextMenuOptions.items.sprTag = '----';
  1534. billsContextMenuOptions.items.showLast = {
  1535. name: '显示至最底层',
  1536. callback: function (key, opt, menu, e) {
  1537. const node = SpreadJsObj.getSelectObject(billsSheet);
  1538. setTimeout(() => {
  1539. showWaitingView();
  1540. billsTree.expandByCustom(x => {
  1541. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1542. });
  1543. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  1544. closeWaitingView();
  1545. }, 100);
  1546. },
  1547. };
  1548. $.contextMenu(billsContextMenuOptions);
  1549. // 计量单元 相关方法&绑定spreadjs事件
  1550. const posSpreadObj = {
  1551. refreshOperationValid: function (sheet, selection) {
  1552. const setObjEnable = function (obj, enable) {
  1553. if (enable) {
  1554. obj.removeClass('disabled');
  1555. } else {
  1556. obj.addClass('disabled');
  1557. }
  1558. };
  1559. const invalidAll = function () {
  1560. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1561. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1562. };
  1563. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1564. const row = sel ? sel.row : -1;
  1565. const first = sheet.zh_data[row];
  1566. if (!first) {
  1567. invalidAll();
  1568. return;
  1569. }
  1570. let last = first;
  1571. if (sel.rowCount > 1 && first) {
  1572. for (let r = 1; r < sel.rowCount; r++) {
  1573. const rNode = sheet.zh_data[sel.row + r];
  1574. if (!rNode) break;
  1575. last = rNode;
  1576. }
  1577. }
  1578. const preNode = sheet.zh_data[row - 1];
  1579. const valid = !sheet.zh_setting.readOnly;
  1580. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  1581. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  1582. },
  1583. loadExprToInput: function () {
  1584. const sel = posSheet.getSelections()[0];
  1585. if (!sel) return;
  1586. const col = posSheet.zh_setting.cols[sel.col];
  1587. const cell = posSheet.getCell(sel.col, sel.col);
  1588. if (col && col.type === 'Number') {
  1589. const data = SpreadJsObj.getSelectObject(posSheet);
  1590. if (data) {
  1591. const exprInfo = getExprInfo(col.field);
  1592. const value = exprInfo
  1593. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1594. : data[col.field];
  1595. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1596. .attr('readOnly', readOnly || (!data.formc && cell.locked()) || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  1597. } else {
  1598. $('#pos-expr').val('').attr('readOnly', true);
  1599. $('#pos-expr').removeAttr('data-row');
  1600. }
  1601. } else {
  1602. $('#pos-expr').val('').attr('readOnly', true);
  1603. $('#pos-expr').removeAttr('data-row');
  1604. }
  1605. },
  1606. /**
  1607. * 加载计量单元 根据当前台账选择节点
  1608. */
  1609. loadCurPosData: function () {
  1610. const node = SpreadJsObj.getSelectObject(billsSheet);
  1611. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  1612. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  1613. if (node) {
  1614. const posData = pos.getLedgerPos(node.id) || [];
  1615. console.log(posData);
  1616. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1617. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  1618. } else {
  1619. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1620. posSheet.zh_setting.readOnly = true;
  1621. }
  1622. SpreadJsObj.massOperationSheet(posSheet, function () {
  1623. if (posSheet.zh_setting) {
  1624. posSheet.zh_setting.cols.forEach(function (col, i) {
  1625. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  1626. if (i !== 0) {
  1627. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  1628. } else {
  1629. let lock = false;
  1630. if (!posSheet.zh_data[iRow]) {
  1631. lock = true;
  1632. }
  1633. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  1634. }
  1635. }
  1636. });
  1637. }
  1638. });
  1639. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  1640. posSpreadObj.loadExprToInput();
  1641. posSpreadObj.refreshOperationValid(posSheet);
  1642. },
  1643. baseOpr: function (sheet, type) {
  1644. const data = {
  1645. postType: 'pos',
  1646. posPostType: type === 'delete' ? type : 'update',
  1647. postData: [],
  1648. };
  1649. const selection = sheet.getSelections();
  1650. const row = selection[0].row, count = selection[0].rowCount;
  1651. const first = sheet.zh_data[row];
  1652. if (type === 'delete') {
  1653. for (let iRow = 0; iRow < count; iRow++) {
  1654. const posData = sheet.zh_data[iRow + row];
  1655. if (posData) {
  1656. if (posData.used) {
  1657. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1658. return;
  1659. }
  1660. if (posData.settle_status) {
  1661. toastr.error('"' + posData.name + '"已结算,请勿删除');
  1662. return;
  1663. }
  1664. data.postData.push(sheet.zh_data[iRow + row].id);
  1665. }
  1666. }
  1667. } else if (type === 'up-move') {
  1668. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1669. for (let iRow = 0; iRow < count; iRow++) {
  1670. const posData = sheet.zh_data[iRow + row];
  1671. if (posData) {
  1672. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1673. preUpdate.porder = posData.porder;
  1674. }
  1675. }
  1676. data.postData.push(preUpdate);
  1677. } else if (type === 'down-move') {
  1678. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1679. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1680. const posData = sheet.zh_data[iRow + row];
  1681. if (posData) {
  1682. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1683. nextUpdate.porder = posData.porder;
  1684. }
  1685. }
  1686. data.postData.push(nextUpdate);
  1687. } else if (type === 'add') {
  1688. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1689. if (billsNode.settle_status === settleStatus.finish) {
  1690. toastr.warning('清单已结算,不可新增计量单元');
  1691. return;
  1692. }
  1693. }
  1694. if (data.postData.length > 0) {
  1695. postData(window.location.pathname + '/update', data, function (result) {
  1696. changeList = result.changeList;
  1697. if (type === 'delete') {
  1698. pos.removeDatas(result.pos);
  1699. sheet.deleteRows(row, count);
  1700. const loadResult = billsTree.loadPostData(result.ledger);
  1701. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1702. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1703. posSpreadObj.refreshOperationValid(posSheet);
  1704. } else {
  1705. pos.updateDatas(result.pos);
  1706. const sel = selection[0];
  1707. if (sel) {
  1708. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1709. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1710. }
  1711. posSpreadObj.loadCurPosData();
  1712. }
  1713. });
  1714. }
  1715. },
  1716. editStarting: function (e, info) {
  1717. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1718. const sel = info.sheet.getSelections();
  1719. if (!sel || !sel[0]) return;
  1720. const col = info.sheet.zh_setting.cols[sel[0].col];
  1721. const node = SpreadJsObj.getSelectObject(info.sheet);
  1722. const exprInfo = getExprInfo(col.field);
  1723. if (node && exprInfo) {
  1724. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1725. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1726. }
  1727. }
  1728. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1729. info.cancel = true;
  1730. }
  1731. },
  1732. buttonClicked: function (e, info) {
  1733. if (info.sheet.zh_setting) {
  1734. const select = SpreadJsObj.getSelectObject(info.sheet);
  1735. const col = info.sheet.zh_setting.cols[info.col];
  1736. if (col.field === 'is_change') {
  1737. if (posCol.readOnly.isChangeList(select)) {
  1738. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  1739. return
  1740. }
  1741. if (info.sheet.isEditing()) {
  1742. info.sheet.endEdit(true);
  1743. }
  1744. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  1745. if (is_change) {
  1746. makeGclGatherData();
  1747. const gclInfo = _.find(gclGatherData, function (item) {
  1748. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  1749. });
  1750. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  1751. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  1752. const data = {
  1753. lid: select.lid,
  1754. code: gclInfo.b_code,
  1755. name: gclInfo.name,
  1756. unit: gclInfo.unit,
  1757. unit_price: gclInfo.unit_price,
  1758. oamount: xmjInfo.quantity,
  1759. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1760. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  1761. xmj_code: xmjInfo.code || '',
  1762. xmj_jldy: xmjInfo.jldy || '',
  1763. xmj_dwgc: xmjInfo.dwgc || '',
  1764. xmj_fbgc: xmjInfo.fbgc || '',
  1765. xmj_fxgc: xmjInfo.fxgc || '',
  1766. gcl_id: select.lid,
  1767. mx_id: select.id,
  1768. }
  1769. if (oldCInfo) {
  1770. data.detail = oldCInfo.detail;
  1771. data.camount = oldCInfo.camount;
  1772. data.spamount = oldCInfo.spamount;
  1773. data.is_valuation = oldCInfo.is_valuation;
  1774. data.delimit = oldCInfo.delimit;
  1775. }
  1776. // 更新至服务器
  1777. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  1778. changeList = result.changeList;
  1779. select.is_change = 1;
  1780. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  1781. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1782. billsNode.is_change = 1;
  1783. const loadResult = { update: [billsNode] };
  1784. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1785. }
  1786. }, function () {
  1787. info.sheet.setValue(info.row, info.col, 0);
  1788. });
  1789. } else {
  1790. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  1791. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  1792. info.sheet.setValue(info.row, info.col, 1);
  1793. return
  1794. }
  1795. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  1796. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  1797. toastr.warning('该计量单元已被使用,无法取消变更');
  1798. info.sheet.setValue(info.row, info.col, 1);
  1799. return
  1800. } else if (checkIsSettle(cInfo)) {
  1801. toastr.warning('该计量单元已结算,无法取消变更');
  1802. info.sheet.setValue(info.row, info.col, 1);
  1803. return
  1804. } else {
  1805. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  1806. changeList = result.changeList;
  1807. select.is_change = 0;
  1808. // 判断是否只剩一个,并同步去勾
  1809. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  1810. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1811. billsNode.is_change = 0;
  1812. const loadResult = { update: [billsNode] };
  1813. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1814. }
  1815. }, function () {
  1816. info.sheet.setValue(info.row, info.col, 1);
  1817. });
  1818. }
  1819. }
  1820. }
  1821. }
  1822. },
  1823. /**
  1824. * 编辑单元格响应事件
  1825. * @param {Object} e
  1826. * @param {Object} info
  1827. */
  1828. editEnded: function (e, info) {
  1829. if (!info.sheet.zh_setting) {
  1830. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1831. return;
  1832. }
  1833. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1834. const col = info.sheet.zh_setting.cols[info.col];
  1835. if (col.field === 'is_change') {
  1836. return;
  1837. }
  1838. const orgText = posData ? posData[col.field] : null;
  1839. const newText = trimInvalidChar(info.editingText);
  1840. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1841. const node = posSpreadObj.billsNode;
  1842. if (!node) {
  1843. toastr.error('数据错误,请选择台账节点后再试');
  1844. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1845. return;
  1846. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1847. toastr.error('父节点不可插入计量单元');
  1848. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1849. return;
  1850. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1851. toastr.error('项目节不可插入计量单元');
  1852. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1853. return;
  1854. }
  1855. const data = {postType: 'pos'};
  1856. if (col.field === 'name') {
  1857. if (newText === '' && posData) {
  1858. toastr.error('部位名称不可为空', 'error');
  1859. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1860. return;
  1861. } else if (!posData) {
  1862. if (newText && newText !== '') {
  1863. data.posPostType = 'add';
  1864. const sortData = info.sheet.zh_data;
  1865. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1866. data.postData = { name: newText, lid: node.id, porder: order};
  1867. if (node.settle_status === settleStatus.finish) {
  1868. toastr.error('已结算清单不可插入计量单元');
  1869. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1870. return;
  1871. }
  1872. } else {
  1873. return;
  1874. }
  1875. } else {
  1876. data.posPostType = 'update';
  1877. data.postData = {id: posData.id, name: newText};
  1878. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  1879. toastr.error('计量单元已结算,不可修改');
  1880. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1881. return;
  1882. }
  1883. }
  1884. } else if (!posData) {
  1885. toastr.warning('新增计量单元请先输入名称');
  1886. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1887. return;
  1888. } else {
  1889. data.posPostType = 'update';
  1890. data.postData = {id: posData.id};
  1891. if (col.type === 'Number') {
  1892. const exprInfo = getExprInfo(col.field);
  1893. const num = _.toNumber(newText);
  1894. if (_.isFinite(num)) {
  1895. data.postData[col.field] = num;
  1896. if (exprInfo) {
  1897. data.postData[exprInfo.expr] = '';
  1898. }
  1899. } else {
  1900. try {
  1901. data.postData[col.field] = math.evaluate(transExpr(newText));
  1902. if (exprInfo) {
  1903. data.postData[exprInfo.expr] = newText;
  1904. }
  1905. } catch(err) {
  1906. toastr.error('输入的表达式非法');
  1907. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1908. return;
  1909. }
  1910. }
  1911. } else if (col.field.indexOf('_expr') > 0) {
  1912. const exprInfo = getExprInfo(col.field, true);
  1913. if (!exprInfo) return;
  1914. if (newText) {
  1915. try {
  1916. data.postData[exprInfo.qty] = math.evaluate(transExpr(newText));
  1917. data.postData[exprInfo.expr] = newText;
  1918. } catch(err) {
  1919. toastr.error('输入的表达式非法');
  1920. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1921. return;
  1922. }
  1923. } else {
  1924. data.postData[exprInfo.qty] = 0;
  1925. data.postData[exprInfo.expr] = '';
  1926. }
  1927. } else {
  1928. data.postData[col.field] = newText;
  1929. }
  1930. }
  1931. postData(window.location.pathname + '/update', data, function (result) {
  1932. changeList = result.changeList;
  1933. const updateRst = pos.updateDatas(result.pos);
  1934. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1935. if (updateRst.create.length > 0) {
  1936. posSpreadObj.loadCurPosData();
  1937. } else {
  1938. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1939. }
  1940. const loadResult = billsTree.loadPostData(result.ledger);
  1941. // 判断是否只剩一个,并同步去勾
  1942. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1943. billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  1944. if (loadResult.update) {
  1945. const r = _.find(loadResult.update, { id: billsNode.id });
  1946. r.is_change = billsNode.is_change;
  1947. } else {
  1948. loadResult.update = [billsNode];
  1949. }
  1950. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1951. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1952. }, function () {
  1953. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1954. });
  1955. },
  1956. /**
  1957. * 删除按钮响应事件
  1958. * @param sheet
  1959. */
  1960. deletePress: function (sheet) {
  1961. if (!sheet.zh_setting) return;
  1962. const sortData = sheet.zh_data;
  1963. const datas = [], posSelects = [];
  1964. const sel = sheet.getSelections()[0];
  1965. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1966. let bDel = false;
  1967. const node = sortData[iRow];
  1968. if (node) {
  1969. const data = {id: node.id};
  1970. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1971. const colSetting = sheet.zh_setting.cols[iCol];
  1972. if (colSetting.field === 'name') {
  1973. toastr.error('部位名称不能为空');
  1974. return;
  1975. }
  1976. const style = sheet.getStyle(iRow, iCol);
  1977. if (!style.locked) {
  1978. const colSetting = sheet.zh_setting.cols[iCol];
  1979. if (colSetting.field.indexOf('_expr') > 0) {
  1980. const exprInfo = getExprInfo(colSetting.field, true);
  1981. if (!exprInfo) continue;
  1982. data[exprInfo.expr] = '';
  1983. data[exprInfo.qty] = 0;
  1984. } else {
  1985. data[colSetting.field] = null;
  1986. const exprInfo = getExprInfo(colSetting.field);
  1987. if (exprInfo) data[exprInfo.expr] = '';
  1988. }
  1989. bDel = true;
  1990. }
  1991. }
  1992. if (bDel) {
  1993. datas.push(data);
  1994. posSelects.push(node);
  1995. }
  1996. }
  1997. }
  1998. if (datas.length > 0) {
  1999. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  2000. changeList = result.changeList;
  2001. pos.updateDatas(result.pos);
  2002. posSpreadObj.loadCurPosData();
  2003. const loadResult = billsTree.loadPostData(result.ledger);
  2004. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2005. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2006. }, function () {
  2007. posSpreadObj.loadCurPosData();
  2008. });
  2009. }
  2010. },
  2011. /**
  2012. * 删除 计量单元
  2013. * @param sheet
  2014. */
  2015. deletePos: function (sheet) {
  2016. const selection = sheet.getSelections();
  2017. const data = {
  2018. postType: 'pos',
  2019. posPostType: 'delete',
  2020. postData: [],
  2021. };
  2022. const row = selection[0].row, count = selection[0].rowCount;
  2023. const sortData = sheet.zh_data;
  2024. for (let iRow = 0; iRow < count; iRow++) {
  2025. const posData = sortData[iRow + row];
  2026. if (posData) {
  2027. if (posData.used) {
  2028. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2029. return;
  2030. }
  2031. if (posData.settle_status === settleStatus.finish) {
  2032. toastr.error(`"${posData.name}"已计量,请勿删除`);
  2033. return;
  2034. }
  2035. data.postData.push(sortData[iRow + row].id);
  2036. }
  2037. }
  2038. if (data.postData.length > 0) {
  2039. postData(window.location.pathname + '/update', data, function (result) {
  2040. changeList = result.changeList;
  2041. pos.removeDatas(result.pos);
  2042. sheet.deleteRows(row, count);
  2043. const loadResult = billsTree.loadPostData(result.ledger);
  2044. // 判断是否只剩一个,并同步去勾
  2045. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2046. billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  2047. if (loadResult.update) {
  2048. const r = _.find(loadResult.update, { id: billsNode.id });
  2049. r.is_change = billsNode.is_change;
  2050. } else {
  2051. loadResult.update = [billsNode];
  2052. }
  2053. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2054. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2055. });
  2056. }
  2057. },
  2058. /**
  2059. * 粘贴单元格响应事件
  2060. * @param e
  2061. * @param info
  2062. */
  2063. clipboardPasted: function (e, info) {
  2064. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2065. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2066. }
  2067. const node = SpreadJsObj.getSelectObject(billsSheet);
  2068. if (node.code && (node.code !== '')) {
  2069. toastr.error('项目节不可含有节点明细');
  2070. posSpreadObj.loadCurPosData();
  2071. return;
  2072. }
  2073. if (node.children && (node.children.length > 0)) {
  2074. toastr.error('仅节点子项可以含有计量单元');
  2075. posSpreadObj.loadCurPosData();
  2076. return;
  2077. }
  2078. if (node.settle_status === settleStatus.finish) {
  2079. toastr.error('清单已结算,请勿修改计量单元数据');
  2080. posSpread.loadCurPosData();
  2081. return;
  2082. }
  2083. if (!info.sheet.zh_setting) {
  2084. posSpreadObj.loadCurPosData();
  2085. return;
  2086. }
  2087. const data = [];
  2088. const sortData = info.sheet.zh_data || [];
  2089. const hint = {
  2090. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2091. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  2092. };
  2093. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2094. if (info.cellRange.col !== 0) {
  2095. toastr.warning('新增计量单元请先输入名称');
  2096. posSpreadObj.loadCurPosData();
  2097. return;
  2098. }
  2099. }
  2100. let bHint = false;
  2101. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2102. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2103. let bPaste = true;
  2104. const curRow = info.cellRange.row + iRow;
  2105. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2106. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2107. const curCol = info.cellRange.col + iCol;
  2108. const colSetting = info.sheet.zh_setting.cols[curCol];
  2109. if (!colSetting) continue;
  2110. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2111. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  2112. bPaste = false;
  2113. toastMessageUniq(hint.settle);
  2114. continue;
  2115. }
  2116. if (colSetting.type === 'Number') {
  2117. const num = _.toNumber(posData[colSetting.field]);
  2118. if (num) {
  2119. posData[colSetting.field] = num;
  2120. } else {
  2121. try {
  2122. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  2123. const exprInfo = getExprInfo(colSetting.field);
  2124. if (exprInfo) {
  2125. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2126. }
  2127. } catch (err) {
  2128. if (!bHint) {
  2129. toastr.warning('粘贴了非法表达式,已过滤');
  2130. bHint = true;
  2131. }
  2132. bPaste = false;
  2133. }
  2134. }
  2135. } else if (colSetting.field.indexOf('_expr') > 0) {
  2136. try {
  2137. const exprInfo = getExprInfo(colSetting.field, true);
  2138. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2139. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  2140. posData[exprInfo.qty] = math.evaluate(transExpr(posData[exprInfo.expr]));
  2141. }
  2142. bPaste = true;
  2143. } catch (err) {
  2144. toastMessageUniq(hint.expr);
  2145. }
  2146. } else {
  2147. bPaste = true;
  2148. }
  2149. }
  2150. if (bPaste) {
  2151. data.push(posData);
  2152. }
  2153. }
  2154. if (data.length === 0) {
  2155. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2156. return;
  2157. }
  2158. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  2159. changeList = result.changeList;
  2160. pos.updateDatas(result.pos);
  2161. posSpreadObj.loadCurPosData();
  2162. const loadResult = billsTree.loadPostData(result.ledger);
  2163. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2164. posSpreadObj.loadCurPosData();
  2165. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2166. }, function () {
  2167. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2168. });
  2169. },
  2170. selectionChanged: function (e, info) {
  2171. posSpreadObj.loadExprToInput();
  2172. posSpreadObj.refreshOperationValid(posSheet);
  2173. },
  2174. addPegs: function (pegs) {
  2175. if (!pegs || pegs.length <= 0) return;
  2176. const node = SpreadJsObj.getSelectObject(billsSheet);
  2177. if (!node) return;
  2178. const sheet = posSpread.getActiveSheet();
  2179. const sortData = sheet.zh_data || [];
  2180. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2181. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2182. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  2183. changeList = result.changeList;
  2184. pos.updateDatas(result.pos);
  2185. posSpreadObj.loadCurPosData();
  2186. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2187. });
  2188. }
  2189. };
  2190. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  2191. if (!readOnly && isTz) {
  2192. $('a[name="pos-opr"]').click(function () {
  2193. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  2194. });
  2195. $('#pos-expr').bind('change onblur', function () {
  2196. if (this.readOnly) return;
  2197. const expr = $(this);
  2198. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2199. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2200. if (!select) return;
  2201. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  2202. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  2203. const data = {id: select.id};
  2204. const exprInfo = getExprInfo(field);
  2205. if (newValue !== '') {
  2206. const num = _.toNumber(newValue);
  2207. if (num) {
  2208. data[field] = num;
  2209. if (exprInfo) data[exprInfo.expr] = '';
  2210. } else {
  2211. try {
  2212. data[field] = math.evaluate(transExpr(newValue));
  2213. if (exprInfo) data[exprInfo.expr] = newValue;
  2214. } catch (err) {
  2215. toastr.error('输入的表达式非法');
  2216. return;
  2217. }
  2218. }
  2219. } else {
  2220. data[field] = null;
  2221. if (exprInfo) data[exprInfo.expr] = '';
  2222. }
  2223. // 更新至服务器
  2224. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  2225. changeList = result.changeList;
  2226. const updateRst = pos.updateDatas(result.pos);
  2227. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2228. SpreadJsObj.reLoadRowData(posSheet, row);
  2229. const loadResult = billsTree.loadPostData(result.ledger);
  2230. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2231. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2232. });
  2233. });
  2234. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  2235. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  2236. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  2237. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  2238. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  2239. $.contextMenu({
  2240. selector: '#pos-spread',
  2241. build: function ($trigger, e) {
  2242. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2243. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2244. },
  2245. items: {
  2246. 'delete': {
  2247. name: '删除',
  2248. icon: 'fa-remove',
  2249. disabled: function (key, opt) {
  2250. if (posSheet.zh_data) {
  2251. const selection = posSheet.getSelections();
  2252. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2253. const row = sel ? sel.row : -1;
  2254. const rowCount = sel.rowCount;
  2255. let settleFinish = false;
  2256. for (let i = row; i < row + rowCount; i++) {
  2257. if (!posSheet.zh_data[i]) continue;
  2258. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  2259. }
  2260. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  2261. } else {
  2262. return true;
  2263. }
  2264. },
  2265. callback: function (key, opt) {
  2266. posSpreadObj.deletePos(posSheet);
  2267. }
  2268. },
  2269. }
  2270. });
  2271. }
  2272. // 加载清单&计量单元数据
  2273. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  2274. let gclGatherData;
  2275. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  2276. for (const b of result.bills) {
  2277. if (!(b.is_leaf && b.b_code)) {
  2278. b.is_change = 0;
  2279. } else {
  2280. const cInfo = _.find(changeList, { gcl_id: b.id });
  2281. b.is_change = cInfo ? 1 : 0;
  2282. }
  2283. }
  2284. billsTree.loadDatas(result.bills);
  2285. pos.loadDatas(result.pos);
  2286. treeCalc.calculateAll(billsTree);
  2287. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  2288. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  2289. checkShowLast(result.bills.length);
  2290. posSpreadObj.loadCurPosData();
  2291. SpreadJsObj.resetTopAndSelect(posSheet);
  2292. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2293. billsTreeSpreadObj.loadExprToInput(billsSheet);
  2294. checkList.loadHisCheckData();
  2295. console.log(billsTree);
  2296. }, null);
  2297. $.divResizer({
  2298. select: '#revise-resize',
  2299. callback: function () {
  2300. billsSpread.refresh();
  2301. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2302. $(".sp-wrap").height(bcontent-30);
  2303. posSpread.refresh();
  2304. }
  2305. });
  2306. function makeGclGatherData() {
  2307. gclGatherModel.loadLedgerData(billsTree.datas);
  2308. gclGatherModel.loadPosData(pos.datas);
  2309. gclGatherData = gclGatherModel.gatherGclData();
  2310. gclGatherData = _.filter(gclGatherData, function (item) {
  2311. return item.leafXmjs && item.leafXmjs.length !== 0;
  2312. });
  2313. gclGatherData = gclGatherData.sort(sortByCode);
  2314. console.log(gclGatherData);
  2315. }
  2316. class DealBills {
  2317. constructor (selector, spreadSetting) {
  2318. const self = this;
  2319. this.loaded = false;
  2320. this.obj = $(selector)[0];
  2321. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2322. this.spreadSetting = spreadSetting;
  2323. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2324. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2325. if (!readOnly) {
  2326. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2327. const dealSheet = info.sheet;
  2328. const mainSheet = billsSheet;
  2329. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2330. if (!dealBills) { return; }
  2331. const mainTree = mainSheet.zh_tree;
  2332. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2333. if (!mainNode || !mainTree) { return; }
  2334. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2335. toastr.warning('非最底层项目下,不应添加节点');
  2336. return;
  2337. }
  2338. if (mainNode.settle_status === settleStatus.finish) {
  2339. toastr.warning('已结算节点下,不应添加签约清单');
  2340. return;
  2341. }
  2342. postData(window.location.pathname + '/update', {
  2343. postType: 'add-deal',
  2344. postData: {
  2345. id: mainNode.ledger_id,
  2346. type: mainNode.code ? 'child' : 'next',
  2347. dealBills: {
  2348. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2349. unit_price: dealBills.unit_price,
  2350. }
  2351. },
  2352. }, function (result) {
  2353. changeList = result.changeList;
  2354. const refreshData = mainTree.loadPostData(result);
  2355. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2356. const sel = mainSheet.getSelections()[0];
  2357. if (sel && refreshData.create[0]) {
  2358. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2359. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2360. }
  2361. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2362. billsSpread.focus();
  2363. posSpreadObj.loadCurPosData();
  2364. });
  2365. });
  2366. }
  2367. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2368. }
  2369. loadData (callback) {
  2370. if (this.loaded) {
  2371. if (callback) callback();
  2372. return;
  2373. }
  2374. const self = this;
  2375. postData(this.url+'/get-data', {}, function (data) {
  2376. self.data = data;
  2377. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2378. self.loaded = true;
  2379. if (callback) callback();
  2380. });
  2381. }
  2382. calculateData () {
  2383. if (this.data) {
  2384. for (const d of this.data) {
  2385. d.total_price = _.multiply(d.quantity, d.unit_price);
  2386. }
  2387. }
  2388. }
  2389. }
  2390. class BatchInsertBillsPosObj {
  2391. constructor (obj) {
  2392. const self = this;
  2393. this.obj = obj;
  2394. this.billsCount = 6;
  2395. this.posCount = 1000;
  2396. this.filter = getLocalCache('zh-calc-batch-filter');
  2397. if (!this.filter) {
  2398. this.filter = '1';
  2399. }
  2400. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2401. // 初始化 清单编号窗口 参数
  2402. this.qdSpreadSetting = {
  2403. cols: [
  2404. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2405. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2406. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2407. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2408. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2409. ],
  2410. emptyRows: this.billsCount,
  2411. headRows: 1,
  2412. headRowHeight: [32],
  2413. headerFont: '12px 微软雅黑',
  2414. font: '12px 微软雅黑',
  2415. };
  2416. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2417. // 初始化 部位数量复核表 参数
  2418. this.posSpreadSetting = {
  2419. cols: [
  2420. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2421. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2422. ],
  2423. emptyRows: this.posCount,
  2424. headRows: 1,
  2425. headRowHeight: [32],
  2426. headerFont: '12px 微软雅黑',
  2427. font: '12px 微软雅黑',
  2428. };
  2429. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2430. this.posSpreadSetting.cols.push(
  2431. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2432. )
  2433. }
  2434. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2435. // 初始化 签约节点 参数
  2436. this.dealSpreadSetting = {
  2437. cols: [
  2438. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2439. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2440. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2441. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2442. ],
  2443. emptyRows: 0,
  2444. headRows: 1,
  2445. headRowHeight: [32],
  2446. headerFont: '12px 微软雅黑',
  2447. font: '12px 微软雅黑',
  2448. };
  2449. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2450. // 初始化 清单编号、部位数量复核表 表格
  2451. this.initView();
  2452. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2453. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2454. // 拉取签约节点数据
  2455. dealBills.loadData(() => {
  2456. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2457. });
  2458. // 双击签约节点,自动添加到清单编号窗口
  2459. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2460. const deal = info.sheet.zh_data[info.row];
  2461. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2462. const sel = qdSheet.getSelections()[0];
  2463. qdSheet.getCell(sel.row, 0).value(deal.code);
  2464. qdSheet.getCell(sel.row, 1).value(deal.name);
  2465. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2466. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2467. if (sel.row + 1 === qdSheet.getRowCount()) {
  2468. const count = sel.row + 2;
  2469. qdSheet.setRowCount(count);
  2470. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2471. const colCount = posSheet.getColumnCount() + 1;
  2472. posSheet.setColumnCount(colCount);
  2473. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2474. }
  2475. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2476. qdSheet.getParent().focus();
  2477. });
  2478. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2479. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  2480. const count = posSheet.getColumnCount() - 2;
  2481. if (billsCount > count) {
  2482. posSheet.setColumnCount(billsCount + 2);
  2483. for (let i = count + 1; i <= billsCount; i++) {
  2484. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2485. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2486. }
  2487. }
  2488. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  2489. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2490. if (dealBills && dealBills.length > 0) {
  2491. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2492. const curRow = iRow + info.cellRange.row;
  2493. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  2494. if (bills) {
  2495. info.sheet.getCell(curRow, 1).value(bills.name);
  2496. info.sheet.getCell(curRow, 2).value(bills.unit);
  2497. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  2498. }
  2499. }
  2500. }
  2501. }
  2502. });
  2503. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2504. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2505. const count = qdSheet.getRowCount();
  2506. if (billsCount > count) {
  2507. qdSheet.setRowCount(billsCount);
  2508. for (let i = count + 1; i <= billsCount; i++) {
  2509. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2510. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2511. }
  2512. }
  2513. });
  2514. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2515. if (info.col === 0) {
  2516. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2517. if (dealBills && dealBills.length > 0) {
  2518. const bills = _.find(dealBills, {code: info.editingText});
  2519. if (bills) {
  2520. info.sheet.getCell(info.row, 1).value(bills.name);
  2521. info.sheet.getCell(info.row, 2).value(bills.unit);
  2522. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2523. }
  2524. }
  2525. }
  2526. });
  2527. this.obj.bind('shown.bs.modal', function () {
  2528. self.qdSpread.refresh();
  2529. self.posSpread.refresh();
  2530. self.dealSpread.refresh();
  2531. });
  2532. $('#batch-ok').click(function () {
  2533. const selection = billsSheet.getSelections();
  2534. const sel = selection[0];
  2535. const row = selection[0].row;
  2536. const select = billsTree.nodes[row];
  2537. if (select) {
  2538. const insertData = {};
  2539. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2540. insertData.id = select[billsTree.setting.id];
  2541. insertData.batchData = self.getBatchData();
  2542. if (insertData.batchData.length > 0) {
  2543. postData(window.location.pathname + '/update', {
  2544. postType: 'batch-insert',
  2545. postData: insertData
  2546. }, function (data) {
  2547. changeList = result.changeList;
  2548. pos.updateDatas(data.pos);
  2549. const result = billsTree.loadPostData(data.ledger);
  2550. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2551. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2552. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2553. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2554. posSpreadObj.loadCurPosData();
  2555. self.obj.modal('hide');
  2556. }, null, true);
  2557. } else {
  2558. self.obj.modal('hide');
  2559. }
  2560. }
  2561. });
  2562. $('input[name=batch-filter]').change(function () {
  2563. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2564. });
  2565. $.contextMenu({
  2566. selector: '.batch-l-t',
  2567. build: function ($trigger, e) {
  2568. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2569. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2570. },
  2571. items: {
  2572. 'create': {
  2573. name: '新增行',
  2574. icon: 'fa-sign-in',
  2575. callback: function (key, opt) {
  2576. const qdSheet = self.qdSpread.getActiveSheet();
  2577. const posSheet = self.posSpread.getActiveSheet();
  2578. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2579. const index = qdSheet.getRowCount();
  2580. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2581. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2582. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2583. },
  2584. },
  2585. 'delete': {
  2586. name: '删除行',
  2587. icon: 'fa-remove',
  2588. callback: function (key, opt) {
  2589. const qdSheet = self.qdSpread.getActiveSheet();
  2590. const posSheet = self.posSpread.getActiveSheet();
  2591. const sel = qdSheet.getSelections()[0];
  2592. qdSheet.deleteRows(sel.row, sel.rowCount);
  2593. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2594. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2595. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2596. }
  2597. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2598. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2599. }
  2600. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2601. },
  2602. },
  2603. }
  2604. });
  2605. }
  2606. // 初始化左侧表格
  2607. initView () {
  2608. // 初始化 清单编号
  2609. const qdSheet = this.qdSpread.getActiveSheet();
  2610. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2611. SpreadJsObj.refreshColumnAlign(qdSheet);
  2612. // 清理原有数据
  2613. SpreadJsObj.beginMassOperation(qdSheet);
  2614. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2615. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2616. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2617. }
  2618. qdSheet.setSelection(0, 0, 1 ,1);
  2619. SpreadJsObj.endMassOperation(qdSheet);
  2620. // 初始化 部位数量复核表
  2621. const posSheet = this.posSpread.getActiveSheet();
  2622. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2623. SpreadJsObj.refreshColumnAlign(posSheet);
  2624. // 清理原有数据
  2625. SpreadJsObj.beginMassOperation(posSheet);
  2626. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2627. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2628. posSheet.setSelection(0, 0, 1 ,1);
  2629. SpreadJsObj.endMassOperation(posSheet);
  2630. // 检查签约节点数据,以工具栏数据为准
  2631. if (dealBills) {
  2632. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2633. }
  2634. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2635. }
  2636. // 获取界面数据
  2637. getBatchData () {
  2638. const result = [];
  2639. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2640. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2641. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2642. const qd = {
  2643. b_code: qdSheet.getText(iRow, 0),
  2644. name: qdSheet.getText(iRow, 1),
  2645. unit: qdSheet.getText(iRow, 2),
  2646. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2647. pos: [],
  2648. };
  2649. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2650. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2651. if (value !== 0 && !isNaN(value)) {
  2652. qd.pos.push({
  2653. name: posSheet.getText(iPosRow, 0),
  2654. drawing_code: posSheet.getText(iPosRow, 1),
  2655. quantity: value, porder: qd.pos.length + 1,
  2656. });
  2657. }
  2658. }
  2659. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2660. }
  2661. return result;
  2662. }
  2663. }
  2664. const dealBills = new DealBills('#deal-bills-spread', {
  2665. cols: [
  2666. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2667. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2668. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2669. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2670. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2671. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2672. ],
  2673. emptyRows: 0,
  2674. headRows: 1,
  2675. headRowHeight: [32],
  2676. headColWidth: [30],
  2677. defaultRowHeight: 21,
  2678. headerFont: '12px 微软雅黑',
  2679. font: '12px 微软雅黑',
  2680. selectedBackColor: '#fffacd',
  2681. });
  2682. class Jlzf {
  2683. constructor (selector, spreadSetting) {
  2684. const self = this;
  2685. this.loaded = false;
  2686. this.obj = $(selector);
  2687. const relaSelect = {
  2688. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2689. searchText: `cb-${spreadSetting.stdType}-st`,
  2690. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2691. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2692. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2693. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2694. };
  2695. this.obj.html(
  2696. '<div class="sjs-bar d-flex">\n' +
  2697. ' <div class="ml-1">\n' +
  2698. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  2699. ' <div class="d-inline-block">\n' +
  2700. ' <div class="input-group input-group-sm mr-1">' +
  2701. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2702. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2703. ' <div class="input-group-append" >\n' +
  2704. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2705. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2706. ' </div>\n' +
  2707. ' </div>\n' +
  2708. ' </div>\n' +
  2709. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2710. ' </div>\n' +
  2711. ' </div>' +
  2712. '</div>\n' +
  2713. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2714. );
  2715. autoFlashHeight();
  2716. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2717. function getObjHeight(select) {
  2718. return select.length > 0 ? select.height() : 0;
  2719. }
  2720. const cHeader = getObjHeight($(".c-header"));
  2721. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2722. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2723. this.spreadSetting = spreadSetting;
  2724. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2725. const searchSheet = this.spread.getActiveSheet();
  2726. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2727. if (!readOnly) {
  2728. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2729. const dealSheet = info.sheet;
  2730. const mainSheet = billsSheet;
  2731. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2732. if (!dealBills) { return; }
  2733. const mainTree = mainSheet.zh_tree;
  2734. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2735. if (!mainNode || !mainTree) { return; }
  2736. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2737. toastr.warning('非最底层项目下,不应添加节点');
  2738. return;
  2739. }
  2740. if (mainNode.settle_status === settleStatus.finish) {
  2741. toastr.warning('已结算节点下,不应添加签约清单');
  2742. return;
  2743. }
  2744. postData(window.location.pathname + '/update', {
  2745. postType: 'add-deal',
  2746. postData: {
  2747. id: mainNode.ledger_id,
  2748. type: mainNode.code ? 'child' : 'next',
  2749. dealBills: {
  2750. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2751. unit_price: dealBills.unit_price,
  2752. }
  2753. },
  2754. }, function (result) {
  2755. changeList = result.changeList;
  2756. const refreshData = mainTree.loadPostData(result);
  2757. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2758. const sel = mainSheet.getSelections()[0];
  2759. if (sel && refreshData.create[0]) {
  2760. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2761. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2762. }
  2763. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2764. billsSpread.focus();
  2765. posSpreadObj.loadCurPosData();
  2766. });
  2767. });
  2768. }
  2769. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2770. const searchObj = {
  2771. result: [],
  2772. cur: 0,
  2773. searchStdNode: function() {
  2774. const keyword = $(`#${relaSelect.searchText}`).val();
  2775. const sortData = SpreadJsObj.getSortData(searchSheet);
  2776. searchObj.result = keyword ? sortData.filter(x => {
  2777. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2778. }) : [];
  2779. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2780. searchObj.cur = 0;
  2781. if (searchObj.result.length > 0) {
  2782. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2783. }
  2784. },
  2785. searchPre: function () {
  2786. if (searchObj.result.length === 0) return;
  2787. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2788. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2789. },
  2790. searchNext: function () {
  2791. if (searchObj.result.length === 0) return;
  2792. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2793. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2794. },
  2795. clear: function () {
  2796. $(`#${relaSelect.searchText}`).val('');
  2797. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2798. searchObj.result = [];
  2799. searchObj.cur = 0;
  2800. }
  2801. };
  2802. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2803. $(`#${relaSelect.searchPre}`).click(function (e) {
  2804. searchObj.searchPre();
  2805. e.stopPropagation();
  2806. });
  2807. $(`#${relaSelect.searchNext}`).click(function (e) {
  2808. searchObj.searchNext();
  2809. e.stopPropagation();
  2810. });
  2811. $(`#${relaSelect.searchClose}`).click(function (e) {
  2812. searchObj.clear();
  2813. e.stopPropagation();
  2814. });
  2815. };
  2816. loadData (callback) {
  2817. // if (this.loaded) {
  2818. // if (callback) callback();
  2819. // return;
  2820. // }
  2821. const self = this;
  2822. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  2823. const showDatas = [];
  2824. for (const d of datas) {
  2825. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  2826. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  2827. }
  2828. }
  2829. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  2830. // self.loaded = true;
  2831. if (callback) callback();
  2832. }
  2833. }
  2834. const jlzfBills = new Jlzf('#jlzf-spread', {
  2835. cols: [
  2836. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2837. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  2838. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2839. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2840. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2841. ],
  2842. emptyRows: 0,
  2843. headRows: 1,
  2844. headRowHeight: [32],
  2845. headColWidth: [30],
  2846. defaultRowHeight: 21,
  2847. headerFont: '12px 微软雅黑',
  2848. font: '12px 微软雅黑',
  2849. selectedBackColor: '#fffacd',
  2850. readOnly: true,
  2851. stdType: 'jlzf',
  2852. });
  2853. class Dsk {
  2854. constructor (selector, spreadSetting) {
  2855. const self = this;
  2856. this.loaded = false;
  2857. this.obj = $(selector);
  2858. const dskProjectHtml = spreadSetting.libs.map(l => {
  2859. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  2860. });
  2861. const relaSelect = {
  2862. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2863. searchText: `cb-${spreadSetting.stdType}-st`,
  2864. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2865. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2866. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2867. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2868. };
  2869. this.obj.html(
  2870. '<div class="sjs-bar d-flex">\n' +
  2871. ' <div class="dropdown mr-1">\n' +
  2872. ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2873. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  2874. ' </button>\n' +
  2875. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  2876. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  2877. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  2878. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  2879. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  2880. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  2881. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  2882. ' </div>\n' +
  2883. ' </div>' +
  2884. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  2885. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  2886. ' <div class="ml-1">\n' +
  2887. ' <div class="dropdown">\n' +
  2888. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2889. ' <i class="fa fa-search"></i>\n' +
  2890. ' </button>\n' +
  2891. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  2892. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  2893. ' <div class="d-inline-block">\n' +
  2894. ' <div class="input-group input-group-sm mr-1">' +
  2895. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2896. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2897. ' <div class="input-group-append" >\n' +
  2898. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2899. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2900. ' </div>\n' +
  2901. ' </div>\n' +
  2902. ' </div>\n' +
  2903. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2904. ' </div>\n' +
  2905. ' </div>\n' +
  2906. ' </div>\n' +
  2907. ' </div>' +
  2908. '</div>\n' +
  2909. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2910. );
  2911. autoFlashHeight();
  2912. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2913. function getObjHeight(select) {
  2914. return select.length > 0 ? select.height() : 0;
  2915. }
  2916. const cHeader = getObjHeight($(".c-header"));
  2917. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2918. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2919. this.spreadSetting = spreadSetting;
  2920. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2921. const searchSheet = this.spread.getActiveSheet();
  2922. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2923. (function (select, sheet) {
  2924. $(select).click(function () {
  2925. if (!sheet.zh_tree) return;
  2926. const tag = $(this).attr('tag');
  2927. const tree = sheet.zh_tree;
  2928. setTimeout(() => {
  2929. switch (tag) {
  2930. case "1":
  2931. case "2":
  2932. case "3":
  2933. case "4":
  2934. case "5":
  2935. tree.expandByLevel(parseInt(tag));
  2936. SpreadJsObj.refreshTreeRowVisible(sheet);
  2937. break;
  2938. case "last":
  2939. tree.expandByCustom(() => { return true; });
  2940. SpreadJsObj.refreshTreeRowVisible(sheet);
  2941. break;
  2942. }
  2943. }, 100);
  2944. });
  2945. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  2946. if (!readOnly) {
  2947. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2948. const dealSheet = info.sheet;
  2949. const mainSheet = billsSheet;
  2950. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2951. if (!dealBills) { return; }
  2952. const mainTree = mainSheet.zh_tree;
  2953. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2954. if (!mainNode || !mainTree) { return; }
  2955. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2956. toastr.warning('非最底层项目下,不应添加节点');
  2957. return;
  2958. }
  2959. if (mainNode.settle_status === settleStatus.finish) {
  2960. toastr.warning('已结算节点下,不应添加签约清单');
  2961. return;
  2962. }
  2963. const is_bill = dealBills.kind === 4;
  2964. const oneBills = {
  2965. b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  2966. unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
  2967. sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
  2968. };
  2969. postData(window.location.pathname + '/update', {
  2970. postType: 'add-deal',
  2971. postData: {
  2972. id: mainNode.ledger_id,
  2973. type: mainNode.code ? 'child' : 'next',
  2974. dealBills: oneBills,
  2975. },
  2976. }, function (result) {
  2977. changeList = result.changeList;
  2978. const refreshData = mainTree.loadPostData(result);
  2979. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2980. const sel = mainSheet.getSelections()[0];
  2981. if (sel && refreshData.create[0]) {
  2982. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2983. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2984. }
  2985. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2986. billsSpread.focus();
  2987. posSpreadObj.loadCurPosData();
  2988. });
  2989. });
  2990. }
  2991. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2992. const searchObj = {
  2993. result: [],
  2994. cur: 0,
  2995. searchStdNode: function() {
  2996. const keyword = $(`#${relaSelect.searchText}`).val();
  2997. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  2998. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2999. }) : [];
  3000. // searchObj.result = [];
  3001. // for (const x of pathTree.nodes) {
  3002. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  3003. // searchObj.result.push(x);
  3004. // }
  3005. // }
  3006. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  3007. searchObj.cur = 0;
  3008. if (searchObj.result.length > 0) {
  3009. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  3010. }
  3011. },
  3012. searchPre: function () {
  3013. if (searchObj.result.length === 0) return;
  3014. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  3015. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3016. },
  3017. searchNext: function () {
  3018. if (searchObj.result.length === 0) return;
  3019. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  3020. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3021. },
  3022. clear: function () {
  3023. $(`#${relaSelect.searchText}`).val('');
  3024. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  3025. searchObj.result = [];
  3026. searchObj.cur = 0;
  3027. }
  3028. };
  3029. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  3030. $(`#${relaSelect.searchPre}`).click(function (e) {
  3031. searchObj.searchPre();
  3032. e.stopPropagation();
  3033. });
  3034. $(`#${relaSelect.searchNext}`).click(function (e) {
  3035. searchObj.searchNext();
  3036. e.stopPropagation();
  3037. });
  3038. $(`#${relaSelect.searchClose}`).click(function (e) {
  3039. searchObj.clear();
  3040. e.stopPropagation();
  3041. });
  3042. };
  3043. loadData (callback) {
  3044. if (this.loaded) {
  3045. if (callback) callback();
  3046. return;
  3047. }
  3048. const self = this;
  3049. if (dskAccountData && dskAccountData.select_project) {
  3050. self.loaded = true;
  3051. changeDskProject(dskAccountData.select_project);
  3052. } else {
  3053. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  3054. self.loaded = true;
  3055. }
  3056. if (callback) callback();
  3057. }
  3058. }
  3059. $('body').on('change', '#change-dsk-project', function () {
  3060. const pid = $(this).val();
  3061. changeDskProject(pid);
  3062. });
  3063. $('body').on('change', '#change-dsk-project-tree', function () {
  3064. const treeId = $(this).val();
  3065. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  3066. changeDskProjectTree(projectInfo, treeId);
  3067. });
  3068. function setDskProjectTreeSelect(trees) {
  3069. let html = '';
  3070. for (const tree of trees) {
  3071. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  3072. }
  3073. $('#change-dsk-project-tree').html(html);
  3074. }
  3075. function changeDskProject(pid) {
  3076. const projectInfo = _.find(dskProjects, { pid });
  3077. if (!projectInfo) {
  3078. dskAccountData.select_project = null;
  3079. dskAccountData.select_tree = null;
  3080. const tree = dskProjectBills2Tree.convert([]);
  3081. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3082. return;
  3083. }
  3084. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  3085. const trees = _.filter(datas, x => x.type === 4);
  3086. dskAccountData.select_project = projectInfo.pid;
  3087. setDskProjectTreeSelect(trees);
  3088. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  3089. });
  3090. }
  3091. function changeDskProjectTree(projectInfo, treeId) {
  3092. dskAccountData.select_tree = treeId;
  3093. if (!treeId) {
  3094. const tree = dskProjectBills2Tree.convert([]);
  3095. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3096. return;
  3097. }
  3098. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  3099. const tree = dskProjectBills2Tree.convert(result);
  3100. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3101. });
  3102. }
  3103. const dskBills = new Dsk('#dsk-spread', {
  3104. cols: [
  3105. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  3106. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3107. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3108. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  3109. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  3110. ],
  3111. emptyRows: 0,
  3112. headRows: 1,
  3113. headRowHeight: [32],
  3114. headColWidth: [30],
  3115. defaultRowHeight: 21,
  3116. headerFont: '12px 微软雅黑',
  3117. font: '12px 微软雅黑',
  3118. selectedBackColor: '#fffacd',
  3119. readOnly: true,
  3120. stdType: 'dsk',
  3121. libs: dskProjects,
  3122. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  3123. });
  3124. const dskProjectBills2Tree = (function () {
  3125. const treeSetting = {
  3126. id: 'dpb_id',
  3127. pid: 'dpb_pid',
  3128. order: 'seq',
  3129. level: 'level',
  3130. rootId: '-1',
  3131. fullPath: 'full_path',
  3132. };
  3133. const tenderTree = createNewPathTree('gather', treeSetting);
  3134. function setChildrenNode(node, dxs, files, tenders) {
  3135. const dxchildren = _.filter(dxs, { parentID: node.bid });
  3136. const children = _.filter(files, { parentID: node.bid });
  3137. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  3138. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  3139. for (const t of checkChildren) {
  3140. const child = {
  3141. bid: t.ID,
  3142. parentID: t.parentID,
  3143. name: t.name,
  3144. kind: t.kind,
  3145. code: t.code,
  3146. quantity: t.quantity,
  3147. quantity2: t.quantity2,
  3148. unit: t.unit,
  3149. unitPrice: t.unitPrice,
  3150. totalPrice: t.totalPrice,
  3151. formulaCode: t.formulaCode,
  3152. flag: t.flag,
  3153. remark: t.remark,
  3154. };
  3155. tenderTree.addNode(child, node);
  3156. setChildrenNode(child, dxs, files, tenders);
  3157. }
  3158. }
  3159. function convert (projects) {
  3160. tenderTree.clearDatas();
  3161. // 区分文件夹及项目
  3162. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  3163. const dxs = _.filter(projects, { kind: 1 });
  3164. const files = _.filter(projects, { kind: 4 });
  3165. const tenders = _.filter(projects, { kind: 8 });
  3166. for (const t of topLevel) {
  3167. const node = {
  3168. bid: t.ID,
  3169. parentID: t.parentID,
  3170. name: t.name,
  3171. kind: t.kind,
  3172. code: t.code,
  3173. quantity: t.quantity,
  3174. quantity2: t.quantity2,
  3175. unit: t.unit,
  3176. unitPrice: t.unitPrice,
  3177. totalPrice: t.totalPrice,
  3178. formulaCode: t.formulaCode,
  3179. flag: t.flag,
  3180. remark: t.remark,
  3181. };
  3182. tenderTree.addNode(node, null);
  3183. setChildrenNode(node, dxs, files, tenders);
  3184. }
  3185. tenderTree.sortTreeNode(true);
  3186. return tenderTree;
  3187. }
  3188. return { tenderTree, convert }
  3189. })();
  3190. $.divResizer({
  3191. select: '#revise-right-spr',
  3192. callback: function () {
  3193. billsSpread.refresh();
  3194. if (posSpread) posSpread.refresh();
  3195. if (stdXmj) stdXmj.spread.refresh();
  3196. if (stdGcl) stdGcl.spread.refresh();
  3197. if (dealBills) dealBills.spread.refresh();
  3198. if (searchLedger) searchLedger.spread.refresh();
  3199. if (errorList) errorList.spread.refresh();
  3200. if (checkList) checkList.spread.refresh();
  3201. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3202. if (jlzfBills) jlzfBills.spread.refresh();
  3203. if (dskBills) dskBills.spread.refresh();
  3204. }
  3205. });
  3206. $.subMenu({
  3207. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  3208. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  3209. key: 'menu.1.0.0',
  3210. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  3211. callback: function (info) {
  3212. if (info.mini) {
  3213. $('.panel-title').addClass('fluid');
  3214. $('#sub-menu').removeClass('panel-sidebar');
  3215. } else {
  3216. $('.panel-title').removeClass('fluid');
  3217. $('#sub-menu').addClass('panel-sidebar');
  3218. }
  3219. autoFlashHeight();
  3220. billsSpread.refresh();
  3221. if (posSpread) posSpread.refresh();
  3222. if (stdXmj) stdXmj.spread.refresh();
  3223. if (stdGcl) stdGcl.spread.refresh();
  3224. if (dealBills) dealBills.spread.refresh();
  3225. if (searchLedger) searchLedger.spread.refresh();
  3226. if (errorList) errorList.spread.refresh();
  3227. if (checkList) checkList.spread.refresh();
  3228. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3229. if (jlzfBills) jlzfBills.spread.refresh();
  3230. if (dskBills) dskBills.spread.refresh();
  3231. }
  3232. });
  3233. // showSideTools(true);
  3234. billsSpread.refresh();
  3235. if (posSpread) posSpread.refresh();
  3236. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  3237. const mainSheet = billsSheet;
  3238. if (!stdTree || !mainSheet.zh_tree) { return; }
  3239. const mainTree = mainSheet.zh_tree;
  3240. const sel = mainSheet.getSelections()[0];
  3241. const mainNode = mainTree.nodes[sel.row];
  3242. if (!stdNode) return;
  3243. if (updateData.postData.stdType === 'gcl') {
  3244. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3245. toastr.warning('非最底层项目下,不应添加节点');
  3246. return;
  3247. }
  3248. if (mainNode.settle_status === settleStatus.finish) {
  3249. toastr.warning('已结算节点下,不可添加工程量清单');
  3250. return;
  3251. }
  3252. } else {
  3253. const stdNodes = stdTree.getAllParents(stdNode);
  3254. for (const node of stdNodes) {
  3255. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  3256. if (parent && parent.settle_status === settleStatus.finish) {
  3257. toastr.warning('项目节父项已结算,不可添加节点');
  3258. return;
  3259. }
  3260. }
  3261. }
  3262. postData(window.location.pathname + '/update', {
  3263. postType: 'add-std',
  3264. postData: {
  3265. id: mainTree.getNodeKey(mainNode),
  3266. tender_id: mainNode.tender_id,
  3267. stdType: updateData.postData.stdType,
  3268. stdLibId: stdNode.list_id,
  3269. stdNode: stdTree.getNodeKey(stdNode)
  3270. }
  3271. }, function (result) {
  3272. changeList = result.changeList;
  3273. const refreshNode = mainTree.loadPostData(result);
  3274. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  3275. if (sel) {
  3276. if (refreshNode.create && refreshNode.create.length > 0) {
  3277. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  3278. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  3279. } else {
  3280. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  3281. if (node) {
  3282. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  3283. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  3284. }
  3285. }
  3286. }
  3287. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3288. billsSpread.focus();
  3289. posSpreadObj.loadCurPosData();
  3290. });
  3291. };
  3292. const stdXmjSetting = {
  3293. selector: '#std-xmj',
  3294. stdType: 'xmj',
  3295. libs: stdChapters,
  3296. treeSetting: {
  3297. id: 'chapter_id',
  3298. pid: 'pid',
  3299. order: 'order',
  3300. level: 'level',
  3301. rootId: -1,
  3302. keys: ['id', 'list_id', 'chapter_id'],
  3303. },
  3304. spreadSetting: {
  3305. cols: [
  3306. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3307. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3308. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3309. ],
  3310. treeCol: 0,
  3311. emptyRows: 0,
  3312. headRows: 1,
  3313. headRowHeight: [32],
  3314. defaultRowHeight: 21,
  3315. headerFont: '12px 微软雅黑',
  3316. font: '12px 微软雅黑',
  3317. headColWidth: [30],
  3318. selectedBackColor: '#fffacd',
  3319. },
  3320. cellDoubleClick: stdLibCellDoubleClick,
  3321. page: 'revise',
  3322. tid: window.location.pathname.split('/')[2],
  3323. };
  3324. const stdGclSetting = {
  3325. selector: '#std-gcl',
  3326. stdType: 'gcl',
  3327. libs: stdBills,
  3328. treeSetting: {
  3329. id: 'bill_id',
  3330. pid: 'pid',
  3331. order: 'order',
  3332. level: 'level',
  3333. rootId: -1,
  3334. keys: ['id', 'list_id', 'bill_id']
  3335. },
  3336. spreadSetting: {
  3337. cols: [
  3338. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3339. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3340. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3341. ],
  3342. treeCol: 0,
  3343. emptyRows: 0,
  3344. headRows: 1,
  3345. headRowHeight: [32],
  3346. defaultRowHeight: 21,
  3347. headerFont: '12px 微软雅黑',
  3348. font: '12px 微软雅黑',
  3349. headColWidth: [30],
  3350. selectedBackColor: '#fffacd',
  3351. },
  3352. cellDoubleClick: stdLibCellDoubleClick,
  3353. page: 'revise',
  3354. tid: window.location.pathname.split('/')[2],
  3355. };
  3356. // 展开收起标准节点
  3357. $('a', '#side-menu').bind('click', function (e) {
  3358. e.preventDefault();
  3359. const tab = $(this), tabPanel = $(tab.attr('content'));
  3360. // 展开工具栏、切换标签
  3361. if (!tab.hasClass('active')) {
  3362. const close = $('.active', '#side-menu').length === 0;
  3363. $('a', '#side-menu').removeClass('active');
  3364. tab.addClass('active');
  3365. $('.tab-content .tab-pane').removeClass('active');
  3366. tabPanel.addClass('active');
  3367. showSideTools(tab.hasClass('active'));
  3368. if (tab.attr('content') === '#std-xmj') {
  3369. if (!stdXmj) {
  3370. stdXmj = $.stdLib(stdXmjSetting);
  3371. }
  3372. stdXmj.spread.refresh();
  3373. } else if (tab.attr('content') === '#std-gcl') {
  3374. if (!stdGcl) {
  3375. stdGcl = $.stdLib(stdGclSetting);
  3376. }
  3377. stdGcl.spread.refresh();
  3378. } else if (tab.attr('content') === '#deal-bills') {
  3379. dealBills.loadData();
  3380. dealBills.spread.refresh();
  3381. } else if (tab.attr('content') === '#search') {
  3382. if (!searchLedger) {
  3383. searchLedger = $.billsSearch({
  3384. selector: '#search',
  3385. searchSpread: billsSpread,
  3386. searchOver: true,
  3387. searchEmpty: true,
  3388. resultSpreadSetting: {
  3389. cols: [
  3390. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3391. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3392. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3393. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3394. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3395. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3396. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  3397. ],
  3398. emptyRows: 0,
  3399. headRows: 1,
  3400. headRowHeight: [32],
  3401. headColWidth: [30],
  3402. defaultRowHeight: 21,
  3403. headerFont: '12px 微软雅黑',
  3404. font: '12px 微软雅黑',
  3405. selectedBackColor: '#fffacd',
  3406. readOnly: true,
  3407. },
  3408. afterLocated: function () {
  3409. posSpreadObj.loadCurPosData();
  3410. },
  3411. customSearch: [
  3412. {
  3413. key: 'revise', title: '新增部位', valid: true, parent: true,
  3414. check: function (node) {
  3415. if (node.formc || node.cid) {
  3416. return true;
  3417. } else {
  3418. return false;
  3419. }
  3420. }
  3421. }
  3422. ],
  3423. });
  3424. }
  3425. searchLedger.spread.refresh();
  3426. } else if (tab.attr('content') === '#error-list') {
  3427. errorList.spread.refresh();
  3428. } else if (tab.attr('content') === '#check-list') {
  3429. checkList.spread.refresh();
  3430. } else if (tab.attr('content') === '#sum-load-miss') {
  3431. sumLoadMiss.spread.refresh();
  3432. } else if (tab.attr('content') === '#dsk-list') {
  3433. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  3434. $(dskActiveTab).addClass('active');
  3435. if (dskActiveTab === '#jlzf-spread') {
  3436. $('#get-dsk-btn').hide();
  3437. $('#get-dsk-bills-btn').hide();
  3438. jlzfBills.loadData();
  3439. jlzfBills.spread.refresh();
  3440. } else if (dskActiveTab === '#dsk-spread') {
  3441. $('#get-dsk-btn').show();
  3442. $('#get-dsk-bills-btn').show();
  3443. dskBills.loadData();
  3444. dskBills.spread.refresh();
  3445. }
  3446. }
  3447. }
  3448. else {// 收起工具栏
  3449. tab.removeClass('active');
  3450. tabPanel.removeClass('active');
  3451. showSideTools(tab.hasClass('active'));
  3452. }
  3453. billsSpread.refresh();
  3454. if (posSpread) posSpread.refresh();
  3455. });
  3456. // 新增清单切换tab
  3457. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  3458. e.preventDefault();
  3459. const dskActiveTab = $(this).attr('href');
  3460. if (dskActiveTab === '#jlzf-spread') {
  3461. $('#get-dsk-btn').hide();
  3462. $('#get-dsk-bills-btn').hide();
  3463. jlzfBills.loadData();
  3464. jlzfBills.spread.refresh();
  3465. } else if (dskActiveTab === '#dsk-spread') {
  3466. $('#get-dsk-btn').show();
  3467. $('#get-dsk-bills-btn').show();
  3468. dskBills.loadData();
  3469. dskBills.spread.refresh();
  3470. }
  3471. });
  3472. // 显示层次
  3473. (function (select, sheet) {
  3474. $(select).click(function () {
  3475. if (!sheet.zh_tree) return;
  3476. const tag = $(this).attr('tag');
  3477. const tree = sheet.zh_tree;
  3478. setTimeout(() => {
  3479. showWaitingView();
  3480. switch (tag) {
  3481. case "1":
  3482. case "2":
  3483. case "3":
  3484. case "4":
  3485. case "5":
  3486. tree.expandByLevel(parseInt(tag));
  3487. SpreadJsObj.refreshTreeRowVisible(sheet);
  3488. break;
  3489. case "last":
  3490. tree.expandByCustom(() => { return true; });
  3491. SpreadJsObj.refreshTreeRowVisible(sheet);
  3492. break;
  3493. case "leafXmj":
  3494. tree.expandToLeafXmj();
  3495. SpreadJsObj.refreshTreeRowVisible(sheet);
  3496. break;
  3497. }
  3498. closeWaitingView();
  3499. }, 100);
  3500. });
  3501. })('a[name=showLevel]', billsSheet);
  3502. if (openRevise) {
  3503. const dataChecker = DataChecker({
  3504. checkUrl: window.location.pathname + '/check',
  3505. completeData: function (data) {
  3506. pos.updateDatas({update: data.source.pos});
  3507. const loadResult = billsTree.loadPostData({update: data.source.bills});
  3508. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3509. posSpreadObj.loadCurPosData();
  3510. for (const e of data.error) {
  3511. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  3512. }
  3513. },
  3514. errorList: errorList,
  3515. });
  3516. $('#ledger-check2').click(() => {
  3517. ledgerCheck2({
  3518. ledgerTree: billsTree,
  3519. ledgerPos: pos,
  3520. checkList: checkList,
  3521. decimal: decimal,
  3522. checkOption: checkOption,
  3523. }).then(result => {
  3524. check2Viewing({
  3525. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  3526. randomWait: true,
  3527. prefix: 'check2-',
  3528. checks: result,
  3529. checkList: checkList,
  3530. });
  3531. });
  3532. });
  3533. if (isYb) {
  3534. let compilationList = [];
  3535. $('#get-dsk-btn').click(function () {
  3536. // 判断是否已绑定dsk用户
  3537. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  3538. if (result === 1) {
  3539. $('#error-dsk .modal-body').find('h5').eq(0).show();
  3540. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  3541. $('#error-dsk').modal('show');
  3542. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  3543. } else if (result === 2) {
  3544. $('#error-dsk .modal-body').find('h5').eq(1).show();
  3545. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  3546. $('#error-dsk').modal('show');
  3547. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  3548. } else {
  3549. postData('/profile/dsk/api', {
  3550. type: 'compilation',
  3551. getProject: 1,
  3552. compilationId: getLocalCache(dskCompilation)
  3553. }, function (result) {
  3554. let html = '';
  3555. for (const data of result.compilation) {
  3556. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  3557. }
  3558. dskAccountData = result.dskAccountData;
  3559. compilationList = result.compilation;
  3560. console.log(compilationList);
  3561. $('#dsk-compilation-list').html(html);
  3562. $('#add-dsk').modal('show');
  3563. setLocalCache(dskCompilation, result.select_compilation);
  3564. makeDskProjectSjsHtml(result.project);
  3565. });
  3566. }
  3567. })
  3568. });
  3569. $('#get-dsk-bills-btn').click(function () {
  3570. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  3571. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  3572. });
  3573. $('body').on('change', '#dsk-compilation-list', function () {
  3574. const compilationId = $(this).val();
  3575. setLocalCache(dskCompilation, compilationId);
  3576. dskProjectSpreadObj.refreshSourceTree();
  3577. });
  3578. $('.hide-dsk-modal').click(function () {
  3579. $('#error-dsk').modal('hide');
  3580. });
  3581. let dp = false;
  3582. let gsObj = {
  3583. setting: null,
  3584. gsSheet: null,
  3585. grSheet: null,
  3586. tenderSourceTree: null,
  3587. grArray: dskProjects ? dskProjects : [],
  3588. orgSelect: null,
  3589. };
  3590. function makeDskProjectSjsHtml(datas) {
  3591. if (!dp) {
  3592. initDskProjectTree();
  3593. dp = true;
  3594. }
  3595. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  3596. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  3597. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  3598. if (datas.length === 0) {
  3599. $('#show-project-0').show();
  3600. } else {
  3601. $('#show-project-0').hide();
  3602. }
  3603. }
  3604. const dskProjectSpreadObj = {
  3605. _addTender: function (tender) {
  3606. const gr = gsObj.grArray.find(function (x) {
  3607. return x.pid === tender.pid;
  3608. });
  3609. const c_id = getLocalCache(dskCompilation);
  3610. const t = {
  3611. pid: tender.pid,
  3612. name: tender.name,
  3613. compilationId: c_id,
  3614. compilationName: _.find(compilationList, {ID: c_id}).name
  3615. };
  3616. if (!gr) gsObj.grArray.push(t);
  3617. return t;
  3618. },
  3619. _removeTender: function (tender) {
  3620. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  3621. return x.pid === tender.pid;
  3622. });
  3623. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  3624. },
  3625. reloadResultData: function () {
  3626. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  3627. },
  3628. refreshSourceTree: function () {
  3629. const c_id = getLocalCache(dskCompilation);
  3630. if (c_id) {
  3631. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  3632. makeDskProjectSjsHtml(result);
  3633. });
  3634. }
  3635. },
  3636. gsButtonClicked: function (e, info) {
  3637. if (!info.sheet.zh_setting) return;
  3638. const col = info.sheet.zh_setting.cols[info.col];
  3639. if (col.field !== 'selected') return;
  3640. const node = SpreadJsObj.getSelectObject(info.sheet);
  3641. node.selected = !node.selected;
  3642. if (node.children && node.children.length > 0) {
  3643. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  3644. for (const p of posterity) {
  3645. p.selected = node.selected;
  3646. if ((!p.children || p.children.length === 0) && p.type === 2) {
  3647. if (p.selected) {
  3648. dskProjectSpreadObj._addTender(p);
  3649. } else {
  3650. dskProjectSpreadObj._removeTender(p);
  3651. }
  3652. }
  3653. }
  3654. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  3655. } else if (node.type === 2) {
  3656. if (node.selected) {
  3657. dskProjectSpreadObj._addTender(node);
  3658. } else {
  3659. dskProjectSpreadObj._removeTender(node);
  3660. }
  3661. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  3662. }
  3663. dskProjectSpreadObj.reloadResultData();
  3664. },
  3665. deleteGr: function () {
  3666. if (gsObj.grArray.length === 0) return;
  3667. if (gsObj.grSheet.getSelections().length === 0) return;
  3668. const selections = gsObj.grSheet.getSelections();
  3669. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  3670. const row = sel && sel.row !== undefined ? sel.row : -1;
  3671. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3672. return false;
  3673. }
  3674. const delList = [];
  3675. for (let r = 0; r < sel.rowCount; r++) {
  3676. const select = gsObj.grArray[row + r];
  3677. delList.push(select);
  3678. }
  3679. _.pullAll(gsObj.grArray, delList);
  3680. dskProjectSpreadObj.reloadResultData();
  3681. dskProjectSpreadObj.refreshSourceTree();
  3682. },
  3683. };
  3684. const initDskProjectTree = function () {
  3685. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  3686. gsObj.gsSheet = gsSpread.getActiveSheet();
  3687. const gsSpreadSetting = {
  3688. cols: [
  3689. {
  3690. title: '选择',
  3691. field: 'selected',
  3692. hAlign: 1,
  3693. width: 40,
  3694. formatter: '@',
  3695. cellType: 'checkbox',
  3696. readOnly: true,
  3697. },
  3698. {
  3699. title: '名称',
  3700. field: 'name',
  3701. hAlign: 0,
  3702. width: 400,
  3703. formatter: '@',
  3704. readOnly: true,
  3705. folderCell: true,
  3706. cellType: 'tree'
  3707. },
  3708. ],
  3709. emptyRows: 0,
  3710. headRows: 1,
  3711. headRowHeight: [32],
  3712. defaultRowHeight: 21,
  3713. headerFont: '12px 微软雅黑',
  3714. font: '12px 微软雅黑',
  3715. headColWidth: [0],
  3716. selectedBackColor: '#fffacd',
  3717. };
  3718. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  3719. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  3720. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  3721. gsObj.grSheet = grSpread.getActiveSheet();
  3722. const grSpreadSetting = {
  3723. cols: [
  3724. {
  3725. title: '名称',
  3726. colSpan: '1',
  3727. rowSpan: '1',
  3728. field: 'name',
  3729. hAlign: 0,
  3730. width: 250,
  3731. formatter: '@',
  3732. readOnly: true,
  3733. cellType: 'ellipsisAutoTip',
  3734. scrollHeightClass: '.modal-height-500'
  3735. },
  3736. {
  3737. title: '所属编办',
  3738. colSpan: '1',
  3739. rowSpan: '1',
  3740. field: 'compilationName',
  3741. hAlign: 0,
  3742. width: 150,
  3743. formatter: '@',
  3744. readOnly: true
  3745. },
  3746. ],
  3747. emptyRows: 0,
  3748. headRows: 1,
  3749. headRowHeight: [32],
  3750. defaultRowHeight: 21,
  3751. headerFont: '12px 微软雅黑',
  3752. font: '12px 微软雅黑',
  3753. headColWidth: []
  3754. };
  3755. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  3756. // 右键删除已选项目
  3757. const gsContextMenuOptions = {
  3758. selector: '#dsk-project-result-spread',
  3759. build: function ($trigger, e) {
  3760. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  3761. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3762. },
  3763. items: {
  3764. delete: {
  3765. name: '删除',
  3766. icon: 'fa-remove',
  3767. callback: function (key, opt) {
  3768. dskProjectSpreadObj.deleteGr();
  3769. },
  3770. disabled: function (key, opt) {
  3771. const selection = gsObj.grSheet.getSelections();
  3772. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  3773. const row = sel && sel.row !== undefined ? sel.row : -1;
  3774. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3775. return true;
  3776. }
  3777. return false;
  3778. }
  3779. },
  3780. }
  3781. };
  3782. $.contextMenu(gsContextMenuOptions);
  3783. $('#add-dsk').bind('shown.bs.modal', function () {
  3784. if (gsSpread) gsSpread.refresh();
  3785. if (grSpread) grSpread.refresh();
  3786. });
  3787. };
  3788. const dskProject2Tree = (function () {
  3789. const treeSetting = {
  3790. id: 'tmt_id',
  3791. pid: 'tmt_pid',
  3792. order: 'seq',
  3793. level: 'level',
  3794. rootId: '-1',
  3795. fullPath: 'full_path',
  3796. };
  3797. const tenderTree = createNewPathTree('gather', treeSetting);
  3798. function setChildrenNode(node, files, tenders) {
  3799. const children = _.filter(files, {parentID: node.pid});
  3800. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  3801. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  3802. for (const c of checkChildren) {
  3803. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  3804. // // 判断文件夹下有无东西,没有就不插入
  3805. // continue;
  3806. // }
  3807. const child = {
  3808. pid: c.ID,
  3809. parentID: c.parentID,
  3810. name: c.name,
  3811. type: c.type,
  3812. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  3813. };
  3814. tenderTree.addNode(child, node);
  3815. if (c.type === 1) setChildrenNode(child, files, tenders);
  3816. }
  3817. }
  3818. function convert(projects) {
  3819. tenderTree.clearDatas();
  3820. const result = filterFolders(projects);
  3821. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  3822. const files = _.filter(result, {type: 1});
  3823. const tenders = _.filter(result, {type: 2});
  3824. for (const t of topLevel) {
  3825. const node = {
  3826. pid: t.ID,
  3827. parentID: t.parentID,
  3828. name: t.name,
  3829. type: t.type,
  3830. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  3831. };
  3832. tenderTree.addNode(node, null);
  3833. if (t.type === 1) setChildrenNode(node, files, tenders);
  3834. }
  3835. tenderTree.sortTreeNode(true);
  3836. return tenderTree;
  3837. }
  3838. return {tenderTree, convert}
  3839. })();
  3840. function filterFolders(data) {
  3841. // 构建ID到节点的映射
  3842. const idMap = data.reduce((map, node) => {
  3843. map[node.ID] = node;
  3844. return map;
  3845. }, {});
  3846. // 建立父子关系映射
  3847. const parentMap = data.reduce((map, node) => {
  3848. if (node.parentID !== '-1') {
  3849. if (!map[node.parentID]) {
  3850. map[node.parentID] = [];
  3851. }
  3852. map[node.parentID].push(node.ID);
  3853. }
  3854. return map;
  3855. }, {});
  3856. // 检查节点及其子节点是否包含清单(type=1)
  3857. const hasChecklist = (id) => {
  3858. const node = idMap[id];
  3859. if (node.type === 2) {
  3860. return true;
  3861. }
  3862. if (!parentMap[id]) {
  3863. return false;
  3864. }
  3865. return parentMap[id].some(childID => hasChecklist(childID));
  3866. };
  3867. // 过滤节点
  3868. const filteredIDs = new Set();
  3869. data.forEach(node => {
  3870. if (node.type === 2 || hasChecklist(node.ID)) {
  3871. let currentID = node.ID;
  3872. while (currentID !== '-1') {
  3873. filteredIDs.add(currentID);
  3874. currentID = idMap[currentID].parentID;
  3875. }
  3876. }
  3877. });
  3878. // 返回过滤后的数据
  3879. return data.filter(node => filteredIDs.has(node.ID));
  3880. }
  3881. $('#set-dsk-project').click(function () {
  3882. postData('/profile/dsk/api', {
  3883. type: 'save_projects',
  3884. tid: window.location.pathname.split('/')[2],
  3885. project_list: gsObj.grArray
  3886. }, function (result) {
  3887. // dskAccountData.select_project = result;
  3888. dskProjects = gsObj.grArray;
  3889. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  3890. dskAccountData.select_project = result;
  3891. changeDskProject(result);
  3892. dskBills.spread.refresh();
  3893. }
  3894. setDskProjectSelect(gsObj.grArray);
  3895. $('#add-dsk').modal('hide');
  3896. });
  3897. });
  3898. $('#add-dsk').on('hide.bs.modal', function () {
  3899. $('#autoTip').hide();
  3900. });
  3901. function setDskProjectSelect(projects) {
  3902. let html = '';
  3903. for (const project of projects) {
  3904. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  3905. }
  3906. $('#change-dsk-project').html(html);
  3907. }
  3908. // 选中所有新增部位/清单
  3909. $('#add-all-revise').click(function() {
  3910. const this_cid = window.location.pathname.split('/')[4];
  3911. makeGclGatherData();
  3912. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3913. type: 'get-revise-list',
  3914. }, function (result) {
  3915. const addDatas = [];
  3916. for (const ggd in gclGatherData) {
  3917. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  3918. let hadcid = 0;
  3919. for (const xmj of gclGatherData[ggd].leafXmjs) {
  3920. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  3921. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  3922. if (changeLedger || changePos) {
  3923. xmj.cid = 1;
  3924. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  3925. hadcid = 1;
  3926. }
  3927. }
  3928. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  3929. }
  3930. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  3931. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  3932. if (leafXmjs.length > 0) {
  3933. gclInfo.is_change = 1;
  3934. for (const xmj of leafXmjs) {
  3935. if (_.findIndex(changeList, function (item) {
  3936. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  3937. }) === -1) {
  3938. addDatas.push({
  3939. lid: xmj.gcl_id,
  3940. code: gclInfo.code,
  3941. name: gclInfo.name || '',
  3942. unit: gclInfo.unit || '',
  3943. unit_price: gclInfo.unit_price,
  3944. oamount: xmj.quantity,
  3945. oamount2: xmj.quantity,
  3946. bwmx: xmj.bwmx || xmj.jldy || '',
  3947. xmj_code: xmj.code || '',
  3948. xmj_jldy: xmj.jldy || '',
  3949. xmj_dwgc: xmj.dwgc || '',
  3950. xmj_fbgc: xmj.fbgc || '',
  3951. xmj_fxgc: xmj.fxgc || '',
  3952. gcl_id: xmj.gcl_id,
  3953. mx_id: xmj.mx_id || '',
  3954. });
  3955. }
  3956. }
  3957. }
  3958. }
  3959. console.log(addDatas);
  3960. if (addDatas.length > 0) {
  3961. // 更新至服务器
  3962. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3963. type: 'add-change-list',
  3964. postData: addDatas,
  3965. }, function (result) {
  3966. toastr.success('已新增当前变更令新增的所有部位/清单');
  3967. changeList = result.changeList;
  3968. const sortData = SpreadJsObj.getSortData(billsSheet);
  3969. const billsNodes = _.filter(sortData, function (item) {
  3970. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  3971. });
  3972. for (const billsNode of billsNodes) {
  3973. billsNode.is_change = 1;
  3974. }
  3975. const loadResult = { update: billsNodes };
  3976. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3977. posSpreadObj.loadCurPosData();
  3978. });
  3979. } else {
  3980. toastr.warning('未存在当前变更令新增的部位/清单');
  3981. }
  3982. });
  3983. });
  3984. }
  3985. }
  3986. });
  3987. // 编号排序,多重判断
  3988. function sortByCode(a, b, code = 'b_code') {
  3989. let code1 = a[code].split('-');
  3990. let code2 = b[code].split('-');
  3991. let code1length = code1.length;
  3992. let code2length = code2.length;
  3993. for (let i = 0; i < code1length; i ++) {
  3994. if (i+1 <= code2length) {
  3995. if (code1[i] != code2[i]) {
  3996. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  3997. return parseInt(code1[i]) - parseInt(code2[i]);
  3998. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  3999. return 1;
  4000. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  4001. return -1;
  4002. } else {
  4003. const str1length = code1[i].length;
  4004. const str2length = code2[i].length;
  4005. for (let j = 0; j < str1length; j++) {
  4006. if (j+1 <= str2length) {
  4007. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  4008. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  4009. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  4010. if (str1length == str2length) {
  4011. return 0;
  4012. } else {
  4013. return str1length - str2length;
  4014. }
  4015. }
  4016. } else {
  4017. if (j+1 >= str1length) {
  4018. return 1;
  4019. } else {
  4020. return -1;
  4021. }
  4022. }
  4023. }
  4024. }
  4025. } else if (i+1 == code1length && code1[i] == code2[i]) {
  4026. if (code1length == code2length) {
  4027. return 0;
  4028. } else {
  4029. return code1length - code2length;
  4030. }
  4031. }
  4032. } else {
  4033. if (i+1 >= code1length) {
  4034. return 1;
  4035. } else {
  4036. return -1;
  4037. }
  4038. }
  4039. }
  4040. }