PanelController.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Ext.define('school.view.setting.msgtemplate.PanelController', {
  2. extend: 'Ext.app.ViewController',
  3. alias: 'controller.setting-msgtemplate-panel',
  4. afterrender: function() {
  5. let me = this,
  6. view = me.getView();
  7. view.setLoading(true);
  8. school.util.BaseUtil.request({
  9. // url: 'http://10.1.80.47:9520/api/school/template/list'
  10. url: '/api/school/template/list'
  11. }).then(function(res) {
  12. view.setLoading(false);
  13. let data = res.data.list.map(function(l) {
  14. return {
  15. id: l.st_id,
  16. title: l.st_name,
  17. templateId: l.st_templateid
  18. }
  19. })
  20. if(data.length > 0) {
  21. me.addTemplate(data);
  22. }else {
  23. me.addEmptyText();
  24. }
  25. }).catch(function(e) {
  26. view.setLoading(false);
  27. me.addEmptyText();
  28. school.util.BaseUtil.showErrorToast(e.message);
  29. });
  30. },
  31. update: function(btn) {
  32. let container = btn.up('fieldcontainer'),
  33. items = container.items.items,
  34. valueField = items[0],
  35. titleField = items[1],
  36. templateIdField = items[2],
  37. id = valueField.value,
  38. title = titleField.value,
  39. templateId = templateIdField.value;
  40. if(!templateIdField.isDirty()) {
  41. school.util.BaseUtil.showErrorToast('数据无修改');
  42. return;
  43. }
  44. container.setLoading(true);
  45. school.util.BaseUtil.request({
  46. // url: 'http://10.1.80.47:9520/api/school/template/save',
  47. url: '/api/school/template/save',
  48. method: 'POST',
  49. params: JSON.stringify({
  50. st_id: id,
  51. st_name: title,
  52. st_templateid: templateId
  53. })
  54. }).then(function(res) {
  55. container.setLoading(false);
  56. templateIdField.originalValue = templateId;
  57. school.util.BaseUtil.showSuccessToast('更新成功');
  58. }).catch(function(e) {
  59. container.setLoading(false);
  60. school.util.BaseUtil.showErrorToast('更新失败: ' + e.message);
  61. });
  62. },
  63. addTemplate: function(datas) {
  64. let me = this,
  65. view = me.getView();
  66. if(datas.length > 0) {
  67. Ext.Array.each(datas, function(data) {
  68. view.add(me.applyTemplate(data));
  69. });
  70. }
  71. },
  72. addEmptyText: function() {
  73. let me = this,
  74. view = me.getView();
  75. view.setHtml('暂无数据');
  76. },
  77. applyTemplate: function(data) {
  78. let template = {
  79. xtype: 'fieldcontainer',
  80. layout: 'hbox',
  81. items: [{
  82. xtype: 'hidden',
  83. fieldLabel: 'ID',
  84. name: 'id',
  85. value: data.id
  86. }, {
  87. xtype: 'displayfield',
  88. fieldLabel: '模板标题',
  89. name: 'title',
  90. value: data.title
  91. }, {
  92. xtype: 'textfield',
  93. fieldLabel: '模板ID',
  94. name: 'templateId',
  95. value: data.templateId
  96. }, {
  97. xtype: 'button',
  98. text: '保存',
  99. handler: 'update'
  100. }]
  101. };
  102. return template;
  103. }
  104. });