ledger.js 194 KB

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