std_ration_lib.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. }
  17. if (!this.sectionRationsSpread) {
  18. this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
  19. this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
  20. this.refreshSettingForHint();
  21. }
  22. },
  23. refreshSpread: function () {
  24. if (this.rationChapterSpread) {
  25. this.rationChapterSpread.refresh();
  26. }
  27. if (this.sectionRationsSpread) {
  28. this.sectionRationsSpread.refresh();
  29. }
  30. },
  31. loadStdRationLibs: function () {
  32. let select = $('#stdRationLibSelect');
  33. select.empty();
  34. let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
  35. ration_lib.forEach(function (data) {
  36. select.append($('<option>').val(data.id).text(data.name));
  37. });
  38. if (select[0].options.length !== 0) {
  39. rationLibObj.loadStdRation(select.val());
  40. }
  41. },
  42. loadStdRation: function (rationLibID) {
  43. var that = this;
  44. var showRationChapterTree = function (datas) {
  45. var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
  46. var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, that.rationChapterSpread.getActiveSheet(), that.rationChapterTreeSetting);
  47. rationChapterTree.loadDatas(datas);
  48. rationChapterTreeController.showTreeData();
  49. rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  50. rationLibObj.loadSectionRations(node.getID());
  51. });
  52. if (rationChapterTree.firstNode()) {
  53. rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
  54. } else {
  55. rationLibObj.loadSectionRations();
  56. };
  57. };
  58. CommonAjax.post('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID}, function (datas) {
  59. showRationChapterTree(datas);
  60. }, function () {
  61. showRationChapterTree([]);
  62. });
  63. },
  64. setTagForHint: function (datas) {
  65. let sheet = this.sectionRationsSpread.getActiveSheet();
  66. sheet.suspendPaint();
  67. sheet.suspendEvent();
  68. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  69. sheet.setTag(i, 1, '');
  70. }
  71. for(let i = 0, len = datas.length; i < len; i++){
  72. sheet.setTag(i, 1, datas[i].hint ? datas[i].hint : '');
  73. }
  74. sheet.resumePaint();
  75. sheet.resumeEvent();
  76. },
  77. loadSectionRations: function (sectionID) {
  78. var showDatas = function (datas, setting) {
  79. SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
  80. SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  81. rationLibObj.setTagForHint(datas);
  82. };
  83. if (sectionID) {
  84. CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID}, function (datas) {
  85. showDatas(datas, rationLibObj.sectionRationsSetting);
  86. }, function () {
  87. showDatas([], rationLibObj.sectionRationsSetting);
  88. });
  89. } else {
  90. showDatas([], rationLibObj.sectionRationsSetting);
  91. }
  92. },
  93. onRationSpreadCellDoubleClick: function (sender, args) {
  94. var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
  95. if (rationCode !== '') {
  96. projectObj.project.Ration.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration);
  97. }
  98. },
  99. loadStdRationContextMenu: function () {
  100. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(), rationModel = projectObj.project.Ration;;
  101. $.contextMenu({
  102. selector: '#stdSectionRations',
  103. build: function ($trigger, e) {
  104. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  105. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  106. },
  107. items: {
  108. "insertStdRation": {
  109. name: "插入定额",
  110. icon: 'fa-sign-in',
  111. callback: function (key, opt) {
  112. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  113. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  114. if (rationCode !== '') {
  115. rationModel.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration);
  116. }
  117. }
  118. },
  119. "replaceStdRation": {
  120. name: "替换定额",
  121. icon: 'fa-sign-in',
  122. callback: function (key, opt) {
  123. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  124. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  125. let mainTreeSelected = projectObj.project.mainTree.selected;
  126. if (rationCode !== ''&&mainTreeSelected&&mainTreeSelected.sourceType == rationModel.getSourceType()) {
  127. rationModel.updateRationCodes([{'node':mainTreeSelected,value:rationCode}]);
  128. }
  129. }
  130. },
  131. }
  132. });
  133. },
  134. rationChapterTreeSetting: {
  135. "emptyRows":0,
  136. "headRows":1,
  137. "headRowHeight":[30],
  138. "defaultRowHeight": 21,
  139. "treeCol": 0,
  140. "cols":[{
  141. "width":400,
  142. "readOnly": true,
  143. "head":{
  144. "titleNames":["名称"],
  145. "spanCols":[1],
  146. "spanRows":[1],
  147. "vAlign":[1],
  148. "hAlign":[1],
  149. "font":["Arial"]
  150. },
  151. "data":{
  152. "field":"name",
  153. "vAlign":1,
  154. "hAlign":0,
  155. "font":"Arial"
  156. }
  157. }]
  158. },
  159. sectionRationsSetting: {
  160. "emptyRows":3,
  161. "headRows":1,
  162. "headRowHeight":[20],
  163. "defaultRowHeight": 21,
  164. "cols":[{
  165. "width":60,
  166. "readOnly": true,
  167. "head":{
  168. "titleNames":["编码"],
  169. "spanCols":[1],
  170. "spanRows":[1],
  171. "vAlign":[1],
  172. "hAlign":[1],
  173. "font":["Arial"]
  174. },
  175. "data":{
  176. "field":"code",
  177. "vAlign":1,
  178. "hAlign":0,
  179. "font":"Arial"
  180. }
  181. }, {
  182. "width":220,
  183. "readOnly": true,
  184. "showHint": true,
  185. "head":{
  186. "titleNames":["名称"],
  187. "spanCols":[1],
  188. "spanRows":[1],
  189. "vAlign":[1],
  190. "hAlign":[1],
  191. "font":["Arial"]
  192. },
  193. "data":{
  194. "field":"name",
  195. "vAlign":1,
  196. "hAlign":0,
  197. "font":"Arial"
  198. }
  199. }, {
  200. "width":55,
  201. "readOnly":true,
  202. "head":{
  203. "titleNames":["单位"],
  204. "spanCols":[1],
  205. "spanRows":[1],
  206. "vAlign":[1],
  207. "hAlign":[1],
  208. "font":["Arial"]
  209. },
  210. "data":{
  211. "field":"unit",
  212. "vAlign":1,
  213. "hAlign":1,
  214. "font":"Arial"
  215. }
  216. }, {
  217. "width":60,
  218. "readOnly":true,
  219. "head":{
  220. "titleNames":["基价"],
  221. "spanCols":[1],
  222. "spanRows":[1],
  223. "vAlign":[1],
  224. "hAlign":[1],
  225. "font":["Arial"]
  226. },
  227. "data":{
  228. "field":"basePrice",
  229. "vAlign":1,
  230. "hAlign":2,
  231. "font":"Arial"
  232. }
  233. }]
  234. }
  235. };
  236. addEventOnResize(rationLibObj.refreshSettingForHint);
  237. $('#stdRationTab').bind('click', function () {
  238. refreshSubSpread();//subSpread、jobSpread、itemSpread显示问题
  239. var select = $('#stdRationLibSelect');
  240. $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  241. rationLibObj.refreshSpread();
  242. rationLibObj.checkSpread();
  243. if (select[0].options.length === 0) {
  244. rationLibObj.loadStdRationLibs();
  245. rationLibObj.loadStdRationContextMenu();
  246. };
  247. });
  248. $('#stdRationLibSelect').change(function () {
  249. var select = $(this);
  250. if (this.children.length !== 0) {
  251. rationLibObj.loadStdRation(select.val());
  252. }
  253. });
  254. $('#rationSearch').click(function () {
  255. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  256. var getResultHtml = function (result) {
  257. var html = [], i, serialNo;
  258. html.push('<div class="d-flex justify-content-between">');
  259. html.push('<span>搜索结果:');
  260. html.push(result.length.toString());
  261. html.push('</span>');
  262. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  263. html.push('</div>');
  264. html.push('<div class="w-100 main-data-side-search">');
  265. html.push('</div>');
  266. return html.join('');
  267. };
  268. var showResult = function (result) {
  269. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  270. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  271. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  272. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  273. };
  274. CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibID, 'keyword': keyword}, function (result) {
  275. //sort
  276. result.sort(function (a, b) {
  277. let rst = 0;
  278. if(a.code > b.code) rst = 1;
  279. else if(a.code < b.code) rst = -1;
  280. return rst;
  281. });
  282. var resultObj = $('#rationSearchResult'), resultSpread = null;
  283. resultObj.empty();
  284. resultObj.append(getResultHtml(result));
  285. $('a', resultObj).click(function () {
  286. resultObj.hide();
  287. $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  288. $(".main-data-side-search", resultObj).height(0);
  289. });
  290. resultObj.show();
  291. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  292. showResult(result);
  293. });
  294. });