|
|
@@ -0,0 +1,115 @@
|
|
|
+Ext.define('school.view.setting.msgtemplate.PanelController', {
|
|
|
+ extend: 'Ext.app.ViewController',
|
|
|
+ alias: 'controller.setting-msgtemplate-panel',
|
|
|
+
|
|
|
+ afterrender: function() {
|
|
|
+ let me = this,
|
|
|
+ view = me.getView();
|
|
|
+
|
|
|
+ view.setLoading(true);
|
|
|
+ school.util.BaseUtil.request({
|
|
|
+ // url: 'http://10.1.80.47:9520/api/school/template/list'
|
|
|
+ url: '/api/school/template/list'
|
|
|
+ }).then(function(res) {
|
|
|
+ view.setLoading(false);
|
|
|
+ let data = res.data.list.map(function(l) {
|
|
|
+ return {
|
|
|
+ id: l.st_id,
|
|
|
+ title: l.st_name,
|
|
|
+ templateId: l.st_templateid
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if(data.length > 0) {
|
|
|
+ me.addTemplate(data);
|
|
|
+ }else {
|
|
|
+ me.addEmptyText();
|
|
|
+ }
|
|
|
+ }).catch(function(e) {
|
|
|
+ view.setLoading(false);
|
|
|
+ school.util.BaseUtil.showErrorToast(e.message);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ update: function(btn) {
|
|
|
+ let container = btn.up('fieldcontainer'),
|
|
|
+ items = container.items.items,
|
|
|
+ valueField = items[0],
|
|
|
+ titleField = items[1],
|
|
|
+ templateIdField = items[2],
|
|
|
+ id = valueField.value,
|
|
|
+ title = titleField.value,
|
|
|
+ templateId = templateIdField.value;
|
|
|
+
|
|
|
+ if(!templateIdField.isDirty()) {
|
|
|
+ school.util.BaseUtil.showErrorToast('数据无修改');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ container.setLoading(true);
|
|
|
+ school.util.BaseUtil.request({
|
|
|
+ // url: 'http://10.1.80.47:9520/api/school/template/save',
|
|
|
+ url: '/api/school/template/save',
|
|
|
+ method: 'POST',
|
|
|
+ params: JSON.stringify({
|
|
|
+ st_id: id,
|
|
|
+ st_name: title,
|
|
|
+ st_templateid: templateId
|
|
|
+ })
|
|
|
+ }).then(function(res) {
|
|
|
+ container.setLoading(false);
|
|
|
+ templateIdField.originalValue = templateId;
|
|
|
+ school.util.BaseUtil.showSuccessToast('更新成功');
|
|
|
+ }).catch(function(e) {
|
|
|
+ container.setLoading(false);
|
|
|
+ school.util.BaseUtil.showErrorToast('更新失败: ' + e.message);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ addTemplate: function(datas) {
|
|
|
+ let me = this,
|
|
|
+ view = me.getView();
|
|
|
+
|
|
|
+ if(datas.length > 0) {
|
|
|
+ Ext.Array.each(datas, function(data) {
|
|
|
+ view.add(me.applyTemplate(data));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ addEmptyText: function() {
|
|
|
+ let me = this,
|
|
|
+ view = me.getView();
|
|
|
+
|
|
|
+ view.setHtml('暂无数据');
|
|
|
+ },
|
|
|
+
|
|
|
+ applyTemplate: function(data) {
|
|
|
+ let template = {
|
|
|
+ xtype: 'fieldcontainer',
|
|
|
+ layout: 'hbox',
|
|
|
+ items: [{
|
|
|
+ xtype: 'hidden',
|
|
|
+ fieldLabel: 'ID',
|
|
|
+ name: 'id',
|
|
|
+ value: data.id
|
|
|
+ }, {
|
|
|
+ xtype: 'displayfield',
|
|
|
+ fieldLabel: '模板标题',
|
|
|
+ name: 'title',
|
|
|
+ value: data.title
|
|
|
+ }, {
|
|
|
+ xtype: 'textfield',
|
|
|
+ fieldLabel: '模板ID',
|
|
|
+ name: 'templateId',
|
|
|
+ value: data.templateId
|
|
|
+ }, {
|
|
|
+ xtype: 'button',
|
|
|
+ text: '保存',
|
|
|
+ handler: 'update'
|
|
|
+ }]
|
|
|
+ };
|
|
|
+
|
|
|
+ return template;
|
|
|
+ }
|
|
|
+
|
|
|
+});
|