ledger.js 178 KB

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