std_ration_lib.js 6.2 KB

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