std_ration_lib.js 15 KB

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