std_ration_lib.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. loadStdRationContextMenu: function () {
  84. let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet();
  85. $.contextMenu({
  86. selector: '#stdSectionRations',
  87. build: function ($trigger, e) {
  88. let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
  89. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  90. },
  91. items: {
  92. "insertStdRation": {
  93. name: "插入定额",
  94. icon: 'fa-sign-in',
  95. callback: function (key, opt) {
  96. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  97. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  98. if (rationCode !== '') {
  99. CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
  100. ProjectController.addRation(projectObj.project, projectObj.mainController, data);
  101. });
  102. }
  103. }
  104. },
  105. "replaceStdRation": {
  106. name: "替换定额",
  107. icon: 'fa-sign-in',
  108. callback: function (key, opt) {
  109. let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
  110. let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
  111. if (rationCode !== '') {
  112. CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
  113. ProjectController.replaceRation(projectObj.project, projectObj.mainController, data);
  114. });
  115. }
  116. }
  117. },
  118. }
  119. });
  120. },
  121. rationChapterTreeSetting: {
  122. "emptyRows":0,
  123. "headRows":1,
  124. "headRowHeight":[30],
  125. "defaultRowHeight": 21,
  126. "treeCol": 0,
  127. "cols":[{
  128. "width":300,
  129. "readOnly": true,
  130. "head":{
  131. "titleNames":["名称"],
  132. "spanCols":[1],
  133. "spanRows":[1],
  134. "vAlign":[1],
  135. "hAlign":[1],
  136. "font":["Arial"]
  137. },
  138. "data":{
  139. "field":"name",
  140. "vAlign":1,
  141. "hAlign":0,
  142. "font":"Arial"
  143. }
  144. }]
  145. },
  146. sectionRationsSetting: {
  147. "emptyRows":3,
  148. "headRows":1,
  149. "headRowHeight":[20],
  150. "defaultRowHeight": 21,
  151. "cols":[{
  152. "width":100,
  153. "readOnly": true,
  154. "head":{
  155. "titleNames":["编码"],
  156. "spanCols":[1],
  157. "spanRows":[1],
  158. "vAlign":[1],
  159. "hAlign":[1],
  160. "font":["Arial"]
  161. },
  162. "data":{
  163. "field":"code",
  164. "vAlign":1,
  165. "hAlign":0,
  166. "font":"Arial"
  167. }
  168. }, {
  169. "width":180,
  170. "readOnly": true,
  171. "head":{
  172. "titleNames":["名称"],
  173. "spanCols":[1],
  174. "spanRows":[1],
  175. "vAlign":[1],
  176. "hAlign":[1],
  177. "font":["Arial"]
  178. },
  179. "data":{
  180. "field":"name",
  181. "vAlign":1,
  182. "hAlign":0,
  183. "font":"Arial"
  184. }
  185. }, {
  186. "width":50,
  187. "readOnly":true,
  188. "head":{
  189. "titleNames":["单位"],
  190. "spanCols":[1],
  191. "spanRows":[1],
  192. "vAlign":[1],
  193. "hAlign":[1],
  194. "font":["Arial"]
  195. },
  196. "data":{
  197. "field":"unit",
  198. "vAlign":1,
  199. "hAlign":1,
  200. "font":"Arial"
  201. }
  202. }, {
  203. "width":80,
  204. "readOnly":true,
  205. "head":{
  206. "titleNames":["基价"],
  207. "spanCols":[1],
  208. "spanRows":[1],
  209. "vAlign":[1],
  210. "hAlign":[1],
  211. "font":["Arial"]
  212. },
  213. "data":{
  214. "field":"basePrice",
  215. "vAlign":1,
  216. "hAlign":2,
  217. "font":"Arial"
  218. }
  219. }]
  220. }
  221. };
  222. $('#stdRationTab').bind('click', function () {
  223. refreshSubSpread();//subSpread、jobSpread、itemSpread显示问题
  224. var select = $('#stdRationLibSelect');
  225. $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
  226. rationLibObj.refreshSpread();
  227. rationLibObj.checkSpread();
  228. if (select[0].options.length === 0) {
  229. rationLibObj.loadStdRationLibs();
  230. rationLibObj.loadStdRationContextMenu();
  231. };
  232. });
  233. $('#stdRationLibSelect').change(function () {
  234. var select = $(this);
  235. if (this.children.length !== 0) {
  236. rationLibObj.loadStdRation(select.val());
  237. }
  238. });
  239. $('#rationSearch').click(function () {
  240. var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
  241. var getResultHtml = function (result) {
  242. var html = [], i, serialNo;
  243. html.push('<div class="d-flex justify-content-between">');
  244. html.push('<span>搜索结果:');
  245. html.push(result.length.toString());
  246. html.push('</span>');
  247. html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
  248. html.push('</div>');
  249. html.push('<div class="w-100 main-data-side-search">');
  250. html.push('</div>');
  251. return html.join('');
  252. };
  253. var showResult = function (result) {
  254. var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
  255. SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
  256. SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
  257. resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
  258. };
  259. CommonAjax.postRationLib('/rationRepository/api/findRation', {'user_id': userID, 'rationLibId': rationLibID, 'keyword': keyword}, function (result) {
  260. var resultObj = $('#rationSearchResult'), resultSpread = null;
  261. resultObj.empty();
  262. resultObj.append(getResultHtml(result));
  263. $('a', resultObj).click(function () {
  264. resultObj.hide();
  265. $(".main-data-side-search", resultObj).height(0);
  266. });
  267. resultObj.show();
  268. $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
  269. showResult(result);
  270. });
  271. });