ledger.js 177 KB

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