std_ration_lib.js 8.7 KB

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