ledger.js 179 KB

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