SchoolInfo.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * 学校信息
  3. */
  4. Ext.define('school.view.basic.school.SchoolInfo', {
  5. // extend: 'school.view.core.form.FormPanel',
  6. extend: 'Ext.form.Panel',
  7. xtype: 'basic-school-schoolinfo',
  8. // controller: 'purchase-purchase-formpanel',
  9. // viewModel: 'purchase-purchase-formpanel',
  10. // readUrl: 'http://10.1.80.35:9560/school/read',
  11. readUrl: '/api/school/school/read',
  12. layout: 'column',
  13. autoScroll: true,
  14. bodyPadding: '12 250 12 250',
  15. fieldDefaults: {
  16. margin: '0 0 10 0',
  17. labelAlign: 'right',
  18. labelWidth: 90,
  19. columnWidth: 0.25,
  20. },
  21. initComponent: function () {
  22. var me = this;
  23. Ext.apply(this, {
  24. dockedItems: [{
  25. xtype: 'toolbar',
  26. dock: 'bottom',
  27. items: ['->', {
  28. xtype: 'button',
  29. text: '更新',
  30. bind: {
  31. disabled: '{!formValid}'
  32. },
  33. handler: function() {
  34. me.onSave();
  35. }
  36. }, '->'],
  37. }],
  38. items: [{
  39. xtype: 'hidden',
  40. name: 'school_id',
  41. bind: '{schoolId}',
  42. fieldLabel: 'id',
  43. columnWidth: 1
  44. }, {
  45. xtype: "textfield",
  46. name: "school_name",
  47. bind: '{schoolName}',
  48. fieldLabel: "学校名称",
  49. allowBlank: false,
  50. columnWidth: 1
  51. }, {
  52. xtype: "textfield",
  53. name: 'school_phone',
  54. bind: '{schoolPhone}',
  55. fieldLabel: '联系电话',
  56. columnWidth: 1
  57. }, {
  58. xtype: "textfield",
  59. name: "school_address",
  60. bind: '{schoolAddress}',
  61. fieldLabel: "学校地址",
  62. allowBlank: true,
  63. columnWidth: 1
  64. }, {
  65. xtype: 'combobox',
  66. name: 'school_status',
  67. bind: '{schoolStatus}',
  68. fieldLabel: '状态',
  69. displayField: 'name',
  70. valueField: 'value',
  71. queryMode: 'local',
  72. editable: false,
  73. store: Ext.create('Ext.data.Store', {
  74. fields: ['name', 'value'],
  75. data: [{
  76. name: '正常',
  77. value: 1
  78. }, {
  79. name: '冻结',
  80. value: 2
  81. }]
  82. }),
  83. columnWidth: 1
  84. }, {
  85. xtype: 'textfield',
  86. name: 'school_appid',
  87. bind: '{schoolAppId}',
  88. fieldLabel: '公众号账号',
  89. readOnly: true,
  90. columnWidth: 1
  91. }, {
  92. xtype: 'textfield',
  93. name: 'school_secret',
  94. bind: '{schoolSecret}',
  95. fieldLabel: '公众号密钥',
  96. columnWidth: 1,
  97. readOnly: true
  98. }, {
  99. xtype: 'textfield',
  100. name: 'school_remarks',
  101. bind: '{schoolRemarks}',
  102. fieldLabel: '备注',
  103. columnWidth: 1
  104. }]
  105. });
  106. this.callParent();
  107. },
  108. onSave: function() {
  109. let me = this,
  110. values = me.getValues();
  111. me.setLoading(true);
  112. school.util.BaseUtil.request({
  113. // url: 'http://10.1.80.35:9560/school/save',
  114. url: '/api/school/school/save',
  115. method: 'POST',
  116. params: JSON.stringify(values)
  117. })
  118. .then(function() {
  119. me.setLoading(false);
  120. school.util.BaseUtil.showSuccessToast('资料更新成功');
  121. me.clearDirty();
  122. })
  123. .catch(function(e) {
  124. me.setLoading(false);
  125. school.util.BaseUtil.showErrorToast('资料更新失败: ' + e.message);
  126. });
  127. },
  128. clearDirty: function() {
  129. let me = this;
  130. let fields = me.getForm().getFields().items;
  131. Ext.Array.each(fields, function(f) {
  132. f.resetOriginalValue ? f.resetOriginalValue() : '';
  133. });
  134. },
  135. //overriders
  136. isValid: function() {
  137. let me = this;
  138. let viewModel = me.getViewModel();
  139. let formItems = me.getForm().getFields().items;
  140. let valid = !Ext.Array.findBy(formItems, function(f) {
  141. return !f.isValid();
  142. });
  143. viewModel.set('formValid', valid);
  144. return valid;
  145. },
  146. });