ledger.js 157 KB

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