revise.js 75 KB

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