| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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);
- me.addEmptyText();
- 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;
- }
- });
|