revise.js 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  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. cut: function (sheet, sel, callback) {
  549. if (!sheet || !sel) return;
  550. if (sel.colCount >= sheet.zh_setting.cols.length) {
  551. toastr.warning('请勿选中整行剪切');
  552. return;
  553. }
  554. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  555. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  556. const node = sortData[iRow];
  557. if (node) {
  558. const data = sheet.zh_tree.getNodeKeyData(node);
  559. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  560. const col = sheet.zh_setting.cols[iCol];
  561. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  562. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  563. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  564. const lPos = pos.getLedgerPos(node.id);
  565. if (lPos && lPos.length > 0) {
  566. toastr.error('不可剪切');
  567. return;
  568. }
  569. }
  570. const style = sheet.getStyle(iRow, iCol);
  571. if (style.locked) {
  572. toastr.error('不可剪切');
  573. return;
  574. }
  575. const colSetting = sheet.zh_setting.cols[iCol];
  576. data[colSetting.field] = null;
  577. }
  578. datas.push(data);
  579. }
  580. }
  581. if (datas.length > 0) {
  582. callback();
  583. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  584. const refreshNode = sheet.zh_tree.loadPostData(result);
  585. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  586. });
  587. }
  588. },
  589. };
  590. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  591. billsTreeSpreadObj.loadExprToInput(billsSheet);
  592. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  593. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  594. if (!readOnly) {
  595. // 增删上下移升降级
  596. $('a[name="base-opr"]').click(function () {
  597. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  598. });
  599. $('a[name=cpc]').click(function () {
  600. billsSpread.commandManager().execute({
  601. cmd: this.getAttribute('type'),
  602. sheetName: billsSpread.getActiveSheet().name()
  603. });
  604. });
  605. $('#bills-expr').bind('change mouseleave', function () {
  606. if (this.readOnly) return;
  607. const expr = $(this);
  608. const select = SpreadJsObj.getSelectObject(billsSheet);
  609. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  610. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  611. const data = {
  612. id: select.id,
  613. tender_id: select.tender_id,
  614. ledger_id: select.ledger_id
  615. };
  616. if (newValue !== '') {
  617. const num = _.toNumber(newValue);
  618. if (num) {
  619. data[field] = num;
  620. } else {
  621. try {
  622. data[field] = math.evaluate(transExpr(newValue));
  623. } catch (err) {
  624. toastr.error('输入的表达式非法');
  625. return;
  626. }
  627. }
  628. } else {
  629. data[field] = null;
  630. }
  631. // 更新至服务器
  632. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  633. const refreshNode = billsTree.loadPostData(result);
  634. expr.val(select[field]);
  635. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  636. });
  637. });
  638. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  639. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  640. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  641. billsSpread.bind(spreadNS.Events.ClipboardPasted, billsTreeSpreadObj.clipboardPasted);
  642. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  643. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  644. let batchInsertObj;
  645. // 右键菜单
  646. $.contextMenu({
  647. selector: '#bills-spread',
  648. build: function ($trigger, e) {
  649. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  650. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  651. },
  652. items: {
  653. 'create': {
  654. name: '新增',
  655. icon: 'fa-sign-in',
  656. callback: function (key, opt) {
  657. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  658. },
  659. disabled: function (key, opt) {
  660. const sheet = billsSheet;
  661. const selection = sheet.getSelections();
  662. const sel = selection ? selection[0] : sheet.getSelections()[0];
  663. const row = sel ? sel.row : -1;
  664. const tree = sheet.zh_tree;
  665. if (!tree) return true;
  666. const first = sheet.zh_tree.nodes[row];
  667. const valid = !sheet.zh_setting.readOnly;
  668. return !(valid && first && first.level > 1);
  669. }
  670. },
  671. 'delete': {
  672. name: '删除',
  673. icon: 'fa-remove',
  674. callback: function (key, opt) {
  675. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  676. },
  677. disabled: function (key, opt) {
  678. const sheet = billsSheet;
  679. const selection = sheet.getSelections();
  680. const sel = selection ? selection[0] : sheet.getSelections()[0];
  681. const row = sel ? sel.row : -1;
  682. const tree = sheet.zh_tree;
  683. if (!tree) return true;
  684. const first = sheet.zh_tree.nodes[row];
  685. let last = first, sameParent = true, nodeUsed = first.used;
  686. if (sel.rowCount > 1 && first) {
  687. for (let r = 1; r < sel.rowCount; r++) {
  688. const rNode = tree.nodes[sel.row + r];
  689. if (!rNode) {
  690. sameParent = false;
  691. break;
  692. }
  693. nodeUsed = nodeUsed || rNode.used;
  694. if (rNode.level > first.level) continue;
  695. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  696. sameParent = false;
  697. break;
  698. }
  699. last = rNode;
  700. }
  701. }
  702. const valid = !sheet.zh_setting.readOnly;
  703. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  704. }
  705. },
  706. 'batchInsertBillsPos': {
  707. name: '批量插入清单-计量单元',
  708. icon: 'fa-sign-in',
  709. disabled: function (key, opt) {
  710. if (!isTz) return true;
  711. const select = SpreadJsObj.getSelectObject(billsSheet);
  712. if (select) {
  713. if (select.code && select.code !== '') {
  714. return !billsTree.isLeafXmj(select);
  715. } else {
  716. const parent = billsTree.getParent(select);
  717. return !(parent && billsTree.isLeafXmj(parent));
  718. }
  719. } else {
  720. return false;
  721. }
  722. },
  723. callback: function (key, opt) {
  724. if (!batchInsertObj) {
  725. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  726. } else {
  727. batchInsertObj.initView();
  728. }
  729. $('#batch').modal('show');
  730. }
  731. }
  732. }
  733. });
  734. }
  735. const posSpreadObj = {
  736. /**
  737. * 加载计量单元 根据当前台账选择节点
  738. */
  739. loadCurPosData: function () {
  740. const node = SpreadJsObj.getSelectObject(billsSheet);
  741. if (node) {
  742. const posData = pos.getLedgerPos(node.id) || [];
  743. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  744. } else {
  745. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  746. }
  747. SpreadJsObj.resetFieldReadOnly(posSheet);
  748. },
  749. editStarting: function (e, info) {
  750. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  751. },
  752. /**
  753. * 编辑单元格响应事件
  754. * @param {Object} e
  755. * @param {Object} info
  756. */
  757. editEnded: function (e, info) {
  758. if (!info.sheet.zh_setting) {
  759. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  760. return;
  761. }
  762. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  763. const col = info.sheet.zh_setting.cols[info.col];
  764. const orgText = posData ? posData[col.field] : null;
  765. const newText = trimInvalidChar(info.sheet.getCell(info.row, info.col).text());
  766. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  767. const node = posSpreadObj.billsNode;
  768. if (!node) {
  769. toastr.error('数据错误,请选择台账节点后再试');
  770. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  771. return;
  772. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  773. toastr.error('父节点不可插入计量单元');
  774. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  775. return;
  776. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  777. toastr.error('项目节不可插入计量单元');
  778. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  779. return;
  780. }
  781. const data = {postType: 'pos'};
  782. if (col.field === 'name') {
  783. if (newText === '' && posData) {
  784. toastr.error('部位名称不可为空', 'error');
  785. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  786. return;
  787. } else if (!posData) {
  788. if (newText && newText !== '') {
  789. data.posPostType = 'add';
  790. const sortData = info.sheet.zh_data;
  791. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  792. data.postData = { name: newText, lid: node.id, porder: order};
  793. } else {
  794. return;
  795. }
  796. } else {
  797. data.posPostType = 'update';
  798. data.postData = {id: posData.id, name: newText};
  799. }
  800. } else if (!posData) {
  801. toastr.warning('新增部位请先输入名称');
  802. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  803. return;
  804. } else {
  805. data.posPostType = 'update';
  806. data.postData = {id: posData.id};
  807. if (col.type === 'Number') {
  808. const num = _.toNumber(newText);
  809. if (_.isFinite(num)) {
  810. data.postData[col.field] = num;
  811. } else {
  812. try {
  813. data.postData[col.field] = math.evaluate(transExpr(newText));
  814. } catch(err) {
  815. toastr.error('输入的表达式非法');
  816. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  817. return;
  818. }
  819. }
  820. } else {
  821. data.postData[col.field] = newText;
  822. }
  823. }
  824. postData(window.location.pathname + '/update', data, function (result) {
  825. const updateRst = pos.updateDatas(result.pos);
  826. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  827. if (updateRst.create.length > 0) {
  828. posSpreadObj.loadCurPosData();
  829. } else {
  830. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  831. }
  832. const loadResult = billsTree.loadPostData(result.ledger);
  833. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  834. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  835. }, function () {
  836. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  837. });
  838. },
  839. /**
  840. * 删除按钮响应事件
  841. * @param sheet
  842. */
  843. deletePress: function (sheet) {
  844. if (!sheet.zh_settting) return;
  845. const sortData = sheet.zh_data;
  846. const datas = [], posSelects = [];
  847. const sel = sheet.getSelections()[0];
  848. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  849. let bDel = false;
  850. const node = sortData[iRow];
  851. if (node) {
  852. const data = {id: node.id};
  853. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  854. const colSetting = sheet.zh_setting.cols[iCol];
  855. if (colSetting.field === 'name') {
  856. toastr.error('部位名称不能为空');
  857. return;
  858. }
  859. const style = sheet.getStyle(iRow, iCol);
  860. if (!style.locked) {
  861. const colSetting = sheet.zh_setting.cols[iCol];
  862. data[colSetting.field] = null;
  863. bDel = true;
  864. }
  865. }
  866. if (bDel) {
  867. datas.push(data);
  868. posSelects.push(node);
  869. }
  870. }
  871. }
  872. if (datas.length > 0) {
  873. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  874. pos.updateDatas(result.pos);
  875. posSpreadObj.loadCurPosData();
  876. const loadResult = billsTree.loadPostData(result.ledger);
  877. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  878. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  879. }, function () {
  880. posSpreadObj.loadCurPosData();
  881. });
  882. }
  883. },
  884. /**
  885. * 删除 计量单元
  886. * @param sheet
  887. */
  888. deletePos: function (sheet) {
  889. const selection = sheet.getSelections();
  890. const data = {
  891. postType: 'pos',
  892. posPostType: 'delete',
  893. postData: [],
  894. };
  895. const row = selection[0].row, count = selection[0].rowCount;
  896. const sortData = sheet.zh_data;
  897. for (let iRow = 0; iRow < count; iRow++) {
  898. const posData = sortData[iRow + row];
  899. if (posData) {
  900. if (posData.used) {
  901. toastr.error('"' + posData.name + '"已计量,请勿删除');
  902. return;
  903. }
  904. data.postData.push(sortData[iRow + row].id);
  905. }
  906. }
  907. if (data.postData.length > 0) {
  908. postData(window.location.pathname + '/update', data, function (result) {
  909. pos.removeDatas(result.pos);
  910. sheet.deleteRows(row, count);
  911. const loadResult = billsTree.loadPostData(result.ledger);
  912. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  913. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  914. });
  915. }
  916. },
  917. clipboardPasting: function (e, info) {
  918. if (!info.sheet.zh_setting) {
  919. info.cancel = true;
  920. return;
  921. }
  922. const range = info.cellRange;
  923. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  924. const posData = info.sheet.zh_data[iRow];
  925. if (posData && posData.used) {
  926. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  927. info.cancel = true;
  928. return;
  929. }
  930. }
  931. },
  932. /**
  933. * 粘贴单元格响应事件
  934. * @param e
  935. * @param info
  936. */
  937. clipboardPasted: function (e, info) {
  938. const node = SpreadJsObj.getSelectObject(billsSheet);
  939. if (node.code && (node.code !== '')) {
  940. toastr.error('项目节不可含有节点明细');
  941. posSpreadObj.loadCurPosData();
  942. return;
  943. }
  944. if (node.children && (node.children.length > 0)) {
  945. toastr.error('仅节点子项可以含有计量单元');
  946. posSpreadObj.loadCurPosData();
  947. return;
  948. }
  949. if (!info.sheet.zh_setting) {
  950. posSpreadObj.loadCurPosData();
  951. return;
  952. }
  953. const data = [];
  954. const sortData = info.sheet.zh_data || [];
  955. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  956. if (info.cellRange.col !== 0) {
  957. toastr.warning('新增部位请先输入名称');
  958. posSpreadObj.loadCurPosData();
  959. return;
  960. }
  961. }
  962. let bHint = false;
  963. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  964. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  965. let bPaste = true;
  966. const curRow = info.cellRange.row + iRow;
  967. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  968. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  969. const curCol = info.cellRange.col + iCol;
  970. const colSetting = info.sheet.zh_setting.cols[curCol];
  971. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  972. if (colSetting.type === 'Number') {
  973. const num = _.toNumber(posData[colSetting.field]);
  974. if (num) {
  975. posData[colSetting.field] = num;
  976. } else {
  977. try {
  978. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  979. } catch (err) {
  980. if (!bHint) {
  981. toastr.warning('粘贴了非法表达式,已过滤');
  982. bHint = true;
  983. }
  984. bPaste = false;
  985. }
  986. }
  987. }
  988. }
  989. if (bPaste) {
  990. data.push(posData);
  991. }
  992. }
  993. if (data.length === 0) {
  994. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  995. return;
  996. }
  997. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  998. pos.updateDatas(result.pos);
  999. posSpreadObj.loadCurPosData();
  1000. const loadResult = billsTree.loadPostData(result.ledger);
  1001. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1002. posSpreadObj.loadCurPosData();
  1003. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1004. }, function () {
  1005. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1006. });
  1007. },
  1008. selectionChanged: function (e, info) {
  1009. const col = info.sheet.zh_setting.cols[info.newSelections[0].col];
  1010. const cell = info.sheet.getCell(info.newSelections[0].col, info.newSelections[0].col);
  1011. if (col.type === 'Number') {
  1012. const data = SpreadJsObj.getSelectObject(info.sheet);
  1013. if (data) {
  1014. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  1015. .attr('row', info.newSelections[0].row).attr('readOnly', readOnly || cell.locked());
  1016. } else {
  1017. $('#pos-expr').val('').attr('readOnly', true);
  1018. }
  1019. } else {
  1020. $('#pos-expr').val('').attr('readOnly', true);
  1021. }
  1022. },
  1023. };
  1024. posSpreadObj.loadCurPosData();
  1025. SpreadJsObj.resetTopAndSelect(posSheet);
  1026. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1027. if (!readOnly) {
  1028. $('#pos-expr').bind('change mouseleave', function () {
  1029. if (this.readOnly) return;
  1030. const expr = $(this);
  1031. const select = SpreadJsObj.getSelectObject(posSheet);
  1032. const row = posSheet.getSelections()[0].row;
  1033. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1034. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1035. const data = {id: select.id};
  1036. if (newValue !== '') {
  1037. const num = _.toNumber(newValue);
  1038. if (num) {
  1039. data[field] = num;
  1040. } else {
  1041. try {
  1042. data[field] = math.evaluate(transExpr(newValue));
  1043. } catch (err) {
  1044. toastr.error('输入的表达式非法');
  1045. return;
  1046. }
  1047. }
  1048. } else {
  1049. data[field] = null;
  1050. }
  1051. // 更新至服务器
  1052. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1053. const updateRst = pos.updateDatas(result.pos);
  1054. expr.val(select[field]);
  1055. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1056. SpreadJsObj.reLoadRowData(posSheet, row);
  1057. const loadResult = billsTree.loadPostData(result.ledger);
  1058. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1059. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1060. });
  1061. });
  1062. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1063. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1064. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  1065. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1066. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1067. $.contextMenu({
  1068. selector: '#pos-spread',
  1069. build: function ($trigger, e) {
  1070. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1071. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1072. },
  1073. items: {
  1074. 'delete': {
  1075. name: '删除',
  1076. icon: 'fa-remove',
  1077. disabled: function (key, opt) {
  1078. if (posSheet.zh_data) {
  1079. const selection = posSheet.getSelections();
  1080. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1081. } else {
  1082. return true;
  1083. }
  1084. },
  1085. callback: function (key, opt) {
  1086. posSpreadObj.deletePos(posSheet);
  1087. }
  1088. }
  1089. }
  1090. });
  1091. }
  1092. $.divResizer({
  1093. select: '#revise-resize',
  1094. callback: function () {
  1095. billsSpread.refresh();
  1096. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1097. $(".sp-wrap").height(bcontent-40);
  1098. posSpread.refresh();
  1099. }
  1100. });
  1101. class DealBills {
  1102. constructor (selector, spreadSetting) {
  1103. const self = this;
  1104. this.loaded = false;
  1105. this.obj = $(selector)[0];
  1106. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1107. this.spreadSetting = spreadSetting;
  1108. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1109. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1110. if (!readOnly) {
  1111. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1112. const dealSheet = info.sheet;
  1113. const mainSheet = billsSheet;
  1114. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1115. if (!dealBills) { return; }
  1116. const mainTree = mainSheet.zh_tree;
  1117. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1118. if (!mainNode || !mainTree) { return; }
  1119. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1120. toastr.warning('非最底层项目下,不应添加节点');
  1121. return;
  1122. }
  1123. postData(window.location.pathname + '/update', {
  1124. postType: 'add-deal',
  1125. postData: {
  1126. id: mainNode.ledger_id,
  1127. type: mainNode.code ? 'child' : 'next',
  1128. dealBills: {
  1129. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1130. unit_price: dealBills.unit_price,
  1131. }
  1132. },
  1133. }, function (result) {
  1134. const refreshData = mainTree.loadPostData(result);
  1135. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1136. const sel = mainSheet.getSelections()[0];
  1137. if (sel && refreshData.create[0]) {
  1138. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1139. }
  1140. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1141. billsSpread.focus();
  1142. posSpreadObj.loadCurPosData();
  1143. });
  1144. });
  1145. }
  1146. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1147. }
  1148. loadData () {
  1149. if (this.loaded) return;
  1150. const self = this;
  1151. postData(this.url+'/get-data', {}, function (data) {
  1152. self.data = data;
  1153. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1154. self.loaded = true;
  1155. });
  1156. }
  1157. calculateData () {
  1158. if (this.data) {
  1159. for (const d of this.data) {
  1160. d.total_price = _.multiply(d.quantity, d.unit_price);
  1161. }
  1162. }
  1163. }
  1164. }
  1165. class BatchInsertBillsPosObj {
  1166. constructor (obj) {
  1167. const self = this;
  1168. this.obj = obj;
  1169. this.billsCount = 6;
  1170. this.posCount = 1000;
  1171. // 初始化 清单编号窗口 参数
  1172. this.qdSpreadSetting = {
  1173. cols: [
  1174. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1175. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1176. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1177. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1178. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1179. ],
  1180. emptyRows: this.billsCount,
  1181. headRows: 1,
  1182. headRowHeight: [32],
  1183. headerFont: '12px 微软雅黑',
  1184. font: '12px 微软雅黑',
  1185. };
  1186. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1187. // 初始化 部位数量复核表 参数
  1188. this.posSpreadSetting = {
  1189. cols: [
  1190. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1191. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1192. ],
  1193. emptyRows: this.posCount,
  1194. headRows: 1,
  1195. headRowHeight: [32],
  1196. headerFont: '12px 微软雅黑',
  1197. font: '12px 微软雅黑',
  1198. };
  1199. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1200. this.posSpreadSetting.cols.push(
  1201. {title: '节点' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1202. )
  1203. }
  1204. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1205. // 初始化 签约节点 参数
  1206. this.dealSpreadSetting = {
  1207. cols: [
  1208. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  1209. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  1210. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  1211. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  1212. ],
  1213. emptyRows: 0,
  1214. headRows: 1,
  1215. headRowHeight: [32],
  1216. headerFont: '12px 微软雅黑',
  1217. font: '12px 微软雅黑',
  1218. };
  1219. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1220. // 初始化 清单编号、部位数量复核表 表格
  1221. this.initView();
  1222. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1223. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1224. // 拉取签约节点数据
  1225. dealBills.loadData();
  1226. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1227. // 双击签约节点,自动添加到清单编号窗口
  1228. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1229. const deal = info.sheet.zh_data[info.row];
  1230. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1231. const sel = qdSheet.getSelections()[0];
  1232. qdSheet.getCell(sel.row, 0).value(deal.code);
  1233. qdSheet.getCell(sel.row, 1).value(deal.name);
  1234. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1235. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1236. if (sel.row + 1 === qdSheet.getRowCount()) {
  1237. const count = sel.row + 2;
  1238. qdSheet.setRowCount(count);
  1239. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('节点' + count);
  1240. const colCount = posSheet.getColumnCount() + 1;
  1241. posSheet.setColumnCount(colCount);
  1242. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
  1243. }
  1244. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1245. qdSheet.getParent().focus();
  1246. });
  1247. this.obj.bind('shown.bs.modal', function () {
  1248. self.qdSpread.refresh();
  1249. self.posSpread.refresh();
  1250. self.dealSpread.refresh();
  1251. });
  1252. $('#batch-ok').click(function () {
  1253. const selection = billsSheet.getSelections();
  1254. const row = selection[0].row;
  1255. const select = billsTree.nodes[row];
  1256. if (select) {
  1257. const insertData = {};
  1258. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1259. insertData.id = select[billsTree.setting.id];
  1260. insertData.batchData = self.getBatchData();
  1261. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1262. pos.updateDatas(data.pos);
  1263. const result = billsTree.loadPostData(data.ledger);
  1264. billsTreeSpreadObj.refreshTree(sheet, result);
  1265. billsTreeSpreadObj.refreshOperationValid(sheet, selection);
  1266. self.obj.modal('hide');
  1267. }, null, true);
  1268. }
  1269. });
  1270. }
  1271. // 初始化左侧表格
  1272. initView () {
  1273. // 初始化 清单编号
  1274. const qdSheet = this.qdSpread.getActiveSheet();
  1275. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1276. SpreadJsObj.refreshColumnAlign(qdSheet);
  1277. // 清理原有数据
  1278. SpreadJsObj.beginMassOperation(qdSheet);
  1279. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1280. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1281. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('节点' + iRow);
  1282. }
  1283. qdSheet.setSelection(0, 0, 1 ,1);
  1284. SpreadJsObj.endMassOperation(qdSheet);
  1285. // 初始化 部位数量复核表
  1286. const posSheet = this.posSpread.getActiveSheet();
  1287. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1288. SpreadJsObj.refreshColumnAlign(posSheet);
  1289. // 清理原有数据
  1290. SpreadJsObj.beginMassOperation(posSheet);
  1291. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1292. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1293. posSheet.setSelection(0, 0, 1 ,1);
  1294. SpreadJsObj.endMassOperation(posSheet);
  1295. // 检查签约节点数据,以工具栏数据为准
  1296. if (dealBills) {
  1297. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1298. }
  1299. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1300. }
  1301. // 获取界面数据
  1302. getBatchData () {
  1303. const result = [];
  1304. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1305. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1306. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1307. const qd = {
  1308. b_code: qdSheet.getText(iRow, 0),
  1309. name: qdSheet.getText(iRow, 1),
  1310. unit: qdSheet.getText(iRow, 2),
  1311. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1312. pos: [],
  1313. };
  1314. result.push(qd);
  1315. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1316. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1317. if (value !== 0 && !isNaN(value)) {
  1318. qd.pos.push({
  1319. name: posSheet.getText(iPosRow, 0),
  1320. drawing_code: posSheet.getText(iPosRow, 1),
  1321. quantity: value,
  1322. });
  1323. }
  1324. }
  1325. }
  1326. return result;
  1327. }
  1328. }
  1329. const dealBills = new DealBills('#deal-bills-spread', {
  1330. cols: [
  1331. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1332. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1333. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1334. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1335. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1336. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1337. ],
  1338. emptyRows: 0,
  1339. headRows: 1,
  1340. headRowHeight: [32],
  1341. defaultRowHeight: 21,
  1342. headerFont: '12px 微软雅黑',
  1343. font: '12px 微软雅黑',
  1344. });
  1345. $.divResizer({
  1346. select: '#revise-right-spr',
  1347. callback: function () {
  1348. billsSpread.refresh();
  1349. if (posSpread) {
  1350. posSpread.refresh();
  1351. }
  1352. if (stdXmj) {
  1353. stdXmj.spread.refresh();
  1354. }
  1355. if (stdGcl) {
  1356. stdGcl.spread.refresh();
  1357. }
  1358. if (dealBills) {
  1359. dealBills.spread.refresh();
  1360. }
  1361. if (searchLedger) {
  1362. searchLedger.spread.refresh();
  1363. }
  1364. }
  1365. });
  1366. $.subMenu({
  1367. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1368. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1369. key: 'menu.1.0.0',
  1370. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1371. callback: function (info) {
  1372. if (info.mini) {
  1373. $('.panel-title').addClass('fluid');
  1374. $('#sub-menu').removeClass('panel-sidebar');
  1375. } else {
  1376. $('.panel-title').removeClass('fluid');
  1377. $('#sub-menu').addClass('panel-sidebar');
  1378. }
  1379. autoFlashHeight();
  1380. billsSpread.refresh();
  1381. if (posSpread) {
  1382. posSpread.refresh();
  1383. }
  1384. if (stdXmj) {
  1385. stdXmj.spread.refresh();
  1386. }
  1387. if (stdGcl) {
  1388. stdGcl.spread.refresh();
  1389. }
  1390. if (dealBills) {
  1391. dealBills.spread.refresh();
  1392. }
  1393. if (searchLedger) {
  1394. searchLedger.spread.refresh();
  1395. }
  1396. }
  1397. });
  1398. const showSideTools = function (show) {
  1399. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1400. if (show) {
  1401. right.show();
  1402. autoFlashHeight();
  1403. /**
  1404. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1405. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1406. * 故需要通过最终的parent.width再计算一次left.width
  1407. *
  1408. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1409. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1410. *
  1411. */
  1412. //left.css('width', parent.width() - right.outerWidth());
  1413. //left.css('width', parent.width() - right.outerWidth());
  1414. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1415. left.css('width', percent + '%');
  1416. } else {
  1417. left.width(parent.width());
  1418. right.hide();
  1419. }
  1420. };
  1421. $('#content-tab').addClass('active');
  1422. $('#xd-content').addClass('active');
  1423. showSideTools(true);
  1424. billsSpread.refresh();
  1425. if (posSpread) {
  1426. posSpread.refresh();
  1427. }
  1428. const stdLibCellDoubleClick = function (e, info) {
  1429. const stdSheet = info.sheet;
  1430. const mainSheet = billsSheet;
  1431. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1432. const stdTree = stdSheet.zh_tree;
  1433. const stdNode = stdTree.nodes[info.row];
  1434. const mainTree = mainSheet.zh_tree;
  1435. const sel = mainSheet.getSelections()[0];
  1436. const mainNode = mainTree.nodes[sel.row];
  1437. if (!stdNode) return;
  1438. if (info.sheet.zh_setting.stdType === 'gcl') {
  1439. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1440. toastr.warning('非最底层项目下,不应添加节点');
  1441. return;
  1442. }
  1443. }
  1444. postData(window.location.pathname + '/update', {
  1445. postType: 'add-std',
  1446. postData: {
  1447. id: mainTree.getNodeKey(mainNode),
  1448. tender_id: mainNode.tender_id,
  1449. stdType: info.sheet.zh_setting.stdType,
  1450. stdLibId: stdNode.list_id,
  1451. stdNode: stdTree.getNodeKey(stdNode)
  1452. }
  1453. }, function (result) {
  1454. const refreshNode = mainTree.loadPostData(result);
  1455. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  1456. if (sel) {
  1457. if (refreshNode.create && refreshNode.create.length > 0) {
  1458. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  1459. } else {
  1460. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  1461. if (node) {
  1462. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  1463. }
  1464. }
  1465. }
  1466. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1467. billsSpread.focus();
  1468. posSpreadObj.loadCurPosData();
  1469. });
  1470. };
  1471. const stdXmjSetting = {
  1472. selector: '#std-xmj',
  1473. stdType: 'xmj',
  1474. treeSetting: {
  1475. id: 'chapter_id',
  1476. pid: 'pid',
  1477. order: 'order',
  1478. level: 'level',
  1479. rootId: -1,
  1480. keys: ['id', 'list_id', 'chapter_id'],
  1481. },
  1482. spreadSetting: {
  1483. cols: [
  1484. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1485. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1486. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1487. ],
  1488. treeCol: 0,
  1489. emptyRows: 0,
  1490. headRows: 1,
  1491. headRowHeight: [32],
  1492. defaultRowHeight: 21,
  1493. headerFont: '12px 微软雅黑',
  1494. font: '12px 微软雅黑',
  1495. headColWidth: [0],
  1496. },
  1497. cellDoubleClick: stdLibCellDoubleClick,
  1498. page: 'revise',
  1499. tid: window.location.pathname.split('/')[2],
  1500. };
  1501. const stdGclSetting = {
  1502. selector: '#std-gcl',
  1503. stdType: 'gcl',
  1504. treeSetting: {
  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. spreadSetting: {
  1513. cols: [
  1514. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1515. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1516. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1517. ],
  1518. treeCol: 0,
  1519. emptyRows: 0,
  1520. headRows: 1,
  1521. headRowHeight: [32],
  1522. defaultRowHeight: 21,
  1523. headerFont: '12px 微软雅黑',
  1524. font: '12px 微软雅黑',
  1525. headColWidth: [0],
  1526. },
  1527. cellDoubleClick: stdLibCellDoubleClick,
  1528. page: 'revise',
  1529. tid: window.location.pathname.split('/')[2],
  1530. };
  1531. // 展开收起标准节点
  1532. $('a', '#side-menu').bind('click', function (e) {
  1533. e.preventDefault();
  1534. const tab = $(this), tabPanel = $(tab.attr('content'));
  1535. // 展开工具栏、切换标签
  1536. if (!tab.hasClass('active')) {
  1537. const close = $('.active', '#side-menu').length === 0;
  1538. $('a', '#side-menu').removeClass('active');
  1539. tab.addClass('active');
  1540. $('.tab-content .tab-pane').removeClass('active');
  1541. tabPanel.addClass('active');
  1542. showSideTools(tab.hasClass('active'));
  1543. if (tab.attr('content') === '#std-xmj') {
  1544. if (!stdXmj) {
  1545. stdXmj = new stdLib(stdXmjSetting);
  1546. }
  1547. stdXmj.spread.refresh();
  1548. } else if (tab.attr('content') === '#std-gcl') {
  1549. if (!stdGcl) {
  1550. stdGcl = new stdLib(stdGclSetting);
  1551. }
  1552. stdGcl.spread.refresh();
  1553. } else if (tab.attr('content') === '#deal-bills') {
  1554. dealBills.loadData();
  1555. dealBills.spread.refresh();
  1556. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1557. if (!searchLedger) {
  1558. searchLedger = $.billsSearch({
  1559. selector: '#search',
  1560. searchSpread: billsSpread,
  1561. resultSpreadSetting: {
  1562. cols: [
  1563. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1564. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1565. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  1566. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1567. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1568. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1569. ],
  1570. emptyRows: 0,
  1571. headRows: 1,
  1572. headRowHeight: [32],
  1573. defaultRowHeight: 21,
  1574. headerFont: '12px 微软雅黑',
  1575. font: '12px 微软雅黑',
  1576. },
  1577. afterLocated: function () {
  1578. posSpreadObj.loadCurPosData();
  1579. }
  1580. });
  1581. }
  1582. searchLedger.spread.refresh();
  1583. }
  1584. }
  1585. else {// 收起工具栏
  1586. tab.removeClass('active');
  1587. tabPanel.removeClass('active');
  1588. showSideTools(tab.hasClass('active'));
  1589. }
  1590. billsSpread.refresh();
  1591. if (posSpread) {
  1592. posSpread.refresh();
  1593. }
  1594. });
  1595. if (!readOnly) {
  1596. // 修订详情 保存
  1597. $('#save').click(function () {
  1598. const content = $('#content').val();
  1599. postData('save', { content: content }, function () {
  1600. $('#content').attr('org-value', content);
  1601. });
  1602. });
  1603. }
  1604. // 显示层次
  1605. (function (select, sheet) {
  1606. $(select).click(function () {
  1607. if (!sheet.zh_tree) return;
  1608. const tag = $(this).attr('tag');
  1609. const tree = sheet.zh_tree;
  1610. switch (tag) {
  1611. case "1":
  1612. case "2":
  1613. case "3":
  1614. case "4":
  1615. case "5":
  1616. tree.expandByLevel(parseInt(tag));
  1617. SpreadJsObj.refreshTreeRowVisible(sheet);
  1618. break;
  1619. case "last":
  1620. tree.expandByCustom(() => { return true; });
  1621. SpreadJsObj.refreshTreeRowVisible(sheet);
  1622. break;
  1623. case "leafXmj":
  1624. tree.expandToLeafXmj();
  1625. SpreadJsObj.refreshTreeRowVisible(sheet);
  1626. break;
  1627. }
  1628. });
  1629. })('a[name=showLevel]', billsSheet);
  1630. });