std_ration_lib.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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.postRationLib('/rationRepository/api/getRationTree', {userId: userID, rationRepositoryId: 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.postRationLib('/rationRepository/api/getRationGljItems', {userId: 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. CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
  97. ProjectController.addRation(projectObj.project, projectObj.mainController, rationType.ration, data);
  98. });
  99. }
  100. },
  101. loadStdRationContextMenu: function () {
  102. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet();
  103. $.contextMenu({
  104. selector: '#stdSectionRations',
  105. build: function ($trigger, e) {
  106. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  107. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  108. },
  109. items: {
  110. "insertStdRation": {
  111. name: "插入定额",
  112. icon: 'fa-sign-in',
  113. callback: function (key, opt) {
  114. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  115. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  116. if (rationCode !== '') {
  117. CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
  118. ProjectController.addRation(projectObj.project, projectObj.mainController, rationType.ration, data);
  119. });
  120. }
  121. }
  122. },
  123. "replaceStdRation": {
  124. name: "替换定额",
  125. icon: 'fa-sign-in',
  126. callback: function (key, opt) {
  127. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  128. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  129. if (rationCode !== '') {
  130. CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
  131. ProjectController.replaceRation(projectObj.project, projectObj.mainController, data);
  132. });
  133. }
  134. }
  135. },
  136. }
  137. });
  138. },
  139. rationChapterTreeSetting: {
  140. "emptyRows":0,
  141. "headRows":1,
  142. "headRowHeight":[30],
  143. "defaultRowHeight": 21,
  144. "treeCol": 0,
  145. "cols":[{
  146. "width":400,
  147. "readOnly": true,
  148. "head":{
  149. "titleNames":["名称"],
  150. "spanCols":[1],
  151. "spanRows":[1],
  152. "vAlign":[1],
  153. "hAlign":[1],
  154. "font":["Arial"]
  155. },
  156. "data":{
  157. "field":"name",
  158. "vAlign":1,
  159. "hAlign":0,
  160. "font":"Arial"
  161. }
  162. }]
  163. },
  164. sectionRationsSetting: {
  165. "emptyRows":3,
  166. "headRows":1,
  167. "headRowHeight":[20],
  168. "defaultRowHeight": 21,
  169. "cols":[{
  170. "width":60,
  171. "readOnly": true,
  172. "head":{
  173. "titleNames":["编码"],
  174. "spanCols":[1],
  175. "spanRows":[1],
  176. "vAlign":[1],
  177. "hAlign":[1],
  178. "font":["Arial"]
  179. },
  180. "data":{
  181. "field":"code",
  182. "vAlign":1,
  183. "hAlign":0,
  184. "font":"Arial"
  185. }
  186. }, {
  187. "width":220,
  188. "readOnly": true,
  189. "showHint": true,
  190. "head":{
  191. "titleNames":["名称"],
  192. "spanCols":[1],
  193. "spanRows":[1],
  194. "vAlign":[1],
  195. "hAlign":[1],
  196. "font":["Arial"]
  197. },
  198. "data":{
  199. "field":"name",
  200. "vAlign":1,
  201. "hAlign":0,
  202. "font":"Arial"
  203. }
  204. }, {
  205. "width":55,
  206. "readOnly":true,
  207. "head":{
  208. "titleNames":["单位"],
  209. "spanCols":[1],
  210. "spanRows":[1],
  211. "vAlign":[1],
  212. "hAlign":[1],
  213. "font":["Arial"]
  214. },
  215. "data":{
  216. "field":"unit",
  217. "vAlign":1,
  218. "hAlign":1,
  219. "font":"Arial"
  220. }
  221. }, {
  222. "width":60,
  223. "readOnly":true,
  224. "head":{
  225. "titleNames":["基价"],
  226. "spanCols":[1],
  227. "spanRows":[1],
  228. "vAlign":[1],
  229. "hAlign":[1],
  230. "font":["Arial"]
  231. },
  232. "data":{
  233. "field":"basePrice",
  234. "vAlign":1,
  235. "hAlign":2,
  236. "font":"Arial"
  237. }
  238. }]
  239. }
  240. };
  241. addEventOnResize(rationLibObj.refreshSettingForHint);
  242. $('#stdRationTab').bind('click', function () {
  243. refreshSubSpread();//subSpread、jobSpread、itemSpread显示问题
  244. var select = $('#stdRationLibSelect');
  245. $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  246. rationLibObj.refreshSpread();
  247. rationLibObj.checkSpread();
  248. if (select[0].options.length === 0) {
  249. rationLibObj.loadStdRationLibs();
  250. rationLibObj.loadStdRationContextMenu();
  251. };
  252. });
  253. $('#stdRationLibSelect').change(function () {
  254. var select = $(this);
  255. if (this.children.length !== 0) {
  256. rationLibObj.loadStdRation(select.val());
  257. }
  258. });
  259. $('#rationSearch').click(function () {
  260. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  261. var getResultHtml = function (result) {
  262. var html = [], i, serialNo;
  263. html.push('<div class="d-flex justify-content-between">');
  264. html.push('<span>搜索结果:');
  265. html.push(result.length.toString());
  266. html.push('</span>');
  267. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  268. html.push('</div>');
  269. html.push('<div class="w-100 main-data-side-search">');
  270. html.push('</div>');
  271. return html.join('');
  272. };
  273. var showResult = function (result) {
  274. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  275. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  276. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  277. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  278. };
  279. CommonAjax.postRationLib('/rationRepository/api/findRation', {'user_id': userID, 'rationLibId': rationLibID, 'keyword': keyword}, function (result) {
  280. var resultObj = $('#rationSearchResult'), resultSpread = null;
  281. resultObj.empty();
  282. resultObj.append(getResultHtml(result));
  283. $('a', resultObj).click(function () {
  284. resultObj.hide();
  285. $(".main-data-side-search", resultObj).height(0);
  286. });
  287. resultObj.show();
  288. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  289. showResult(result);
  290. });
  291. });