ledger.js 179 KB

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