std_ration_lib.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * Created by Mai on 2017/5/16.
  3. */
  4. var rationChapterSpread, sectionRationsSpread;
  5. var LoadStdRationLibs = function () {
  6. CommonAjax.postRationLib('/rationRepository/api/getRationDisplayNames', {user_id: userID}, function (datas) {
  7. var select = $('#stdRationLibSelect');
  8. select.empty();
  9. datas.forEach(function (data) {
  10. select.append($('<option>').val(data.ID).text(data.dispName));
  11. });
  12. if (select[0].options.length !== 0) {
  13. LoadStdRation(select.val());
  14. }
  15. }, function () {
  16. $('#stdRationLibSelect').empty();
  17. });
  18. };
  19. var LoadStdRation = (function () {
  20. var rationChapterTreeSetting = {
  21. "emptyRows":0,
  22. "headRows":1,
  23. "headRowHeight":[30],
  24. "treeCol": 0,
  25. "cols":[{
  26. "width":300,
  27. "readOnly": true,
  28. "head":{
  29. "titleNames":["名称"],
  30. "spanCols":[1],
  31. "spanRows":[1],
  32. "vAlign":[1],
  33. "hAlign":[1],
  34. "font":["9px Arial"]
  35. },
  36. "data":{
  37. "field":"name",
  38. "vAlign":0,
  39. "hAlign":3,
  40. "font":"9px Arial"
  41. }
  42. }]
  43. };
  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, rationChapterSpread.getActiveSheet(), rationChapterTreeSetting);
  47. rationChapterTree.loadDatas(datas);
  48. rationChapterTreeController.showTreeData();
  49. rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  50. LoadSectionRations(node.getID());
  51. });
  52. if (rationChapterTree.firstNode()) {
  53. LoadSectionRations(rationChapterTree.firstNode().getID());
  54. } else {
  55. LoadSectionRations();
  56. };
  57. };
  58. var LoadData = function (rationLibID) {
  59. CommonAjax.postRationLib('/rationRepository/api/getRationTree', {userId: userID, rationRepositoryId: rationLibID}, function (datas) {
  60. showRationChapterTree(datas);
  61. }, function () {
  62. showRationChapterTree([]);
  63. });
  64. };
  65. return LoadData;
  66. })();
  67. var LoadSectionRations = (function () {
  68. var sectionRationsSetting = {
  69. "emptyRows":3,
  70. "headRows":1,
  71. "headRowHeight":[20],
  72. "cols":[
  73. {
  74. "width":100,
  75. "readOnly": true,
  76. "head":{
  77. "titleNames":["编码"],
  78. "spanCols":[1],
  79. "spanRows":[1],
  80. "vAlign":[1],
  81. "hAlign":[1],
  82. "font":["12px Arial"]
  83. },
  84. "data":{
  85. "field":"code",
  86. "vAlign":0,
  87. "hAlign":3,
  88. "font":"12px Arial"
  89. }
  90. },
  91. {
  92. "width":180,
  93. "readOnly": true,
  94. "head":{
  95. "titleNames":["名称"],
  96. "spanCols":[1],
  97. "spanRows":[1],
  98. "vAlign":[1],
  99. "hAlign":[1],
  100. "font":["12px Arial"]
  101. },
  102. "data":{
  103. "field":"name",
  104. "vAlign":0,
  105. "hAlign":3,
  106. "font":"12px Arial"
  107. }
  108. },
  109. {
  110. "width":50,
  111. "readOnly":true,
  112. "head":{
  113. "titleNames":["单位"],
  114. "spanCols":[1],
  115. "spanRows":[1],
  116. "vAlign":[1],
  117. "hAlign":[1],
  118. "font":["12px Arial"]
  119. },
  120. "data":{
  121. "field":"unit",
  122. "vAlign":0,
  123. "hAlign":1,
  124. "font":"12px Arial"
  125. }
  126. }
  127. ]
  128. };
  129. var LoadData = function (sectionID) {
  130. if (sectionID) {
  131. CommonAjax.postRationLib('/rationRepository/api/getRationItems', {userId: userID, sectionID: sectionID}, function (datas) {
  132. SheetDataHelper.loadSheetHeader(sectionRationsSetting, sectionRationsSpread.getActiveSheet());
  133. SheetDataHelper.loadSheetData(sectionRationsSetting, sectionRationsSpread.getActiveSheet(), datas);
  134. }, function () {
  135. SheetDataHelper.loadSheetHeader(sectionRationsSetting, sectionRationsSpread.getActiveSheet());
  136. SheetDataHelper.loadSheetData(sectionRationsSetting, sectionRationsSpread.getActiveSheet(), []);
  137. });
  138. } else {
  139. SheetDataHelper.loadSheetHeader(sectionRationsSetting, sectionRationsSpread.getActiveSheet());
  140. SheetDataHelper.loadSheetData(sectionRationsSetting, sectionRationsSpread.getActiveSheet(), []);
  141. }
  142. };
  143. return LoadData;
  144. })();
  145. $('#stdRationTab').on('shown.bs.tab', function (e) {
  146. var select = $('#stdRationLibSelect');
  147. if (!rationChapterSpread) {
  148. rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
  149. }
  150. if (!sectionRationsSpread) {
  151. sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
  152. }
  153. if (select[0].options.length === 0) {
  154. LoadStdRationLibs();
  155. };
  156. });
  157. $('#stdRationLibSelect').change(function () {
  158. var select = $(this);
  159. if (this.children.length !== 0) {
  160. LoadStdRation(select.val());
  161. }
  162. rationChapterSpread.getActiveSheet().repaint();
  163. });