ledger.js 180 KB

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