ledger.js 172 KB

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