ListController.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. Ext.define('school.view.setting.device.ListController', {
  2. extend: 'school.view.core.base.BasePanelController',
  3. alias: 'controller.setting-device-list',
  4. onAddClick: function () {
  5. let me = this,
  6. view = me.getView(),
  7. win = Ext.getCmp('device-addwin');
  8. if (!win) {
  9. win = Ext.create('Ext.window.Window', {
  10. title: '新增设备信息',
  11. width: 450,
  12. height: 380,
  13. id: 'device-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: 'deviceIp',
  27. emptyText: '设备IP',
  28. allowBlank: false,
  29. maxLength: 20
  30. }, {
  31. xtype: 'textfield',
  32. name: 'deviceName',
  33. emptyText: '设备名称',
  34. allowBlank: false,
  35. maxLength: 20
  36. }, {
  37. xtype: 'textfield',
  38. name: 'deviceUser',
  39. emptyText: '用户',
  40. allowBlank: false,
  41. maxLength: 20
  42. }, {
  43. xtype: 'textfield',
  44. name: 'devicePassword',
  45. emptyText: '密码',
  46. allowBlank: false,
  47. maxLength: 20
  48. }, {
  49. xtype: 'textfield',
  50. name: 'devicePort',
  51. emptyText: '端口',
  52. allowBlank: false,
  53. maxLength: 20
  54. }, {
  55. xtype: 'textfield',
  56. name: 'deviceRemark',
  57. emptyText: '备注'
  58. }],
  59. buttonAlign: 'center',
  60. buttons: [{
  61. text: '确定',
  62. formBind: true,
  63. handler: function () {
  64. let form = this.up('form');
  65. let values = form.getValues();
  66. let url, params, headers;
  67. params = JSON.stringify(values);
  68. view.setLoading(true);
  69. school.util.BaseUtil.request({
  70. // url: 'http://10.1.80.47:9520/api/device/device/save',
  71. url: '/api/device/device/save',
  72. method: 'POST',
  73. params: params,
  74. headers: headers
  75. }).then(function (res) {
  76. view.setLoading(false);
  77. win.close();
  78. school.util.BaseUtil.showSuccessToast('添加成功');
  79. view.refresh();
  80. }).catch(function (e) {
  81. view.setLoading(false);
  82. school.util.BaseUtil.showErrorToast('添加失败: ' + e.message);
  83. });
  84. }
  85. }]
  86. }]
  87. });
  88. view.add(win);
  89. }
  90. win.show();
  91. },
  92. onActionClick: function(tableView, td, row, col, e, record, tr) {
  93. let me = this;
  94. let targetCls = event.target.classList;
  95. if(targetCls.contains('fa-pencil')) {
  96. me.modifyClick(record.data);
  97. }else if(targetCls.contains('fa-trash-o')) {
  98. me.onDeleteClick(record);
  99. }
  100. },
  101. modifyClick: function (data) {
  102. let me = this,
  103. view = me.getView(),
  104. win = Ext.getCmp('device-modifywin');
  105. if (!win) {
  106. win = Ext.create('Ext.window.Window', {
  107. title: '修改设备信息',
  108. width: 450,
  109. height: 380,
  110. id: 'device-modifywin',
  111. constrain: true,
  112. modal: true,
  113. bodyPadding: 10,
  114. layout: 'fit',
  115. items: [{
  116. xtype: 'form',
  117. layout: 'column',
  118. defaults: {
  119. columnWidth: 1
  120. },
  121. items: [{
  122. xtype: 'textfield',
  123. name: 'deviceId',
  124. emptyText: '设备ID',
  125. hidden: true,
  126. maxLength: 20
  127. }, {
  128. xtype: 'textfield',
  129. name: 'deviceIp',
  130. emptyText: '设备IP',
  131. allowBlank: false,
  132. maxLength: 20
  133. }, {
  134. xtype: 'textfield',
  135. name: 'deviceName',
  136. emptyText: '设备名称',
  137. allowBlank: false,
  138. maxLength: 20
  139. }, {
  140. xtype: 'textfield',
  141. name: 'deviceUser',
  142. emptyText: '用户',
  143. allowBlank: false,
  144. maxLength: 20
  145. }, {
  146. xtype: 'textfield',
  147. name: 'devicePassword',
  148. emptyText: '密码',
  149. allowBlank: false,
  150. maxLength: 20
  151. }, {
  152. xtype: 'textfield',
  153. name: 'devicePort',
  154. emptyText: '端口',
  155. allowBlank: false,
  156. maxLength: 20
  157. }, {
  158. xtype: 'textfield',
  159. name: 'deviceRemark',
  160. emptyText: '备注'
  161. }],
  162. buttonAlign: 'center',
  163. buttons: [{
  164. text: '确定',
  165. formBind: true,
  166. handler: function () {
  167. let form = this.up('form');
  168. let values = form.getValues();
  169. let params, headers;
  170. params = JSON.stringify(values);
  171. view.setLoading(true);
  172. school.util.BaseUtil.request({
  173. // url: 'http://10.1.80.47:9520/api/device/device/save',
  174. url: '/api/device/device/save',
  175. method: 'POST',
  176. params: params,
  177. headers: headers
  178. }).then(function (res) {
  179. view.setLoading(false);
  180. win.close();
  181. school.util.BaseUtil.showSuccessToast('修改成功');
  182. view.refresh();
  183. }).catch(function (e) {
  184. view.setLoading(false);
  185. school.util.BaseUtil.showErrorToast('修改失败: ' + e.message);
  186. });
  187. }
  188. }]
  189. }]
  190. });
  191. view.add(win);
  192. win.down('form').getForm().findField('deviceId').setValue(data.deviceId);
  193. win.down('form').getForm().findField('deviceIp').setValue(data.deviceIp);
  194. win.down('form').getForm().findField('deviceName').setValue(data.deviceName);
  195. win.down('form').getForm().findField('deviceUser').setValue(data.deviceUser);
  196. win.down('form').getForm().findField('devicePassword').setValue(data.devicePassword);
  197. win.down('form').getForm().findField('devicePort').setValue(data.devicePort);
  198. win.down('form').getForm().findField('deviceRemark').setValue(data.deviceRemark);
  199. }
  200. win.show();
  201. },
  202. onDeleteClick: function(record) {
  203. let me = this,
  204. view = me.getView(),
  205. grid = view.down('grid'),
  206. id = record.data.deviceId,
  207. data;
  208. data = [{
  209. id: id
  210. }];
  211. school.util.BaseUtil.showConfirm('确认删除', '确定要删除设备' + record.get('deviceName') + '吗?')
  212. .then(function(yes) {
  213. if(yes == 'yes') {
  214. grid.setLoading(true);
  215. school.util.BaseUtil.request({
  216. // url: 'http://10.1.80.47:9520/api/device/device/batchDelete',
  217. url: '/api/device/device/batchDelete',
  218. method: 'POST',
  219. params: JSON.stringify({
  220. baseDTOs: data
  221. })
  222. }).then(function(res) {
  223. grid.setLoading(false);
  224. school.util.BaseUtil.showSuccessToast('成功删除' + data.length + '条记录');
  225. grid.store.loadPage(grid.store.currentPage);
  226. }).catch(function(e) {
  227. grid.setLoading(false);
  228. school.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  229. });
  230. }
  231. });
  232. }
  233. });