ledger.js 177 KB

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