ListController.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. Ext.define('school.view.basic.subject.ListController', {
  2. extend: 'school.view.core.base.BasePanelController',
  3. alias: 'controller.basic-subject-list',
  4. onAddClick: function () {
  5. let me = this,
  6. view = me.getView(),
  7. win = Ext.getCmp('subject-addwin');
  8. if (!win) {
  9. win = Ext.create('Ext.window.Window', {
  10. title: '新增学科信息',
  11. width: 300,
  12. height: 180,
  13. id: 'subject-addwin',
  14. constrain: true,
  15. modal: true,
  16. bodyPadding: 10,
  17. layout: 'fit',
  18. items: [{
  19. xtype: 'form',
  20. layout: 'column',
  21. defaults: {
  22. columnWidth: 1
  23. },
  24. items: [{
  25. xtype: 'textfield',
  26. name: 'text',
  27. emptyText: '学科名称',
  28. allowBlank: false,
  29. maxLength: 20
  30. }],
  31. buttonAlign: 'center',
  32. buttons: [{
  33. text: '确定',
  34. formBind: true,
  35. handler: function () {
  36. let form = this.up('form');
  37. let text = form.getValues().text;
  38. let url, params, headers;
  39. params = JSON.stringify({
  40. subject_name: text
  41. });
  42. view.setLoading(true);
  43. school.util.BaseUtil.request({
  44. url: '/api/school/subject/save',
  45. method: 'POST',
  46. params: params,
  47. headers: headers
  48. }).then(function (res) {
  49. view.setLoading(false);
  50. win.close();
  51. school.util.BaseUtil.showSuccessToast('添加成功');
  52. view.refresh();
  53. }).catch(function (e) {
  54. view.setLoading(false);
  55. school.util.BaseUtil.showErrorToast('添加失败: ' + e.message);
  56. });
  57. }
  58. }]
  59. }]
  60. });
  61. view.add(win);
  62. }
  63. win.show();
  64. },
  65. onActionClick: function(tableView, td, row, col, e, record, tr) {
  66. let me = this;
  67. let targetCls = event.target.classList;
  68. if(targetCls.contains('fa-pencil')) {
  69. me.modifyClick(record.data);
  70. }else if(targetCls.contains('fa-trash-o')) {
  71. me.onDeleteClick(record.data.subject_id);
  72. }
  73. },
  74. modifyClick: function (data) {
  75. let me = this,
  76. view = me.getView(),
  77. win = Ext.getCmp('subject-modifywin');
  78. if (!win) {
  79. win = Ext.create('Ext.window.Window', {
  80. title: '修改学科信息',
  81. width: 300,
  82. height: 180,
  83. id: 'subject-modifywin',
  84. constrain: true,
  85. modal: true,
  86. bodyPadding: 10,
  87. layout: 'fit',
  88. items: [{
  89. xtype: 'form',
  90. layout: 'column',
  91. defaults: {
  92. columnWidth: 1
  93. },
  94. items: [{
  95. xtype: 'textfield',
  96. name: 'text',
  97. emptyText: '学科名称',
  98. allowBlank: false,
  99. maxLength: 20
  100. }],
  101. buttonAlign: 'center',
  102. buttons: [{
  103. text: '确定',
  104. formBind: true,
  105. handler: function () {
  106. let form = this.up('form');
  107. let text = form.getValues().text;
  108. let url, params, headers;
  109. params = JSON.stringify({
  110. subject_id: data.subject_id,
  111. subject_name: text
  112. });
  113. view.setLoading(true);
  114. school.util.BaseUtil.request({
  115. url: '/api/school/subject/save',
  116. method: 'POST',
  117. params: params,
  118. headers: headers
  119. }).then(function (res) {
  120. view.setLoading(false);
  121. win.close();
  122. school.util.BaseUtil.showSuccessToast('修改成功');
  123. view.refresh();
  124. }).catch(function (e) {
  125. view.setLoading(false);
  126. school.util.BaseUtil.showErrorToast('修改失败: ' + e.message);
  127. });
  128. }
  129. }]
  130. }]
  131. });
  132. view.add(win);
  133. win.down('form').getForm().findField('text').setValue(data.subject_name);
  134. }
  135. win.show();
  136. },
  137. onDeleteClick: function(id) {
  138. let me = this,
  139. view = me.getView(),
  140. grid = view.down('grid'),
  141. selectedRecords = grid.getSelection(),
  142. data;
  143. data = id ? [{
  144. id: id
  145. }] : selectedRecords.map(function(r) {
  146. return {
  147. id: r.get('subject_id')
  148. };
  149. });
  150. if(data.length == 0) {
  151. school.util.BaseUtil.showErrorToast('请先勾选需要删除的记录');
  152. return;
  153. }
  154. grid.setLoading(true);
  155. school.util.BaseUtil.request({
  156. // url: 'http://10.1.80.47:9560/student/batchDelete',
  157. url: '/api/school/subject/batchDelete',
  158. method: 'POST',
  159. params: JSON.stringify({
  160. baseDTOs: data
  161. })
  162. }).then(function(res) {
  163. grid.setLoading(false);
  164. school.util.BaseUtil.showSuccessToast('成功删除' + data.length + '条记录');
  165. grid.store.loadPage(grid.store.currentPage);
  166. }).catch(function(e) {
  167. grid.setLoading(false);
  168. school.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  169. });
  170. }
  171. });