ledger.js 177 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890
  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 getChildSort = function (i, split) {
  964. if (i <= 0) throw '参数错误';
  965. switch(split) {
  966. case '0': return i < 10 ? split + i : i + '';
  967. case '-': return split + i;
  968. }
  969. };
  970. const recursiveSortCode = function (data, parentCode, children, split) {
  971. if (!children || children.length === 0) return;
  972. for (const [i, child] of children.entries()) {
  973. if (!child.b_code || child.b_code === '') {
  974. const code = parentCode + getChildSort(i + 1, split);
  975. const cData = tree.getNodeKeyData(child);
  976. cData.code = code;
  977. data.push(cData);
  978. if (!tree.isLeafXmj(child)) {
  979. recursiveSortCode(data, code, child.children);
  980. }
  981. }
  982. }
  983. };
  984. const data = [];
  985. recursiveSortCode(data, select.code, select.children, tree.getCodeSplit());
  986. if (data.length > 0) {
  987. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  988. const refreshNode = tree.loadPostData(result);
  989. treeOperationObj.refreshTree(sheet, refreshNode);
  990. })
  991. }
  992. },
  993. };
  994. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  995. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  996. ledgerTreeCol.initSpreadSetting(ledgerSpreadSetting);
  997. ledgerSpreadSetting.headColWidth = [50];
  998. ledgerSpreadSetting.rowHeader = [
  999. {
  1000. rowHeaderType: 'tag',
  1001. setting: {
  1002. indent: 14,
  1003. tagSize: 0.8,
  1004. tagFont: '8px 微软雅黑',
  1005. getColor: function (index, data) {
  1006. if (!data) return;
  1007. return billsTag.getBillsTagsColor(data.id);
  1008. },
  1009. getTagHtml: function (index, data) {
  1010. if (!data) return;
  1011. const getHtml = function (list) {
  1012. if (!list || list.length === 0) return '';
  1013. const html = [];
  1014. for (const l of list) {
  1015. html.push('<div class="row mr-1">');
  1016. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  1017. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  1018. html.push('</div>');
  1019. }
  1020. return html.join('');
  1021. };
  1022. return getHtml(billsTag.getBillsTagsInfo(data.id));
  1023. }
  1024. },
  1025. },
  1026. ];
  1027. // ledgerSpreadSetting.cols.push(
  1028. // {title: 'ledger_id', colSpan: '1', rowSpan: '2', field: 'ledger_id', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1029. // {title: 'ledger_pid', colSpan: '1', rowSpan: '2', field: 'ledger_pid', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1030. // {title: 'level', colSpan: '1', rowSpan: '2', field: 'level', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1031. // {title: 'order', colSpan: '1', rowSpan: '2', field: 'order', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1032. // {title: 'is_leaf', colSpan: '1', rowSpan: '2', field: 'is_leaf', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1033. // {title: 'full_path', colSpan: '1', rowSpan: '2', field: 'full_path', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1034. // {title: 'node_type', colSpan: '1', rowSpan: '2', field: 'node_type', hAlign: 2, width: 60, type: 'Number', readOnly: true}
  1035. // );
  1036. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  1037. SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
  1038. // 绑定事件
  1039. ledgerSpread.bind(spreadNS.Events.SelectionChanged, treeOperationObj.selectionChanged);
  1040. ledgerSpread.bind(spreadNS.Events.TopRowChanged, treeOperationObj.topRowChanged);
  1041. if (!ledgerSpreadSetting.readOnly) {
  1042. ledgerSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1043. treeOperationObj.refreshOperationValid(info.sheet, info.newSelections);
  1044. });
  1045. ledgerSpread.bind(spreadNS.Events.EditEnded, treeOperationObj.editEnded);
  1046. SpreadJsObj.addDeleteBind(ledgerSpread, treeOperationObj.deletePress);
  1047. ledgerSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1048. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1049. SpreadJsObj.Clipboard.setCopyData(copyText);
  1050. });
  1051. ledgerSpread.bind(spreadNS.Events.ClipboardPasting, treeOperationObj.clipboardPasting);
  1052. ledgerSpread.bind(spreadNS.Events.EditStarting, treeOperationObj.editStarting);
  1053. SpreadJsObj.addCutEvents(ledgerSpread, treeOperationObj.cut);
  1054. // 绑定 删除等 顶部按钮
  1055. $('#insert').click(() => {
  1056. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1057. });
  1058. $('#delete').click(function () {
  1059. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1060. });
  1061. $('#up-move').click(function () {
  1062. treeOperationObj.upMove(ledgerSpread.getActiveSheet());
  1063. });
  1064. $('#down-move').click(function () {
  1065. treeOperationObj.downMove(ledgerSpread.getActiveSheet());
  1066. });
  1067. $('#up-level').click(function () {
  1068. treeOperationObj.upLevel(ledgerSpread.getActiveSheet());
  1069. });
  1070. $('#down-level').click(function () {
  1071. treeOperationObj.downLevel(ledgerSpread.getActiveSheet());
  1072. });
  1073. $('#copy').click(function () {
  1074. ledgerSpread.commandManager().execute({
  1075. cmd: 'copy',
  1076. sheetName: ledgerSpread.getActiveSheet().name()
  1077. });
  1078. });
  1079. $('#paste').click(function () {
  1080. ledgerSpread.commandManager().execute({
  1081. cmd: 'paste',
  1082. sheetName: ledgerSpread.getActiveSheet().name()
  1083. });
  1084. });
  1085. $('#cut').click(function () {
  1086. ledgerSpread.commandManager().execute({
  1087. cmd: 'cut',
  1088. sheetName: ledgerSpread.getActiveSheet().name()
  1089. });
  1090. });
  1091. $('#bills-expr').bind('change onblur', function () {
  1092. const expr = $(this);
  1093. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1094. const select = ledgerTree.getItemsByIndex(row);
  1095. if (!select) return;
  1096. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1097. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1098. // 台账模式,检查计量单元相关
  1099. if (checkTzMeasureType()) {
  1100. if (field === 'sgfh_qty' || field === 'sgfh_tp' ||
  1101. field === 'sjcl_qty' || field === 'sjcl_tp' ||
  1102. field === 'qtcl_qty' || field === 'qtcl_tp') {
  1103. if (!select.children || select.children.length === 0) {
  1104. const lPos = pos.getLedgerPos(select.id);
  1105. if (lPos && lPos.length > 0) {
  1106. toastr.error('清单含有计量单元,请在计量单元输入数量');
  1107. expr.val('');
  1108. return;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. const data = {
  1114. id: select.id,
  1115. tender_id: select.tender_id,
  1116. ledger_id: select.ledger_id
  1117. };
  1118. const exprInfo = getExprInfo(field);
  1119. if (newValue !== '') {
  1120. const num = _.toNumber(newValue);
  1121. if (num) {
  1122. data[field] = num;
  1123. if (exprInfo) {
  1124. data[exprInfo.expr] = '';
  1125. }
  1126. } else {
  1127. try {
  1128. data[field] = math.evaluate(transExpr(newValue));
  1129. if (exprInfo) {
  1130. data[exprInfo.expr] = newValue;
  1131. }
  1132. } catch (err) {
  1133. toastr.error('输入的表达式非法');
  1134. return;
  1135. }
  1136. }
  1137. } else {
  1138. data[field] = null;
  1139. if (exprInfo) {
  1140. data[exprInfo.expr] = '';
  1141. }
  1142. }
  1143. // 更新至服务器
  1144. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1145. const refreshNode = ledgerTree.loadPostData(result);
  1146. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  1147. });
  1148. });
  1149. }
  1150. let batchInsertObj;
  1151. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1152. const self = this;
  1153. if ($.isFunction(item.icon)) {
  1154. item._icon = item.icon.call(this, this, $t, key, item);
  1155. } else {
  1156. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1157. // to enable font awesome
  1158. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1159. } else {
  1160. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1161. }
  1162. }
  1163. this.addClass(item._icon);
  1164. 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>')
  1165. .appendTo(this);
  1166. const $input = $obj.find('input');
  1167. const event = () => {
  1168. if (self.hasClass('context-menu-disabled')) return;
  1169. item.batchInsert($input[0], root);
  1170. };
  1171. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1172. $input.click((e) => {e.stopPropagation();})
  1173. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1174. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1175. };
  1176. // $.contextMenu.types.switch = function (item, opt, root) {
  1177. // const self = this;
  1178. // if ($.isFunction(item.icon)) {
  1179. // item._icon = item.icon.call(this, this, $t, key, item);
  1180. // } else {
  1181. // if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1182. // // to enable font awesome
  1183. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1184. // } else {
  1185. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1186. // }
  1187. // }
  1188. // const html = [];
  1189. // html.push('<div>');
  1190. // html.push('</div>');
  1191. // const $obj = $('<div>' + item.name +)
  1192. // };
  1193. // 右键菜单
  1194. const addTag = newTag({ledgerSheet: ledgerSpread.getActiveSheet(), billsTag});
  1195. const billsContextMenuOptions = {
  1196. selector: '#ledger-spread',
  1197. build: function ($trigger, e) {
  1198. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  1199. treeOperationObj.loadRelaData();
  1200. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1201. },
  1202. items: {},
  1203. };
  1204. if (!readOnly) {
  1205. billsContextMenuOptions.items.create = {
  1206. name: '新增',
  1207. icon: 'fa-sign-in',
  1208. callback: function (key, opt) {
  1209. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1210. },
  1211. disabled: function (key, opt) {
  1212. const sheet = ledgerSpread.getActiveSheet();
  1213. const selection = sheet.getSelections();
  1214. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1215. const row = sel ? sel.row : -1;
  1216. const tree = sheet.zh_tree;
  1217. if (!tree) return true;
  1218. const first = sheet.zh_tree.nodes[row];
  1219. let last = first, sameParent = true;
  1220. if (sel.rowCount > 1) {
  1221. for (let r = 1; r < sel.rowCount; r++) {
  1222. const rNode = tree.nodes[sel.row + r];
  1223. if (rNode.level > first.level) continue;
  1224. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1225. sameParent = false;
  1226. break;
  1227. }
  1228. last = rNode;
  1229. }
  1230. }
  1231. const valid = !sheet.zh_setting.readOnly;
  1232. return !(valid && first && first.level > 1);
  1233. },
  1234. visible: function (key, opt) {
  1235. return !readOnly;
  1236. }
  1237. };
  1238. billsContextMenuOptions.items.delete = {
  1239. name: '删除',
  1240. icon: 'fa-remove',
  1241. callback: function (key, opt) {
  1242. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1243. },
  1244. disabled: function (key, opt) {
  1245. const sheet = ledgerSpread.getActiveSheet();
  1246. const selection = sheet.getSelections();
  1247. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1248. const row = sel ? sel.row : -1;
  1249. const tree = sheet.zh_tree;
  1250. if (!tree) return true;
  1251. const first = sheet.zh_tree.nodes[row];
  1252. let last = first, sameParent = true;
  1253. if (sel.rowCount > 1) {
  1254. for (let r = 1; r < sel.rowCount; r++) {
  1255. const rNode = tree.nodes[sel.row + r];
  1256. if (rNode.level > first.level) continue;
  1257. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1258. sameParent = false;
  1259. break;
  1260. }
  1261. last = rNode;
  1262. }
  1263. }
  1264. const valid = !sheet.zh_setting.readOnly;
  1265. return !(valid && first && sameParent && !(first.level === 1 && first.node_type));
  1266. },
  1267. visible: function (key, opt) {
  1268. return !readOnly;
  1269. }
  1270. };
  1271. billsContextMenuOptions.items.sprBase = '----';
  1272. }
  1273. billsContextMenuOptions.items.copyBlock = {
  1274. name: '复制整块',
  1275. icon: 'fa-files-o',
  1276. callback: function (key, opt) {
  1277. /*ledgerSpread.commandManager().execute({
  1278. cmd:"copy",
  1279. sheetName:ledgerSpread.getActiveSheet().name()
  1280. });*/
  1281. treeOperationObj.block = [];
  1282. const copyBlockList = [];
  1283. const sheet = ledgerSpread.getActiveSheet();
  1284. const sel = sheet.getSelections()[0];
  1285. let iRow = sel.row;
  1286. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1287. while (iRow < sel.row + sel.rowCount) {
  1288. const node = sheet.zh_tree.nodes[iRow];
  1289. if (node.ledger_pid !== pid) {
  1290. toastr.error('仅可同时选中同层节点');
  1291. return;
  1292. }
  1293. const posterity = sheet.zh_tree.getPosterity(node);
  1294. iRow += posterity.length + 1;
  1295. posterity.unshift(node);
  1296. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1297. }
  1298. for (const cbl of copyBlockList) {
  1299. for (const b of cbl) {
  1300. const posRange = pos.getLedgerPos(b.id);
  1301. if (posRange && posRange.length > 0) b.pos = posRange;
  1302. }
  1303. }
  1304. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1305. },
  1306. visible: 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;
  1312. },
  1313. disabled: function (key, opt) {
  1314. const sheet = ledgerSpread.getActiveSheet();
  1315. const selection = sheet.getSelections();
  1316. const row = selection[0].row;
  1317. const select = ledgerTree.nodes[row];
  1318. return select && select.level <= 1;
  1319. }
  1320. };
  1321. billsContextMenuOptions.items.copyBlockXmj = {
  1322. name: '复制整块(只复制项目节)',
  1323. icon: 'fa-files-o',
  1324. callback: function (key, opt) {
  1325. treeOperationObj.block = [];
  1326. const copyBlockList = [];
  1327. const sheet = ledgerSpread.getActiveSheet();
  1328. const sel = sheet.getSelections()[0];
  1329. let iRow = sel.row;
  1330. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1331. while (iRow < sel.row + sel.rowCount) {
  1332. const node = sheet.zh_tree.nodes[iRow];
  1333. if (node.ledger_pid !== pid) {
  1334. toastr.error('仅可同时选中同层节点');
  1335. return;
  1336. }
  1337. const posterity = sheet.zh_tree.getPosterity(node);
  1338. iRow += posterity.length + 1;
  1339. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1340. copyPosterity.unshift(node);
  1341. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1342. for (const p of copyData) {
  1343. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1344. p.is_leaf = children.length === 0;
  1345. }
  1346. copyBlockList.push(copyData);
  1347. }
  1348. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1349. },
  1350. visible: 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;
  1356. },
  1357. disabled: function (key, opt) {
  1358. const sheet = ledgerSpread.getActiveSheet();
  1359. const selection = sheet.getSelections();
  1360. const row = selection[0].row;
  1361. const select = ledgerTree.nodes[row];
  1362. return select && select.level <= 1;
  1363. }
  1364. };
  1365. if (!readOnly) {
  1366. billsContextMenuOptions.items.pasteBlock = {
  1367. name: '粘贴整块',
  1368. icon: 'fa-clipboard',
  1369. disabled: function (key, opt) {
  1370. //const block = treeOperationObj.block || [];
  1371. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1372. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1373. },
  1374. callback: function (key, opt) {
  1375. //const block = treeOperationObj.block || [];
  1376. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1377. if (copyInfo.block.length > 0) {
  1378. treeOperationObj.pasteBlock(ledgerSpread, copyInfo);
  1379. } else {
  1380. document.execCommand('paste');
  1381. }
  1382. },
  1383. visible: function (key, opt) {
  1384. return !readOnly;
  1385. }
  1386. };
  1387. }
  1388. billsContextMenuOptions.items.sprBlock = '----';
  1389. if (!readOnly) {
  1390. billsContextMenuOptions.items.sortChildren = {
  1391. name: '顺序重排子项编号',
  1392. icon: 'fa-sort-numeric-asc',
  1393. disabled: function (key, opt) {
  1394. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1395. return !node || !node.code || !node.children || node.children === 0;// || node.code.indexOf('-') < 0;
  1396. },
  1397. callback: function (key, opt) {
  1398. treeOperationObj.sortCode(ledgerSpread.getActiveSheet());
  1399. },
  1400. visible: function (key, opt) {
  1401. return !readOnly;
  1402. }
  1403. };
  1404. if (!checkTzMeasureType()) {
  1405. billsContextMenuOptions.items.applyDeal2Sgfh = {
  1406. name: '填设计量',
  1407. icon: 'fa-pencil',
  1408. callback: function (key, opt) {
  1409. postData(window.location.pathname + '/deal2sgfh', null, function (result) {
  1410. ledgerTree.loadDatas(result.bills);
  1411. treeCalc.calculateAll(ledgerTree);
  1412. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1413. });
  1414. }
  1415. };
  1416. }
  1417. billsContextMenuOptions.items.sprSort = '----';
  1418. }
  1419. if (!readOnly) {
  1420. billsContextMenuOptions.items.batchInsert = {
  1421. name: '批量插入',
  1422. type: 'batchInsert',
  1423. value: '2',
  1424. icon: 'fa-sign-in',
  1425. batchInsert: function (obj, root) {
  1426. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1427. obj.value = obj.max;
  1428. toastr.warning('批量插入不可多于' + obj.max);
  1429. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1430. obj.value = obj.min;
  1431. toastr.warning('批量插入不可少于' + obj.min);
  1432. } else {
  1433. treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  1434. root.$menu.trigger('contextmenu:hide');
  1435. }
  1436. },
  1437. disabled: function (key, opt) {
  1438. const sheet = ledgerSpread.getActiveSheet();
  1439. const selection = sheet.getSelections();
  1440. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1441. const row = sel ? sel.row : -1;
  1442. const tree = sheet.zh_tree;
  1443. if (!tree) return true;
  1444. const first = sheet.zh_tree.nodes[row];
  1445. let last = first, sameParent = true;
  1446. if (sel.rowCount > 1) {
  1447. for (let r = 1; r < sel.rowCount; r++) {
  1448. const rNode = tree.nodes[sel.row + r];
  1449. if (rNode.level > first.level) continue;
  1450. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1451. sameParent = false;
  1452. break;
  1453. }
  1454. last = rNode;
  1455. }
  1456. }
  1457. const valid = !sheet.zh_setting.readOnly;
  1458. return !(valid && first && first.level > 1);
  1459. },
  1460. visible: function (key, opt) {
  1461. return !readOnly;
  1462. }
  1463. };
  1464. billsContextMenuOptions.items.batchInsertBillsPos = {
  1465. name: '批量插入清单-计量单元',
  1466. icon: 'fa-sign-in',
  1467. disabled: function (key, opt) {
  1468. if (!checkTzMeasureType()) return true;
  1469. const sheet = ledgerSpread.getActiveSheet();
  1470. const selection = sheet.getSelections();
  1471. const row = selection[0].row;
  1472. const select = ledgerTree.nodes[row];
  1473. if (select) {
  1474. if (select.code && select.code !== '') {
  1475. return !ledgerTree.isLeafXmj(select);
  1476. } else {
  1477. const parent = ledgerTree.getParent(select);
  1478. return !(parent && ledgerTree.isLeafXmj(parent));
  1479. }
  1480. } else {
  1481. return true;
  1482. }
  1483. },
  1484. callback: function (key, opt) {
  1485. if (!batchInsertObj) {
  1486. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1487. } else {
  1488. batchInsertObj.initView();
  1489. }
  1490. $('#batch').modal('show');
  1491. },
  1492. visible: function (key, opt) {
  1493. return !readOnly;
  1494. }
  1495. };
  1496. billsContextMenuOptions.items.sprBatch = '----';
  1497. }
  1498. if (!readOnly) {
  1499. const tenderSelect = TenderSelect({
  1500. type: 'ledger',
  1501. afterLoad: function (result) {
  1502. const ledgerSheet = ledgerSpread.getActiveSheet();
  1503. const refreshNode = ledgerTree.loadPostData(result);
  1504. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1505. treeOperationObj.refreshOperationValid(ledgerSheet);
  1506. }
  1507. });
  1508. billsContextMenuOptions.items.importExcel = {
  1509. name: '导入分项清单Excel',
  1510. icon: 'fa-file-excel-o',
  1511. disabled: function (key, opt) {
  1512. return readOnly;
  1513. },
  1514. callback: function (key, opt) {
  1515. importExcel.doImport({
  1516. template: {
  1517. hint: '0号台账',
  1518. url: '/template/导入分项清单EXCEL格式.xlsx',
  1519. },
  1520. filter: true,
  1521. callback: function (sheet, filter) {
  1522. postDataCompress(window.location.pathname + '/upload-excel/tz', {sheet, filter}, function (result) {
  1523. ledgerTree.loadDatas(result.bills);
  1524. treeCalc.calculateAll(ledgerTree);
  1525. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1526. pos.loadDatas(result.pos);
  1527. posOperationObj.loadCurPosData();
  1528. checkShowLast(result.bills.length);
  1529. }, null);
  1530. },
  1531. // callback: function (file, select) {
  1532. // const formData = new FormData();
  1533. // formData.append('file', file.files[0]);
  1534. // postDataWithFileProgress(window.location.pathname + '/upload-excel?ueType=tz&sheetName=' + select, formData, function (result) {
  1535. // ledgerTree.loadDatas(result.bills);
  1536. // treeCalc.calculateAll(ledgerTree);
  1537. // SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1538. // pos.loadDatas(result.pos);
  1539. // posOperationObj.loadCurPosData();
  1540. // }, null);
  1541. // }
  1542. //u_type: importExcel.uploadType.file,
  1543. });
  1544. }
  1545. };
  1546. billsContextMenuOptions.items.importGclBills2Xmj = {
  1547. name: '导入工程量清单至项目节',
  1548. icon: 'fa-file-excel-o',
  1549. disabled: function (key, opt) {
  1550. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1551. return readOnly || !node
  1552. || (node.children && node.children.length > 0)
  1553. || (!_.isNil(node.b_code) && node.b_code !== '');
  1554. },
  1555. callback: function (key, opt) {
  1556. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1557. importExcel.doImport({
  1558. template: {
  1559. hint: '工程量清单',
  1560. url: '/template/导入工程量清单EXCEL格式.xls',
  1561. },
  1562. callback: function (sheet) {
  1563. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1564. const ledgerSheet = ledgerSpread.getActiveSheet();
  1565. const sel = ledgerSheet.getSelections();
  1566. const refreshNode = ledgerTree.loadPostData(result);
  1567. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1568. if (refreshNode.create[0]) {
  1569. if (sel && sel[0]) {
  1570. ledgerSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1571. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [sel[0].row, refreshNode.create[0].index]);
  1572. } else {
  1573. ledgerSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1574. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [refreshNode.create[0].index]);
  1575. }
  1576. }
  1577. treeOperationObj.refreshOperationValid(ledgerSheet);
  1578. }, null);
  1579. }
  1580. });
  1581. }
  1582. };
  1583. billsContextMenuOptions.items.importOtherTender = {
  1584. name: '导入(其他标段)工程量清单至项目节',
  1585. icon: 'fa-link',
  1586. disabled: function (key, opt) {
  1587. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1588. return readOnly || !node
  1589. || (node.children && node.children.length > 0)
  1590. || !ledgerTree.isLeafXmj(node);
  1591. },
  1592. callback: function (key, opt) {
  1593. tenderSelect.showSelect(SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet()));
  1594. }
  1595. };
  1596. billsContextMenuOptions.items.sprImport = '----';
  1597. }
  1598. billsContextMenuOptions.items.tag = {
  1599. name: '书签',
  1600. callback: function (key, opt, menu, e) {
  1601. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1602. addTag.do(node);
  1603. },
  1604. disabled: function (key, opt) {
  1605. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1606. return !node;
  1607. }
  1608. };
  1609. billsContextMenuOptions.items.sprTag = '----';
  1610. billsContextMenuOptions.items.showLast = {
  1611. name: '显示至最底层',
  1612. callback: function (key, opt, menu, e) {
  1613. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1614. setTimeout(() => {
  1615. showWaitingView();
  1616. ledgerTree.expandByCustom(x => {
  1617. return x.expanded ||(x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1618. });
  1619. SpreadJsObj.refreshTreeRowVisible(ledgerSpread.getActiveSheet());
  1620. closeWaitingView();
  1621. }, 100);
  1622. },
  1623. };
  1624. $.contextMenu(billsContextMenuOptions);
  1625. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  1626. // 台账模式加载计量单元数据
  1627. if (checkTzMeasureType()) {
  1628. $.divResizer({
  1629. select: '#main-resize',
  1630. callback: function () {
  1631. ledgerSpread.refresh();
  1632. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1633. $(".sp-wrap").height(bcontent-30);
  1634. posSpread.refresh();
  1635. }
  1636. });
  1637. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  1638. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  1639. }
  1640. //绑定计量单元编辑事件
  1641. const posOperationObj = {
  1642. /**
  1643. * 刷新顶部按钮是否可用
  1644. * @param sheet
  1645. * @param selections
  1646. */
  1647. refreshOperationValid: function (sheet, selection) {
  1648. const setObjEnable = function (obj, enable) {
  1649. if (enable) {
  1650. obj.removeClass('disabled');
  1651. } else {
  1652. obj.addClass('disabled');
  1653. }
  1654. };
  1655. const invalidAll = function () {
  1656. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1657. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1658. };
  1659. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1660. const row = sel ? sel.row : -1;
  1661. const first = sheet.zh_data[row];
  1662. if (!first) {
  1663. invalidAll();
  1664. return;
  1665. }
  1666. let last = first;
  1667. if (sel.rowCount > 1 && first) {
  1668. for (let r = 1; r < sel.rowCount; r++) {
  1669. const rNode = sheet.zh_data[sel.row + r];
  1670. if (!rNode) break;
  1671. last = rNode;
  1672. }
  1673. }
  1674. const preNode = sheet.zh_data[row - 1];
  1675. const valid = !sheet.zh_setting.readOnly;
  1676. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1677. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1678. },
  1679. editStarting: function (e, info) {
  1680. posOperationObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1681. const sel = info.sheet.getSelections();
  1682. if (!sel || !sel[0]) return;
  1683. const col = info.sheet.zh_setting.cols[sel[0].col];
  1684. const node = SpreadJsObj.getSelectObject(info.sheet);
  1685. const exprInfo = getExprInfo(col.field);
  1686. if (exprInfo) {
  1687. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1688. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1689. }
  1690. }
  1691. },
  1692. loadExprToInput: function () {
  1693. const sheet = posSpread.getActiveSheet();
  1694. const sel = sheet.getSelections()[0];
  1695. if (!sel || !sheet.zh_setting) return;
  1696. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1697. if (col && col.type === 'Number') {
  1698. const data = SpreadJsObj.getSelectObject(sheet);
  1699. if (data) {
  1700. const exprInfo = getExprInfo(col.field);
  1701. const value = exprInfo
  1702. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1703. : data[col.field];
  1704. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1705. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1706. } else {
  1707. $('#pos-expr').val('').attr('readOnly', true);
  1708. $('#pos-expr').removeAttr('data-row');
  1709. }
  1710. } else {
  1711. $('#pos-expr').val('').attr('readOnly', true);
  1712. $('#pos-expr').removeAttr('data-row');
  1713. }
  1714. },
  1715. /**
  1716. * 加载计量单元 根据当前台账选择节点
  1717. */
  1718. loadCurPosData: function () {
  1719. //spreadJsObj.reinitSheet(posSpread.getActiveSheet());
  1720. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1721. if (node) {
  1722. const posData = pos.ledgerPos[itemsPre + node.id] || [];
  1723. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', posData);
  1724. getNodeList(node.id);
  1725. } else {
  1726. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', []);
  1727. }
  1728. posOperationObj.loadExprToInput();
  1729. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  1730. },
  1731. baseOpr: function (sheet, type) {
  1732. const data = {
  1733. updateType: type === 'delete' ? type : 'update',
  1734. updateData: [],
  1735. };
  1736. const selection = sheet.getSelections();
  1737. const row = selection[0].row, count = selection[0].rowCount;
  1738. const first = sheet.zh_data[row];
  1739. if (type === 'delete') {
  1740. for (let iRow = 0; iRow < count; iRow++) {
  1741. const posData = sheet.zh_data[iRow + row];
  1742. if (posData) {
  1743. data.updateData.push(sheet.zh_data[iRow + row].id);
  1744. }
  1745. }
  1746. } else if (type === 'up-move') {
  1747. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1748. for (let iRow = 0; iRow < count; iRow++) {
  1749. const posData = sheet.zh_data[iRow + row];
  1750. if (posData) {
  1751. data.updateData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1752. preUpdate.porder = posData.porder;
  1753. }
  1754. }
  1755. data.updateData.push(preUpdate);
  1756. } else if (type === 'down-move') {
  1757. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1758. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1759. const posData = sheet.zh_data[iRow + row];
  1760. if (posData) {
  1761. data.updateData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1762. nextUpdate.porder = posData.porder;
  1763. }
  1764. }
  1765. data.updateData.push(nextUpdate);
  1766. }
  1767. if (data.updateData.length > 0) {
  1768. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1769. if (type === 'delete') {
  1770. pos.removeDatas(result.pos);
  1771. sheet.deleteRows(row, count);
  1772. const loadResult = ledgerTree.loadPostData(result.ledger);
  1773. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1774. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1775. } else {
  1776. pos.updateDatas(result.pos);
  1777. const sel = selection[0];
  1778. if (sel) {
  1779. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1780. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1781. }
  1782. posOperationObj.loadCurPosData();
  1783. }
  1784. });
  1785. }
  1786. },
  1787. /**
  1788. * 编辑单元格响应事件
  1789. * @param {Object} e
  1790. * @param {Object} info
  1791. */
  1792. editEnded: function (e, info) {
  1793. if (info.sheet.zh_setting) {
  1794. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1795. const col = info.sheet.zh_setting.cols[info.col];
  1796. const orgText = posData ? posData[col.field] : null;
  1797. const newText = trimInvalidChar(info.editingText);
  1798. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
  1799. return;
  1800. }
  1801. const node = posOperationObj.ledgerTreeNode;
  1802. if (!node) {
  1803. toastr.error('数据错误,请选择台账节点后再试');
  1804. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1805. return;
  1806. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1807. toastr.error('父节点不可插入计量单元');
  1808. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1809. return;
  1810. }else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1811. toastr.error('项目节不可插入计量单元');
  1812. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1813. return;
  1814. }
  1815. const data = { updateType: posData ? 'update' : 'add' };
  1816. if (!posData) {
  1817. const sortData = info.sheet.zh_data;
  1818. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1819. data.updateData = { lid: node.id, tid: tender.id, porder: order };
  1820. } else {
  1821. data.updateData = { id: posData.id };
  1822. }
  1823. if (col.type === 'Number') {
  1824. const exprInfo = getExprInfo(col.field);
  1825. const num = _.toNumber(newText);
  1826. if (_.isFinite(num)) {
  1827. data.updateData[col.field] = num;
  1828. if (exprInfo) {
  1829. data.updateData[exprInfo.expr] = '';
  1830. }
  1831. } else {
  1832. try {
  1833. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1834. if (exprInfo) {
  1835. data.updateData[exprInfo.expr] = newText;
  1836. }
  1837. } catch(err) {
  1838. toastr.error('输入的表达式非法');
  1839. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1840. return;
  1841. }
  1842. }
  1843. } else {
  1844. data.updateData[col.field] = newText;
  1845. }
  1846. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1847. const updateRst = pos.updateDatas(result.pos);
  1848. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1849. if (updateRst.create.length > 0) {
  1850. // info.sheet.addRows(info.row, 1);
  1851. // if (info.sheet.zh_data.length === 0) {
  1852. // info.sheet.zh_data = pos.ledgerPos[itemsPre + node.id] || [];
  1853. // }
  1854. // SpreadJsObj.reLoadRowData(info.sheet, info.sheet.zh_data.length - 1);
  1855. posOperationObj.loadCurPosData();
  1856. } else {
  1857. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1858. }
  1859. const loadResult = ledgerTree.loadPostData(result.ledger);
  1860. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1861. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1862. }, function () {
  1863. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1864. });
  1865. }
  1866. },
  1867. /**
  1868. * 删除按钮响应事件
  1869. * @param sheet
  1870. */
  1871. deletePress: function (sheet) {
  1872. const self = this;
  1873. if (sheet.zh_setting) {
  1874. const sortData = sheet.zh_data;
  1875. const datas = [], posSelects = [];
  1876. const sel = sheet.getSelections()[0];
  1877. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1878. let bDel = false;
  1879. const node = sortData[iRow];
  1880. if (node) {
  1881. const data = {id: node.id};
  1882. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1883. const colSetting = sheet.zh_setting.cols[iCol];
  1884. const style = sheet.getStyle(iRow, iCol);
  1885. if (!style.locked) {
  1886. const colSetting = sheet.zh_setting.cols[iCol];
  1887. data[colSetting.field] = null;
  1888. const exprInfo = getExprInfo(colSetting.field);
  1889. if (exprInfo) data[exprInfo.expr] = '';
  1890. bDel = true;
  1891. }
  1892. }
  1893. if (bDel) {
  1894. datas.push(data);
  1895. posSelects.push(node);
  1896. }
  1897. }
  1898. }
  1899. if (datas.length > 0) {
  1900. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: datas}, function (result) {
  1901. pos.updateDatas(result.pos);
  1902. posOperationObj.loadCurPosData();
  1903. const loadResult = ledgerTree.loadPostData(result.ledger);
  1904. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1905. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1906. }, function () {
  1907. posOperationObj.loadCurPosData();
  1908. });
  1909. }
  1910. }
  1911. },
  1912. /**
  1913. * 删除 计量单元
  1914. * @param sheet
  1915. */
  1916. deletePos: function (sheet) {
  1917. const selection = sheet.getSelections();
  1918. const data = {
  1919. updateType: 'delete',
  1920. updateData: [],
  1921. };
  1922. const row = selection[0].row, count = selection[0].rowCount;
  1923. const sortData = sheet.zh_data;
  1924. for (let iRow = 0; iRow < count; iRow++) {
  1925. if (sortData[iRow + row]) {
  1926. data.updateData.push(sortData[iRow + row].id);
  1927. }
  1928. }
  1929. if (data.updateData.length > 0) {
  1930. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1931. pos.removeDatas(result.pos);
  1932. sheet.deleteRows(row, count);
  1933. const loadResult = ledgerTree.loadPostData(result.ledger);
  1934. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1935. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1936. });
  1937. }
  1938. },
  1939. insertPos: function (sheet) {
  1940. const selection = sheet.getSelections();
  1941. const sortData = sheet.zh_data;
  1942. const row = selection[0].row;
  1943. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1944. const select = SpreadJsObj.getSelectObject(sheet);
  1945. const porder = select ? select.porder : sortData.length + 1;
  1946. const data = {
  1947. updateType: 'insert',
  1948. updateData: [ { lid: node.id, tid: tender.id, porder } ],
  1949. };
  1950. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1951. const updateRst = pos.updateDatas(result.pos);
  1952. posOperationObj.loadCurPosData();
  1953. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1954. });
  1955. },
  1956. /**
  1957. * 粘贴单元格响应事件
  1958. * @param e
  1959. * @param info
  1960. */
  1961. clipboardPasted: function (e, info) {
  1962. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1963. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1964. }
  1965. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1966. if (node.code && (node.code !== '')) {
  1967. toastr.error('项目节不可含有清单明细');
  1968. posOperationObj.loadCurPosData();
  1969. return;
  1970. }
  1971. if (node.children && (node.children.length > 0)) {
  1972. toastr.error('仅清单子项可以含有计量单元');
  1973. posOperationObj.loadCurPosData();
  1974. return;
  1975. }
  1976. const hint = {
  1977. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  1978. };
  1979. if (info.sheet.zh_setting) {
  1980. const data = [];
  1981. const sortData = info.sheet.zh_data || [];
  1982. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1983. if (info.cellRange.col !== 0) {
  1984. toastr.warning('新增计量单元请先输入名称');
  1985. posOperationObj.loadCurPosData();
  1986. return;
  1987. }
  1988. }
  1989. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1990. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1991. let bPaste = false;
  1992. const curRow = info.cellRange.row + iRow;
  1993. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1994. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1995. const curCol = info.cellRange.col + iCol;
  1996. const colSetting = info.sheet.zh_setting.cols[curCol];
  1997. if (!colSetting) continue;
  1998. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1999. if (colSetting.type === 'Number') {
  2000. const num = _.toNumber(posData[colSetting.field]);
  2001. if (num) {
  2002. posData[colSetting.field] = num;
  2003. bPaste = true;
  2004. } else {
  2005. try {
  2006. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  2007. const exprInfo = getExprInfo(colSetting.field);
  2008. if (exprInfo) {
  2009. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2010. }
  2011. bPaste = true;
  2012. } catch (err) {
  2013. delete posData[colSetting.field];
  2014. toastMessageUniq(hint.expr);
  2015. }
  2016. }
  2017. } else {
  2018. bPaste = true;
  2019. }
  2020. }
  2021. if (bPaste) {
  2022. data.push(posData);
  2023. }
  2024. }
  2025. if (data.length > 0) {
  2026. postData('/tender/' + getTenderId() + '/pos/paste', data, function (result) {
  2027. pos.updateDatas(result.pos);
  2028. posOperationObj.loadCurPosData();
  2029. const loadResult = ledgerTree.loadPostData(result.ledger);
  2030. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2031. posOperationObj.loadCurPosData();
  2032. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2033. }, function () {
  2034. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2035. });
  2036. } else {
  2037. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2038. }
  2039. }
  2040. },
  2041. selectionChanged: function (e, info) {
  2042. posOperationObj.loadExprToInput();
  2043. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  2044. },
  2045. addPegs: function (pegs) {
  2046. if (!pegs || pegs.length <= 0) return;
  2047. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2048. if (!node) return;
  2049. const sheet = posSpread.getActiveSheet();
  2050. const sortData = sheet.zh_data || [];
  2051. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2052. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2053. postData('/tender/' + getTenderId() + '/pos/paste', pegs, function (result) {
  2054. pos.updateDatas(result.pos);
  2055. posOperationObj.loadCurPosData();
  2056. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2057. });
  2058. }
  2059. };
  2060. posSpread.bind(spreadNS.Events.SelectionChanged, posOperationObj.selectionChanged);
  2061. if (!posSpreadSetting.readOnly) {
  2062. $('a[name="pos-opr"]').click(function () {
  2063. posOperationObj.baseOpr(posSpread.getActiveSheet(), this.getAttribute('type'));
  2064. });
  2065. $('#pos-expr').bind('change onblur', function () {
  2066. const expr = $(this);
  2067. const posSheet = posSpread.getActiveSheet();
  2068. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2069. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2070. if (!select) return;
  2071. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2072. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2073. const data = {id: select.id};
  2074. const exprInfo = getExprInfo(field);
  2075. if (newValue !== '') {
  2076. const num = _.toNumber(newValue);
  2077. if (num) {
  2078. data[field] = num;
  2079. if (exprInfo) {
  2080. data[exprInfo.expr] = '';
  2081. }
  2082. } else {
  2083. try {
  2084. data[field] = math.evaluate(transExpr(newValue));
  2085. if (exprInfo) {
  2086. data[exprInfo.expr] = newValue;
  2087. }
  2088. } catch (err) {
  2089. toastr.error('输入的表达式非法');
  2090. return;
  2091. }
  2092. }
  2093. } else {
  2094. data[field] = null;
  2095. if (exprInfo) {
  2096. data[exprInfo.expr] = '';
  2097. }
  2098. }
  2099. // 更新至服务器
  2100. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: data}, function (result) {
  2101. const updateRst = pos.updateDatas(result.pos);
  2102. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2103. const loadResult = ledgerTree.loadPostData(result.ledger);
  2104. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2105. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2106. });
  2107. });
  2108. SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
  2109. posSpread.bind(spreadNS.Events.EditStarting, posOperationObj.editStarting);
  2110. posSpread.bind(spreadNS.Events.EditEnded, posOperationObj.editEnded);
  2111. posSpread.bind(spreadNS.Events.ClipboardPasted, posOperationObj.clipboardPasted);
  2112. const mergePeg = NewMergePeg({ callback: posOperationObj.addPegs });
  2113. // 右键菜单
  2114. $.contextMenu({
  2115. selector: '#pos-spread',
  2116. build: function ($trigger, e) {
  2117. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2118. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2119. },
  2120. items: {
  2121. 'insert': {
  2122. name: '插入',
  2123. icon: 'fa-plus',
  2124. disabled: function (key, opt) {
  2125. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2126. return node && node.children && node.children.length > 0;
  2127. },
  2128. callback: function (key, opt) {
  2129. posOperationObj.insertPos(posSpread.getActiveSheet());
  2130. }
  2131. },
  2132. 'delete': {
  2133. name: '删除',
  2134. icon: 'fa-remove',
  2135. disabled: function (key, opt) {
  2136. const sheet = posSpread.getActiveSheet();
  2137. if (sheet.zh_data) {
  2138. const selection = sheet.getSelections();
  2139. return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2140. } else {
  2141. return true;
  2142. }
  2143. },
  2144. callback: function (key, opt) {
  2145. posOperationObj.deletePos(posSpread.getActiveSheet());
  2146. }
  2147. },
  2148. 'merge-peg': {
  2149. name: '合并起讫桩号',
  2150. disabled: function (key, opt) {
  2151. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2152. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  2153. },
  2154. callback: function (key, opt) {
  2155. mergePeg.show();
  2156. }
  2157. }
  2158. }
  2159. });
  2160. }
  2161. postData(window.location.pathname + '/load', {}, function (data) {
  2162. ledgerTree.loadDatas(data.bills);
  2163. treeCalc.calculateAll(ledgerTree);
  2164. for (const t of data.tags) {
  2165. t.node = ledgerTree.datas.find(x => {return x.id === t.lid});
  2166. }
  2167. billsTag.loadDatas(data.tags);
  2168. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  2169. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  2170. checkShowLast(data.bills.length);
  2171. pos.loadDatas(data.pos);
  2172. posOperationObj.loadCurPosData();
  2173. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  2174. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2175. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  2176. checkList.loadHisCheckData();
  2177. }, null, true);
  2178. $.divResizer({
  2179. select: '#right-spr',
  2180. callback: function () {
  2181. ledgerSpread.refresh();
  2182. if (posSpread) {
  2183. posSpread.refresh();
  2184. }
  2185. if (stdXmj) {
  2186. stdXmj.spread.refresh();
  2187. }
  2188. if (stdGcl) {
  2189. stdGcl.spread.refresh();
  2190. }
  2191. if (dealBills) {
  2192. dealBills.spread.refresh();
  2193. }
  2194. if (searchLedger) {
  2195. searchLedger.spread.refresh();
  2196. }
  2197. if (errorList) {
  2198. errorList.spread.refresh();
  2199. }
  2200. if (checkList) {
  2201. checkList.spread.refresh();
  2202. }
  2203. }
  2204. });
  2205. const stdLibCellDoubleClick = function (e, info) {
  2206. const stdSheet = info.sheet;
  2207. const mainSheet = ledgerSpread.getActiveSheet();
  2208. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2209. const stdTree = stdSheet.zh_tree;
  2210. const stdNode = stdTree.nodes[info.row];
  2211. const mainTree = mainSheet.zh_tree;
  2212. const sel = mainSheet.getSelections()[0];
  2213. const mainNode = mainTree.nodes[sel.row];
  2214. if (!stdNode) { return; }
  2215. if (info.sheet.zh_setting.stdType === 'gcl') {
  2216. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2217. toastr.warning('非最底层项目下,不应添加清单');
  2218. return;
  2219. }
  2220. }
  2221. postData(window.location.pathname + '/update', {
  2222. postType: 'add-std',
  2223. postData: {
  2224. id: ledgerTree.getNodeKey(mainNode),
  2225. tender_id: mainNode.tender_id,
  2226. stdType: info.sheet.zh_setting.stdType,
  2227. stdLibId: stdNode.list_id,
  2228. stdNode: stdTree.getNodeKey(stdNode)
  2229. }
  2230. }, function (result) {
  2231. const refreshNode = mainTree.loadPostData(result);
  2232. treeOperationObj.refreshTree(mainSheet, refreshNode);
  2233. if (refreshNode.create && refreshNode.create.length > 0) {
  2234. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2235. const refreshRow = [sel.row, refreshNode.create[refreshNode.create.length - 1].index];
  2236. const curIndex = mainTree.nodes.indexOf(mainNode);
  2237. if (sel.row !== curIndex && curIndex >= 0) refreshRow.push(curIndex);
  2238. SpreadJsObj.reloadRowsBackColor(mainSheet, refreshRow);
  2239. } else {
  2240. const node = _.find(ledgerTree.nodes, {code: stdNode.code, name: stdNode.name});
  2241. if (node) {
  2242. mainSheet.setSelection(ledgerTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2243. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, ledgerTree.nodes.indexOf(node)]);
  2244. }
  2245. }
  2246. treeOperationObj.refreshOperationValid(mainSheet);
  2247. ledgerSpread.focus();
  2248. posOperationObj.loadCurPosData();
  2249. });
  2250. };
  2251. const stdXmjSetting = {
  2252. selector: '#std-xmj',
  2253. stdType: 'xmj',
  2254. libs: stdChapters,
  2255. treeSetting: {
  2256. id: 'chapter_id',
  2257. pid: 'pid',
  2258. order: 'order',
  2259. level: 'level',
  2260. rootId: -1,
  2261. keys: ['id', 'list_id', 'chapter_id'],
  2262. },
  2263. spreadSetting: {
  2264. cols: [
  2265. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2266. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2267. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2268. ],
  2269. treeCol: 0,
  2270. emptyRows: 0,
  2271. headRows: 1,
  2272. headRowHeight: [32],
  2273. defaultRowHeight: 21,
  2274. headerFont: '12px 微软雅黑',
  2275. font: '12px 微软雅黑',
  2276. headColWidth: [30],
  2277. selectedBackColor: '#fffacd',
  2278. },
  2279. cellDoubleClick: stdLibCellDoubleClick,
  2280. page: 'ledger',
  2281. tid: getTenderId(),
  2282. };
  2283. const stdGclSetting = {
  2284. selector: '#std-gcl',
  2285. stdType: 'gcl',
  2286. libs: stdBills,
  2287. treeSetting: {
  2288. id: 'bill_id',
  2289. pid: 'pid',
  2290. order: 'order',
  2291. level: 'level',
  2292. rootId: -1,
  2293. keys: ['id', 'list_id', 'bill_id']
  2294. },
  2295. spreadSetting: {
  2296. cols: [
  2297. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2298. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2299. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2300. ],
  2301. treeCol: 0,
  2302. emptyRows: 0,
  2303. headRows: 1,
  2304. headRowHeight: [32],
  2305. defaultRowHeight: 21,
  2306. headerFont: '12px 微软雅黑',
  2307. font: '12px 微软雅黑',
  2308. headColWidth: [30],
  2309. selectedBackColor: '#fffacd',
  2310. },
  2311. cellDoubleClick: stdLibCellDoubleClick,
  2312. page: 'ledger',
  2313. tid: getTenderId(),
  2314. };
  2315. // 展开收起标准清单
  2316. $('a', '#side-menu').bind('click', function (e) {
  2317. e.preventDefault();
  2318. const tab = $(this), tabPanel = $(tab.attr('content'));
  2319. // 展开工具栏、切换标签
  2320. if (!tab.hasClass('active')) {
  2321. // const close = $('.active', '#side-menu').length === 0;
  2322. $('a', '#side-menu').removeClass('active');
  2323. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  2324. tab.addClass('active');
  2325. tabPanel.addClass('active');
  2326. // $('.tab-content .tab-pane').removeClass('active');
  2327. showSideTools(tab.hasClass('active'));
  2328. if (tab.attr('content') === '#std-xmj') {
  2329. if (!stdXmj) {
  2330. stdXmj = $.stdLib(stdXmjSetting);
  2331. }
  2332. stdXmj.spread.refresh();
  2333. } else if (tab.attr('content') === '#std-gcl') {
  2334. if (!stdGcl) {
  2335. stdGcl = $.stdLib(stdGclSetting);
  2336. }
  2337. stdGcl.spread.refresh();
  2338. } else if (tab.attr('content') === '#deal-bills') {
  2339. if (!dealBills) {
  2340. dealBills = new DealBills('#deal-bills-spread', {
  2341. cols: [
  2342. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2343. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2344. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2345. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2346. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2347. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2348. ],
  2349. emptyRows: 3,
  2350. headRows: 1,
  2351. headRowHeight: [32],
  2352. defaultRowHeight: 21,
  2353. headerFont: '12px 微软雅黑',
  2354. font: '12px 微软雅黑',
  2355. headColWidth: [30],
  2356. selectedBackColor: '#fffacd',
  2357. readOnly: true,
  2358. });
  2359. dealBills.loadData();
  2360. }
  2361. dealBills.spread.refresh();
  2362. } else if (tab.attr('content') === '#search') {
  2363. if (!searchLedger) {
  2364. searchLedger = $.billsSearch({
  2365. selector: '#search',
  2366. searchSpread: ledgerSpread,
  2367. resultSpreadSetting: {
  2368. cols: [
  2369. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
  2370. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2371. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  2372. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  2373. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2374. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2375. ],
  2376. emptyRows: 0,
  2377. headRows: 1,
  2378. headRowHeight: [32],
  2379. headColWidth: [30],
  2380. defaultRowHeight: 21,
  2381. headerFont: '12px 微软雅黑',
  2382. font: '12px 微软雅黑',
  2383. selectedBackColor: '#fffacd',
  2384. },
  2385. afterLocated: function () {
  2386. posOperationObj.loadCurPosData();
  2387. }
  2388. });
  2389. }
  2390. searchLedger.spread.refresh();
  2391. } else if (tab.attr('content') === '#bills-tag') {
  2392. // do something
  2393. } else if (tab.attr('content') === '#error-list') {
  2394. errorList.spread.refresh();
  2395. } else if (tab.attr('content') === '#check-list') {
  2396. checkList.spread.refresh();
  2397. } else if (tab.attr('content') === '#fujian') {
  2398. $('#showAttachment').hide();
  2399. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2400. getNodeList(node.id);
  2401. getAllList();
  2402. }
  2403. } else { // 收起工具栏
  2404. tab.removeClass('active');
  2405. tabPanel.removeClass('active');
  2406. showSideTools(tab.hasClass('active'));
  2407. }
  2408. ledgerSpread.refresh();
  2409. if (posSpread) {
  2410. posSpread.refresh();
  2411. }
  2412. });
  2413. class DealBills {
  2414. constructor (selector, spreadSetting) {
  2415. const self = this;
  2416. this.obj = $(selector)[0];
  2417. this.url = '/tender/' + getTenderId() + '/deal';
  2418. this.spreadSetting = spreadSetting;
  2419. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2420. this.sheet = this.spread.getActiveSheet();
  2421. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2422. this.OprObj = {
  2423. /**
  2424. * 删除按钮响应事件
  2425. * @param sheet
  2426. */
  2427. deletePress: function (sheet) {
  2428. if (!sheet.zh_setting || readOnly || sheet.zh_setting.readOnly) return;
  2429. const sortData = sheet.zh_data;
  2430. const datas = [];
  2431. const sels = sheet.getSelections();
  2432. if (!sels || !sels[0]) return;
  2433. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  2434. let bDel = false;
  2435. const node = sortData[iRow];
  2436. if (node) {
  2437. const data = {id: node.id};
  2438. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  2439. const colSetting = sheet.zh_setting.cols[iCol];
  2440. if (colSetting.field === 'code') {
  2441. toastr.error('清单编号不能为空,如需删除签约清单请使用右键删除');
  2442. return;
  2443. }
  2444. const style = sheet.getStyle(iRow, iCol);
  2445. if (!style.locked) {
  2446. const colSetting = sheet.zh_setting.cols[iCol];
  2447. data[colSetting.field] = null;
  2448. bDel = true;
  2449. }
  2450. }
  2451. if (bDel) {
  2452. datas.push(data);
  2453. }
  2454. }
  2455. }
  2456. if (datas.length > 0) {
  2457. postData(self.url + '/update', {update: datas}, function (result) {
  2458. self.loadUpdateData(result);
  2459. SpreadJsObj.reLoadSheetData(sheet);
  2460. }, function () {
  2461. SpreadJsObj.reLoadSheetData(sheet);
  2462. });
  2463. }
  2464. },
  2465. delete: function (sheet) {
  2466. if (!sheet.zh_setting || readOnly || sheet.zh_setting.readOnly) return;
  2467. const sortData = sheet.zh_data;
  2468. const datas = [];
  2469. const sels = sheet.getSelections();
  2470. if (!sels || !sels[0]) return;
  2471. for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
  2472. const node = sortData[iRow];
  2473. datas.push(node.id);
  2474. }
  2475. if (datas.length > 0) {
  2476. postData(self.url + '/update', {del: datas}, function (result) {
  2477. self.loadUpdateData(result);
  2478. SpreadJsObj.reLoadSheetData(sheet);
  2479. }, function () {
  2480. SpreadJsObj.reLoadSheetData(sheet);
  2481. });
  2482. }
  2483. },
  2484. editEnded: function (e, info) {
  2485. if (!info.sheet.zh_setting || !info.sheet.zh_data || info.sheet.zh_setting.readOnly) return;
  2486. const node = info.sheet.zh_data[info.row];
  2487. const col = info.sheet.zh_setting.cols[info.col];
  2488. const data = {};
  2489. if (node) {
  2490. data.update = {};
  2491. data.update.id = node.id;
  2492. const oldValue = node ? node[col.field] : null;
  2493. const newValue = trimInvalidChar(info.editingText);
  2494. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  2495. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2496. return;
  2497. }
  2498. data.update[col.field] = newValue;
  2499. } else {
  2500. if (col.field !== 'code') {
  2501. toastr.warning('新增签约清单,请先输入清单编号');
  2502. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2503. return;
  2504. }
  2505. data.add = {};
  2506. data.add.order = info.row + 1;
  2507. data.add.code = trimInvalidChar(info.editingText);
  2508. }
  2509. postData(self.url + '/update', data, function (result) {
  2510. self.loadUpdateData(result);
  2511. SpreadJsObj.reLoadSheetData(info.sheet);
  2512. }, function () {
  2513. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2514. });
  2515. },
  2516. clipboardPasting(e, info) {
  2517. const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
  2518. info.cancel = true;
  2519. if (!setting || !sortData || setting.readOnly) return;
  2520. const pasteData = info.pasteData.html
  2521. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  2522. : (info.pasteData.text === ''
  2523. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  2524. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  2525. const hint = {
  2526. code: {type: 'warning', msg: '签约清单编号不可为空,已过滤'},
  2527. unit_price: {type: 'warning', msg: '输入的 单价 非法,已过滤'},
  2528. quantity: {type: 'warning', msg: '输入的 数量 非法,已过滤'},
  2529. };
  2530. const uDatas = [], iDatas = [];
  2531. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2532. const curRow = info.cellRange.row + iRow;
  2533. const node = sortData[curRow];
  2534. let bPaste = false;
  2535. const data = {};
  2536. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2537. const curCol = info.cellRange.col + iCol;
  2538. const colSetting = setting.cols[curCol];
  2539. const value = trimInvalidChar(pasteData[iRow][iCol]);
  2540. if (colSetting.field === 'code' && (!value || value === '')) {
  2541. toastMessageUniq(hint.code);
  2542. break;
  2543. }
  2544. if (colSetting.type === 'Number') {
  2545. const num = _.toNumber(value);
  2546. if (num) {
  2547. data[colSetting.field] = num;
  2548. bPaste = true;
  2549. } else if (colSetting.field === 'unit_price') {
  2550. toastMessageUniq(hint.unit_price);
  2551. } else if (colSetting.field === 'quantity') {
  2552. toastMessageUniq(hint.quantity);
  2553. }
  2554. } else {
  2555. data[colSetting.field] = value;
  2556. bPaste = true;
  2557. }
  2558. }
  2559. if (bPaste) {
  2560. if (node) {
  2561. data.id = node.id;
  2562. uDatas.push(data);
  2563. } else {
  2564. data.order = curRow + 1;
  2565. iDatas.push(data);
  2566. }
  2567. }
  2568. }
  2569. const updateData = {};
  2570. if (uDatas.length > 0) updateData.update = uDatas;
  2571. if (iDatas.length > 0) updateData.add = iDatas;
  2572. if (uDatas.length > 0 || iDatas.length > 0) {
  2573. postData(self.url + '/update', updateData, function (result) {
  2574. self.loadUpdateData(result);
  2575. SpreadJsObj.reLoadSheetData(info.sheet);
  2576. });
  2577. } else {
  2578. SpreadJsObj.reLoadSheetData(info.sheet);
  2579. }
  2580. },
  2581. };
  2582. if (!readOnly) {
  2583. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2584. const dealSheet = info.sheet;
  2585. if (!dealSheet.zh_setting.readOnly) return;
  2586. const mainSheet = ledgerSpread.getActiveSheet();
  2587. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2588. if (!dealBills) { return; }
  2589. const mainTree = mainSheet.zh_tree;
  2590. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2591. if (!mainNode || !mainTree) { return; }
  2592. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2593. toastr.error('非最底层项目下,不应添加清单');
  2594. return;
  2595. }
  2596. postData(window.location.pathname + '/update', {
  2597. postType: 'add-deal',
  2598. postData: {
  2599. id: mainNode.ledger_id,
  2600. type: mainNode.code ? 'child' : 'next',
  2601. dealBills: {
  2602. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2603. unit_price: dealBills.unit_price,
  2604. }
  2605. },
  2606. }, function (result) {
  2607. const refreshData = mainTree.loadPostData(result);
  2608. treeOperationObj.refreshTree(mainSheet, refreshData);
  2609. const sel = mainSheet.getSelections()[0];
  2610. mainSheet.setSelection(refreshData.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2611. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshData.create[0].index]);
  2612. treeOperationObj.refreshOperationValid(mainSheet);
  2613. ledgerSpread.focus();
  2614. posOperationObj.loadCurPosData();
  2615. });
  2616. });
  2617. this.spread.bind(spreadNS.Events.EditEnded, this.OprObj.editEnded);
  2618. this.spread.bind(spreadNS.Events.ClipboardPasting, this.OprObj.clipboardPasting);
  2619. SpreadJsObj.addDeleteBind(this.spread, this.OprObj.deletePress);
  2620. }
  2621. $('#upload-deal-bills').click(function () {
  2622. const file = $('#deal-bills-file')[0];
  2623. const formData = new FormData();
  2624. formData.append('file', file.files[0]);
  2625. postDataWithFile(self.url+'/upload-excel', formData, function (data) {
  2626. self.data = data;
  2627. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2628. $('#upload-deal').modal('hide');
  2629. }, function () {
  2630. $('#upload-deal').modal('hide');
  2631. });
  2632. });
  2633. if (!readOnly) {
  2634. $.contextMenu({
  2635. selector: selector,
  2636. build: function ($trigger, e) {
  2637. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
  2638. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2639. },
  2640. items: {
  2641. edit: {
  2642. name: '进入编辑模式',
  2643. icon: 'fa-edit',
  2644. visible: function (key, opt) {
  2645. return self.sheet.zh_setting.readOnly;
  2646. },
  2647. callback: function (key, opt) {
  2648. self.sheet.zh_setting.readOnly = false;
  2649. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  2650. },
  2651. },
  2652. read: {
  2653. name: '退出编辑模式',
  2654. icon: 'fa-sign-out',
  2655. visible: function (key, opt) {
  2656. return !self.sheet.zh_setting.readOnly;
  2657. },
  2658. callback: function (key, opt) {
  2659. self.sheet.zh_setting.readOnly = true;
  2660. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  2661. },
  2662. },
  2663. del: {
  2664. name: '删除',
  2665. icon: 'fa-times',
  2666. visible: function (key, opt) {
  2667. return !self.sheet.zh_setting.readOnly;
  2668. },
  2669. disabled: function (key, opt) {
  2670. const select = SpreadJsObj.getSelectObject(self.sheet);
  2671. return !select;
  2672. },
  2673. callback: function (key, opt) {
  2674. self.OprObj.delete(self.sheet);
  2675. },
  2676. },
  2677. sprEdit: '----',
  2678. apply: {
  2679. name: '应用全部清单单价至台账',
  2680. icon: 'fa-magic',
  2681. disabled: function (key, opt) {
  2682. const sheet = self.spread.getActiveSheet();
  2683. return sheet.getRowCount() === 0;
  2684. },
  2685. callback: function (key, opt) {
  2686. const datas = [], sourceData = self.spread.getActiveSheet().zh_data;
  2687. for (const db of sourceData) {
  2688. const targets = ledgerTree.nodes.filter(function (x) {
  2689. return x.b_code === db.code && x.name === db.name && x.unit === db.unit;
  2690. });
  2691. for (const t of targets) {
  2692. if (t.children && t.children.length > 0) continue;
  2693. const data = ledgerTree.getNodeKeyData(t);
  2694. data.unit_price = db.unit_price;
  2695. datas.push(data);
  2696. }
  2697. }
  2698. if (datas.length > 0) {
  2699. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  2700. const refreshNode = ledgerTree.loadPostData(result);
  2701. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  2702. });
  2703. } else {
  2704. toastr.warning('没有可应用的清单。');
  2705. }
  2706. }
  2707. }
  2708. }
  2709. });
  2710. }
  2711. this.initDealBillsSearch();
  2712. }
  2713. search(keyword) {
  2714. this.searchResult = [];
  2715. this.searchCur = 0;
  2716. if (keyword) {
  2717. for (const [i, d] of this.data.entries()) {
  2718. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  2719. }
  2720. }
  2721. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  2722. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.sheet, this.searchResult[0]);
  2723. }
  2724. searchPre() {
  2725. this.searchCur = this.searchCur - 1;
  2726. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  2727. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  2728. }
  2729. searchNext() {
  2730. this.searchCur = this.searchCur + 1;
  2731. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  2732. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  2733. }
  2734. searchClear() {
  2735. $('#dbs-keyword').val('');
  2736. this.searchResult = [];
  2737. this.searchCur = 0;
  2738. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  2739. }
  2740. initDealBillsSearch() {
  2741. const self = this;
  2742. $('#dbs-keyword').change(function () { self.search(this.value); });
  2743. $('#dbs-pre').click(function (e) {
  2744. self.searchPre();
  2745. e.stopPropagation();
  2746. });
  2747. $('#dbs-next').click(function (e) {
  2748. self.searchNext();
  2749. e.stopPropagation();
  2750. });
  2751. $('#dbs-clear').click(function (e) {
  2752. self.searchClear();
  2753. e.stopPropagation();
  2754. });
  2755. }
  2756. loadData () {
  2757. const self = this;
  2758. postData(this.url+'/get-data', {}, function (data) {
  2759. self.data = data;
  2760. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2761. if (data.length > 0) self.spread.getActiveSheet().setSelection(0, 0, 1, 1);
  2762. });
  2763. }
  2764. calculateData () {
  2765. if (this.data) {
  2766. for (const d of this.data) {
  2767. d.total_price = _.multiply(d.quantity, d.unit_price);
  2768. }
  2769. }
  2770. }
  2771. loadUpdateData(updateData) {
  2772. if (updateData.add) {
  2773. for (const a of updateData.add) {
  2774. this.data.push(a);
  2775. }
  2776. }
  2777. if (updateData.update) {
  2778. for (const u of updateData.update) {
  2779. const d = this.data.find(function (x) {
  2780. return u.id === x.id;
  2781. });
  2782. if (d) {
  2783. _.assign(d, u);
  2784. } else {
  2785. this.data.push(d);
  2786. }
  2787. }
  2788. }
  2789. if (updateData.del) {
  2790. _.remove(this.data, function (d) {
  2791. return updateData.del.indexOf(d.id) >= 0;
  2792. });
  2793. }
  2794. }
  2795. }
  2796. class BatchInsertBillsPosObj {
  2797. constructor (obj) {
  2798. const self = this;
  2799. this.obj = obj;
  2800. this.billsCount = 6;
  2801. this.posCount = 1000;
  2802. this.filter = getLocalCache('zh-calc-batch-filter');
  2803. if (!this.filter) {
  2804. this.filter = '1';
  2805. }
  2806. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2807. // 初始化 清单编号窗口 参数
  2808. this.qdSpreadSetting = {
  2809. cols: [
  2810. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2811. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2812. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2813. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2814. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2815. ],
  2816. emptyRows: this.billsCount,
  2817. headRows: 1,
  2818. headRowHeight: [32],
  2819. headerFont: '12px 微软雅黑',
  2820. font: '12px 微软雅黑',
  2821. };
  2822. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2823. // 初始化 部位数量复核表 参数
  2824. this.posSpreadSetting = {
  2825. cols: [
  2826. {title: '计量单元', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2827. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2828. ],
  2829. emptyRows: this.posCount,
  2830. headRows: 1,
  2831. headRowHeight: [32],
  2832. headerFont: '12px 微软雅黑',
  2833. font: '12px 微软雅黑',
  2834. };
  2835. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2836. this.posSpreadSetting.cols.push(
  2837. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2838. )
  2839. }
  2840. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2841. // 初始化 签约清单 参数
  2842. this.dealSpreadSetting = {
  2843. cols: [
  2844. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2845. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2846. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2847. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2848. ],
  2849. emptyRows: 0,
  2850. headRows: 1,
  2851. headRowHeight: [32],
  2852. headerFont: '12px 微软雅黑',
  2853. font: '12px 微软雅黑',
  2854. };
  2855. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2856. this.dealSheet = this.dealSpread.getActiveSheet();
  2857. // 初始化 清单编号、部位数量复核表 表格
  2858. this.initView();
  2859. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2860. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2861. $.contextMenu({
  2862. selector: '.batch-l-t',
  2863. build: function ($trigger, e) {
  2864. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2865. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2866. },
  2867. items: {
  2868. 'create': {
  2869. name: '新增行',
  2870. icon: 'fa-sign-in',
  2871. callback: function (key, opt) {
  2872. const qdSheet = self.qdSpread.getActiveSheet();
  2873. const posSheet = self.posSpread.getActiveSheet();
  2874. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2875. const index = qdSheet.getRowCount();
  2876. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2877. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2878. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2879. },
  2880. },
  2881. 'delete': {
  2882. name: '删除行',
  2883. icon: 'fa-remove',
  2884. callback: function (key, opt) {
  2885. const qdSheet = self.qdSpread.getActiveSheet();
  2886. const posSheet = self.posSpread.getActiveSheet();
  2887. const sel = qdSheet.getSelections()[0];
  2888. qdSheet.deleteRows(sel.row, sel.rowCount);
  2889. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2890. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2891. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2892. }
  2893. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2894. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2895. }
  2896. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2897. },
  2898. }
  2899. }
  2900. });
  2901. // 拉取签约清单数据
  2902. if (dealBills) {
  2903. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2904. } else {
  2905. postData('/tender/' + getTenderId() + '/deal/get-data', {}, function (data) {
  2906. SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
  2907. });
  2908. }
  2909. // 双击签约清单,自动添加到清单编号窗口
  2910. this.dealSpread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2911. const deal = info.sheet.zh_data[info.row];
  2912. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2913. const sel = qdSheet.getSelections()[0];
  2914. qdSheet.getCell(sel.row, 0).value(deal.code);
  2915. qdSheet.getCell(sel.row, 1).value(deal.name);
  2916. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2917. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2918. if (sel.row + 1 === qdSheet.getRowCount()) {
  2919. const count = sel.row + 2;
  2920. qdSheet.setRowCount(count);
  2921. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2922. const colCount = posSheet.getColumnCount() + 1
  2923. posSheet.setColumnCount(colCount);
  2924. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2925. }
  2926. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2927. });
  2928. this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
  2929. info.cancel = true;
  2930. const transpose = $('[name=batch-transpose]')[0].checked;
  2931. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
  2932. const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
  2933. const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
  2934. SpreadJsObj.beginMassOperation(billsSheet);
  2935. if (finalCount > billsCount) {
  2936. billsSheet.setRowCount(finalCount);
  2937. posSheet.setColumnCount(finalCount + 2);
  2938. for (let i = billsCount - 1; i <= finalCount; i++) {
  2939. billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2940. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2941. }
  2942. }
  2943. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  2944. const curRow = iRow + info.cellRange.row;
  2945. pasteData[iRow].forEach((value, iCol) => {
  2946. billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
  2947. });
  2948. if ([0, 1].indexOf(info.cellRange.col) >= 0) {
  2949. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2950. const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
  2951. if (bills) {
  2952. billsSheet.getCell(curRow, 1).value(bills.name);
  2953. billsSheet.getCell(curRow, 2).value(bills.unit);
  2954. billsSheet.getCell(curRow, 3).value(bills.unit_price);
  2955. }
  2956. }
  2957. }
  2958. SpreadJsObj.endMassOperation(billsSheet);
  2959. });
  2960. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2961. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2962. const count = qdSheet.getRowCount();
  2963. if (billsCount > count) {
  2964. qdSheet.setRowCount(billsCount);
  2965. for (let i = count + 1; i <= billsCount; i++) {
  2966. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2967. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2968. }
  2969. }
  2970. });
  2971. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2972. if (info.col === 0) {
  2973. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2974. if (dealBills && dealBills.length > 0) {
  2975. const bills = _.find(dealBills, {code: info.editingText});
  2976. if (bills) {
  2977. info.sheet.getCell(info.row, 1).value(bills.name);
  2978. info.sheet.getCell(info.row, 2).value(bills.unit);
  2979. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2980. }
  2981. }
  2982. }
  2983. });
  2984. this.obj.bind('shown.bs.modal', function () {
  2985. self.qdSpread.refresh();
  2986. self.posSpread.refresh();
  2987. self.dealSpread.refresh();
  2988. });
  2989. $('#batch-ok').click(function () {
  2990. const sheet = ledgerSpread.getActiveSheet();
  2991. const sel = sheet.getSelections()[0];
  2992. const row = sel.row;
  2993. const select = ledgerTree.nodes[row];
  2994. if (select) {
  2995. const insertData = {};
  2996. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2997. insertData.id = ledgerTree.getNodeKey(select);
  2998. insertData.batchData = self.getBatchData();
  2999. if (insertData.batchData.length > 0) {
  3000. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  3001. pos.updateDatas(data.pos);
  3002. const result = ledgerTree.loadPostData(data.ledger);
  3003. treeOperationObj.refreshTree(sheet, result);
  3004. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3005. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  3006. treeOperationObj.refreshOperationValid(sheet);
  3007. posOperationObj.loadCurPosData();
  3008. self.obj.modal('hide');
  3009. }, null, true);
  3010. } else {
  3011. self.obj.modal('hide');
  3012. }
  3013. }
  3014. });
  3015. $('input[name=batch-filter]').change(function () {
  3016. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3017. });
  3018. this.initDealBillsSearch();
  3019. }
  3020. search(keyword) {
  3021. this.searchResult = [];
  3022. this.searchCur = 0;
  3023. if (keyword) {
  3024. for (const [i, d] of this.dealSheet.zh_data.entries()) {
  3025. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  3026. }
  3027. }
  3028. $('#batch-dbs-count').html(`结果:${this.searchResult.length}`);
  3029. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.dealSheet, this.searchResult[0]);
  3030. }
  3031. searchPre() {
  3032. this.searchCur = this.searchCur - 1;
  3033. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3034. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3035. }
  3036. searchNext() {
  3037. this.searchCur = this.searchCur + 1;
  3038. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3039. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3040. }
  3041. initDealBillsSearch() {
  3042. const self = this;
  3043. $('#batch-dbs-keyword').change(function () { self.search(this.value); });
  3044. $('#batch-dbs-pre').click(function (e) {
  3045. self.searchPre();
  3046. e.stopPropagation();
  3047. });
  3048. $('#batch-dbs-next').click(function (e) {
  3049. self.searchNext();
  3050. e.stopPropagation();
  3051. });
  3052. }
  3053. // 初始化左侧表格
  3054. initView () {
  3055. // 初始化 清单编号
  3056. const qdSheet = this.qdSpread.getActiveSheet();
  3057. qdSheet.setColumnWidth(0, 45, spreadNS.SheetArea.rowHeader);
  3058. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3059. SpreadJsObj.refreshColumnAlign(qdSheet);
  3060. // 清理原有数据
  3061. SpreadJsObj.beginMassOperation(qdSheet);
  3062. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3063. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3064. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3065. }
  3066. qdSheet.setSelection(0, 0, 1 ,1);
  3067. SpreadJsObj.endMassOperation(qdSheet);
  3068. // 初始化 部位数量复核表
  3069. const posSheet = this.posSpread.getActiveSheet();
  3070. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3071. SpreadJsObj.refreshColumnAlign(posSheet);
  3072. // 清理原有数据
  3073. SpreadJsObj.beginMassOperation(posSheet);
  3074. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3075. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3076. posSheet.setSelection(0, 0, 1 ,1);
  3077. SpreadJsObj.endMassOperation(posSheet);
  3078. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3079. }
  3080. // 获取界面数据
  3081. getBatchData () {
  3082. const result = [];
  3083. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3084. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3085. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3086. const qd = {
  3087. b_code: qdSheet.getText(iRow, 0),
  3088. name: qdSheet.getText(iRow, 1),
  3089. unit: qdSheet.getText(iRow, 2),
  3090. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3091. pos: [],
  3092. };
  3093. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3094. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3095. if (value !== 0 && !isNaN(value)) {
  3096. qd.pos.push({
  3097. name: posSheet.getText(iPosRow, 0),
  3098. drawing_code: posSheet.getText(iPosRow, 1),
  3099. quantity: value, porder: qd.pos.length + 1,
  3100. });
  3101. }
  3102. }
  3103. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3104. }
  3105. return result;
  3106. }
  3107. }
  3108. // $('#searchAccount').click(() => {
  3109. // const data = {
  3110. // keyword: $('#searchName').val(),
  3111. // };
  3112. // postData('/search/user', data, (data) => {
  3113. // const resultDiv = $('#searchResult');
  3114. // if (data) {
  3115. // $('h5>span', resultDiv).text(data.name);
  3116. // $('#addAuditor').attr('auditorId', data.id);
  3117. // $('h6', resultDiv).text(data.role);
  3118. // $('p', resultDiv).text(data.company);
  3119. // resultDiv.show();
  3120. // } else {
  3121. // toastr.info('未查询到该审核人');
  3122. // resultDiv.hide();
  3123. // }
  3124. // }, () => {
  3125. // $('#searchResult').hide();
  3126. // });
  3127. // });
  3128. // // 审批人分组选择
  3129. // $('#account_group').change(function () {
  3130. // let account_html = '<option value="0">选择审批人</option>';
  3131. // for (const account of accountList) {
  3132. // if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  3133. // const role = account.role !== '' ? '(' + account.role + ')' : '';
  3134. // const company = account.company !== '' ? ' -' + account.company : '';
  3135. // account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  3136. // }
  3137. // }
  3138. // $('#account_list').html(account_html);
  3139. // });
  3140. let timer = null;
  3141. let oldSearchVal = null;
  3142. $('#gr-search').bind('input propertychange', function(e) {
  3143. oldSearchVal = e.target.value
  3144. timer && clearTimeout(timer)
  3145. timer = setTimeout(() => {
  3146. const newVal = $('#gr-search').val()
  3147. let html = ''
  3148. if (newVal && newVal === oldSearchVal) {
  3149. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  3150. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3151. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3152. class="ml-auto">${item.mobile || ''}</span></p>
  3153. <span class="text-muted">${item.role || ''}</span>
  3154. </dd>`
  3155. })
  3156. $('.book-list').empty()
  3157. $('.book-list').append(html)
  3158. } else {
  3159. if (!$('.acc-btn').length) {
  3160. accountGroup.forEach((group, idx) => {
  3161. if (!group) return
  3162. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  3163. </a> ${group.groupName}</dt>
  3164. <div class="dd-content" data-toggleid="${idx}">`
  3165. group.groupList.forEach(item => {
  3166. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3167. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3168. class="ml-auto">${item.mobile || ''}</span></p>
  3169. <span class="text-muted">${item.role || ''}</span>
  3170. </dd>`
  3171. });
  3172. html += '</div>'
  3173. })
  3174. $('.book-list').empty()
  3175. $('.book-list').append(html)
  3176. }
  3177. }
  3178. }, 400);
  3179. });
  3180. // 添加审批流程按钮逻辑
  3181. $('.book-list').on('click', 'dt', function () {
  3182. const idx = $(this).find('.acc-btn').attr('data-groupid')
  3183. const type = $(this).find('.acc-btn').attr('data-type')
  3184. if (type === 'hide') {
  3185. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  3186. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  3187. $(this).find('.acc-btn').attr('data-type', 'show')
  3188. })
  3189. } else {
  3190. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  3191. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  3192. $(this).find('.acc-btn').attr('data-type', 'hide')
  3193. })
  3194. }
  3195. return false
  3196. });
  3197. // 添加到审批流程中
  3198. $('dl').on('click', 'dd', function () {
  3199. const auditorId = parseInt($(this).data('id'))
  3200. if (auditorId) {
  3201. postData('/tender/' + getTenderId() + '/ledger/audit/add', { auditorId }, (datas) => {
  3202. const html = [];
  3203. // 如果是重新上报,添加到重新上报列表中
  3204. const auditorshtml = [];
  3205. for (const [index,data] of datas.entries()) {
  3206. if (index !== 0) {
  3207. html.push('<li class="list-group-item" auditorId="' + data.audit_id + '">');
  3208. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  3209. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  3210. }
  3211. html.push('<span>');
  3212. html.push(data.audit_order + ' ');
  3213. html.push(data.name + ' ');
  3214. html.push('</span>');
  3215. html.push('<small class="text-muted">');
  3216. html.push(data.role);
  3217. html.push('</small></li>');
  3218. }
  3219. auditorshtml.push('<li class="list-group-item" ' + (index !== 0 ? 'data-auditorid="' + data.audit_id + '"' : '') + '>');
  3220. auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  3221. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  3222. if (index === 0) {
  3223. auditorshtml.push('<span class="pull-right">原报</span>');
  3224. } else if (index+1 === datas.length) {
  3225. auditorshtml.push('<span class="pull-right">终审</span>');
  3226. } else {
  3227. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  3228. }
  3229. auditorshtml.push('</li>');
  3230. }
  3231. $('#auditors').html(html.join(''));
  3232. $('#auditors-list').html(auditorshtml.join(''));
  3233. });
  3234. }
  3235. });
  3236. $('body').on('click', '#auditors li>a', function () {
  3237. const li = $(this).parent();
  3238. const data = {
  3239. auditorId: parseInt(li.attr('auditorId')),
  3240. };
  3241. postData('/tender/' + getTenderId() + '/ledger/audit/delete', data, (data2) => {
  3242. li.remove();
  3243. for (const a of data2) {
  3244. const aLi = $('li[auditorId=' + a.audit_id + ']');
  3245. $('span', aLi).text(a.audit_order + ' ' + a.name + ' ');
  3246. }
  3247. // 如果是重新上报
  3248. // 令最后一个图标转换
  3249. $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
  3250. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  3251. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  3252. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  3253. }
  3254. // $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  3255. // if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  3256. // $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  3257. // .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  3258. // }
  3259. for (let i = 0; i < $('#auditors-list li').length; i++) {
  3260. $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审')
  3261. // $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审')
  3262. }
  3263. });
  3264. });
  3265. $('#hideSp').click(function () {
  3266. $('#sp-list').modal('hide');
  3267. });
  3268. // 多层modal关闭后的滚动bug修复
  3269. $('#sp-list').on('hidden.bs.modal', function (e) {
  3270. $(document.body).addClass('modal-open');
  3271. });
  3272. // 显示层次
  3273. (function (select, sheet) {
  3274. $(select).click(function () {
  3275. const tag = $(this).attr('tag');
  3276. const tree = sheet.zh_tree;
  3277. if (!tree) return;
  3278. setTimeout(() => {
  3279. showWaitingView();
  3280. switch (tag) {
  3281. case "1":
  3282. case "2":
  3283. case "3":
  3284. case "4":
  3285. case "5":
  3286. tree.expandByLevel(parseInt(tag));
  3287. SpreadJsObj.refreshTreeRowVisible(sheet);
  3288. break;
  3289. case "last":
  3290. tree.expandByCustom(() => { return true; });
  3291. SpreadJsObj.refreshTreeRowVisible(sheet);
  3292. break;
  3293. case "leafXmj":
  3294. tree.expandToLeafXmj();
  3295. SpreadJsObj.refreshTreeRowVisible(sheet);
  3296. break;
  3297. }
  3298. closeWaitingView();
  3299. }, 100);
  3300. });
  3301. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  3302. // $('#exportLedger').click(function () {
  3303. // const data = [];
  3304. // const setting = {
  3305. // header: ['项目节编号', '清单子目号', '部位明细', '名称', '单位', '清单数量', '设计数量1', '设计数量2', '单价', '合价', '图号', '备注'],
  3306. // width: [100, 70, 70, 300, 60, 80, 80, 80, 80, 80, 100, 100],
  3307. // hAlign: ['left', 'left', 'left', 'left','center', 'right', 'right', 'right', 'right', 'right', 'left', 'left'],
  3308. // };
  3309. // for (const node of ledgerTree.nodes) {
  3310. // data.push([node.code, node.b_code, '', node.name, node.unit,
  3311. // node.quantity, node.dgn_qty1, node.dgn_qty2, node.unit_price, node.total_price,
  3312. // node.drawing_code, node.memo
  3313. // ]);
  3314. // const posRange = pos.getLedgerPos(node.id);
  3315. // if (posRange && posRange.length > 0) {
  3316. // for (const [i, p] of posRange.entries()) {
  3317. // data.push(['', '', (i + 1) + '', p.name, '',
  3318. // p.quantity, '', '', '', '',
  3319. // p.drawing_code, p.memo
  3320. // ]);
  3321. // }
  3322. // }
  3323. // }
  3324. //
  3325. // XLSXObj.exportXlsxSheet(setting, data, "台账分解.xlsx");
  3326. // });
  3327. $('#exportLedger').click(function () {
  3328. const data = [];
  3329. const setting = {
  3330. cols: [
  3331. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  3332. {title: '清单子目号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  3333. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'pos_code', hAlign: 1, width: 70, formatter: '@'},
  3334. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  3335. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  3336. {title: '清单数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  3337. {title: '设计数量1', colSpan: '1', rowSpan: '1', field: 'dgn_qty1', hAlign: 2, width: 80, type: 'Number'},
  3338. {title: '设计数量2', colSpan: '1', rowSpan: '1', field: 'dgn_qty2', hAlign: 2, width: 80, type: 'Number'},
  3339. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  3340. {title: '合价', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3341. {title: '图号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 100, formatter: '@'},
  3342. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 100, formatter: '@'},
  3343. ],
  3344. headRows: 1,
  3345. headRowHeight: [32],
  3346. defaultRowHeight: 21,
  3347. headerFont: 'bold 10px 微软雅黑',
  3348. font: '10px 微软雅黑'
  3349. };
  3350. const hasCl = ledgerSpreadSetting.cols.find(x => { return x.field === 'sjcl_qty'});
  3351. const qtyF = hasCl ? 'quantity' : 'sgfh_qty';
  3352. const tpF = hasCl ? 'total_price' : 'sgfh_tp';
  3353. for (const node of ledgerTree.nodes) {
  3354. data.push({
  3355. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  3356. unit_price: node.unit_price, quantity: node[qtyF], total_price: node[tpF],
  3357. dgn_qty1: node.dgn_qty1, dgn_qty2: node.dgn_qty2,
  3358. drawing_code: node.drawing_code, memo: node.memo
  3359. });
  3360. const posRange = pos.getLedgerPos(node.id);
  3361. if (posRange && posRange.length > 0) {
  3362. for (const [i, p] of posRange.entries()) {
  3363. data.push({
  3364. pos_code: (i + 1) + '', name: p.name,
  3365. quantity: p[qtyF], drawing_code: p.drawing_code, memo: p.memo
  3366. });
  3367. }
  3368. }
  3369. }
  3370. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, "台账分解.xlsx");
  3371. });
  3372. const dataChecker = DataChecker({
  3373. checkUrl: window.location.pathname + '/check',
  3374. completeData: function (data) {
  3375. pos.updateDatas({update: data.source.pos});
  3376. const loadResult = ledgerTree.loadPostData({update: data.source.bills});
  3377. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  3378. posOperationObj.loadCurPosData();
  3379. for (const e of data.error) {
  3380. e.serialNo = ledgerTree.getNodeIndex(ledgerTree.getItems(e.ledger_id)) + 1;
  3381. }
  3382. },
  3383. errorList: errorList,
  3384. });
  3385. $('[name=audit-start]').submit(function (e) {
  3386. if (checkAuditorFrom()) {
  3387. $(this).parent().parent().parent().modal('hide');
  3388. dataChecker.checkAndPost(this.action, {});
  3389. $('#hide-all').hide();
  3390. }
  3391. return false;
  3392. });
  3393. $('#ledger-check2').click(() => {
  3394. const result = ledgerCheck2({
  3395. ledgerTree: ledgerTree,
  3396. ledgerPos: pos,
  3397. checkList: checkList,
  3398. decimal: tenderInfo.decimal,
  3399. checkOption: checkOption,
  3400. });
  3401. check2Viewing({
  3402. extra: ZhCalc.div(ledgerTree.datas.length + pos.datas.length, 10000, 0),
  3403. randomWait: true,
  3404. prefix: 'check2-',
  3405. checks: result,
  3406. checkList: checkList,
  3407. })
  3408. });
  3409. // 切换附件里节点和所有附件
  3410. $('#fujian .nav-link').on('click', function () {
  3411. const tabPanel = $(this).attr('fujian-content');
  3412. if (tabPanel !== 'syfujian') {
  3413. $('#showPage').hide();
  3414. $('#bach-download').prop('type', 'curr');
  3415. } else {
  3416. $('#showPage').show();
  3417. $('#bach-download').prop('type', 'all');
  3418. }
  3419. $('#showAttachment').hide();
  3420. });
  3421. // 上传附件
  3422. $('#upload-file-btn').click(function () {
  3423. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3424. // return toastr.error('当前操作没有权限!');
  3425. // }
  3426. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  3427. if (!node) return;
  3428. const files = $('#upload-file')[0].files;
  3429. const formData = new FormData();
  3430. formData.append('lid', node.id);
  3431. for (const file of files) {
  3432. if (file === undefined) {
  3433. toastr.error('未选择上传文件!');
  3434. return false;
  3435. }
  3436. const filesize = file.size;
  3437. if (filesize > 30 * 1024 * 1024) {
  3438. toastr.error('存在上传文件大小过大!');
  3439. return false;
  3440. }
  3441. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3442. if (whiteList && !whiteList.includes(fileext)) {
  3443. toastr.error('只能上传指定格式的附件!');
  3444. return false;
  3445. }
  3446. formData.append('size', filesize);
  3447. formData.append('file[]', file);
  3448. }
  3449. postDataWithFile('/tender/' + tender.id + '/ledger/upload/file', formData, function (data) {
  3450. $('#upload').modal('hide');
  3451. // 插入到attData中
  3452. attData = data.concat(attData);
  3453. // 重新生成List
  3454. getAllList();
  3455. getNodeList(node.id);
  3456. }, function () {
  3457. toastr.error('附件上传失败');
  3458. });
  3459. $('#upload-file').val('');
  3460. });
  3461. // 获取附件信息
  3462. $('.list-table').on('click', '.att-file-name', function () {
  3463. const fid = $(this).attr('file-id');
  3464. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3465. return;
  3466. }
  3467. const att = attData.find(function (item) {
  3468. return item.id === parseInt(fid);
  3469. });
  3470. $('#edit-att').hide();
  3471. $('#show-att').show();
  3472. if (att !== undefined) {
  3473. // 进来先把编辑功能隐藏
  3474. $('#btn-att a').eq(3).hide()
  3475. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3476. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3477. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3478. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3479. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3480. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3481. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3482. $('#show-att tr').eq(3).children('td').text(att.remark);
  3483. // 附件uid等于当前用户id, 附件上传本人
  3484. if (parseInt(cur_uid) === att.uid) {
  3485. $('#btn-att').show();
  3486. const showDel = tender.ledger_status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3487. if (showDel) $('#btn-att a').eq(3).show();
  3488. // $('#btn-att a').eq(3).show();
  3489. $('#btn-att a').eq(2).hide();
  3490. $('#btn-att a').eq(4).hide();
  3491. $('#btn-att a').eq(5).hide();
  3492. } else {
  3493. $('#btn-att').hide();
  3494. $('#btn-att a').eq(3).hide();
  3495. $('#btn-att a').eq(2).hide();
  3496. $('#btn-att a').eq(4).hide();
  3497. $('#btn-att a').eq(5).hide();
  3498. }
  3499. $('#showAttachment').attr('file-id', fid);
  3500. $('#showAttachment').show();
  3501. } else {
  3502. $('#showAttachment').hide();
  3503. $('#showAttachment').attr('file-id', '');
  3504. toastr.error('附件信息获取失败');
  3505. }
  3506. });
  3507. // $('body').on('click', '.alllist-table a', handleFileList);
  3508. $('body').on('click', '#btn-att a', function () {
  3509. const content = $(this).attr('content');
  3510. const fid = $('#showAttachment').attr('file-id');
  3511. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  3512. if (content === 'edit') {
  3513. $('#btn-att a').eq(3).hide();
  3514. $('#btn-att a').eq(2).show();
  3515. $('#btn-att a').eq(4).show();
  3516. $('#btn-att a').eq(5).show();
  3517. $('#show-att').hide();
  3518. $('#edit-att').show();
  3519. const att = attData.find(function (item) {
  3520. return item.id === parseInt(fid);
  3521. });
  3522. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3523. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3524. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3525. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3526. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3527. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3528. } else if (content === 'cancel') {
  3529. $('#show-att').show();
  3530. $('#edit-att').hide();
  3531. $('#btn-att a').eq(3).show();
  3532. $('#btn-att a').eq(2).hide();
  3533. $('#btn-att a').eq(4).hide();
  3534. $('#btn-att a').eq(5).hide();
  3535. } else if (content === 'save') {
  3536. const formData = new FormData();
  3537. formData.append('id', fid);
  3538. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3539. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3540. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3541. const file = $('#change-att-btn')[0];
  3542. if (file.files[0] !== undefined) {
  3543. const filesize = file.files[0].size;
  3544. formData.append('size', filesize);
  3545. formData.append('file', file.files[0]);
  3546. }
  3547. postDataWithFile('/tender/' + tender.id + '/ledger/save/file', formData, function (data) {
  3548. // 替换到attData中
  3549. const att_index = attData.findIndex(function (item) {
  3550. return item.id === parseInt(fid);
  3551. });
  3552. attData.splice(att_index, 1, data);
  3553. // 重新生成List
  3554. getAllList(parseInt($('#currentPage').text()));
  3555. getNodeList(node.id);
  3556. $('#show-att').show();
  3557. $('#edit-att').hide();
  3558. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3559. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3560. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3561. $('#show-att tr').eq(2).children('td').eq(0).text(data.username);
  3562. $('#show-att tr').eq(2).children('td').eq(1).text(data.in_time);
  3563. $('#show-att tr').eq(3).children('td').text(data.remark);
  3564. $('#btn-att a').eq(3).show();
  3565. $('#btn-att a').eq(2).hide();
  3566. $('#btn-att a').eq(4).hide();
  3567. $('#btn-att a').eq(5).hide();
  3568. }, function () {
  3569. toastr.error('附件上传失败');
  3570. });
  3571. $('#change-att-btn').val('');
  3572. } else if (content === 'del') {
  3573. const data = {id: fid};
  3574. postData('/tender/' + tender.id + '/ledger/delete/file', data, function (result) {
  3575. // 删除到attData中
  3576. const att_index = attData.findIndex(function (item) {
  3577. return item.id === parseInt(fid);
  3578. });
  3579. attData.splice(att_index, 1);
  3580. // 重新生成List
  3581. if ($('#alllist-table tr').length === 1) {
  3582. getAllList(parseInt($('#currentPage').text()) - 1);
  3583. } else {
  3584. getAllList(parseInt($('#currentPage').text()));
  3585. }
  3586. getNodeList(node.id);
  3587. $('#showAttachment').hide();
  3588. $('#showAttachment').attr('file-id', '');
  3589. });
  3590. } else if (content === 'view') {
  3591. const data = {id: fid};
  3592. postData('/tender/' + tender.id + '/ledger/check/file', data, function (result) {
  3593. const { filepath } = result
  3594. $('#load-file').attr('href', filepath);
  3595. $('#load-file')[0].click();
  3596. });
  3597. } else if (content === 'location') {
  3598. const att = attData.find(item => item.id === parseInt(fid));
  3599. if (Object.keys(att).length) {
  3600. SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), att.ledger_id, true);
  3601. posOperationObj.loadCurPosData();
  3602. }
  3603. }
  3604. });
  3605. // 替换附件
  3606. $('#change-att-btn').on('change', function () {
  3607. const file = $('#change-att-btn')[0].files[0];
  3608. const name = file.name;
  3609. const filename = name.substring(0, name.lastIndexOf("."));
  3610. const fileext = name.substr(name.indexOf("."));
  3611. const filesize = file.size;
  3612. if (filesize > 30 * 1024 * 1024) {
  3613. toastr.error('文件大小过大!');
  3614. $('#change-att-btn').val('');
  3615. return false;
  3616. }
  3617. if (whiteList && !whiteList.includes(fileext)) {
  3618. toastr.error('只能上传指定格式的附件!');
  3619. $('#change-att-btn').val('');
  3620. return false;
  3621. }
  3622. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3623. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3624. });
  3625. // 切换页数
  3626. $('.page-select').on('click', function () {
  3627. const totalPageNum = parseInt($('#totalPage').text());
  3628. const lastPageNum = parseInt($('#currentPage').text());
  3629. const status = $(this).attr('content');
  3630. if (status === 'pre' && lastPageNum > 1) {
  3631. getAllList(lastPageNum-1);
  3632. $('#showAttachment').hide();
  3633. $('#syfujian .check-all-file').prop('checked', false)
  3634. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3635. getAllList(lastPageNum+1);
  3636. $('#showAttachment').hide();
  3637. $('#syfujian .check-all-file').prop('checked', false)
  3638. }
  3639. });
  3640. // 批量下载
  3641. $('#bach-download').click(function() {
  3642. const fileIds = [];
  3643. const type = $(this).attr('type');
  3644. let node = ''
  3645. if (type === 'curr') {
  3646. node = '#nodelist-table .check-file:checked'
  3647. } else {
  3648. node = '#alllist-table .check-file:checked'
  3649. }
  3650. $(node).each(function() {
  3651. const fileId = $(this).attr('file-id');
  3652. fileId && fileIds.push(fileId);
  3653. });
  3654. if (fileIds.length) {
  3655. if (fileIds.length > 20) {
  3656. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  3657. }
  3658. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  3659. $(this).attr('disabled', "true")
  3660. const btn = $(this);
  3661. const fileArr = [];
  3662. for (const id of fileIds) {
  3663. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  3664. fileArr.push({
  3665. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  3666. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  3667. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  3668. });
  3669. }
  3670. const packageName = `${tender.name}-台账分解-附件.zip`;
  3671. try {
  3672. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  3673. } catch (e) {
  3674. btn.removeAttr('disabled');
  3675. toastr.clear();
  3676. toastr.error('批量下载失败');
  3677. }
  3678. // postCompressFile(`/tender/${tender.id}/ledger/compresse/file`, {fileIds}, function(result) {
  3679. // toastr.clear()
  3680. // toastr.success('压缩文件成功')
  3681. // btn.removeAttr('disabled')
  3682. // const href = window.URL.createObjectURL(result)
  3683. // $('#zipDown').attr('href', href);
  3684. // $('#zipDown').attr('download', `${tender.name}-台账分解-附件.zip`);
  3685. // $("#zipDown")[0].click();
  3686. // }, () => {
  3687. // btn.removeAttr('disabled')
  3688. // toastr.clear()
  3689. // toastr.error('批量下载失败')
  3690. // });
  3691. // const url = `/tender/${tender.id}/ledger/compresse/file?fileIds=${JSON.stringify(fileIds)}`;
  3692. }
  3693. });
  3694. // 监听附件check是否选中
  3695. $('.list-table').on('click', '.check-file', function() {
  3696. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  3697. const childs = $(this).parents('.list-table').children().length;
  3698. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  3699. if (checkedList.length === childs) {
  3700. checkBox.prop("checked", true);
  3701. } else {
  3702. checkBox.prop("checked", false);
  3703. }
  3704. });
  3705. $('.check-all-file').click(function() {
  3706. const isCheck = $(this).is(':checked');
  3707. $(this).parents('table').find('.list-table').each(function() {
  3708. $(this).find('input:checkbox').prop("checked", isCheck);
  3709. })
  3710. });
  3711. });
  3712. // 生成当前节点列表
  3713. function getNodeList(node) {
  3714. let html = '';
  3715. for(const att of attData) {
  3716. if (node === att.lid) {
  3717. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  3718. html += `<tr>
  3719. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  3720. <td>
  3721. <div class="d-flex">
  3722. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  3723. <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>
  3724. </div>
  3725. </td><td>${att.username}</td></tr>`
  3726. }
  3727. }
  3728. $('#nodelist-table').html(html);
  3729. $('#nodelist-table').on('click', 'tr', function() {
  3730. $('#nodelist-table tr').removeClass('bg-light')
  3731. $(this).addClass('bg-light')
  3732. })
  3733. }
  3734. // 生成所有附件列表
  3735. function getAllList(currPageNum = 1) {
  3736. // 每页最多几个附件
  3737. const pageCount = 20;
  3738. // 附件总数
  3739. const total = attData.length;
  3740. // 总页数
  3741. const pageNum = Math.ceil(total/pageCount);
  3742. $('#totalPage').text(pageNum);
  3743. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  3744. // 当前页附件内容
  3745. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  3746. currPageFileData = currPageAttData;
  3747. let html = '';
  3748. for(const att of currPageAttData) {
  3749. html += `<tr>
  3750. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  3751. <td>
  3752. <div class="d-flex">
  3753. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  3754. <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>
  3755. </div>
  3756. </td><td>${att.username}</td></tr>`
  3757. }
  3758. $('#alllist-table').html(html);
  3759. $('#alllist-table').on('click', 'tr', function() {
  3760. $('#alllist-table tr').removeClass('bg-light')
  3761. $(this).addClass('bg-light')
  3762. })
  3763. }
  3764. // 检查上报情况
  3765. function checkAuditorFrom () {
  3766. if ($('#auditors li').length === 0) {
  3767. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  3768. toastr.error('请联系管理员添加审批人');
  3769. } else {
  3770. toastr.error('请先选择审批人,再上报数据');
  3771. }
  3772. return false;
  3773. } else {
  3774. $('#hide-all').show();
  3775. return true;
  3776. }
  3777. }