SchoolInfo.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. maxLength: 100
  52. }, {
  53. xtype: "textfield",
  54. name: 'school_phone',
  55. bind: '{schoolPhone}',
  56. fieldLabel: '联系电话',
  57. columnWidth: 1
  58. }, {
  59. xtype: "textfield",
  60. name: "school_address",
  61. bind: '{schoolAddress}',
  62. fieldLabel: "学校地址",
  63. allowBlank: true,
  64. columnWidth: 1,
  65. maxLength: 200
  66. }, {
  67. xtype: 'combobox',
  68. name: 'school_status',
  69. bind: '{schoolStatus}',
  70. fieldLabel: '状态',
  71. displayField: 'name',
  72. valueField: 'value',
  73. queryMode: 'local',
  74. editable: false,
  75. store: Ext.create('Ext.data.Store', {
  76. fields: ['name', 'value'],
  77. data: [{
  78. name: '正常',
  79. value: 1
  80. }, {
  81. name: '冻结',
  82. value: 2
  83. }]
  84. }),
  85. columnWidth: 1
  86. }, {
  87. xtype: 'textfield',
  88. name: 'school_appid',
  89. bind: '{schoolAppId}',
  90. fieldLabel: '公众号账号',
  91. readOnly: true,
  92. columnWidth: 1
  93. }, {
  94. xtype: 'textfield',
  95. name: 'school_secret',
  96. bind: '{schoolSecret}',
  97. fieldLabel: '公众号密钥',
  98. columnWidth: 1,
  99. readOnly: true
  100. }, {
  101. xtype: 'textfield',
  102. name: 'school_remarks',
  103. bind: '{schoolRemarks}',
  104. fieldLabel: '备注',
  105. columnWidth: 1,
  106. maxLength: 250
  107. }]
  108. });
  109. this.callParent();
  110. },
  111. onSave: function() {
  112. let me = this,
  113. values = me.getValues();
  114. me.setLoading(true);
  115. school.util.BaseUtil.request({
  116. // url: 'http://10.1.80.35:9560/school/save',
  117. url: '/api/school/school/save',
  118. method: 'POST',
  119. params: JSON.stringify(values)
  120. })
  121. .then(function() {
  122. me.setLoading(false);
  123. school.util.BaseUtil.showSuccessToast('资料更新成功');
  124. me.clearDirty();
  125. })
  126. .catch(function(e) {
  127. me.setLoading(false);
  128. school.util.BaseUtil.showErrorToast('资料更新失败: ' + e.message);
  129. });
  130. },
  131. clearDirty: function() {
  132. let me = this;
  133. let fields = me.getForm().getFields().items;
  134. Ext.Array.each(fields, function(f) {
  135. f.resetOriginalValue ? f.resetOriginalValue() : '';
  136. });
  137. },
  138. //overriders
  139. isValid: function() {
  140. let me = this;
  141. let viewModel = me.getViewModel();
  142. let formItems = me.getForm().getFields().items;
  143. let valid = !Ext.Array.findBy(formItems, function(f) {
  144. return !f.isValid();
  145. });
  146. viewModel.set('formValid', valid);
  147. return valid;
  148. },
  149. });