std_ration_lib.js 15 KB

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