ledger.js 171 KB

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