ledger.js 173 KB

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