ledger.js 174 KB

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