std_ration_lib.js 8.7 KB

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