| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- Ext.define('school.view.setting.device.ListController', {
- extend: 'school.view.core.base.BasePanelController',
- alias: 'controller.setting-device-list',
- onAddClick: function () {
- let me = this,
- view = me.getView(),
- win = Ext.getCmp('device-addwin');
- if (!win) {
- win = Ext.create('Ext.window.Window', {
- title: '新增设备信息',
- width: 450,
- height: 380,
- id: 'device-addwin',
- constrain: true,
- modal: true,
- bodyPadding: 10,
- layout: 'fit',
- items: [{
- xtype: 'form',
- layout: 'column',
- defaults: {
- columnWidth: 1
- },
- items: [{
- xtype: 'textfield',
- name: 'deviceIp',
- emptyText: '设备IP',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'deviceName',
- emptyText: '设备名称',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'deviceUser',
- emptyText: '用户',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'devicePassword',
- emptyText: '密码',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'devicePort',
- emptyText: '端口',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'deviceRemark',
- emptyText: '备注'
- }],
- buttonAlign: 'center',
- buttons: [{
- text: '确定',
- formBind: true,
- handler: function () {
- let form = this.up('form');
- let values = form.getValues();
- let url, params, headers;
-
- params = JSON.stringify(values);
- view.setLoading(true);
- school.util.BaseUtil.request({
- // url: 'http://10.1.80.47:9520/api/device/device/save',
- url: '/api/device/device/save',
- method: 'POST',
- params: params,
- headers: headers
- }).then(function (res) {
- view.setLoading(false);
- win.close();
- school.util.BaseUtil.showSuccessToast('添加成功');
- view.refresh();
- }).catch(function (e) {
- view.setLoading(false);
- school.util.BaseUtil.showErrorToast('添加失败: ' + e.message);
- });
- }
- }]
- }]
- });
- view.add(win);
- }
- win.show();
- },
- onActionClick: function(tableView, td, row, col, e, record, tr) {
- let me = this;
- let targetCls = event.target.classList;
- if(targetCls.contains('fa-pencil')) {
- me.modifyClick(record.data);
- }else if(targetCls.contains('fa-trash-o')) {
- me.onDeleteClick(record);
- }
- },
- modifyClick: function (data) {
- let me = this,
- view = me.getView(),
- win = Ext.getCmp('device-modifywin');
- if (!win) {
- win = Ext.create('Ext.window.Window', {
- title: '修改设备信息',
- width: 450,
- height: 380,
- id: 'device-modifywin',
- constrain: true,
- modal: true,
- bodyPadding: 10,
- layout: 'fit',
- items: [{
- xtype: 'form',
- layout: 'column',
- defaults: {
- columnWidth: 1
- },
- items: [{
- xtype: 'textfield',
- name: 'deviceId',
- emptyText: '设备ID',
- hidden: true,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'deviceIp',
- emptyText: '设备IP',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'deviceName',
- emptyText: '设备名称',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'deviceUser',
- emptyText: '用户',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'devicePassword',
- emptyText: '密码',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'devicePort',
- emptyText: '端口',
- allowBlank: false,
- maxLength: 20
- }, {
- xtype: 'textfield',
- name: 'deviceRemark',
- emptyText: '备注'
- }],
- buttonAlign: 'center',
- buttons: [{
- text: '确定',
- formBind: true,
- handler: function () {
- let form = this.up('form');
- let values = form.getValues();
- let params, headers;
-
- params = JSON.stringify(values);
- view.setLoading(true);
- school.util.BaseUtil.request({
- // url: 'http://10.1.80.47:9520/api/device/device/save',
- url: '/api/device/device/save',
- method: 'POST',
- params: params,
- headers: headers
- }).then(function (res) {
- view.setLoading(false);
- win.close();
- school.util.BaseUtil.showSuccessToast('修改成功');
- view.refresh();
- }).catch(function (e) {
- view.setLoading(false);
- school.util.BaseUtil.showErrorToast('修改失败: ' + e.message);
- });
- }
- }]
- }]
- });
- view.add(win);
- win.down('form').getForm().findField('deviceId').setValue(data.deviceId);
- win.down('form').getForm().findField('deviceIp').setValue(data.deviceIp);
- win.down('form').getForm().findField('deviceName').setValue(data.deviceName);
- win.down('form').getForm().findField('deviceUser').setValue(data.deviceUser);
- win.down('form').getForm().findField('devicePassword').setValue(data.devicePassword);
- win.down('form').getForm().findField('devicePort').setValue(data.devicePort);
- win.down('form').getForm().findField('deviceRemark').setValue(data.deviceRemark);
- }
- win.show();
- },
- onDeleteClick: function(record) {
- let me = this,
- view = me.getView(),
- grid = view.down('grid'),
- id = record.data.deviceId,
- data;
- data = [{
- id: id
- }];
- school.util.BaseUtil.showConfirm('确认删除', '确定要删除设备' + record.get('deviceName') + '吗?')
- .then(function(yes) {
- if(yes == 'yes') {
- grid.setLoading(true);
- school.util.BaseUtil.request({
- // url: 'http://10.1.80.47:9520/api/device/device/batchDelete',
- url: '/api/device/device/batchDelete',
- method: 'POST',
- params: JSON.stringify({
- baseDTOs: data
- })
- }).then(function(res) {
- grid.setLoading(false);
- school.util.BaseUtil.showSuccessToast('成功删除' + data.length + '条记录');
- grid.store.loadPage(grid.store.currentPage);
- }).catch(function(e) {
- grid.setLoading(false);
- school.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
- });
- }
- });
- }
- });
|