ledger.js 171 KB

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