std_ration_lib.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /**
  2. * Standard Ration Lib
  3. * Created by Mai on 2017/5/16.
  4. */
  5. /*var rationChapterSpread, sectionRationsSpread;*/
  6. var rationLibObj = {
  7. rationChapterSpread: null,
  8. sectionRationsSpread: null,
  9. rationChapterTreeController: null,
  10. refreshSettingForHint: function () {
  11. TREE_SHEET_HELPER.initSetting($('#stdSectionRations')[0], rationLibObj.sectionRationsSetting);
  12. },
  13. checkSpread: function () {
  14. if (!this.rationChapterSpread) {
  15. this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
  16. sheetCommonObj.spreadDefaultStyle(this.rationChapterSpread);
  17. this.rationChapterSpread.getSheet(0).name('stdRationLib_chapter');
  18. this.rationChapterSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onChapterSpreadCellDoubleClick);
  19. }
  20. if (!this.sectionRationsSpread) {
  21. this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
  22. sheetCommonObj.spreadDefaultStyle(this.sectionRationsSpread);
  23. this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
  24. this.refreshSettingForHint();
  25. }
  26. },
  27. refreshSpread: function () {
  28. if (this.rationChapterSpread) {
  29. this.rationChapterSpread.refresh();
  30. }
  31. if (this.sectionRationsSpread) {
  32. this.sectionRationsSpread.refresh();
  33. }
  34. },
  35. loadStdRationLibs: function () {
  36. let select = $('#stdRationLibSelect');
  37. select.empty();
  38. let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
  39. let selectedRationLib = sessionStorage.getItem('stdRationLib');
  40. ration_lib.forEach(function (data) {
  41. let option = $('<option>').val(data.id).text(data.name);
  42. //select.append($('<option>').val(data.id).text(data.name));
  43. if(selectedRationLib && data.id == selectedRationLib){
  44. option.attr('selected', 'selected');
  45. }
  46. select.append(option);
  47. });
  48. if (select[0].options.length !== 0) {
  49. rationLibObj.loadStdRation(select.val());
  50. }
  51. },
  52. loadStdRation: function (rationLibID) {
  53. var that = this;
  54. var showRationChapterTree = function (datas) {
  55. var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
  56. that.tree = rationChapterTree;
  57. var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, that.rationChapterSpread.getActiveSheet(), that.rationChapterTreeSetting);
  58. rationChapterTree.loadDatas(datas);
  59. //读取展开收起状态
  60. let currentExpState = sessionStorage.getItem('stdRationLibExpState');
  61. if(currentExpState){
  62. that.tree.setExpandedByState(that.tree.items, currentExpState);
  63. }
  64. else {
  65. //展开至第二层
  66. for(let root of that.tree.roots){
  67. root.setExpanded(true);
  68. that.tree.setRootExpanded(root.children, false);
  69. }
  70. }
  71. rationChapterTreeController.showTreeData();
  72. rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  73. rationLibObj.loadSectionRations(node.getID());
  74. });
  75. if (rationChapterTree.firstNode()) {
  76. rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
  77. } else {
  78. rationLibObj.loadSectionRations();
  79. };
  80. };
  81. CommonAjax.post('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID}, function (datas) {
  82. showRationChapterTree(datas);
  83. }, function () {
  84. showRationChapterTree([]);
  85. });
  86. },
  87. //双击隐藏显示
  88. onChapterSpreadCellDoubleClick: function (sender, args) {
  89. let me = rationLibObj;
  90. let node = me.tree.items[args.row];
  91. if (!node || node.children.length === 0)
  92. return;
  93. node.setExpanded(!node.expanded);
  94. sessionStorage.setItem('stdRationLibExpState', me.tree.getExpState(me.tree.items));
  95. TREE_SHEET_HELPER.massOperationSheet(args.sheet, function () {
  96. let iCount = node.posterityCount(), i, child;
  97. for (i = 0; i < iCount; i++) {
  98. child = me.tree.items[args.row + i + 1];
  99. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  100. }
  101. args.sheet.invalidateLayout();
  102. });
  103. args.sheet.repaint();
  104. },
  105. setTagForHint: function (datas) {
  106. let sheet = this.sectionRationsSpread.getActiveSheet();
  107. sheet.suspendPaint();
  108. sheet.suspendEvent();
  109. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  110. sheet.setTag(i, 1, '');
  111. }
  112. for(let i = 0, len = datas.length; i < len; i++){
  113. sheet.setTag(i, 1, datas[i].hint ? datas[i].hint : '');
  114. }
  115. sheet.resumePaint();
  116. sheet.resumeEvent();
  117. },
  118. loadSectionRations: function (sectionID) {
  119. var showDatas = function (datas, setting) {
  120. let rationSheet = rationLibObj.sectionRationsSpread.getActiveSheet();
  121. TREE_SHEET_HELPER.massOperationSheet(rationSheet, function () {
  122. rationSheet.setColumnWidth(0, 25, GC.Spread.Sheets.SheetArea.rowHeader);
  123. });
  124. SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
  125. SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  126. rationLibObj.setTagForHint(datas);
  127. };
  128. if (sectionID) {
  129. CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID}, function (datas) {
  130. showDatas(datas, rationLibObj.sectionRationsSetting);
  131. }, function () {
  132. showDatas([], rationLibObj.sectionRationsSetting);
  133. });
  134. } else {
  135. showDatas([], rationLibObj.sectionRationsSetting);
  136. }
  137. },
  138. onRationSpreadCellDoubleClick: function (sender, args) {
  139. var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
  140. if (rationCode !== '') {
  141. projectObj.project.Ration.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration, function () {
  142. projectObj.setActiveCell('quantity', true);
  143. });
  144. }
  145. },
  146. loadStdRationContextMenu: function () {
  147. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(), rationModel = projectObj.project.Ration;;
  148. $.contextMenu({
  149. selector: '#stdSectionRations',
  150. build: function ($trigger, e) {
  151. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  152. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  153. },
  154. items: {
  155. "insertStdRation": {
  156. name: "插入定额",
  157. icon: 'fa-sign-in',
  158. callback: function (key, opt) {
  159. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  160. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  161. if (rationCode !== '') {
  162. rationModel.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration, function () {
  163. });
  164. }
  165. }
  166. },
  167. "replaceStdRation": {
  168. name: "替换定额",
  169. icon: 'fa-sign-in',
  170. callback: function (key, opt) {
  171. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  172. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  173. let mainTreeSelected = projectObj.project.mainTree.selected;
  174. if (rationCode !== ''&&mainTreeSelected&&mainTreeSelected.sourceType == rationModel.getSourceType()) {
  175. rationModel.updateRationCodes([{'node':mainTreeSelected,value:rationCode}]);
  176. }
  177. }
  178. },
  179. }
  180. });
  181. },
  182. rationChapterTreeSetting: {
  183. "emptyRows":0,
  184. "headRows":1,
  185. "headRowHeight":[30],
  186. "defaultRowHeight": 21,
  187. "treeCol": 0,
  188. "cols":[{
  189. "width":400,
  190. "readOnly": true,
  191. "head":{
  192. "titleNames":["名称"],
  193. "spanCols":[1],
  194. "spanRows":[1],
  195. "vAlign":[1],
  196. "hAlign":[1],
  197. "font":["Arial"]
  198. },
  199. "data":{
  200. "field":"name",
  201. "vAlign":1,
  202. "hAlign":0,
  203. "font":"Arial"
  204. }
  205. }]
  206. },
  207. sectionRationsSetting: {
  208. "emptyRows":3,
  209. "headRows":1,
  210. "headRowHeight":[20],
  211. "defaultRowHeight": 21,
  212. "cols":[{
  213. "width":60,
  214. "readOnly": true,
  215. "head":{
  216. "titleNames":["编码"],
  217. "spanCols":[1],
  218. "spanRows":[1],
  219. "vAlign":[1],
  220. "hAlign":[1],
  221. "font":["Arial"]
  222. },
  223. "data":{
  224. "field":"code",
  225. "vAlign":1,
  226. "hAlign":0,
  227. "font":"Arial"
  228. }
  229. }, {
  230. "width":220,
  231. "readOnly": true,
  232. "showHint": true,
  233. "head":{
  234. "titleNames":["名称"],
  235. "spanCols":[1],
  236. "spanRows":[1],
  237. "vAlign":[1],
  238. "hAlign":[1],
  239. "font":["Arial"]
  240. },
  241. "data":{
  242. "field":"name",
  243. "vAlign":1,
  244. "hAlign":0,
  245. "font":"Arial"
  246. }
  247. }, {
  248. "width":55,
  249. "readOnly":true,
  250. "head":{
  251. "titleNames":["单位"],
  252. "spanCols":[1],
  253. "spanRows":[1],
  254. "vAlign":[1],
  255. "hAlign":[1],
  256. "font":["Arial"]
  257. },
  258. "data":{
  259. "field":"unit",
  260. "vAlign":1,
  261. "hAlign":1,
  262. "font":"Arial"
  263. }
  264. }, {
  265. "width":60,
  266. "readOnly":true,
  267. "head":{
  268. "titleNames":["基价"],
  269. "spanCols":[1],
  270. "spanRows":[1],
  271. "vAlign":[1],
  272. "hAlign":[1],
  273. "font":["Arial"]
  274. },
  275. "data":{
  276. "field":"basePrice",
  277. "vAlign":1,
  278. "hAlign":2,
  279. "font":"Arial"
  280. }
  281. }]
  282. },
  283. getStdRationLibIDs: function () {
  284. let ids = [];
  285. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  286. alert('当前项目无定额库,请添加定额库。');
  287. return null;
  288. }
  289. for(let rationLib of projectInfoObj.projectInfo.engineeringInfo.ration_lib){
  290. ids.push(rationLib.id);
  291. }
  292. return ids;
  293. },
  294. getCurrentStdRationLibID:function () {
  295. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  296. alert('当前项目无定额库,请添加定额库。');
  297. return null;
  298. }
  299. if($('#stdRationLibSelect').val()){
  300. return parseInt($('#stdRationLibSelect').val());
  301. }else {
  302. return projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
  303. }
  304. },
  305. getFirstStdRationLibID: function () {
  306. if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
  307. alert('当前项目无定额库,请添加定额库。');
  308. return null;
  309. }
  310. return parseInt(projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id);
  311. }
  312. };
  313. addEventOnResize(rationLibObj.refreshSettingForHint);
  314. //赋初始高度
  315. if($('#stdRationChapter').height() === 0 || $('#stdSectionRations').height() === 0){
  316. $('#stdRationChapter').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
  317. $('#stdSectionRations').height(270);
  318. }
  319. $('#stdRationTab').bind('click', function () {
  320. var select = $('#stdRationLibSelect');
  321. rationLibObj.checkSpread();
  322. if (select[0].options.length === 0) {
  323. rationLibObj.loadStdRationLibs();
  324. rationLibObj.loadStdRationContextMenu();
  325. };
  326. });
  327. $('#stdRationLibSelect').change(function () {
  328. var select = $(this);
  329. if (this.children.length !== 0) {
  330. let rationLibId = select.val();
  331. sessionStorage.setItem('stdRationLib', rationLibId);
  332. sessionStorage.removeItem('stdRationLibExpState');
  333. rationLibObj.loadStdRation(rationLibId);
  334. }
  335. });
  336. //回车键搜索
  337. $('#rationSearchKeyword').bind('keypress', function (event) {
  338. if(event.keyCode === 13){
  339. $(this).blur();
  340. $('#rationSearch').click();
  341. }
  342. });
  343. $('#rationSearch').click(function () {
  344. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  345. var getResultHtml = function (result) {
  346. var html = [], i, serialNo;
  347. html.push('<div class="d-flex justify-content-between">');
  348. html.push('<span>搜索结果:');
  349. html.push(result.length.toString());
  350. html.push('</span>');
  351. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  352. html.push('</div>');
  353. html.push('<div class="w-100 main-data-side-search">');
  354. html.push('</div>');
  355. return html.join('');
  356. };
  357. var showResult = function (result) {
  358. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  359. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  360. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  361. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  362. };
  363. CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibID, 'keyword': keyword}, function (result) {
  364. //sort
  365. result.sort(function (a, b) {
  366. let rst = 0;
  367. if(a.code > b.code) rst = 1;
  368. else if(a.code < b.code) rst = -1;
  369. return rst;
  370. });
  371. var resultObj = $('#rationSearchResult'), resultSpread = null;
  372. resultObj.empty();
  373. resultObj.append(getResultHtml(result));
  374. $('a', resultObj).click(function () {
  375. resultObj.hide();
  376. $(".main-data-side-search", resultObj).height(0);
  377. autoFlashHeight();
  378. //$(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  379. rationLibObj.refreshSpread();
  380. });
  381. resultObj.show();
  382. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  383. showResult(result);
  384. });
  385. });