std_ration_lib.js 6.5 KB

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