std_ration_lib.js 8.4 KB

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