ledger.js 126 KB

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