ledger.js 179 KB

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