std_ration_lib.js 6.5 KB

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