change_revise.js 187 KB

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