change_revise.js 196 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161
  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. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  2095. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  2096. toastr.warning('新增计量单元请先输入名称');
  2097. posSpreadObj.loadCurPosData();
  2098. return;
  2099. }
  2100. }
  2101. let bHint = false;
  2102. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2103. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2104. let bPaste = true;
  2105. const curRow = info.cellRange.row + iRow;
  2106. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2107. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2108. const curCol = info.cellRange.col + iCol;
  2109. const colSetting = info.sheet.zh_setting.cols[curCol];
  2110. if (!colSetting) continue;
  2111. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2112. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  2113. bPaste = false;
  2114. toastMessageUniq(hint.settle);
  2115. continue;
  2116. }
  2117. if (colSetting.type === 'Number') {
  2118. const num = _.toNumber(posData[colSetting.field]);
  2119. if (num) {
  2120. posData[colSetting.field] = num;
  2121. } else {
  2122. try {
  2123. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  2124. const exprInfo = getExprInfo(colSetting.field);
  2125. if (exprInfo) {
  2126. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2127. }
  2128. } catch (err) {
  2129. if (!bHint) {
  2130. toastr.warning('粘贴了非法表达式,已过滤');
  2131. bHint = true;
  2132. }
  2133. bPaste = false;
  2134. }
  2135. }
  2136. } else if (colSetting.field.indexOf('_expr') > 0) {
  2137. try {
  2138. const exprInfo = getExprInfo(colSetting.field, true);
  2139. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2140. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  2141. posData[exprInfo.qty] = math.evaluate(transExpr(posData[exprInfo.expr]));
  2142. }
  2143. bPaste = true;
  2144. } catch (err) {
  2145. toastMessageUniq(hint.expr);
  2146. }
  2147. } else {
  2148. bPaste = true;
  2149. }
  2150. }
  2151. if (bPaste) {
  2152. data.push(posData);
  2153. }
  2154. }
  2155. if (data.length === 0) {
  2156. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2157. return;
  2158. }
  2159. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  2160. changeList = result.changeList;
  2161. pos.updateDatas(result.pos);
  2162. posSpreadObj.loadCurPosData();
  2163. const loadResult = billsTree.loadPostData(result.ledger);
  2164. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2165. posSpreadObj.loadCurPosData();
  2166. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2167. }, function () {
  2168. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2169. });
  2170. },
  2171. selectionChanged: function (e, info) {
  2172. posSpreadObj.loadExprToInput();
  2173. posSpreadObj.refreshOperationValid(posSheet);
  2174. },
  2175. addPegs: function (pegs) {
  2176. if (!pegs || pegs.length <= 0) return;
  2177. const node = SpreadJsObj.getSelectObject(billsSheet);
  2178. if (!node) return;
  2179. const sheet = posSpread.getActiveSheet();
  2180. const sortData = sheet.zh_data || [];
  2181. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2182. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2183. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  2184. changeList = result.changeList;
  2185. pos.updateDatas(result.pos);
  2186. posSpreadObj.loadCurPosData();
  2187. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2188. });
  2189. }
  2190. };
  2191. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  2192. if (!readOnly && isTz) {
  2193. $('a[name="pos-opr"]').click(function () {
  2194. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  2195. });
  2196. $('#pos-expr').bind('change onblur', function () {
  2197. if (this.readOnly) return;
  2198. const expr = $(this);
  2199. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2200. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2201. if (!select) return;
  2202. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  2203. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  2204. const data = {id: select.id};
  2205. const exprInfo = getExprInfo(field);
  2206. if (newValue !== '') {
  2207. const num = _.toNumber(newValue);
  2208. if (num) {
  2209. data[field] = num;
  2210. if (exprInfo) data[exprInfo.expr] = '';
  2211. } else {
  2212. try {
  2213. data[field] = math.evaluate(transExpr(newValue));
  2214. if (exprInfo) data[exprInfo.expr] = newValue;
  2215. } catch (err) {
  2216. toastr.error('输入的表达式非法');
  2217. return;
  2218. }
  2219. }
  2220. } else {
  2221. data[field] = null;
  2222. if (exprInfo) data[exprInfo.expr] = '';
  2223. }
  2224. // 更新至服务器
  2225. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  2226. changeList = result.changeList;
  2227. const updateRst = pos.updateDatas(result.pos);
  2228. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2229. SpreadJsObj.reLoadRowData(posSheet, row);
  2230. const loadResult = billsTree.loadPostData(result.ledger);
  2231. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2232. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2233. });
  2234. });
  2235. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  2236. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  2237. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  2238. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  2239. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  2240. $.contextMenu({
  2241. selector: '#pos-spread',
  2242. build: function ($trigger, e) {
  2243. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2244. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2245. },
  2246. items: {
  2247. 'delete': {
  2248. name: '删除',
  2249. icon: 'fa-remove',
  2250. disabled: function (key, opt) {
  2251. if (posSheet.zh_data) {
  2252. const selection = posSheet.getSelections();
  2253. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2254. const row = sel ? sel.row : -1;
  2255. const rowCount = sel.rowCount;
  2256. let settleFinish = false;
  2257. for (let i = row; i < row + rowCount; i++) {
  2258. if (!posSheet.zh_data[i]) continue;
  2259. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  2260. }
  2261. 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;
  2262. } else {
  2263. return true;
  2264. }
  2265. },
  2266. callback: function (key, opt) {
  2267. posSpreadObj.deletePos(posSheet);
  2268. }
  2269. },
  2270. }
  2271. });
  2272. }
  2273. // 加载清单&计量单元数据
  2274. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  2275. let gclGatherData;
  2276. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  2277. for (const b of result.bills) {
  2278. if (!(b.is_leaf && b.b_code)) {
  2279. b.is_change = 0;
  2280. } else {
  2281. const cInfo = _.find(changeList, { gcl_id: b.id });
  2282. b.is_change = cInfo ? 1 : 0;
  2283. }
  2284. }
  2285. billsTree.loadDatas(result.bills);
  2286. pos.loadDatas(result.pos);
  2287. treeCalc.calculateAll(billsTree);
  2288. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  2289. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  2290. checkShowLast(result.bills.length);
  2291. posSpreadObj.loadCurPosData();
  2292. SpreadJsObj.resetTopAndSelect(posSheet);
  2293. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2294. billsTreeSpreadObj.loadExprToInput(billsSheet);
  2295. checkList.loadHisCheckData();
  2296. console.log(billsTree);
  2297. }, null);
  2298. $.divResizer({
  2299. select: '#revise-resize',
  2300. callback: function () {
  2301. billsSpread.refresh();
  2302. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2303. $(".sp-wrap").height(bcontent-30);
  2304. posSpread.refresh();
  2305. }
  2306. });
  2307. function makeGclGatherData() {
  2308. gclGatherModel.loadLedgerData(billsTree.datas);
  2309. gclGatherModel.loadPosData(pos.datas);
  2310. gclGatherData = gclGatherModel.gatherGclData();
  2311. gclGatherData = _.filter(gclGatherData, function (item) {
  2312. return item.leafXmjs && item.leafXmjs.length !== 0;
  2313. });
  2314. gclGatherData = gclGatherData.sort(sortByCode);
  2315. console.log(gclGatherData);
  2316. }
  2317. class DealBills {
  2318. constructor (selector, spreadSetting) {
  2319. const self = this;
  2320. this.loaded = false;
  2321. this.obj = $(selector)[0];
  2322. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2323. this.spreadSetting = spreadSetting;
  2324. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2325. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2326. if (!readOnly) {
  2327. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2328. const dealSheet = info.sheet;
  2329. const mainSheet = billsSheet;
  2330. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2331. if (!dealBills) { return; }
  2332. const mainTree = mainSheet.zh_tree;
  2333. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2334. if (!mainNode || !mainTree) { return; }
  2335. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2336. toastr.warning('非最底层项目下,不应添加节点');
  2337. return;
  2338. }
  2339. if (mainNode.settle_status === settleStatus.finish) {
  2340. toastr.warning('已结算节点下,不应添加签约清单');
  2341. return;
  2342. }
  2343. postData(window.location.pathname + '/update', {
  2344. postType: 'add-deal',
  2345. postData: {
  2346. id: mainNode.ledger_id,
  2347. type: mainNode.code ? 'child' : 'next',
  2348. dealBills: {
  2349. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2350. unit_price: dealBills.unit_price,
  2351. }
  2352. },
  2353. }, function (result) {
  2354. changeList = result.changeList;
  2355. const refreshData = mainTree.loadPostData(result);
  2356. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2357. const sel = mainSheet.getSelections()[0];
  2358. if (sel && refreshData.create[0]) {
  2359. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2360. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2361. }
  2362. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2363. billsSpread.focus();
  2364. posSpreadObj.loadCurPosData();
  2365. });
  2366. });
  2367. }
  2368. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2369. }
  2370. loadData (callback) {
  2371. if (this.loaded) {
  2372. if (callback) callback();
  2373. return;
  2374. }
  2375. const self = this;
  2376. postData(this.url+'/get-data', {}, function (data) {
  2377. self.data = data;
  2378. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2379. self.loaded = true;
  2380. if (callback) callback();
  2381. });
  2382. }
  2383. calculateData () {
  2384. if (this.data) {
  2385. for (const d of this.data) {
  2386. d.total_price = _.multiply(d.quantity, d.unit_price);
  2387. }
  2388. }
  2389. }
  2390. }
  2391. class BatchInsertBillsPosObj {
  2392. constructor (obj) {
  2393. const self = this;
  2394. this.obj = obj;
  2395. this.billsCount = 6;
  2396. this.posCount = 1000;
  2397. this.filter = getLocalCache('zh-calc-batch-filter');
  2398. if (!this.filter) {
  2399. this.filter = '1';
  2400. }
  2401. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2402. // 初始化 清单编号窗口 参数
  2403. this.qdSpreadSetting = {
  2404. cols: [
  2405. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2406. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2407. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2408. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2409. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2410. ],
  2411. emptyRows: this.billsCount,
  2412. headRows: 1,
  2413. headRowHeight: [32],
  2414. headerFont: '12px 微软雅黑',
  2415. font: '12px 微软雅黑',
  2416. };
  2417. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2418. // 初始化 部位数量复核表 参数
  2419. this.posSpreadSetting = {
  2420. cols: [
  2421. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2422. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2423. ],
  2424. emptyRows: this.posCount,
  2425. headRows: 1,
  2426. headRowHeight: [32],
  2427. headerFont: '12px 微软雅黑',
  2428. font: '12px 微软雅黑',
  2429. };
  2430. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2431. this.posSpreadSetting.cols.push(
  2432. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2433. )
  2434. }
  2435. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2436. // 初始化 签约节点 参数
  2437. this.dealSpreadSetting = {
  2438. cols: [
  2439. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2440. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2441. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2442. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2443. ],
  2444. emptyRows: 0,
  2445. headRows: 1,
  2446. headRowHeight: [32],
  2447. headerFont: '12px 微软雅黑',
  2448. font: '12px 微软雅黑',
  2449. };
  2450. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2451. // 初始化 清单编号、部位数量复核表 表格
  2452. this.initView();
  2453. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2454. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2455. // 拉取签约节点数据
  2456. dealBills.loadData(() => {
  2457. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2458. });
  2459. // 双击签约节点,自动添加到清单编号窗口
  2460. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2461. const deal = info.sheet.zh_data[info.row];
  2462. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2463. const sel = qdSheet.getSelections()[0];
  2464. qdSheet.getCell(sel.row, 0).value(deal.code);
  2465. qdSheet.getCell(sel.row, 1).value(deal.name);
  2466. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2467. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2468. if (sel.row + 1 === qdSheet.getRowCount()) {
  2469. const count = sel.row + 2;
  2470. qdSheet.setRowCount(count);
  2471. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2472. const colCount = posSheet.getColumnCount() + 1;
  2473. posSheet.setColumnCount(colCount);
  2474. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2475. }
  2476. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2477. qdSheet.getParent().focus();
  2478. });
  2479. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2480. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  2481. const count = posSheet.getColumnCount() - 2;
  2482. if (billsCount > count) {
  2483. posSheet.setColumnCount(billsCount + 2);
  2484. for (let i = count + 1; i <= billsCount; i++) {
  2485. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2486. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2487. }
  2488. }
  2489. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  2490. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2491. if (dealBills && dealBills.length > 0) {
  2492. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2493. const curRow = iRow + info.cellRange.row;
  2494. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  2495. if (bills) {
  2496. info.sheet.getCell(curRow, 1).value(bills.name);
  2497. info.sheet.getCell(curRow, 2).value(bills.unit);
  2498. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  2499. }
  2500. }
  2501. }
  2502. }
  2503. });
  2504. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2505. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2506. const count = qdSheet.getRowCount();
  2507. if (billsCount > count) {
  2508. qdSheet.setRowCount(billsCount);
  2509. for (let i = count + 1; i <= billsCount; i++) {
  2510. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2511. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2512. }
  2513. }
  2514. });
  2515. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2516. if (info.col === 0) {
  2517. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2518. if (dealBills && dealBills.length > 0) {
  2519. const bills = _.find(dealBills, {code: info.editingText});
  2520. if (bills) {
  2521. info.sheet.getCell(info.row, 1).value(bills.name);
  2522. info.sheet.getCell(info.row, 2).value(bills.unit);
  2523. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2524. }
  2525. }
  2526. }
  2527. });
  2528. this.obj.bind('shown.bs.modal', function () {
  2529. self.qdSpread.refresh();
  2530. self.posSpread.refresh();
  2531. self.dealSpread.refresh();
  2532. });
  2533. $('#batch-ok').click(function () {
  2534. const selection = billsSheet.getSelections();
  2535. const sel = selection[0];
  2536. const row = selection[0].row;
  2537. const select = billsTree.nodes[row];
  2538. if (select) {
  2539. const insertData = {};
  2540. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2541. insertData.id = select[billsTree.setting.id];
  2542. insertData.batchData = self.getBatchData();
  2543. if (insertData.batchData.length > 0) {
  2544. postData(window.location.pathname + '/update', {
  2545. postType: 'batch-insert',
  2546. postData: insertData
  2547. }, function (data) {
  2548. changeList = result.changeList;
  2549. pos.updateDatas(data.pos);
  2550. const result = billsTree.loadPostData(data.ledger);
  2551. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2552. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2553. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2554. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2555. posSpreadObj.loadCurPosData();
  2556. self.obj.modal('hide');
  2557. }, null, true);
  2558. } else {
  2559. self.obj.modal('hide');
  2560. }
  2561. }
  2562. });
  2563. $('input[name=batch-filter]').change(function () {
  2564. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2565. });
  2566. $.contextMenu({
  2567. selector: '.batch-l-t',
  2568. build: function ($trigger, e) {
  2569. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2570. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2571. },
  2572. items: {
  2573. 'create': {
  2574. name: '新增行',
  2575. icon: 'fa-sign-in',
  2576. callback: function (key, opt) {
  2577. const qdSheet = self.qdSpread.getActiveSheet();
  2578. const posSheet = self.posSpread.getActiveSheet();
  2579. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2580. const index = qdSheet.getRowCount();
  2581. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2582. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2583. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2584. },
  2585. },
  2586. 'delete': {
  2587. name: '删除行',
  2588. icon: 'fa-remove',
  2589. callback: function (key, opt) {
  2590. const qdSheet = self.qdSpread.getActiveSheet();
  2591. const posSheet = self.posSpread.getActiveSheet();
  2592. const sel = qdSheet.getSelections()[0];
  2593. qdSheet.deleteRows(sel.row, sel.rowCount);
  2594. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2595. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2596. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2597. }
  2598. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2599. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2600. }
  2601. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2602. },
  2603. },
  2604. }
  2605. });
  2606. }
  2607. // 初始化左侧表格
  2608. initView () {
  2609. // 初始化 清单编号
  2610. const qdSheet = this.qdSpread.getActiveSheet();
  2611. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2612. SpreadJsObj.refreshColumnAlign(qdSheet);
  2613. // 清理原有数据
  2614. SpreadJsObj.beginMassOperation(qdSheet);
  2615. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2616. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2617. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2618. }
  2619. qdSheet.setSelection(0, 0, 1 ,1);
  2620. SpreadJsObj.endMassOperation(qdSheet);
  2621. // 初始化 部位数量复核表
  2622. const posSheet = this.posSpread.getActiveSheet();
  2623. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2624. SpreadJsObj.refreshColumnAlign(posSheet);
  2625. // 清理原有数据
  2626. SpreadJsObj.beginMassOperation(posSheet);
  2627. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2628. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2629. posSheet.setSelection(0, 0, 1 ,1);
  2630. SpreadJsObj.endMassOperation(posSheet);
  2631. // 检查签约节点数据,以工具栏数据为准
  2632. if (dealBills) {
  2633. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2634. }
  2635. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2636. }
  2637. // 获取界面数据
  2638. getBatchData () {
  2639. const result = [];
  2640. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2641. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2642. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2643. const qd = {
  2644. b_code: qdSheet.getText(iRow, 0),
  2645. name: qdSheet.getText(iRow, 1),
  2646. unit: qdSheet.getText(iRow, 2),
  2647. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2648. pos: [],
  2649. };
  2650. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2651. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2652. if (value !== 0 && !isNaN(value)) {
  2653. qd.pos.push({
  2654. name: posSheet.getText(iPosRow, 0),
  2655. drawing_code: posSheet.getText(iPosRow, 1),
  2656. quantity: value, porder: qd.pos.length + 1,
  2657. });
  2658. }
  2659. }
  2660. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2661. }
  2662. return result;
  2663. }
  2664. }
  2665. const dealBills = new DealBills('#deal-bills-spread', {
  2666. cols: [
  2667. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2668. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2669. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2670. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2671. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2672. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2673. ],
  2674. emptyRows: 0,
  2675. headRows: 1,
  2676. headRowHeight: [32],
  2677. headColWidth: [30],
  2678. defaultRowHeight: 21,
  2679. headerFont: '12px 微软雅黑',
  2680. font: '12px 微软雅黑',
  2681. selectedBackColor: '#fffacd',
  2682. });
  2683. class Jlzf {
  2684. constructor (selector, spreadSetting) {
  2685. const self = this;
  2686. this.loaded = false;
  2687. this.obj = $(selector);
  2688. const relaSelect = {
  2689. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2690. searchText: `cb-${spreadSetting.stdType}-st`,
  2691. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2692. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2693. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2694. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2695. };
  2696. this.obj.html(
  2697. '<div class="sjs-bar d-flex">\n' +
  2698. ' <div class="ml-1">\n' +
  2699. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  2700. ' <div class="d-inline-block">\n' +
  2701. ' <div class="input-group input-group-sm mr-1">' +
  2702. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2703. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2704. ' <div class="input-group-append" >\n' +
  2705. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2706. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2707. ' </div>\n' +
  2708. ' </div>\n' +
  2709. ' </div>\n' +
  2710. ` <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` +
  2711. ' </div>\n' +
  2712. ' </div>' +
  2713. '</div>\n' +
  2714. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2715. );
  2716. autoFlashHeight();
  2717. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2718. function getObjHeight(select) {
  2719. return select.length > 0 ? select.height() : 0;
  2720. }
  2721. const cHeader = getObjHeight($(".c-header"));
  2722. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2723. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2724. this.spreadSetting = spreadSetting;
  2725. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2726. const searchSheet = this.spread.getActiveSheet();
  2727. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2728. if (!readOnly) {
  2729. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2730. const dealSheet = info.sheet;
  2731. const mainSheet = billsSheet;
  2732. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2733. if (!dealBills) { return; }
  2734. const mainTree = mainSheet.zh_tree;
  2735. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2736. if (!mainNode || !mainTree) { return; }
  2737. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2738. toastr.warning('非最底层项目下,不应添加节点');
  2739. return;
  2740. }
  2741. if (mainNode.settle_status === settleStatus.finish) {
  2742. toastr.warning('已结算节点下,不应添加签约清单');
  2743. return;
  2744. }
  2745. postData(window.location.pathname + '/update', {
  2746. postType: 'add-deal',
  2747. postData: {
  2748. id: mainNode.ledger_id,
  2749. type: mainNode.code ? 'child' : 'next',
  2750. dealBills: {
  2751. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2752. unit_price: dealBills.unit_price,
  2753. }
  2754. },
  2755. }, function (result) {
  2756. changeList = result.changeList;
  2757. const refreshData = mainTree.loadPostData(result);
  2758. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2759. const sel = mainSheet.getSelections()[0];
  2760. if (sel && refreshData.create[0]) {
  2761. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2762. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2763. }
  2764. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2765. billsSpread.focus();
  2766. posSpreadObj.loadCurPosData();
  2767. });
  2768. });
  2769. }
  2770. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2771. const searchObj = {
  2772. result: [],
  2773. cur: 0,
  2774. searchStdNode: function() {
  2775. const keyword = $(`#${relaSelect.searchText}`).val();
  2776. const sortData = SpreadJsObj.getSortData(searchSheet);
  2777. searchObj.result = keyword ? sortData.filter(x => {
  2778. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2779. }) : [];
  2780. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2781. searchObj.cur = 0;
  2782. if (searchObj.result.length > 0) {
  2783. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2784. }
  2785. },
  2786. searchPre: function () {
  2787. if (searchObj.result.length === 0) return;
  2788. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2789. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2790. },
  2791. searchNext: function () {
  2792. if (searchObj.result.length === 0) return;
  2793. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2794. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2795. },
  2796. clear: function () {
  2797. $(`#${relaSelect.searchText}`).val('');
  2798. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2799. searchObj.result = [];
  2800. searchObj.cur = 0;
  2801. }
  2802. };
  2803. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2804. $(`#${relaSelect.searchPre}`).click(function (e) {
  2805. searchObj.searchPre();
  2806. e.stopPropagation();
  2807. });
  2808. $(`#${relaSelect.searchNext}`).click(function (e) {
  2809. searchObj.searchNext();
  2810. e.stopPropagation();
  2811. });
  2812. $(`#${relaSelect.searchClose}`).click(function (e) {
  2813. searchObj.clear();
  2814. e.stopPropagation();
  2815. });
  2816. };
  2817. loadData (callback) {
  2818. // if (this.loaded) {
  2819. // if (callback) callback();
  2820. // return;
  2821. // }
  2822. const self = this;
  2823. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  2824. const showDatas = [];
  2825. for (const d of datas) {
  2826. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  2827. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  2828. }
  2829. }
  2830. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  2831. // self.loaded = true;
  2832. if (callback) callback();
  2833. }
  2834. }
  2835. const jlzfBills = new Jlzf('#jlzf-spread', {
  2836. cols: [
  2837. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2838. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  2839. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2840. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2841. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2842. ],
  2843. emptyRows: 0,
  2844. headRows: 1,
  2845. headRowHeight: [32],
  2846. headColWidth: [30],
  2847. defaultRowHeight: 21,
  2848. headerFont: '12px 微软雅黑',
  2849. font: '12px 微软雅黑',
  2850. selectedBackColor: '#fffacd',
  2851. readOnly: true,
  2852. stdType: 'jlzf',
  2853. });
  2854. class Dsk {
  2855. constructor (selector, spreadSetting) {
  2856. const self = this;
  2857. this.loaded = false;
  2858. this.obj = $(selector);
  2859. const dskProjectHtml = spreadSetting.libs.map(l => {
  2860. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  2861. });
  2862. const relaSelect = {
  2863. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2864. searchText: `cb-${spreadSetting.stdType}-st`,
  2865. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2866. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2867. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2868. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2869. };
  2870. this.obj.html(
  2871. '<div class="sjs-bar d-flex">\n' +
  2872. ' <div class="dropdown mr-1">\n' +
  2873. ' <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' +
  2874. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  2875. ' </button>\n' +
  2876. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  2877. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  2878. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  2879. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  2880. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  2881. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  2882. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  2883. ' </div>\n' +
  2884. ' </div>' +
  2885. ` <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` +
  2886. ` <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` +
  2887. ' <div class="ml-1">\n' +
  2888. ' <div class="dropdown">\n' +
  2889. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2890. ' <i class="fa fa-search"></i>\n' +
  2891. ' </button>\n' +
  2892. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  2893. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  2894. ' <div class="d-inline-block">\n' +
  2895. ' <div class="input-group input-group-sm mr-1">' +
  2896. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2897. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2898. ' <div class="input-group-append" >\n' +
  2899. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2900. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2901. ' </div>\n' +
  2902. ' </div>\n' +
  2903. ' </div>\n' +
  2904. ` <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` +
  2905. ' </div>\n' +
  2906. ' </div>\n' +
  2907. ' </div>\n' +
  2908. ' </div>' +
  2909. '</div>\n' +
  2910. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2911. );
  2912. autoFlashHeight();
  2913. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2914. function getObjHeight(select) {
  2915. return select.length > 0 ? select.height() : 0;
  2916. }
  2917. const cHeader = getObjHeight($(".c-header"));
  2918. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2919. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2920. this.spreadSetting = spreadSetting;
  2921. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2922. const searchSheet = this.spread.getActiveSheet();
  2923. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2924. (function (select, sheet) {
  2925. $(select).click(function () {
  2926. if (!sheet.zh_tree) return;
  2927. const tag = $(this).attr('tag');
  2928. const tree = sheet.zh_tree;
  2929. setTimeout(() => {
  2930. switch (tag) {
  2931. case "1":
  2932. case "2":
  2933. case "3":
  2934. case "4":
  2935. case "5":
  2936. tree.expandByLevel(parseInt(tag));
  2937. SpreadJsObj.refreshTreeRowVisible(sheet);
  2938. break;
  2939. case "last":
  2940. tree.expandByCustom(() => { return true; });
  2941. SpreadJsObj.refreshTreeRowVisible(sheet);
  2942. break;
  2943. }
  2944. }, 100);
  2945. });
  2946. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  2947. if (!readOnly) {
  2948. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2949. const dealSheet = info.sheet;
  2950. const mainSheet = billsSheet;
  2951. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2952. if (!dealBills) { return; }
  2953. const mainTree = mainSheet.zh_tree;
  2954. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2955. if (!mainNode || !mainTree) { return; }
  2956. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2957. toastr.warning('非最底层项目下,不应添加节点');
  2958. return;
  2959. }
  2960. if (mainNode.settle_status === settleStatus.finish) {
  2961. toastr.warning('已结算节点下,不应添加签约清单');
  2962. return;
  2963. }
  2964. const is_bill = dealBills.kind === 4;
  2965. const oneBills = {
  2966. b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  2967. unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
  2968. sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
  2969. };
  2970. postData(window.location.pathname + '/update', {
  2971. postType: 'add-deal',
  2972. postData: {
  2973. id: mainNode.ledger_id,
  2974. type: mainNode.code ? 'child' : 'next',
  2975. dealBills: oneBills,
  2976. },
  2977. }, function (result) {
  2978. changeList = result.changeList;
  2979. const refreshData = mainTree.loadPostData(result);
  2980. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2981. const sel = mainSheet.getSelections()[0];
  2982. if (sel && refreshData.create[0]) {
  2983. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2984. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2985. }
  2986. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2987. billsSpread.focus();
  2988. posSpreadObj.loadCurPosData();
  2989. });
  2990. });
  2991. }
  2992. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2993. const searchObj = {
  2994. result: [],
  2995. cur: 0,
  2996. searchStdNode: function() {
  2997. const keyword = $(`#${relaSelect.searchText}`).val();
  2998. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  2999. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  3000. }) : [];
  3001. // searchObj.result = [];
  3002. // for (const x of pathTree.nodes) {
  3003. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  3004. // searchObj.result.push(x);
  3005. // }
  3006. // }
  3007. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  3008. searchObj.cur = 0;
  3009. if (searchObj.result.length > 0) {
  3010. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  3011. }
  3012. },
  3013. searchPre: function () {
  3014. if (searchObj.result.length === 0) return;
  3015. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  3016. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3017. },
  3018. searchNext: function () {
  3019. if (searchObj.result.length === 0) return;
  3020. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  3021. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3022. },
  3023. clear: function () {
  3024. $(`#${relaSelect.searchText}`).val('');
  3025. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  3026. searchObj.result = [];
  3027. searchObj.cur = 0;
  3028. }
  3029. };
  3030. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  3031. $(`#${relaSelect.searchPre}`).click(function (e) {
  3032. searchObj.searchPre();
  3033. e.stopPropagation();
  3034. });
  3035. $(`#${relaSelect.searchNext}`).click(function (e) {
  3036. searchObj.searchNext();
  3037. e.stopPropagation();
  3038. });
  3039. $(`#${relaSelect.searchClose}`).click(function (e) {
  3040. searchObj.clear();
  3041. e.stopPropagation();
  3042. });
  3043. };
  3044. loadData (callback) {
  3045. if (this.loaded) {
  3046. if (callback) callback();
  3047. return;
  3048. }
  3049. const self = this;
  3050. if (dskAccountData && dskAccountData.select_project) {
  3051. self.loaded = true;
  3052. changeDskProject(dskAccountData.select_project);
  3053. } else {
  3054. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  3055. self.loaded = true;
  3056. }
  3057. if (callback) callback();
  3058. }
  3059. }
  3060. $('body').on('change', '#change-dsk-project', function () {
  3061. const pid = $(this).val();
  3062. changeDskProject(pid);
  3063. });
  3064. $('body').on('change', '#change-dsk-project-tree', function () {
  3065. const treeId = $(this).val();
  3066. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  3067. changeDskProjectTree(projectInfo, treeId);
  3068. });
  3069. function setDskProjectTreeSelect(trees) {
  3070. let html = '';
  3071. for (const tree of trees) {
  3072. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  3073. }
  3074. $('#change-dsk-project-tree').html(html);
  3075. }
  3076. function changeDskProject(pid) {
  3077. const projectInfo = _.find(dskProjects, { pid });
  3078. if (!projectInfo) {
  3079. dskAccountData.select_project = null;
  3080. dskAccountData.select_tree = null;
  3081. const tree = dskProjectBills2Tree.convert([]);
  3082. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3083. return;
  3084. }
  3085. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  3086. const trees = _.filter(datas, x => x.type === 4);
  3087. dskAccountData.select_project = projectInfo.pid;
  3088. setDskProjectTreeSelect(trees);
  3089. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  3090. });
  3091. }
  3092. function changeDskProjectTree(projectInfo, treeId) {
  3093. dskAccountData.select_tree = treeId;
  3094. if (!treeId) {
  3095. const tree = dskProjectBills2Tree.convert([]);
  3096. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3097. return;
  3098. }
  3099. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  3100. const tree = dskProjectBills2Tree.convert(result);
  3101. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3102. });
  3103. }
  3104. const dskBills = new Dsk('#dsk-spread', {
  3105. cols: [
  3106. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  3107. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3108. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3109. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  3110. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  3111. ],
  3112. emptyRows: 0,
  3113. headRows: 1,
  3114. headRowHeight: [32],
  3115. headColWidth: [30],
  3116. defaultRowHeight: 21,
  3117. headerFont: '12px 微软雅黑',
  3118. font: '12px 微软雅黑',
  3119. selectedBackColor: '#fffacd',
  3120. readOnly: true,
  3121. stdType: 'dsk',
  3122. libs: dskProjects,
  3123. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  3124. });
  3125. const dskProjectBills2Tree = (function () {
  3126. const treeSetting = {
  3127. id: 'dpb_id',
  3128. pid: 'dpb_pid',
  3129. order: 'seq',
  3130. level: 'level',
  3131. rootId: '-1',
  3132. fullPath: 'full_path',
  3133. };
  3134. const tenderTree = createNewPathTree('gather', treeSetting);
  3135. function setChildrenNode(node, dxs, files, tenders) {
  3136. const dxchildren = _.filter(dxs, { parentID: node.bid });
  3137. const children = _.filter(files, { parentID: node.bid });
  3138. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  3139. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  3140. for (const t of checkChildren) {
  3141. const child = {
  3142. bid: t.ID,
  3143. parentID: t.parentID,
  3144. name: t.name,
  3145. kind: t.kind,
  3146. code: t.code,
  3147. quantity: t.quantity,
  3148. quantity2: t.quantity2,
  3149. unit: t.unit,
  3150. unitPrice: t.unitPrice,
  3151. totalPrice: t.totalPrice,
  3152. formulaCode: t.formulaCode,
  3153. flag: t.flag,
  3154. remark: t.remark,
  3155. };
  3156. tenderTree.addNode(child, node);
  3157. setChildrenNode(child, dxs, files, tenders);
  3158. }
  3159. }
  3160. function convert (projects) {
  3161. tenderTree.clearDatas();
  3162. // 区分文件夹及项目
  3163. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  3164. const dxs = _.filter(projects, { kind: 1 });
  3165. const files = _.filter(projects, { kind: 4 });
  3166. const tenders = _.filter(projects, { kind: 8 });
  3167. for (const t of topLevel) {
  3168. const node = {
  3169. bid: t.ID,
  3170. parentID: t.parentID,
  3171. name: t.name,
  3172. kind: t.kind,
  3173. code: t.code,
  3174. quantity: t.quantity,
  3175. quantity2: t.quantity2,
  3176. unit: t.unit,
  3177. unitPrice: t.unitPrice,
  3178. totalPrice: t.totalPrice,
  3179. formulaCode: t.formulaCode,
  3180. flag: t.flag,
  3181. remark: t.remark,
  3182. };
  3183. tenderTree.addNode(node, null);
  3184. setChildrenNode(node, dxs, files, tenders);
  3185. }
  3186. tenderTree.sortTreeNode(true);
  3187. return tenderTree;
  3188. }
  3189. return { tenderTree, convert }
  3190. })();
  3191. $.divResizer({
  3192. select: '#revise-right-spr',
  3193. callback: function () {
  3194. billsSpread.refresh();
  3195. if (posSpread) posSpread.refresh();
  3196. if (stdXmj) stdXmj.spread.refresh();
  3197. if (stdGcl) stdGcl.spread.refresh();
  3198. if (dealBills) dealBills.spread.refresh();
  3199. if (searchLedger) searchLedger.spread.refresh();
  3200. if (errorList) errorList.spread.refresh();
  3201. if (checkList) checkList.spread.refresh();
  3202. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3203. if (jlzfBills) jlzfBills.spread.refresh();
  3204. if (dskBills) dskBills.spread.refresh();
  3205. }
  3206. });
  3207. $.subMenu({
  3208. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  3209. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  3210. key: 'menu.1.0.0',
  3211. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  3212. callback: function (info) {
  3213. if (info.mini) {
  3214. $('.panel-title').addClass('fluid');
  3215. $('#sub-menu').removeClass('panel-sidebar');
  3216. } else {
  3217. $('.panel-title').removeClass('fluid');
  3218. $('#sub-menu').addClass('panel-sidebar');
  3219. }
  3220. autoFlashHeight();
  3221. billsSpread.refresh();
  3222. if (posSpread) posSpread.refresh();
  3223. if (stdXmj) stdXmj.spread.refresh();
  3224. if (stdGcl) stdGcl.spread.refresh();
  3225. if (dealBills) dealBills.spread.refresh();
  3226. if (searchLedger) searchLedger.spread.refresh();
  3227. if (errorList) errorList.spread.refresh();
  3228. if (checkList) checkList.spread.refresh();
  3229. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3230. if (jlzfBills) jlzfBills.spread.refresh();
  3231. if (dskBills) dskBills.spread.refresh();
  3232. }
  3233. });
  3234. // showSideTools(true);
  3235. billsSpread.refresh();
  3236. if (posSpread) posSpread.refresh();
  3237. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  3238. const mainSheet = billsSheet;
  3239. if (!stdTree || !mainSheet.zh_tree) { return; }
  3240. const mainTree = mainSheet.zh_tree;
  3241. const sel = mainSheet.getSelections()[0];
  3242. const mainNode = mainTree.nodes[sel.row];
  3243. if (!stdNode) return;
  3244. if (updateData.postData.stdType === 'gcl') {
  3245. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3246. toastr.warning('非最底层项目下,不应添加节点');
  3247. return;
  3248. }
  3249. if (mainNode.settle_status === settleStatus.finish) {
  3250. toastr.warning('已结算节点下,不可添加工程量清单');
  3251. return;
  3252. }
  3253. } else {
  3254. const stdNodes = stdTree.getAllParents(stdNode);
  3255. for (const node of stdNodes) {
  3256. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  3257. if (parent && parent.settle_status === settleStatus.finish) {
  3258. toastr.warning('项目节父项已结算,不可添加节点');
  3259. return;
  3260. }
  3261. }
  3262. }
  3263. postData(window.location.pathname + '/update', {
  3264. postType: 'add-std',
  3265. postData: {
  3266. id: mainTree.getNodeKey(mainNode),
  3267. tender_id: mainNode.tender_id,
  3268. stdType: updateData.postData.stdType,
  3269. stdLibId: stdNode.list_id,
  3270. stdNode: stdTree.getNodeKey(stdNode)
  3271. }
  3272. }, function (result) {
  3273. changeList = result.changeList;
  3274. const refreshNode = mainTree.loadPostData(result);
  3275. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  3276. if (sel) {
  3277. if (refreshNode.create && refreshNode.create.length > 0) {
  3278. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  3279. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  3280. } else {
  3281. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  3282. if (node) {
  3283. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  3284. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  3285. }
  3286. }
  3287. }
  3288. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3289. billsSpread.focus();
  3290. posSpreadObj.loadCurPosData();
  3291. });
  3292. };
  3293. const stdXmjSetting = {
  3294. selector: '#std-xmj',
  3295. stdType: 'xmj',
  3296. libs: stdChapters,
  3297. treeSetting: {
  3298. id: 'chapter_id',
  3299. pid: 'pid',
  3300. order: 'order',
  3301. level: 'level',
  3302. rootId: -1,
  3303. keys: ['id', 'list_id', 'chapter_id'],
  3304. },
  3305. spreadSetting: {
  3306. cols: [
  3307. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3308. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3309. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3310. ],
  3311. treeCol: 0,
  3312. emptyRows: 0,
  3313. headRows: 1,
  3314. headRowHeight: [32],
  3315. defaultRowHeight: 21,
  3316. headerFont: '12px 微软雅黑',
  3317. font: '12px 微软雅黑',
  3318. headColWidth: [30],
  3319. selectedBackColor: '#fffacd',
  3320. },
  3321. cellDoubleClick: stdLibCellDoubleClick,
  3322. page: 'revise',
  3323. tid: window.location.pathname.split('/')[2],
  3324. };
  3325. const stdGclSetting = {
  3326. selector: '#std-gcl',
  3327. stdType: 'gcl',
  3328. libs: stdBills,
  3329. treeSetting: {
  3330. id: 'bill_id',
  3331. pid: 'pid',
  3332. order: 'order',
  3333. level: 'level',
  3334. rootId: -1,
  3335. keys: ['id', 'list_id', 'bill_id']
  3336. },
  3337. spreadSetting: {
  3338. cols: [
  3339. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3340. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3341. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3342. ],
  3343. treeCol: 0,
  3344. emptyRows: 0,
  3345. headRows: 1,
  3346. headRowHeight: [32],
  3347. defaultRowHeight: 21,
  3348. headerFont: '12px 微软雅黑',
  3349. font: '12px 微软雅黑',
  3350. headColWidth: [30],
  3351. selectedBackColor: '#fffacd',
  3352. },
  3353. cellDoubleClick: stdLibCellDoubleClick,
  3354. page: 'revise',
  3355. tid: window.location.pathname.split('/')[2],
  3356. };
  3357. // 展开收起标准节点
  3358. $('a', '#side-menu').bind('click', function (e) {
  3359. e.preventDefault();
  3360. const tab = $(this), tabPanel = $(tab.attr('content'));
  3361. // 展开工具栏、切换标签
  3362. if (!tab.hasClass('active')) {
  3363. const close = $('.active', '#side-menu').length === 0;
  3364. $('a', '#side-menu').removeClass('active');
  3365. tab.addClass('active');
  3366. $('.tab-content .tab-pane').removeClass('active');
  3367. tabPanel.addClass('active');
  3368. showSideTools(tab.hasClass('active'));
  3369. if (tab.attr('content') === '#std-xmj') {
  3370. if (!stdXmj) {
  3371. stdXmj = $.stdLib(stdXmjSetting);
  3372. }
  3373. stdXmj.spread.refresh();
  3374. } else if (tab.attr('content') === '#std-gcl') {
  3375. if (!stdGcl) {
  3376. stdGcl = $.stdLib(stdGclSetting);
  3377. }
  3378. stdGcl.spread.refresh();
  3379. } else if (tab.attr('content') === '#deal-bills') {
  3380. dealBills.loadData();
  3381. dealBills.spread.refresh();
  3382. } else if (tab.attr('content') === '#search') {
  3383. if (!searchLedger) {
  3384. searchLedger = $.billsSearch({
  3385. selector: '#search',
  3386. searchSpread: billsSpread,
  3387. searchOver: true,
  3388. searchEmpty: true,
  3389. resultSpreadSetting: {
  3390. cols: [
  3391. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3392. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3393. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3394. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3395. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3396. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3397. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  3398. ],
  3399. emptyRows: 0,
  3400. headRows: 1,
  3401. headRowHeight: [32],
  3402. headColWidth: [30],
  3403. defaultRowHeight: 21,
  3404. headerFont: '12px 微软雅黑',
  3405. font: '12px 微软雅黑',
  3406. selectedBackColor: '#fffacd',
  3407. readOnly: true,
  3408. },
  3409. afterLocated: function () {
  3410. posSpreadObj.loadCurPosData();
  3411. },
  3412. customSearch: [
  3413. {
  3414. key: 'revise', title: '新增部位', valid: true, parent: true,
  3415. check: function (node) {
  3416. if (node.formc || node.cid) {
  3417. return true;
  3418. } else {
  3419. return false;
  3420. }
  3421. }
  3422. }
  3423. ],
  3424. });
  3425. }
  3426. searchLedger.spread.refresh();
  3427. } else if (tab.attr('content') === '#error-list') {
  3428. errorList.spread.refresh();
  3429. } else if (tab.attr('content') === '#check-list') {
  3430. checkList.spread.refresh();
  3431. } else if (tab.attr('content') === '#sum-load-miss') {
  3432. sumLoadMiss.spread.refresh();
  3433. } else if (tab.attr('content') === '#dsk-list') {
  3434. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  3435. $(dskActiveTab).addClass('active');
  3436. if (dskActiveTab === '#jlzf-spread') {
  3437. $('#get-dsk-btn').hide();
  3438. $('#get-dsk-bills-btn').hide();
  3439. jlzfBills.loadData();
  3440. jlzfBills.spread.refresh();
  3441. } else if (dskActiveTab === '#dsk-spread') {
  3442. $('#get-dsk-btn').show();
  3443. $('#get-dsk-bills-btn').show();
  3444. dskBills.loadData();
  3445. dskBills.spread.refresh();
  3446. }
  3447. }
  3448. }
  3449. else {// 收起工具栏
  3450. tab.removeClass('active');
  3451. tabPanel.removeClass('active');
  3452. showSideTools(tab.hasClass('active'));
  3453. }
  3454. billsSpread.refresh();
  3455. if (posSpread) posSpread.refresh();
  3456. });
  3457. // 新增清单切换tab
  3458. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  3459. e.preventDefault();
  3460. const dskActiveTab = $(this).attr('href');
  3461. if (dskActiveTab === '#jlzf-spread') {
  3462. $('#get-dsk-btn').hide();
  3463. $('#get-dsk-bills-btn').hide();
  3464. jlzfBills.loadData();
  3465. jlzfBills.spread.refresh();
  3466. } else if (dskActiveTab === '#dsk-spread') {
  3467. $('#get-dsk-btn').show();
  3468. $('#get-dsk-bills-btn').show();
  3469. dskBills.loadData();
  3470. dskBills.spread.refresh();
  3471. }
  3472. });
  3473. // 显示层次
  3474. (function (select, sheet) {
  3475. $(select).click(function () {
  3476. if (!sheet.zh_tree) return;
  3477. const tag = $(this).attr('tag');
  3478. const tree = sheet.zh_tree;
  3479. setTimeout(() => {
  3480. showWaitingView();
  3481. switch (tag) {
  3482. case "1":
  3483. case "2":
  3484. case "3":
  3485. case "4":
  3486. case "5":
  3487. tree.expandByLevel(parseInt(tag));
  3488. SpreadJsObj.refreshTreeRowVisible(sheet);
  3489. break;
  3490. case "last":
  3491. tree.expandByCustom(() => { return true; });
  3492. SpreadJsObj.refreshTreeRowVisible(sheet);
  3493. break;
  3494. case "leafXmj":
  3495. tree.expandToLeafXmj();
  3496. SpreadJsObj.refreshTreeRowVisible(sheet);
  3497. break;
  3498. }
  3499. closeWaitingView();
  3500. }, 100);
  3501. });
  3502. })('a[name=showLevel]', billsSheet);
  3503. if (openRevise) {
  3504. const dataChecker = DataChecker({
  3505. checkUrl: window.location.pathname + '/check',
  3506. completeData: function (data) {
  3507. pos.updateDatas({update: data.source.pos});
  3508. const loadResult = billsTree.loadPostData({update: data.source.bills});
  3509. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3510. posSpreadObj.loadCurPosData();
  3511. for (const e of data.error) {
  3512. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  3513. }
  3514. },
  3515. errorList: errorList,
  3516. });
  3517. $('#ledger-check2').click(() => {
  3518. ledgerCheck2({
  3519. ledgerTree: billsTree,
  3520. ledgerPos: pos,
  3521. checkList: checkList,
  3522. decimal: decimal,
  3523. checkOption: checkOption,
  3524. }).then(result => {
  3525. check2Viewing({
  3526. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  3527. randomWait: true,
  3528. prefix: 'check2-',
  3529. checks: result,
  3530. checkList: checkList,
  3531. });
  3532. });
  3533. });
  3534. if (isYb) {
  3535. let compilationList = [];
  3536. $('#get-dsk-btn').click(function () {
  3537. // 判断是否已绑定dsk用户
  3538. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  3539. if (result === 1) {
  3540. $('#error-dsk .modal-body').find('h5').eq(0).show();
  3541. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  3542. $('#error-dsk').modal('show');
  3543. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  3544. } else if (result === 2) {
  3545. $('#error-dsk .modal-body').find('h5').eq(1).show();
  3546. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  3547. $('#error-dsk').modal('show');
  3548. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  3549. } else {
  3550. postData('/profile/dsk/api', {
  3551. type: 'compilation',
  3552. getProject: 1,
  3553. compilationId: getLocalCache(dskCompilation)
  3554. }, function (result) {
  3555. let html = '';
  3556. for (const data of result.compilation) {
  3557. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  3558. }
  3559. dskAccountData = result.dskAccountData;
  3560. compilationList = result.compilation;
  3561. console.log(compilationList);
  3562. $('#dsk-compilation-list').html(html);
  3563. $('#add-dsk').modal('show');
  3564. setLocalCache(dskCompilation, result.select_compilation);
  3565. makeDskProjectSjsHtml(result.project);
  3566. });
  3567. }
  3568. })
  3569. });
  3570. $('#get-dsk-bills-btn').click(function () {
  3571. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  3572. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  3573. });
  3574. $('body').on('change', '#dsk-compilation-list', function () {
  3575. const compilationId = $(this).val();
  3576. setLocalCache(dskCompilation, compilationId);
  3577. dskProjectSpreadObj.refreshSourceTree();
  3578. });
  3579. $('.hide-dsk-modal').click(function () {
  3580. $('#error-dsk').modal('hide');
  3581. });
  3582. let dp = false;
  3583. let gsObj = {
  3584. setting: null,
  3585. gsSheet: null,
  3586. grSheet: null,
  3587. tenderSourceTree: null,
  3588. grArray: dskProjects ? dskProjects : [],
  3589. orgSelect: null,
  3590. };
  3591. function makeDskProjectSjsHtml(datas) {
  3592. if (!dp) {
  3593. initDskProjectTree();
  3594. dp = true;
  3595. }
  3596. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  3597. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  3598. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  3599. if (datas.length === 0) {
  3600. $('#show-project-0').show();
  3601. } else {
  3602. $('#show-project-0').hide();
  3603. }
  3604. }
  3605. const dskProjectSpreadObj = {
  3606. _addTender: function (tender) {
  3607. const gr = gsObj.grArray.find(function (x) {
  3608. return x.pid === tender.pid;
  3609. });
  3610. const c_id = getLocalCache(dskCompilation);
  3611. const t = {
  3612. pid: tender.pid,
  3613. name: tender.name,
  3614. compilationId: c_id,
  3615. compilationName: _.find(compilationList, {ID: c_id}).name
  3616. };
  3617. if (!gr) gsObj.grArray.push(t);
  3618. return t;
  3619. },
  3620. _removeTender: function (tender) {
  3621. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  3622. return x.pid === tender.pid;
  3623. });
  3624. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  3625. },
  3626. reloadResultData: function () {
  3627. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  3628. },
  3629. refreshSourceTree: function () {
  3630. const c_id = getLocalCache(dskCompilation);
  3631. if (c_id) {
  3632. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  3633. makeDskProjectSjsHtml(result);
  3634. });
  3635. }
  3636. },
  3637. gsButtonClicked: function (e, info) {
  3638. if (!info.sheet.zh_setting) return;
  3639. const col = info.sheet.zh_setting.cols[info.col];
  3640. if (col.field !== 'selected') return;
  3641. const node = SpreadJsObj.getSelectObject(info.sheet);
  3642. node.selected = !node.selected;
  3643. if (node.children && node.children.length > 0) {
  3644. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  3645. for (const p of posterity) {
  3646. p.selected = node.selected;
  3647. if ((!p.children || p.children.length === 0) && p.type === 2) {
  3648. if (p.selected) {
  3649. dskProjectSpreadObj._addTender(p);
  3650. } else {
  3651. dskProjectSpreadObj._removeTender(p);
  3652. }
  3653. }
  3654. }
  3655. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  3656. } else if (node.type === 2) {
  3657. if (node.selected) {
  3658. dskProjectSpreadObj._addTender(node);
  3659. } else {
  3660. dskProjectSpreadObj._removeTender(node);
  3661. }
  3662. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  3663. }
  3664. dskProjectSpreadObj.reloadResultData();
  3665. },
  3666. deleteGr: function () {
  3667. if (gsObj.grArray.length === 0) return;
  3668. if (gsObj.grSheet.getSelections().length === 0) return;
  3669. const selections = gsObj.grSheet.getSelections();
  3670. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  3671. const row = sel && sel.row !== undefined ? sel.row : -1;
  3672. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3673. return false;
  3674. }
  3675. const delList = [];
  3676. for (let r = 0; r < sel.rowCount; r++) {
  3677. const select = gsObj.grArray[row + r];
  3678. delList.push(select);
  3679. }
  3680. _.pullAll(gsObj.grArray, delList);
  3681. dskProjectSpreadObj.reloadResultData();
  3682. dskProjectSpreadObj.refreshSourceTree();
  3683. },
  3684. };
  3685. const initDskProjectTree = function () {
  3686. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  3687. gsObj.gsSheet = gsSpread.getActiveSheet();
  3688. const gsSpreadSetting = {
  3689. cols: [
  3690. {
  3691. title: '选择',
  3692. field: 'selected',
  3693. hAlign: 1,
  3694. width: 40,
  3695. formatter: '@',
  3696. cellType: 'checkbox',
  3697. readOnly: true,
  3698. },
  3699. {
  3700. title: '名称',
  3701. field: 'name',
  3702. hAlign: 0,
  3703. width: 400,
  3704. formatter: '@',
  3705. readOnly: true,
  3706. folderCell: true,
  3707. cellType: 'tree'
  3708. },
  3709. ],
  3710. emptyRows: 0,
  3711. headRows: 1,
  3712. headRowHeight: [32],
  3713. defaultRowHeight: 21,
  3714. headerFont: '12px 微软雅黑',
  3715. font: '12px 微软雅黑',
  3716. headColWidth: [0],
  3717. selectedBackColor: '#fffacd',
  3718. };
  3719. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  3720. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  3721. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  3722. gsObj.grSheet = grSpread.getActiveSheet();
  3723. const grSpreadSetting = {
  3724. cols: [
  3725. {
  3726. title: '名称',
  3727. colSpan: '1',
  3728. rowSpan: '1',
  3729. field: 'name',
  3730. hAlign: 0,
  3731. width: 250,
  3732. formatter: '@',
  3733. readOnly: true,
  3734. cellType: 'ellipsisAutoTip',
  3735. scrollHeightClass: '.modal-height-500'
  3736. },
  3737. {
  3738. title: '所属编办',
  3739. colSpan: '1',
  3740. rowSpan: '1',
  3741. field: 'compilationName',
  3742. hAlign: 0,
  3743. width: 150,
  3744. formatter: '@',
  3745. readOnly: true
  3746. },
  3747. ],
  3748. emptyRows: 0,
  3749. headRows: 1,
  3750. headRowHeight: [32],
  3751. defaultRowHeight: 21,
  3752. headerFont: '12px 微软雅黑',
  3753. font: '12px 微软雅黑',
  3754. headColWidth: []
  3755. };
  3756. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  3757. // 右键删除已选项目
  3758. const gsContextMenuOptions = {
  3759. selector: '#dsk-project-result-spread',
  3760. build: function ($trigger, e) {
  3761. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  3762. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3763. },
  3764. items: {
  3765. delete: {
  3766. name: '删除',
  3767. icon: 'fa-remove',
  3768. callback: function (key, opt) {
  3769. dskProjectSpreadObj.deleteGr();
  3770. },
  3771. disabled: function (key, opt) {
  3772. const selection = gsObj.grSheet.getSelections();
  3773. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  3774. const row = sel && sel.row !== undefined ? sel.row : -1;
  3775. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3776. return true;
  3777. }
  3778. return false;
  3779. }
  3780. },
  3781. }
  3782. };
  3783. $.contextMenu(gsContextMenuOptions);
  3784. $('#add-dsk').bind('shown.bs.modal', function () {
  3785. if (gsSpread) gsSpread.refresh();
  3786. if (grSpread) grSpread.refresh();
  3787. });
  3788. };
  3789. const dskProject2Tree = (function () {
  3790. const treeSetting = {
  3791. id: 'tmt_id',
  3792. pid: 'tmt_pid',
  3793. order: 'seq',
  3794. level: 'level',
  3795. rootId: '-1',
  3796. fullPath: 'full_path',
  3797. };
  3798. const tenderTree = createNewPathTree('gather', treeSetting);
  3799. function setChildrenNode(node, files, tenders) {
  3800. const children = _.filter(files, {parentID: node.pid});
  3801. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  3802. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  3803. for (const c of checkChildren) {
  3804. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  3805. // // 判断文件夹下有无东西,没有就不插入
  3806. // continue;
  3807. // }
  3808. const child = {
  3809. pid: c.ID,
  3810. parentID: c.parentID,
  3811. name: c.name,
  3812. type: c.type,
  3813. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  3814. };
  3815. tenderTree.addNode(child, node);
  3816. if (c.type === 1) setChildrenNode(child, files, tenders);
  3817. }
  3818. }
  3819. function convert(projects) {
  3820. tenderTree.clearDatas();
  3821. const result = filterFolders(projects);
  3822. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  3823. const files = _.filter(result, {type: 1});
  3824. const tenders = _.filter(result, {type: 2});
  3825. for (const t of topLevel) {
  3826. const node = {
  3827. pid: t.ID,
  3828. parentID: t.parentID,
  3829. name: t.name,
  3830. type: t.type,
  3831. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  3832. };
  3833. tenderTree.addNode(node, null);
  3834. if (t.type === 1) setChildrenNode(node, files, tenders);
  3835. }
  3836. tenderTree.sortTreeNode(true);
  3837. return tenderTree;
  3838. }
  3839. return {tenderTree, convert}
  3840. })();
  3841. function filterFolders(data) {
  3842. // 构建ID到节点的映射
  3843. const idMap = data.reduce((map, node) => {
  3844. map[node.ID] = node;
  3845. return map;
  3846. }, {});
  3847. // 建立父子关系映射
  3848. const parentMap = data.reduce((map, node) => {
  3849. if (node.parentID !== '-1') {
  3850. if (!map[node.parentID]) {
  3851. map[node.parentID] = [];
  3852. }
  3853. map[node.parentID].push(node.ID);
  3854. }
  3855. return map;
  3856. }, {});
  3857. // 检查节点及其子节点是否包含清单(type=1)
  3858. const hasChecklist = (id) => {
  3859. const node = idMap[id];
  3860. if (node.type === 2) {
  3861. return true;
  3862. }
  3863. if (!parentMap[id]) {
  3864. return false;
  3865. }
  3866. return parentMap[id].some(childID => hasChecklist(childID));
  3867. };
  3868. // 过滤节点
  3869. const filteredIDs = new Set();
  3870. data.forEach(node => {
  3871. if (node.type === 2 || hasChecklist(node.ID)) {
  3872. let currentID = node.ID;
  3873. while (currentID !== '-1') {
  3874. filteredIDs.add(currentID);
  3875. currentID = idMap[currentID].parentID;
  3876. }
  3877. }
  3878. });
  3879. // 返回过滤后的数据
  3880. return data.filter(node => filteredIDs.has(node.ID));
  3881. }
  3882. $('#set-dsk-project').click(function () {
  3883. postData('/profile/dsk/api', {
  3884. type: 'save_projects',
  3885. tid: window.location.pathname.split('/')[2],
  3886. project_list: gsObj.grArray
  3887. }, function (result) {
  3888. // dskAccountData.select_project = result;
  3889. dskProjects = gsObj.grArray;
  3890. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  3891. dskAccountData.select_project = result;
  3892. changeDskProject(result);
  3893. dskBills.spread.refresh();
  3894. }
  3895. setDskProjectSelect(gsObj.grArray);
  3896. $('#add-dsk').modal('hide');
  3897. });
  3898. });
  3899. $('#add-dsk').on('hide.bs.modal', function () {
  3900. $('#autoTip').hide();
  3901. });
  3902. function setDskProjectSelect(projects) {
  3903. let html = '';
  3904. for (const project of projects) {
  3905. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  3906. }
  3907. $('#change-dsk-project').html(html);
  3908. }
  3909. // 选中所有新增部位/清单
  3910. $('#add-all-revise').click(function() {
  3911. const this_cid = window.location.pathname.split('/')[4];
  3912. makeGclGatherData();
  3913. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3914. type: 'get-revise-list',
  3915. }, function (result) {
  3916. const addDatas = [];
  3917. for (const ggd in gclGatherData) {
  3918. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  3919. let hadcid = 0;
  3920. for (const xmj of gclGatherData[ggd].leafXmjs) {
  3921. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  3922. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  3923. if (changeLedger || changePos) {
  3924. xmj.cid = 1;
  3925. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  3926. hadcid = 1;
  3927. }
  3928. }
  3929. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  3930. }
  3931. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  3932. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  3933. if (leafXmjs.length > 0) {
  3934. gclInfo.is_change = 1;
  3935. for (const xmj of leafXmjs) {
  3936. if (_.findIndex(changeList, function (item) {
  3937. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  3938. }) === -1) {
  3939. addDatas.push({
  3940. lid: xmj.gcl_id,
  3941. code: gclInfo.code,
  3942. name: gclInfo.name || '',
  3943. unit: gclInfo.unit || '',
  3944. unit_price: gclInfo.unit_price,
  3945. oamount: xmj.quantity,
  3946. oamount2: xmj.quantity,
  3947. bwmx: xmj.bwmx || xmj.jldy || '',
  3948. xmj_code: xmj.code || '',
  3949. xmj_jldy: xmj.jldy || '',
  3950. xmj_dwgc: xmj.dwgc || '',
  3951. xmj_fbgc: xmj.fbgc || '',
  3952. xmj_fxgc: xmj.fxgc || '',
  3953. gcl_id: xmj.gcl_id,
  3954. mx_id: xmj.mx_id || '',
  3955. });
  3956. }
  3957. }
  3958. }
  3959. }
  3960. console.log(addDatas);
  3961. if (addDatas.length > 0) {
  3962. // 更新至服务器
  3963. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3964. type: 'add-change-list',
  3965. postData: addDatas,
  3966. }, function (result) {
  3967. toastr.success('已新增当前变更令新增的所有部位/清单');
  3968. changeList = result.changeList;
  3969. const sortData = SpreadJsObj.getSortData(billsSheet);
  3970. const billsNodes = _.filter(sortData, function (item) {
  3971. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  3972. });
  3973. for (const billsNode of billsNodes) {
  3974. billsNode.is_change = 1;
  3975. }
  3976. const loadResult = { update: billsNodes };
  3977. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3978. posSpreadObj.loadCurPosData();
  3979. });
  3980. } else {
  3981. toastr.warning('未存在当前变更令新增的部位/清单');
  3982. }
  3983. });
  3984. });
  3985. }
  3986. }
  3987. });
  3988. // 编号排序,多重判断
  3989. function sortByCode(a, b, code = 'b_code') {
  3990. let code1 = a[code].split('-');
  3991. let code2 = b[code].split('-');
  3992. let code1length = code1.length;
  3993. let code2length = code2.length;
  3994. for (let i = 0; i < code1length; i ++) {
  3995. if (i+1 <= code2length) {
  3996. if (code1[i] != code2[i]) {
  3997. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  3998. return parseInt(code1[i]) - parseInt(code2[i]);
  3999. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  4000. return 1;
  4001. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  4002. return -1;
  4003. } else {
  4004. const str1length = code1[i].length;
  4005. const str2length = code2[i].length;
  4006. for (let j = 0; j < str1length; j++) {
  4007. if (j+1 <= str2length) {
  4008. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  4009. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  4010. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  4011. if (str1length == str2length) {
  4012. return 0;
  4013. } else {
  4014. return str1length - str2length;
  4015. }
  4016. }
  4017. } else {
  4018. if (j+1 >= str1length) {
  4019. return 1;
  4020. } else {
  4021. return -1;
  4022. }
  4023. }
  4024. }
  4025. }
  4026. } else if (i+1 == code1length && code1[i] == code2[i]) {
  4027. if (code1length == code2length) {
  4028. return 0;
  4029. } else {
  4030. return code1length - code2length;
  4031. }
  4032. }
  4033. } else {
  4034. if (i+1 >= code1length) {
  4035. return 1;
  4036. } else {
  4037. return -1;
  4038. }
  4039. }
  4040. }
  4041. }