ledger.js 77 KB

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