ledger.js 86 KB

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