ledger.js 177 KB

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