std_ration_lib.js 15 KB

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