revise.js 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. posXmj: ['code'],
  16. };
  17. function transExpr(expr) {
  18. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  19. }
  20. $(document).ready(() => {
  21. let stdXmj, stdGcl, searchLedger;
  22. autoFlashHeight();
  23. // 初始化spread
  24. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  25. const billsSheet = billsSpread.getActiveSheet();
  26. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  27. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  28. const posSheet = posSpread.getActiveSheet();
  29. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  30. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  31. // 初始化 节点树结构
  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. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  40. };
  41. if (!isTz) {
  42. treeSetting.calcFields.push('deal_tp');
  43. }
  44. treeSetting.calcFun = function (node) {
  45. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  46. };
  47. const billsTree = createNewPathTree('revise', treeSetting);
  48. // 初始化 计量单元
  49. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  50. // 清单 相关方法&绑定spreadjs事件
  51. const billsTreeSpreadObj = {
  52. loadExprToInput(sheet) {
  53. const sel = sheet.getSelections()[0];
  54. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  55. if (col && col.type === 'Number') {
  56. const data = SpreadJsObj.getSelectObject(sheet);
  57. if (data) {
  58. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  59. if (col.field.indexOf('dgn') >= 0) {
  60. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  61. } else if (col.field === 'unit_price') {
  62. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true));
  63. } else {
  64. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  65. }
  66. } else {
  67. $('#bills-expr').val('').attr('readOnly', true);
  68. }
  69. } else {
  70. $('#bills-expr').val('').attr('readOnly', true);
  71. }
  72. },
  73. getDefaultSelectInfo: function (sheet) {
  74. const tree = sheet.zh_tree;
  75. if (!tree) return;
  76. const sel = sheet.getSelections()[0];
  77. const node = sheet.zh_tree.nodes[sel.row];
  78. if (!node) return;
  79. let count = 1;
  80. if (sel.rowCount > 1) {
  81. for (let r = 1; r < sel.rowCount; r++) {
  82. const rNode = sheet.zh_tree.nodes[sel.row + r];
  83. if (rNode.level > node.level) continue;
  84. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  85. toastr.warning('请选择同一节点下的节点,进行该操作');
  86. return;
  87. }
  88. count += 1;
  89. }
  90. }
  91. return [tree, node, count];
  92. },
  93. /**
  94. * 刷新顶部按钮是否可用
  95. * @param sheet
  96. * @param selections
  97. */
  98. refreshOperationValid: function (sheet, selection) {
  99. const setObjEnable = function (obj, enable) {
  100. if (enable) {
  101. obj.removeClass('disabled');
  102. } else {
  103. obj.addClass('disabled');
  104. }
  105. };
  106. const invalidAll = function () {
  107. setObjEnable($('a[type=add]'), false);
  108. setObjEnable($('a[type=delete]'), false);
  109. setObjEnable($('a[type=up-move]'), false);
  110. setObjEnable($('a[type=down-move]'), false);
  111. setObjEnable($('a[type=up-level]'), false);
  112. setObjEnable($('a[type=down-level]'), false);
  113. };
  114. const sel = selection ? selection[0] : sheet.getSelections()[0];
  115. const row = sel ? sel.row : -1;
  116. const tree = sheet.zh_tree;
  117. if (!tree) {
  118. invalidAll();
  119. return;
  120. }
  121. const first = sheet.zh_tree.nodes[row];
  122. if (!first) {
  123. invalidAll();
  124. return;
  125. }
  126. let last = first, sameParent = true, nodeUsed = first.used;
  127. if (sel.rowCount > 1 && first) {
  128. for (let r = 1; r < sel.rowCount; r++) {
  129. const rNode = tree.nodes[sel.row + r];
  130. if (!rNode) {
  131. sameParent = false;
  132. break;
  133. }
  134. nodeUsed = nodeUsed || rNode.used;
  135. if (rNode.level > first.level) continue;
  136. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  137. sameParent = false;
  138. break;
  139. }
  140. last = rNode;
  141. }
  142. }
  143. const preNode = tree.getPreSiblingNode(first);
  144. const valid = !sheet.zh_setting.readOnly;
  145. setObjEnable($('a[type=add]'), valid && first && first.level > 1);
  146. setObjEnable($('a[type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed);
  147. setObjEnable($('a[type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
  148. setObjEnable($('a[type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  149. if (isTz) {
  150. const posRange = last ? pos.getLedgerPos(last.id) : [];
  151. setObjEnable($('a[type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  152. && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  153. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  154. setObjEnable($('a[type=down-level]'), valid && first && sameParent && !nodeUsed
  155. && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  156. } else {
  157. setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
  158. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
  159. }
  160. setObjEnable($('#cut'), valid);
  161. setObjEnable($('#paste'), valid);
  162. },
  163. /**
  164. *
  165. * @param sheet
  166. * @param data
  167. */
  168. refreshTree: function (sheet, data) {
  169. SpreadJsObj.massOperationSheet(sheet, function () {
  170. const tree = sheet.zh_tree;
  171. // 处理删除
  172. if (data.delete) {
  173. data.delete.sort(function (a, b) {
  174. return b.deleteIndex - a.deleteIndex;
  175. });
  176. for (const d of data.delete) {
  177. sheet.deleteRows(d.deleteIndex, 1);
  178. }
  179. }
  180. // 处理新增
  181. if (data.create) {
  182. const newNodes = data.create;
  183. if (newNodes) {
  184. newNodes.sort(function (a, b) {
  185. return a.index - b.index;
  186. });
  187. for (const node of newNodes) {
  188. sheet.addRows(node.index, 1);
  189. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  190. }
  191. }
  192. }
  193. // 处理更新
  194. if (data.update) {
  195. const rows = [];
  196. for (const u of data.update) {
  197. rows.push(tree.nodes.indexOf(u));
  198. }
  199. SpreadJsObj.reLoadRowsData(sheet, rows);
  200. }
  201. // 处理展开
  202. if (data.expand) {
  203. const expanded = [];
  204. for (const e of data.expand) {
  205. if (expanded.indexOf(e) === -1) {
  206. const posterity = tree.getPosterity(e);
  207. for (const p of posterity) {
  208. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  209. expanded.push(p);
  210. }
  211. }
  212. }
  213. }
  214. });
  215. },
  216. selectionChanged: function (e, info) {
  217. if (info.newSelections[0].row !== info.oldSelections[0].row) {
  218. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  219. posSpreadObj.loadCurPosData();
  220. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  221. posSearch.search($('#pos-keyword').val());
  222. }
  223. billsTreeSpreadObj.loadExprToInput(info.sheet);
  224. },
  225. /**
  226. * 新增节点
  227. * @param spread
  228. */
  229. baseOpr: function (sheet, type, addCount = 1) {
  230. const self = this;
  231. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  232. if (!tree || !node || !count) return;
  233. if (type === 'delete') {
  234. const parent = tree.getParent(node);
  235. const children = parent ? parent.children : tree.children;
  236. const index = children.indexOf(node);
  237. for (let i = 0; i < count; i++) {
  238. const child = children[i+index];
  239. if (tree.checkNodeUsed(child, pos)) {
  240. toastr.warning('选中的节点已计量,不可删除');
  241. return;
  242. }
  243. }
  244. } else if (type === 'up-level') {
  245. const parent = tree.getParent(node);
  246. const children = parent ? parent.children : tree.children;
  247. const index = children.indexOf(node);
  248. for (let i = index; i < children.length; i++) {
  249. const child = children[index];
  250. if (tree.checkNodeUsed(child, pos)) {
  251. if (i >= index + count) {
  252. toastr.warning('其后节点已计量,选中的节点不可升级');
  253. } else {
  254. toastr.warning('选中的节点已计量,不可升级');
  255. }
  256. return;
  257. }
  258. }
  259. } else if (type === 'down-level') {
  260. const parent = tree.getParent(node);
  261. const children = parent ? parent.children : tree.children;
  262. const index = children.indexOf(node);
  263. for (let i = 0; i < count; i++) {
  264. const child = children[i+index];
  265. if (tree.checkNodeUsed(child, pos)) {
  266. toastr.warning('选中的节点已计量,不可降级');
  267. return;
  268. }
  269. }
  270. }
  271. postData(window.location.pathname + '/update', {
  272. postType: type,
  273. postData: {
  274. id: node.ledger_id,
  275. count: type === 'add' ? addCount : count,
  276. }
  277. }, function (result) {
  278. const refreshData = tree.loadPostData(result);
  279. self.refreshTree(sheet, refreshData);
  280. if (type === 'delete') {
  281. const sel = sheet.getSelections()[0];
  282. if (sel) {
  283. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  284. }
  285. } else if (['up-move', 'down-move'].indexOf(type) > -1) {
  286. const sel = sheet.getSelections()[0];
  287. if (sel) {
  288. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  289. }
  290. } else if (type === 'add') {
  291. const sel = sheet.getSelections()[0];
  292. if (sel) {
  293. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  294. }
  295. }
  296. self.refreshOperationValid(sheet);
  297. });
  298. },
  299. /**
  300. * 编辑单元格响应事件
  301. * @param {Object} e
  302. * @param {Object} info
  303. */
  304. editEnded: function (e, info) {
  305. if (info.sheet.zh_setting) {
  306. const col = info.sheet.zh_setting.cols[info.col];
  307. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  308. const node = sortData[info.row];
  309. const data = {
  310. id: node.id,
  311. tender_id: node.tender_id,
  312. ledger_id: node.ledger_id
  313. };
  314. // 未改变值则不提交
  315. const orgValue = node[col.field];
  316. const newValue = trimInvalidChar(info.editingText);
  317. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  318. return;
  319. }
  320. // 台账模式,检查计量单元相关
  321. if (isTz) {
  322. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  323. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  324. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  325. if (!node.children || node.children.length ===0) {
  326. const lPos = pos.getLedgerPos(node.id);
  327. if (lPos && lPos.length > 0) {
  328. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  329. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  330. return;
  331. }
  332. }
  333. }
  334. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  335. const lPos = pos.getLedgerPos(node.id);
  336. if (lPos && lPos.length > 0) {
  337. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  338. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  339. return;
  340. }
  341. }
  342. }
  343. // 获取更新数据
  344. if (info.editingText) {
  345. const text = newValue;
  346. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  347. toastr.error('节点已计量,请勿删除编号');
  348. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  349. return;
  350. }
  351. if (col.type === 'Number') {
  352. const num = _.toNumber(text);
  353. if (_.isFinite(num)) {
  354. data[col.field] = num;
  355. } else {
  356. try {
  357. data[col.field] = math.evaluate(transExpr(text));
  358. } catch(err) {
  359. toastr.error('输入的表达式非法');
  360. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  361. return;
  362. }
  363. }
  364. } else {
  365. data[col.field] = text;
  366. }
  367. } else {
  368. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  369. toastr.error('节点已计量,请勿删除编号');
  370. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  371. return;
  372. }
  373. data[col.field] = null;
  374. }
  375. // 更新至服务器
  376. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  377. const refreshNode = billsTree.loadPostData(result);
  378. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  379. });
  380. }
  381. },
  382. clipboardPasting: function (e, info) {
  383. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  384. info.cancel = true;
  385. if (!setting || !tree) return;
  386. // const range = info.cellRange;
  387. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  388. // const node = tree.nodes[iRow];
  389. // if (tree.checkNodeUsed(node, pos)) {
  390. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  391. // return;
  392. // }
  393. // }
  394. const pasteData = info.pasteData.html
  395. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  396. : (info.pasteData.text === ''
  397. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  398. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  399. const hint = {
  400. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  401. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  402. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  403. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  404. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  405. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  406. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  407. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  408. };
  409. const datas = [], filterNodes = [];
  410. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  411. const curRow = info.cellRange.row + iRow;
  412. const node = tree.nodes[curRow];
  413. if (!node) continue;
  414. let bPaste = false;
  415. const data = info.sheet.zh_tree.getNodeKeyData(node);
  416. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  417. const curCol = info.cellRange.col + iCol;
  418. const colSetting = info.sheet.zh_setting.cols[curCol];
  419. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  420. toastMessageUniq(hint.parent);
  421. continue;
  422. }
  423. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  424. toastMessageUniq(hint.gcl);
  425. continue;
  426. }
  427. const lPos = pos.getLedgerPos(node.id);
  428. if (lPos && lPos.length > 0) {
  429. if (value === '' && colSetting.field === 'b_code') {
  430. toastMessageUniq(hint.posCode);
  431. continue;
  432. }
  433. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  434. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  435. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  436. toastMessageUniq(hint.posQty);
  437. continue;
  438. }
  439. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  440. toastMessageUniq(hint.posXmj);
  441. continue;
  442. }
  443. }
  444. const value = trimInvalidChar(pasteData[iRow][iCol]);
  445. if (tree.checkNodeUsed(node, pos) && col.field === 'unit_price') {
  446. toastMessageUniq (hint.usedUp);
  447. continue;
  448. }
  449. if (colSetting.type === 'Number') {
  450. const num = _.toNumber(value);
  451. if (num) {
  452. data[colSetting.field] = num;
  453. } else {
  454. try {
  455. data[colSetting.field] = math.evaluate(transExpr(value));
  456. } catch (err) {
  457. toastMessageUniq(hint.invalidExpr);
  458. continue;
  459. }
  460. }
  461. } else {
  462. if (node.used && (col.field === 'code' || col.field ==='b_code')
  463. && data[colSetting.field] !== '' && value === '') {
  464. toastMessageUniq(hint.usedCode);
  465. continue;
  466. }
  467. data[colSetting.field] = value;
  468. }
  469. bPaste = true;
  470. }
  471. if (bPaste) {
  472. datas.push(data);
  473. } else {
  474. filterNodes.push(node);
  475. }
  476. }
  477. if (datas.length > 0) {
  478. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  479. const refreshNode = tree.loadPostData(result);
  480. if (refreshNode.update) {
  481. refreshNode.update = refreshNode.update.concat(filterNodes);
  482. }
  483. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  484. }, function () {
  485. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  486. });
  487. } else {
  488. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  489. }
  490. },
  491. clipboardPasted: function (e, info) {
  492. const hint = {
  493. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  494. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  495. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  496. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  497. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  498. };
  499. const tree = info.sheet.zh_tree;
  500. if (!tree) { return; }
  501. const sortData = info.sheet.zh_tree.nodes;
  502. const datas = [], filterNodes = [];
  503. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  504. let bPaste = false;
  505. const curRow = info.cellRange.row + iRow;
  506. const node = sortData[curRow];
  507. if (node) {
  508. const data = info.sheet.zh_tree.getNodeKeyData(node);
  509. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  510. const curCol = info.cellRange.col + iCol;
  511. const colSetting = info.sheet.zh_setting.cols[curCol];
  512. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  513. const lPos = pos.getLedgerPos(node.id);
  514. if (lPos && lPos.length > 0) {
  515. if (value === '' && colSetting.field === 'b_code') {
  516. toastMessageUniq(hint.posCode);
  517. continue;
  518. }
  519. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  520. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  521. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  522. toastMessageUniq(hint.posQty);
  523. continue;
  524. }
  525. }
  526. if (node.used && col.field === 'unit_price') {
  527. toastMessageUniq (hint.usedUp);
  528. continue;
  529. }
  530. if (colSetting.type === 'Number') {
  531. const num = _.toNumber(value);
  532. if (num) {
  533. data[colSetting.field] = num;
  534. } else {
  535. try {
  536. data[colSetting.field] = math.evaluate(transExpr(value));
  537. } catch (err) {
  538. toastMessageUniq(hint.invalidExpr);
  539. continue;
  540. }
  541. }
  542. } else {
  543. if (node.used && (col.field === 'code' || col.field ==='b_code')
  544. && data[colSetting.field] !== '' && value === '') {
  545. toastMessageUniq(hint.usedCode);
  546. continue;
  547. }
  548. data[colSetting.field] = value;
  549. }
  550. bPaste = true;
  551. }
  552. if (bPaste) {
  553. datas.push(data);
  554. } else {
  555. filterNodes.push(node);
  556. }
  557. }
  558. }
  559. if (datas.length > 0) {
  560. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  561. const refreshNode = tree.loadPostData(result);
  562. if (refreshNode.update) {
  563. refreshNode.update = refreshNode.update.concat(filterNodes);
  564. }
  565. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  566. }, function () {
  567. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  568. });
  569. } else {
  570. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  571. }
  572. },
  573. deletePress: function (sheet) {
  574. if (!sheet.zh_setting) return;
  575. const sel = sheet.getSelections()[0], datas = [];
  576. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  577. const node = sheet.zh_tree.nodes[iRow];
  578. if (sheet.zh_tree.checkNodeUsed(node, pos)) {
  579. toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  580. return;
  581. }
  582. const data = sheet.zh_tree.getNodeKeyData(node);
  583. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  584. const col = sheet.zh_setting.cols[iCol];
  585. data[col.field] = null;
  586. }
  587. datas.push(data);
  588. }
  589. if (datas.length > 0) {
  590. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  591. const refreshNode = sheet.zh_tree.loadPostData(result);
  592. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  593. });
  594. }
  595. },
  596. pasteBlock: function (spread, copyInfo) {
  597. const self = this;
  598. const sheet = spread.getActiveSheet();
  599. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  600. postData(window.location.pathname + '/update', {
  601. postType: 'paste-block',
  602. postData: {
  603. id: tree.getNodeKey(node),
  604. tid: copyInfo.tid,
  605. block: copyInfo.block,
  606. }
  607. }, function (data) {
  608. pos.updateDatas(data.pos);
  609. const result = tree.loadPostData(data.ledger);
  610. self.refreshTree(sheet, result);
  611. const sel = sheet.getSelections()[0];
  612. if (sel) {
  613. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  614. }
  615. self.refreshOperationValid(sheet);
  616. removeLocalCache(copyBlockTag);
  617. }, null, true);
  618. },
  619. topRowChanged: function (e, info) {
  620. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  621. },
  622. editStarting(e, info) {
  623. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  624. const col = info.sheet.zh_setting.cols[info.col];
  625. const node = info.sheet.zh_tree.nodes[info.row];
  626. if (!node) {
  627. info.cancel = true;
  628. return;
  629. }
  630. switch (col.field) {
  631. case 'code':
  632. const posRange = pos.getLedgerPos(node.id);
  633. return posRange && posRange.length > 0;
  634. case 'unit_price':
  635. info.cancel = (node.children && node.children.length > 0) || node.used;
  636. break;
  637. case 'sgfh_qty':
  638. case 'sgfh_tp':
  639. case 'sjcl_qty':
  640. case 'sjcl_tp':
  641. case 'qtcl_qty':
  642. case 'qtcl_tp':
  643. case 'deal_qty':
  644. case 'deal_tp':
  645. info.cancel = (node.children && node.children.length > 0);
  646. break;
  647. case 'dgn_qty1':
  648. case 'dgn_qty2':
  649. info.cancel = !_.isEmpty(node.b_code);
  650. break;
  651. }
  652. },
  653. cut: function (sheet, sel, callback) {
  654. if (!sheet || !sel) return;
  655. if (sel.colCount >= sheet.zh_setting.cols.length) {
  656. toastr.warning('请勿选中整行剪切');
  657. return;
  658. }
  659. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  660. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  661. const node = sortData[iRow];
  662. if (node) {
  663. const data = sheet.zh_tree.getNodeKeyData(node);
  664. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  665. const col = sheet.zh_setting.cols[iCol];
  666. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  667. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  668. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  669. const lPos = pos.getLedgerPos(node.id);
  670. if (lPos && lPos.length > 0) {
  671. toastr.error('不可剪切');
  672. return;
  673. }
  674. }
  675. const style = sheet.getStyle(iRow, iCol);
  676. if (style.locked) {
  677. toastr.error('不可剪切');
  678. return;
  679. }
  680. const colSetting = sheet.zh_setting.cols[iCol];
  681. data[colSetting.field] = null;
  682. }
  683. datas.push(data);
  684. }
  685. }
  686. if (datas.length > 0) {
  687. callback();
  688. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  689. const refreshNode = sheet.zh_tree.loadPostData(result);
  690. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  691. });
  692. }
  693. },
  694. sortCode: function (sheet) {
  695. const tree = sheet.zh_tree;
  696. if (!tree) return;
  697. const select = SpreadJsObj.getSelectObject(sheet);
  698. if (!select || !select.code || select.code === '') return;
  699. const recursiveSortCode = function (data, parentCode, children) {
  700. if (!children || children.length === 0) return;
  701. for (const [i, child] of children.entries()) {
  702. if (!child.b_code || child.b_code === '') {
  703. const code = parentCode + '-' + (i + 1);
  704. const cData = tree.getNodeKeyData(child);
  705. cData.code = code;
  706. data.push(cData);
  707. if (!tree.isLeafXmj(child)) {
  708. recursiveSortCode(data, code, child.children);
  709. }
  710. }
  711. }
  712. };
  713. const data = [];
  714. recursiveSortCode(data, select.code, select.children);
  715. if (data.length > 0) {
  716. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  717. const refreshNode = tree.loadPostData(result);
  718. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  719. })
  720. }
  721. }
  722. };
  723. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  724. billsTreeSpreadObj.loadExprToInput(billsSheet);
  725. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  726. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  727. if (!readOnly) {
  728. // 增删上下移升降级
  729. $('a[name="base-opr"]').click(function () {
  730. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  731. });
  732. $('a[name=cpc]').click(function () {
  733. billsSpread.commandManager().execute({
  734. cmd: this.getAttribute('type'),
  735. sheetName: billsSheet.name()
  736. });
  737. });
  738. $('#bills-expr').bind('change mouseleave', function () {
  739. if (this.readOnly) return;
  740. const expr = $(this);
  741. const select = SpreadJsObj.getSelectObject(billsSheet);
  742. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  743. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  744. const data = {
  745. id: select.id,
  746. tender_id: select.tender_id,
  747. ledger_id: select.ledger_id
  748. };
  749. if (newValue !== '') {
  750. const num = _.toNumber(newValue);
  751. if (num) {
  752. data[field] = num;
  753. } else {
  754. try {
  755. data[field] = math.evaluate(transExpr(newValue));
  756. } catch (err) {
  757. toastr.error('输入的表达式非法');
  758. return;
  759. }
  760. }
  761. } else {
  762. data[field] = null;
  763. }
  764. // 更新至服务器
  765. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  766. const refreshNode = billsTree.loadPostData(result);
  767. expr.val(select[field]);
  768. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  769. });
  770. });
  771. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  772. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  773. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  774. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  775. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  776. SpreadJsObj.Clipboard.setCopyData(copyText);
  777. });
  778. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  779. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  780. let batchInsertObj;
  781. $.contextMenu.types.batchInsert = function (item, opt, root) {
  782. const self = this;
  783. if ($.isFunction(item.icon)) {
  784. item._icon = item.icon.call(this, this, $t, key, item);
  785. } else {
  786. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  787. // to enable font awesome
  788. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  789. } else {
  790. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  791. }
  792. }
  793. this.addClass(item._icon);
  794. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  795. .appendTo(this);
  796. const $input = $obj.find('input');
  797. const event = () => {
  798. if (self.hasClass('context-menu-disabled')) return;
  799. item.batchInsert($input[0], root);
  800. };
  801. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  802. $input.click((e) => {e.stopPropagation();})
  803. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  804. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  805. };
  806. // 右键菜单
  807. $.contextMenu({
  808. selector: '#bills-spread',
  809. build: function ($trigger, e) {
  810. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  811. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  812. },
  813. items: {
  814. 'create': {
  815. name: '新增',
  816. icon: 'fa-sign-in',
  817. callback: function (key, opt) {
  818. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  819. },
  820. disabled: function (key, opt) {
  821. const sheet = billsSheet;
  822. const selection = sheet.getSelections();
  823. const sel = selection ? selection[0] : sheet.getSelections()[0];
  824. const row = sel ? sel.row : -1;
  825. const tree = sheet.zh_tree;
  826. if (!tree) return true;
  827. const first = sheet.zh_tree.nodes[row];
  828. const valid = !sheet.zh_setting.readOnly;
  829. return !(valid && first && first.level > 1);
  830. }
  831. },
  832. 'delete': {
  833. name: '删除',
  834. icon: 'fa-remove',
  835. callback: function (key, opt) {
  836. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  837. },
  838. disabled: function (key, opt) {
  839. const sheet = billsSheet;
  840. const selection = sheet.getSelections();
  841. const sel = selection ? selection[0] : sheet.getSelections()[0];
  842. const row = sel ? sel.row : -1;
  843. const tree = sheet.zh_tree;
  844. if (!tree) return true;
  845. const first = sheet.zh_tree.nodes[row];
  846. let last = first, sameParent = true, nodeUsed = first.used;
  847. if (sel.rowCount > 1 && first) {
  848. for (let r = 1; r < sel.rowCount; r++) {
  849. const rNode = tree.nodes[sel.row + r];
  850. if (!rNode) {
  851. sameParent = false;
  852. break;
  853. }
  854. nodeUsed = nodeUsed || rNode.used;
  855. if (rNode.level > first.level) continue;
  856. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  857. sameParent = false;
  858. break;
  859. }
  860. last = rNode;
  861. }
  862. }
  863. const valid = !sheet.zh_setting.readOnly;
  864. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  865. }
  866. },
  867. 'sprBase': '-----------',
  868. 'batchInsert': {
  869. name: '批量插入',
  870. type: 'batchInsert',
  871. value: '2',
  872. icon: 'fa-sign-in',
  873. batchInsert: function (obj, root) {
  874. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  875. obj.value = obj.max;
  876. toastr.warning('批量插入不可多于' + obj.max);
  877. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  878. obj.value = obj.min;
  879. toastr.warning('批量插入不可少于' + obj.min);
  880. } else {
  881. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  882. root.$menu.trigger('contextmenu:hide');
  883. }
  884. },
  885. disabled: function (key, opt) {
  886. const sheet = billsSheet;
  887. const selection = sheet.getSelections();
  888. const sel = selection ? selection[0] : sheet.getSelections()[0];
  889. const row = sel ? sel.row : -1;
  890. const tree = sheet.zh_tree;
  891. if (!tree) return true;
  892. const first = sheet.zh_tree.nodes[row];
  893. const valid = !sheet.zh_setting.readOnly;
  894. return !(valid && first && first.level > 1);
  895. }
  896. },
  897. 'batchInsertBillsPos': {
  898. name: '批量插入清单-计量单元',
  899. icon: 'fa-sign-in',
  900. disabled: function (key, opt) {
  901. if (!isTz) return true;
  902. const select = SpreadJsObj.getSelectObject(billsSheet);
  903. if (select) {
  904. if (select.code && select.code !== '') {
  905. return !billsTree.isLeafXmj(select);
  906. } else {
  907. const parent = billsTree.getParent(select);
  908. return !(parent && billsTree.isLeafXmj(parent));
  909. }
  910. } else {
  911. return false;
  912. }
  913. },
  914. callback: function (key, opt) {
  915. if (!batchInsertObj) {
  916. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  917. } else {
  918. batchInsertObj.initView();
  919. }
  920. $('#batch').modal('show');
  921. }
  922. },
  923. 'sprBatch': '-----------',
  924. 'importGclBills2Xmj': {
  925. name: '导入工程量清单至项目节',
  926. icon: 'fa-file-excel-o',
  927. disabled: function (key, opt) {
  928. const node = SpreadJsObj.getSelectObject(billsSheet);
  929. return readOnly
  930. || (node.children && node.children.length > 0)
  931. || (!_.isNil(node.b_code) && node.b_code !== '')
  932. || billsTree.checkNodeUsed(node, pos);
  933. },
  934. callback: function (key, opt) {
  935. const node = SpreadJsObj.getSelectObject(billsSheet);
  936. importExcel.doImport({
  937. template: {
  938. hint: '工程量清单',
  939. url: '/template/导入工程量清单EXCEL格式.xls',
  940. },
  941. callback: function (sheet) {
  942. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  943. const sel = billsSheet.getSelections();
  944. const refreshNode = billsTree.loadPostData(result);
  945. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  946. if (refreshNode.create[0]) {
  947. if (sel && sel[0]) {
  948. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  949. } else {
  950. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  951. }
  952. }
  953. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  954. }, null);
  955. }
  956. });
  957. }
  958. },
  959. }
  960. });
  961. }
  962. // 计量单元 相关方法&绑定spreadjs事件
  963. const posSpreadObj = {
  964. /**
  965. * 加载计量单元 根据当前台账选择节点
  966. */
  967. loadCurPosData: function () {
  968. const node = SpreadJsObj.getSelectObject(billsSheet);
  969. if (node) {
  970. const posData = pos.getLedgerPos(node.id) || [];
  971. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  972. } else {
  973. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  974. }
  975. SpreadJsObj.resetFieldReadOnly(posSheet);
  976. },
  977. editStarting: function (e, info) {
  978. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  979. },
  980. /**
  981. * 编辑单元格响应事件
  982. * @param {Object} e
  983. * @param {Object} info
  984. */
  985. editEnded: function (e, info) {
  986. if (!info.sheet.zh_setting) {
  987. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  988. return;
  989. }
  990. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  991. const col = info.sheet.zh_setting.cols[info.col];
  992. const orgText = posData ? posData[col.field] : null;
  993. const newText = trimInvalidChar(info.editingText);
  994. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  995. const node = posSpreadObj.billsNode;
  996. if (!node) {
  997. toastr.error('数据错误,请选择台账节点后再试');
  998. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  999. return;
  1000. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1001. toastr.error('父节点不可插入计量单元');
  1002. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1003. return;
  1004. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1005. toastr.error('项目节不可插入计量单元');
  1006. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1007. return;
  1008. }
  1009. const data = {postType: 'pos'};
  1010. if (col.field === 'name') {
  1011. if (newText === '' && posData) {
  1012. toastr.error('部位名称不可为空', 'error');
  1013. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1014. return;
  1015. } else if (!posData) {
  1016. if (newText && newText !== '') {
  1017. data.posPostType = 'add';
  1018. const sortData = info.sheet.zh_data;
  1019. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1020. data.postData = { name: newText, lid: node.id, porder: order};
  1021. } else {
  1022. return;
  1023. }
  1024. } else {
  1025. data.posPostType = 'update';
  1026. data.postData = {id: posData.id, name: newText};
  1027. }
  1028. } else if (!posData) {
  1029. toastr.warning('新增计量单元请先输入名称');
  1030. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1031. return;
  1032. } else {
  1033. data.posPostType = 'update';
  1034. data.postData = {id: posData.id};
  1035. if (col.type === 'Number') {
  1036. const num = _.toNumber(newText);
  1037. if (_.isFinite(num)) {
  1038. data.postData[col.field] = num;
  1039. } else {
  1040. try {
  1041. data.postData[col.field] = math.evaluate(transExpr(newText));
  1042. } catch(err) {
  1043. toastr.error('输入的表达式非法');
  1044. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1045. return;
  1046. }
  1047. }
  1048. } else {
  1049. data.postData[col.field] = newText;
  1050. }
  1051. }
  1052. postData(window.location.pathname + '/update', data, function (result) {
  1053. const updateRst = pos.updateDatas(result.pos);
  1054. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1055. if (updateRst.create.length > 0) {
  1056. posSpreadObj.loadCurPosData();
  1057. } else {
  1058. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1059. }
  1060. const loadResult = billsTree.loadPostData(result.ledger);
  1061. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1062. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1063. }, function () {
  1064. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1065. });
  1066. },
  1067. /**
  1068. * 删除按钮响应事件
  1069. * @param sheet
  1070. */
  1071. deletePress: function (sheet) {
  1072. if (!sheet.zh_settting) return;
  1073. const sortData = sheet.zh_data;
  1074. const datas = [], posSelects = [];
  1075. const sel = sheet.getSelections()[0];
  1076. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1077. let bDel = false;
  1078. const node = sortData[iRow];
  1079. if (node) {
  1080. const data = {id: node.id};
  1081. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1082. const colSetting = sheet.zh_setting.cols[iCol];
  1083. if (colSetting.field === 'name') {
  1084. toastr.error('部位名称不能为空');
  1085. return;
  1086. }
  1087. const style = sheet.getStyle(iRow, iCol);
  1088. if (!style.locked) {
  1089. const colSetting = sheet.zh_setting.cols[iCol];
  1090. data[colSetting.field] = null;
  1091. bDel = true;
  1092. }
  1093. }
  1094. if (bDel) {
  1095. datas.push(data);
  1096. posSelects.push(node);
  1097. }
  1098. }
  1099. }
  1100. if (datas.length > 0) {
  1101. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1102. pos.updateDatas(result.pos);
  1103. posSpreadObj.loadCurPosData();
  1104. const loadResult = billsTree.loadPostData(result.ledger);
  1105. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1106. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1107. }, function () {
  1108. posSpreadObj.loadCurPosData();
  1109. });
  1110. }
  1111. },
  1112. /**
  1113. * 删除 计量单元
  1114. * @param sheet
  1115. */
  1116. deletePos: function (sheet) {
  1117. const selection = sheet.getSelections();
  1118. const data = {
  1119. postType: 'pos',
  1120. posPostType: 'delete',
  1121. postData: [],
  1122. };
  1123. const row = selection[0].row, count = selection[0].rowCount;
  1124. const sortData = sheet.zh_data;
  1125. for (let iRow = 0; iRow < count; iRow++) {
  1126. const posData = sortData[iRow + row];
  1127. if (posData) {
  1128. if (posData.used) {
  1129. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1130. return;
  1131. }
  1132. data.postData.push(sortData[iRow + row].id);
  1133. }
  1134. }
  1135. if (data.postData.length > 0) {
  1136. postData(window.location.pathname + '/update', data, function (result) {
  1137. pos.removeDatas(result.pos);
  1138. sheet.deleteRows(row, count);
  1139. const loadResult = billsTree.loadPostData(result.ledger);
  1140. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1141. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1142. });
  1143. }
  1144. },
  1145. clipboardPasting: function (e, info) {
  1146. if (!info.sheet.zh_setting) {
  1147. info.cancel = true;
  1148. return;
  1149. }
  1150. const range = info.cellRange;
  1151. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1152. const posData = info.sheet.zh_data[iRow];
  1153. if (posData && posData.used) {
  1154. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  1155. info.cancel = true;
  1156. return;
  1157. }
  1158. }
  1159. },
  1160. /**
  1161. * 粘贴单元格响应事件
  1162. * @param e
  1163. * @param info
  1164. */
  1165. clipboardPasted: function (e, info) {
  1166. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1167. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1168. }
  1169. const node = SpreadJsObj.getSelectObject(billsSheet);
  1170. if (node.code && (node.code !== '')) {
  1171. toastr.error('项目节不可含有节点明细');
  1172. posSpreadObj.loadCurPosData();
  1173. return;
  1174. }
  1175. if (node.children && (node.children.length > 0)) {
  1176. toastr.error('仅节点子项可以含有计量单元');
  1177. posSpreadObj.loadCurPosData();
  1178. return;
  1179. }
  1180. if (!info.sheet.zh_setting) {
  1181. posSpreadObj.loadCurPosData();
  1182. return;
  1183. }
  1184. const data = [];
  1185. const sortData = info.sheet.zh_data || [];
  1186. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1187. if (info.cellRange.col !== 0) {
  1188. toastr.warning('新增计量单元请先输入名称');
  1189. posSpreadObj.loadCurPosData();
  1190. return;
  1191. }
  1192. }
  1193. let bHint = false;
  1194. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1195. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1196. let bPaste = true;
  1197. const curRow = info.cellRange.row + iRow;
  1198. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1199. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1200. const curCol = info.cellRange.col + iCol;
  1201. const colSetting = info.sheet.zh_setting.cols[curCol];
  1202. if (!colSetting) continue;
  1203. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1204. if (colSetting.type === 'Number') {
  1205. const num = _.toNumber(posData[colSetting.field]);
  1206. if (num) {
  1207. posData[colSetting.field] = num;
  1208. } else {
  1209. try {
  1210. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1211. } catch (err) {
  1212. if (!bHint) {
  1213. toastr.warning('粘贴了非法表达式,已过滤');
  1214. bHint = true;
  1215. }
  1216. bPaste = false;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. if (bPaste) {
  1222. data.push(posData);
  1223. }
  1224. }
  1225. if (data.length === 0) {
  1226. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1227. return;
  1228. }
  1229. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1230. pos.updateDatas(result.pos);
  1231. posSpreadObj.loadCurPosData();
  1232. const loadResult = billsTree.loadPostData(result.ledger);
  1233. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1234. posSpreadObj.loadCurPosData();
  1235. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1236. }, function () {
  1237. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1238. });
  1239. },
  1240. selectionChanged: function (e, info) {
  1241. const col = info.sheet.zh_setting.cols[info.newSelections[0].col];
  1242. const cell = info.sheet.getCell(info.newSelections[0].col, info.newSelections[0].col);
  1243. if (col && col.type === 'Number') {
  1244. const data = SpreadJsObj.getSelectObject(info.sheet);
  1245. if (data) {
  1246. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  1247. .attr('row', info.newSelections[0].row).attr('readOnly', readOnly || cell.locked());
  1248. } else {
  1249. $('#pos-expr').val('').attr('readOnly', true);
  1250. }
  1251. } else {
  1252. $('#pos-expr').val('').attr('readOnly', true);
  1253. }
  1254. },
  1255. addPegs: function (pegs) {
  1256. if (!pegs || pegs.length <= 0) return;
  1257. const node = SpreadJsObj.getSelectObject(billsSheet);
  1258. if (!node) return;
  1259. const sheet = posSpread.getActiveSheet();
  1260. const sortData = sheet.zh_data || [];
  1261. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1262. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1263. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1264. pos.updateDatas(result.pos);
  1265. posSpreadObj.loadCurPosData();
  1266. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1267. });
  1268. }
  1269. };
  1270. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1271. if (!readOnly && isTz) {
  1272. $('#pos-expr').bind('change mouseleave', function () {
  1273. if (this.readOnly) return;
  1274. const expr = $(this);
  1275. const select = SpreadJsObj.getSelectObject(posSheet);
  1276. const row = posSheet.getSelections()[0].row;
  1277. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1278. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1279. const data = {id: select.id};
  1280. if (newValue !== '') {
  1281. const num = _.toNumber(newValue);
  1282. if (num) {
  1283. data[field] = num;
  1284. } else {
  1285. try {
  1286. data[field] = math.evaluate(transExpr(newValue));
  1287. } catch (err) {
  1288. toastr.error('输入的表达式非法');
  1289. return;
  1290. }
  1291. }
  1292. } else {
  1293. data[field] = null;
  1294. }
  1295. // 更新至服务器
  1296. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1297. const updateRst = pos.updateDatas(result.pos);
  1298. expr.val(select[field]);
  1299. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1300. SpreadJsObj.reLoadRowData(posSheet, row);
  1301. const loadResult = billsTree.loadPostData(result.ledger);
  1302. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1303. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1304. });
  1305. });
  1306. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1307. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1308. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  1309. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1310. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1311. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1312. $.contextMenu({
  1313. selector: '#pos-spread',
  1314. build: function ($trigger, e) {
  1315. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1316. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1317. },
  1318. items: {
  1319. 'delete': {
  1320. name: '删除',
  1321. icon: 'fa-remove',
  1322. disabled: function (key, opt) {
  1323. if (posSheet.zh_data) {
  1324. const selection = posSheet.getSelections();
  1325. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1326. } else {
  1327. return true;
  1328. }
  1329. },
  1330. callback: function (key, opt) {
  1331. posSpreadObj.deletePos(posSheet);
  1332. }
  1333. },
  1334. 'merge-peg': {
  1335. name: '合并起讫桩号',
  1336. disabled: function (key, opt) {
  1337. const node = SpreadJsObj.getSelectObject(billsSheet);
  1338. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1339. },
  1340. callback: function (key, opt) {
  1341. mergePeg.show();
  1342. },
  1343. visible: function (key, opt) {
  1344. return isTz;
  1345. }
  1346. }
  1347. }
  1348. });
  1349. }
  1350. // 加载清单&计量单元数据
  1351. postData(window.location.pathname + '/load', {}, function (result) {
  1352. billsTree.loadDatas(result.bills);
  1353. treeCalc.calculateAll(billsTree);
  1354. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  1355. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  1356. pos.loadDatas(result.pos);
  1357. posSpreadObj.loadCurPosData();
  1358. SpreadJsObj.resetTopAndSelect(posSheet);
  1359. }, null);
  1360. $.divResizer({
  1361. select: '#revise-resize',
  1362. callback: function () {
  1363. billsSpread.refresh();
  1364. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1365. $(".sp-wrap").height(bcontent-30);
  1366. posSpread.refresh();
  1367. }
  1368. });
  1369. class DealBills {
  1370. constructor (selector, spreadSetting) {
  1371. const self = this;
  1372. this.loaded = false;
  1373. this.obj = $(selector)[0];
  1374. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1375. this.spreadSetting = spreadSetting;
  1376. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1377. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1378. if (!readOnly) {
  1379. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1380. const dealSheet = info.sheet;
  1381. const mainSheet = billsSheet;
  1382. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1383. if (!dealBills) { return; }
  1384. const mainTree = mainSheet.zh_tree;
  1385. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1386. if (!mainNode || !mainTree) { return; }
  1387. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1388. toastr.warning('非最底层项目下,不应添加节点');
  1389. return;
  1390. }
  1391. postData(window.location.pathname + '/update', {
  1392. postType: 'add-deal',
  1393. postData: {
  1394. id: mainNode.ledger_id,
  1395. type: mainNode.code ? 'child' : 'next',
  1396. dealBills: {
  1397. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1398. unit_price: dealBills.unit_price,
  1399. }
  1400. },
  1401. }, function (result) {
  1402. const refreshData = mainTree.loadPostData(result);
  1403. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1404. const sel = mainSheet.getSelections()[0];
  1405. if (sel && refreshData.create[0]) {
  1406. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1407. }
  1408. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1409. billsSpread.focus();
  1410. posSpreadObj.loadCurPosData();
  1411. });
  1412. });
  1413. }
  1414. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1415. }
  1416. loadData (callback) {
  1417. if (this.loaded) {
  1418. if (callback) callback();
  1419. return;
  1420. }
  1421. const self = this;
  1422. postData(this.url+'/get-data', {}, function (data) {
  1423. self.data = data;
  1424. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1425. self.loaded = true;
  1426. if (callback) callback();
  1427. });
  1428. }
  1429. calculateData () {
  1430. if (this.data) {
  1431. for (const d of this.data) {
  1432. d.total_price = _.multiply(d.quantity, d.unit_price);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. class BgBills {
  1438. constructor (selector, spreadSetting) {
  1439. this.loaded = false;
  1440. this.obj = $(selector)[0];
  1441. this.spreadSetting = spreadSetting;
  1442. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1443. this.sheet = this.spread.getActiveSheet();
  1444. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1445. if (!readOnly) {
  1446. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1447. const dealSheet = info.sheet;
  1448. const mainSheet = billsSheet;
  1449. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1450. if (!bgBills) { return; }
  1451. const mainTree = mainSheet.zh_tree;
  1452. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1453. if (!mainNode || !mainTree) { return; }
  1454. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1455. toastr.warning('非最底层项目下,不应添加变更清单');
  1456. return;
  1457. }
  1458. postData(window.location.pathname + '/update', {
  1459. postType: 'add-bg',
  1460. postData: {
  1461. id: mainNode.ledger_id,
  1462. type: mainNode.code ? 'child' : 'next',
  1463. dealBills: {
  1464. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1465. unit_price: bgBills.unit_price,
  1466. }
  1467. },
  1468. }, function (result) {
  1469. const refreshData = mainTree.loadPostData(result);
  1470. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1471. const sel = mainSheet.getSelections()[0];
  1472. if (sel && refreshData.create[0]) {
  1473. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1474. }
  1475. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1476. billsSpread.focus();
  1477. posSpreadObj.loadCurPosData();
  1478. });
  1479. });
  1480. }
  1481. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1482. }
  1483. loadData () {
  1484. if (this.loaded) return;
  1485. const self = this;
  1486. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1487. self.data = data;
  1488. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1489. self.loaded = true;
  1490. });
  1491. }
  1492. }
  1493. class BatchInsertBillsPosObj {
  1494. constructor (obj) {
  1495. const self = this;
  1496. this.obj = obj;
  1497. this.billsCount = 6;
  1498. this.posCount = 1000;
  1499. // 初始化 清单编号窗口 参数
  1500. this.qdSpreadSetting = {
  1501. cols: [
  1502. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1503. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1504. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1505. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1506. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1507. ],
  1508. emptyRows: this.billsCount,
  1509. headRows: 1,
  1510. headRowHeight: [32],
  1511. headerFont: '12px 微软雅黑',
  1512. font: '12px 微软雅黑',
  1513. };
  1514. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1515. // 初始化 部位数量复核表 参数
  1516. this.posSpreadSetting = {
  1517. cols: [
  1518. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1519. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1520. ],
  1521. emptyRows: this.posCount,
  1522. headRows: 1,
  1523. headRowHeight: [32],
  1524. headerFont: '12px 微软雅黑',
  1525. font: '12px 微软雅黑',
  1526. };
  1527. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1528. this.posSpreadSetting.cols.push(
  1529. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1530. )
  1531. }
  1532. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1533. // 初始化 签约节点 参数
  1534. this.dealSpreadSetting = {
  1535. cols: [
  1536. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  1537. {title: '名称', field: 'name', width: 120, hAlign: 0, formatter: '@', readOnly: true},
  1538. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1539. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1540. ],
  1541. emptyRows: 0,
  1542. headRows: 1,
  1543. headRowHeight: [32],
  1544. headerFont: '12px 微软雅黑',
  1545. font: '12px 微软雅黑',
  1546. };
  1547. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1548. // 初始化 清单编号、部位数量复核表 表格
  1549. this.initView();
  1550. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1551. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1552. // 拉取签约节点数据
  1553. dealBills.loadData(() => {
  1554. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1555. });
  1556. // 双击签约节点,自动添加到清单编号窗口
  1557. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1558. const deal = info.sheet.zh_data[info.row];
  1559. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1560. const sel = qdSheet.getSelections()[0];
  1561. qdSheet.getCell(sel.row, 0).value(deal.code);
  1562. qdSheet.getCell(sel.row, 1).value(deal.name);
  1563. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1564. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1565. if (sel.row + 1 === qdSheet.getRowCount()) {
  1566. const count = sel.row + 2;
  1567. qdSheet.setRowCount(count);
  1568. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1569. const colCount = posSheet.getColumnCount() + 1;
  1570. posSheet.setColumnCount(colCount);
  1571. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  1572. }
  1573. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1574. qdSheet.getParent().focus();
  1575. });
  1576. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1577. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  1578. const count = posSheet.getColumnCount() - 2;
  1579. if (billsCount > count) {
  1580. posSheet.setColumnCount(billsCount + 2);
  1581. for (let i = count + 1; i <= billsCount; i++) {
  1582. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1583. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1584. }
  1585. }
  1586. });
  1587. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  1588. if (info.col === 0) {
  1589. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1590. if (dealBills && dealBills.length > 0) {
  1591. const bills = _.find(dealBills, {code: info.editingText});
  1592. if (bills) {
  1593. info.sheet.getCell(info.row, 1).value(bills.name);
  1594. info.sheet.getCell(info.row, 2).value(bills.unit);
  1595. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  1596. }
  1597. }
  1598. }
  1599. });
  1600. this.obj.bind('shown.bs.modal', function () {
  1601. self.qdSpread.refresh();
  1602. self.posSpread.refresh();
  1603. self.dealSpread.refresh();
  1604. });
  1605. $('#batch-ok').click(function () {
  1606. const selection = billsSheet.getSelections();
  1607. const row = selection[0].row;
  1608. const select = billsTree.nodes[row];
  1609. if (select) {
  1610. const insertData = {};
  1611. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1612. insertData.id = select[billsTree.setting.id];
  1613. insertData.batchData = self.getBatchData();
  1614. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1615. pos.updateDatas(data.pos);
  1616. const result = billsTree.loadPostData(data.ledger);
  1617. billsTreeSpreadObj.refreshTree(billsSheet, result);
  1618. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  1619. self.obj.modal('hide');
  1620. }, null, true);
  1621. }
  1622. });
  1623. $.contextMenu({
  1624. selector: '.batch-l-t',
  1625. build: function ($trigger, e) {
  1626. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  1627. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1628. },
  1629. items: {
  1630. 'create': {
  1631. name: '新增行',
  1632. icon: 'fa-sign-in',
  1633. callback: function (key, opt) {
  1634. const qdSheet = self.qdSpread.getActiveSheet();
  1635. const posSheet = self.posSpread.getActiveSheet();
  1636. qdSheet.addRows(qdSheet.getRowCount(), 1);
  1637. const index = qdSheet.getRowCount();
  1638. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  1639. posSheet.addColumns(posSheet.getColumnCount(), 1);
  1640. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  1641. },
  1642. },
  1643. 'delete': {
  1644. name: '删除行',
  1645. icon: 'fa-remove',
  1646. callback: function (key, opt) {
  1647. const qdSheet = self.qdSpread.getActiveSheet();
  1648. const posSheet = self.posSpread.getActiveSheet();
  1649. const sel = qdSheet.getSelections()[0];
  1650. qdSheet.deleteRows(sel.row, sel.rowCount);
  1651. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  1652. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  1653. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  1654. }
  1655. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  1656. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  1657. }
  1658. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  1659. },
  1660. },
  1661. }
  1662. });
  1663. }
  1664. // 初始化左侧表格
  1665. initView () {
  1666. // 初始化 清单编号
  1667. const qdSheet = this.qdSpread.getActiveSheet();
  1668. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1669. SpreadJsObj.refreshColumnAlign(qdSheet);
  1670. // 清理原有数据
  1671. SpreadJsObj.beginMassOperation(qdSheet);
  1672. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1673. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1674. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1675. }
  1676. qdSheet.setSelection(0, 0, 1 ,1);
  1677. SpreadJsObj.endMassOperation(qdSheet);
  1678. // 初始化 部位数量复核表
  1679. const posSheet = this.posSpread.getActiveSheet();
  1680. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1681. SpreadJsObj.refreshColumnAlign(posSheet);
  1682. // 清理原有数据
  1683. SpreadJsObj.beginMassOperation(posSheet);
  1684. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1685. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1686. posSheet.setSelection(0, 0, 1 ,1);
  1687. SpreadJsObj.endMassOperation(posSheet);
  1688. // 检查签约节点数据,以工具栏数据为准
  1689. if (dealBills) {
  1690. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1691. }
  1692. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1693. }
  1694. // 获取界面数据
  1695. getBatchData () {
  1696. const result = [];
  1697. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1698. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1699. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1700. const qd = {
  1701. b_code: qdSheet.getText(iRow, 0),
  1702. name: qdSheet.getText(iRow, 1),
  1703. unit: qdSheet.getText(iRow, 2),
  1704. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1705. pos: [],
  1706. };
  1707. result.push(qd);
  1708. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1709. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1710. if (value !== 0 && !isNaN(value)) {
  1711. qd.pos.push({
  1712. name: posSheet.getText(iPosRow, 0),
  1713. drawing_code: posSheet.getText(iPosRow, 1),
  1714. quantity: value,
  1715. });
  1716. }
  1717. }
  1718. }
  1719. return result;
  1720. }
  1721. }
  1722. const dealBills = new DealBills('#deal-bills-spread', {
  1723. cols: [
  1724. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1725. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1726. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1727. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1728. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1729. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1730. ],
  1731. emptyRows: 0,
  1732. headRows: 1,
  1733. headRowHeight: [32],
  1734. defaultRowHeight: 21,
  1735. headerFont: '12px 微软雅黑',
  1736. font: '12px 微软雅黑',
  1737. });
  1738. const bgBills = new BgBills('#bg-bills-spread', {
  1739. cols: [
  1740. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1741. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1742. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1743. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1744. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1745. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1746. ],
  1747. emptyRows: 0,
  1748. headRows: 1,
  1749. headRowHeight: [32],
  1750. defaultRowHeight: 21,
  1751. headerFont: '12px 微软雅黑',
  1752. font: '12px 微软雅黑',
  1753. });
  1754. $.divResizer({
  1755. select: '#revise-right-spr',
  1756. callback: function () {
  1757. billsSpread.refresh();
  1758. if (posSpread) {
  1759. posSpread.refresh();
  1760. }
  1761. if (stdXmj) {
  1762. stdXmj.spread.refresh();
  1763. }
  1764. if (stdGcl) {
  1765. stdGcl.spread.refresh();
  1766. }
  1767. if (dealBills) {
  1768. dealBills.spread.refresh();
  1769. }
  1770. if (bgBills) {
  1771. bgBills.spread.refresh();
  1772. }
  1773. if (searchLedger) {
  1774. searchLedger.spread.refresh();
  1775. }
  1776. }
  1777. });
  1778. $.subMenu({
  1779. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1780. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1781. key: 'menu.1.0.0',
  1782. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1783. callback: function (info) {
  1784. if (info.mini) {
  1785. $('.panel-title').addClass('fluid');
  1786. $('#sub-menu').removeClass('panel-sidebar');
  1787. } else {
  1788. $('.panel-title').removeClass('fluid');
  1789. $('#sub-menu').addClass('panel-sidebar');
  1790. }
  1791. autoFlashHeight();
  1792. billsSpread.refresh();
  1793. if (posSpread) {
  1794. posSpread.refresh();
  1795. }
  1796. if (stdXmj) {
  1797. stdXmj.spread.refresh();
  1798. }
  1799. if (stdGcl) {
  1800. stdGcl.spread.refresh();
  1801. }
  1802. if (dealBills) {
  1803. dealBills.spread.refresh();
  1804. }
  1805. if (bgBills) {
  1806. bgBills.spread.refresh();
  1807. }
  1808. if (searchLedger) {
  1809. searchLedger.spread.refresh();
  1810. }
  1811. }
  1812. });
  1813. const showSideTools = function (show) {
  1814. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1815. if (show) {
  1816. right.show();
  1817. autoFlashHeight();
  1818. /**
  1819. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1820. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1821. * 故需要通过最终的parent.width再计算一次left.width
  1822. *
  1823. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1824. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1825. *
  1826. */
  1827. //left.css('width', parent.width() - right.outerWidth());
  1828. //left.css('width', parent.width() - right.outerWidth());
  1829. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1830. left.css('width', percent + '%');
  1831. } else {
  1832. left.width(parent.width());
  1833. right.hide();
  1834. }
  1835. };
  1836. $('#content-tab').addClass('active');
  1837. $('#xd-content').addClass('active');
  1838. showSideTools(true);
  1839. billsSpread.refresh();
  1840. if (posSpread) {
  1841. posSpread.refresh();
  1842. }
  1843. const stdLibCellDoubleClick = function (e, info) {
  1844. const stdSheet = info.sheet;
  1845. const mainSheet = billsSheet;
  1846. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1847. const stdTree = stdSheet.zh_tree;
  1848. const stdNode = stdTree.nodes[info.row];
  1849. const mainTree = mainSheet.zh_tree;
  1850. const sel = mainSheet.getSelections()[0];
  1851. const mainNode = mainTree.nodes[sel.row];
  1852. if (!stdNode) return;
  1853. if (info.sheet.zh_setting.stdType === 'gcl') {
  1854. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1855. toastr.warning('非最底层项目下,不应添加节点');
  1856. return;
  1857. }
  1858. }
  1859. postData(window.location.pathname + '/update', {
  1860. postType: 'add-std',
  1861. postData: {
  1862. id: mainTree.getNodeKey(mainNode),
  1863. tender_id: mainNode.tender_id,
  1864. stdType: info.sheet.zh_setting.stdType,
  1865. stdLibId: stdNode.list_id,
  1866. stdNode: stdTree.getNodeKey(stdNode)
  1867. }
  1868. }, function (result) {
  1869. const refreshNode = mainTree.loadPostData(result);
  1870. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  1871. if (sel) {
  1872. if (refreshNode.create && refreshNode.create.length > 0) {
  1873. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  1874. } else {
  1875. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  1876. if (node) {
  1877. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  1878. }
  1879. }
  1880. }
  1881. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1882. billsSpread.focus();
  1883. posSpreadObj.loadCurPosData();
  1884. });
  1885. };
  1886. const stdXmjSetting = {
  1887. selector: '#std-xmj',
  1888. stdType: 'xmj',
  1889. treeSetting: {
  1890. id: 'chapter_id',
  1891. pid: 'pid',
  1892. order: 'order',
  1893. level: 'level',
  1894. rootId: -1,
  1895. keys: ['id', 'list_id', 'chapter_id'],
  1896. },
  1897. spreadSetting: {
  1898. cols: [
  1899. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1900. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1901. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1902. ],
  1903. treeCol: 0,
  1904. emptyRows: 0,
  1905. headRows: 1,
  1906. headRowHeight: [32],
  1907. defaultRowHeight: 21,
  1908. headerFont: '12px 微软雅黑',
  1909. font: '12px 微软雅黑',
  1910. headColWidth: [0],
  1911. },
  1912. cellDoubleClick: stdLibCellDoubleClick,
  1913. page: 'revise',
  1914. tid: window.location.pathname.split('/')[2],
  1915. };
  1916. const stdGclSetting = {
  1917. selector: '#std-gcl',
  1918. stdType: 'gcl',
  1919. treeSetting: {
  1920. id: 'bill_id',
  1921. pid: 'pid',
  1922. order: 'order',
  1923. level: 'level',
  1924. rootId: -1,
  1925. keys: ['id', 'list_id', 'bill_id']
  1926. },
  1927. spreadSetting: {
  1928. cols: [
  1929. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1930. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1931. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1932. ],
  1933. treeCol: 0,
  1934. emptyRows: 0,
  1935. headRows: 1,
  1936. headRowHeight: [32],
  1937. defaultRowHeight: 21,
  1938. headerFont: '12px 微软雅黑',
  1939. font: '12px 微软雅黑',
  1940. headColWidth: [0],
  1941. },
  1942. cellDoubleClick: stdLibCellDoubleClick,
  1943. page: 'revise',
  1944. tid: window.location.pathname.split('/')[2],
  1945. };
  1946. // 展开收起标准节点
  1947. $('a', '#side-menu').bind('click', function (e) {
  1948. e.preventDefault();
  1949. const tab = $(this), tabPanel = $(tab.attr('content'));
  1950. // 展开工具栏、切换标签
  1951. if (!tab.hasClass('active')) {
  1952. const close = $('.active', '#side-menu').length === 0;
  1953. $('a', '#side-menu').removeClass('active');
  1954. tab.addClass('active');
  1955. $('.tab-content .tab-pane').removeClass('active');
  1956. tabPanel.addClass('active');
  1957. showSideTools(tab.hasClass('active'));
  1958. if (tab.attr('content') === '#std-xmj') {
  1959. if (!stdXmj) {
  1960. stdXmj = new stdLib(stdXmjSetting);
  1961. }
  1962. stdXmj.spread.refresh();
  1963. } else if (tab.attr('content') === '#std-gcl') {
  1964. if (!stdGcl) {
  1965. stdGcl = new stdLib(stdGclSetting);
  1966. }
  1967. stdGcl.spread.refresh();
  1968. } else if (tab.attr('content') === '#deal-bills') {
  1969. dealBills.loadData();
  1970. dealBills.spread.refresh();
  1971. } else if (tab.attr('content') === '#bg-bills') {
  1972. bgBills.loadData();
  1973. bgBills.spread.refresh();
  1974. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1975. if (!searchLedger) {
  1976. searchLedger = $.billsSearch({
  1977. selector: '#search',
  1978. searchSpread: billsSpread,
  1979. resultSpreadSetting: {
  1980. cols: [
  1981. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1982. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1983. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  1984. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1985. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1986. {title: '数量', field: 'quantity', 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. },
  1995. afterLocated: function () {
  1996. posSpreadObj.loadCurPosData();
  1997. }
  1998. });
  1999. }
  2000. searchLedger.spread.refresh();
  2001. }
  2002. }
  2003. else {// 收起工具栏
  2004. tab.removeClass('active');
  2005. tabPanel.removeClass('active');
  2006. showSideTools(tab.hasClass('active'));
  2007. }
  2008. billsSpread.refresh();
  2009. if (posSpread) {
  2010. posSpread.refresh();
  2011. }
  2012. });
  2013. if (!readOnly) {
  2014. // 修订详情 保存
  2015. $('#save').click(function () {
  2016. const content = $('#content').val();
  2017. postData('save', { content: content }, function () {
  2018. $('#content').attr('org-value', content);
  2019. });
  2020. });
  2021. }
  2022. // 显示层次
  2023. (function (select, sheet) {
  2024. $(select).click(function () {
  2025. if (!sheet.zh_tree) return;
  2026. const tag = $(this).attr('tag');
  2027. const tree = sheet.zh_tree;
  2028. switch (tag) {
  2029. case "1":
  2030. case "2":
  2031. case "3":
  2032. case "4":
  2033. case "5":
  2034. tree.expandByLevel(parseInt(tag));
  2035. SpreadJsObj.refreshTreeRowVisible(sheet);
  2036. break;
  2037. case "last":
  2038. tree.expandByCustom(() => { return true; });
  2039. SpreadJsObj.refreshTreeRowVisible(sheet);
  2040. break;
  2041. case "leafXmj":
  2042. tree.expandToLeafXmj();
  2043. SpreadJsObj.refreshTreeRowVisible(sheet);
  2044. break;
  2045. }
  2046. });
  2047. })('a[name=showLevel]', billsSheet);
  2048. });