std_ration_lib.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. checkSpread: function () {
  11. if (!this.rationChapterSpread) {
  12. this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
  13. }
  14. if (!this.sectionRationsSpread) {
  15. this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
  16. this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
  17. }
  18. },
  19. refreshSpread: function () {
  20. if (this.rationChapterSpread) {
  21. this.rationChapterSpread.refresh();
  22. }
  23. if (this.sectionRationsSpread) {
  24. this.sectionRationsSpread.refresh();
  25. }
  26. },
  27. loadStdRationLibs: function () {
  28. CommonAjax.postRationLib('/rationRepository/api/getRationDisplayNames', {user_id: userID}, function (datas) {
  29. var select = $('#stdRationLibSelect');
  30. select.empty();
  31. datas.forEach(function (data) {
  32. select.append($('<option>').val(data.ID).text(data.dispName));
  33. });
  34. if (select[0].options.length !== 0) {
  35. rationLibObj.loadStdRation(select.val());
  36. }
  37. }, function () {
  38. $('#stdRationLibSelect').empty();
  39. });
  40. },
  41. loadStdRation: function (rationLibID) {
  42. var that = this;
  43. var showRationChapterTree = function (datas) {
  44. var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
  45. var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, that.rationChapterSpread.getActiveSheet(), that.rationChapterTreeSetting);
  46. rationChapterTree.loadDatas(datas);
  47. rationChapterTreeController.showTreeData();
  48. rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  49. rationLibObj.loadSectionRations(node.getID());
  50. });
  51. if (rationChapterTree.firstNode()) {
  52. rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
  53. } else {
  54. rationLibObj.loadSectionRations();
  55. };
  56. };
  57. CommonAjax.postRationLib('/rationRepository/api/getRationTree', {userId: userID, rationRepositoryId: rationLibID}, function (datas) {
  58. showRationChapterTree(datas);
  59. }, function () {
  60. showRationChapterTree([]);
  61. });
  62. },
  63. loadSectionRations: function (sectionID) {
  64. var showDatas = function (datas, setting) {
  65. SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
  66. SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  67. };
  68. if (sectionID) {
  69. CommonAjax.postRationLib('/rationRepository/api/getRationItems', {userId: userID, sectionID: sectionID}, function (datas) {
  70. showDatas(datas, rationLibObj.sectionRationsSetting);
  71. }, function () {
  72. showDatas([], rationLibObj.sectionRationsSetting);
  73. });
  74. } else {
  75. showDatas([], rationLibObj.sectionRationsSetting);
  76. }
  77. },
  78. onRationSpreadCellDoubleClick: function (sender, args) {
  79. var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
  80. if (rationCode !== '') {
  81. CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
  82. ProjectController.addRation(projectObj.project, projectObj.mainController, data);
  83. });
  84. }
  85. },
  86. rationChapterTreeSetting: {
  87. "emptyRows":0,
  88. "headRows":1,
  89. "headRowHeight":[30],
  90. "defaultRowHeight": 21,
  91. "treeCol": 0,
  92. "cols":[{
  93. "width":300,
  94. "readOnly": true,
  95. "head":{
  96. "titleNames":["名称"],
  97. "spanCols":[1],
  98. "spanRows":[1],
  99. "vAlign":[1],
  100. "hAlign":[1],
  101. "font":["Arial"]
  102. },
  103. "data":{
  104. "field":"name",
  105. "vAlign":1,
  106. "hAlign":0,
  107. "font":"Arial"
  108. }
  109. }]
  110. },
  111. sectionRationsSetting: {
  112. "emptyRows":3,
  113. "headRows":1,
  114. "headRowHeight":[20],
  115. "defaultRowHeight": 21,
  116. "cols":[{
  117. "width":100,
  118. "readOnly": true,
  119. "head":{
  120. "titleNames":["编码"],
  121. "spanCols":[1],
  122. "spanRows":[1],
  123. "vAlign":[1],
  124. "hAlign":[1],
  125. "font":["Arial"]
  126. },
  127. "data":{
  128. "field":"code",
  129. "vAlign":1,
  130. "hAlign":0,
  131. "font":"Arial"
  132. }
  133. }, {
  134. "width":180,
  135. "readOnly": true,
  136. "head":{
  137. "titleNames":["名称"],
  138. "spanCols":[1],
  139. "spanRows":[1],
  140. "vAlign":[1],
  141. "hAlign":[1],
  142. "font":["Arial"]
  143. },
  144. "data":{
  145. "field":"name",
  146. "vAlign":1,
  147. "hAlign":0,
  148. "font":"Arial"
  149. }
  150. }, {
  151. "width":50,
  152. "readOnly":true,
  153. "head":{
  154. "titleNames":["单位"],
  155. "spanCols":[1],
  156. "spanRows":[1],
  157. "vAlign":[1],
  158. "hAlign":[1],
  159. "font":["Arial"]
  160. },
  161. "data":{
  162. "field":"unit",
  163. "vAlign":1,
  164. "hAlign":1,
  165. "font":"Arial"
  166. }
  167. }, {
  168. "width":80,
  169. "readOnly":true,
  170. "head":{
  171. "titleNames":["基价"],
  172. "spanCols":[1],
  173. "spanRows":[1],
  174. "vAlign":[1],
  175. "hAlign":[1],
  176. "font":["Arial"]
  177. },
  178. "data":{
  179. "field":"basePrice",
  180. "vAlign":1,
  181. "hAlign":2,
  182. "font":"Arial"
  183. }
  184. }]
  185. }
  186. };
  187. $('#stdRationTab').bind('click', function () {
  188. var select = $('#stdRationLibSelect');
  189. $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  190. rationLibObj.refreshSpread();
  191. rationLibObj.checkSpread();
  192. if (select[0].options.length === 0) {
  193. rationLibObj.loadStdRationLibs();
  194. };
  195. });
  196. $('#stdRationLibSelect').change(function () {
  197. var select = $(this);
  198. if (this.children.length !== 0) {
  199. rationLibObj.loadStdRation(select.val());
  200. }
  201. });
  202. $('#rationSearch').click(function () {
  203. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  204. var getResultHtml = function (result) {
  205. var html = [], i, serialNo;
  206. html.push('<div class="d-flex justify-content-between">');
  207. html.push('<span>搜索结果:');
  208. html.push(result.length.toString());
  209. html.push('</span>');
  210. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  211. html.push('</div>');
  212. html.push('<div class="w-100 main-data-side-search">');
  213. html.push('</div>');
  214. return html.join('');
  215. };
  216. var showResult = function (result) {
  217. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  218. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  219. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  220. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  221. };
  222. CommonAjax.postRationLib('/rationRepository/api/findRation', {'user_id': userID, 'rationLibId': rationLibID, 'keyword': keyword}, function (result) {
  223. var resultObj = $('#rationSearchResult'), resultSpread = null;
  224. resultObj.empty();
  225. resultObj.append(getResultHtml(result));
  226. $('a', resultObj).click(function () {
  227. resultObj.hide();
  228. $(".main-data-side-search", resultObj).height(0);
  229. });
  230. resultObj.show();
  231. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  232. showResult(result);
  233. });
  234. });