ledger.js 137 KB

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