SchoolInfo.js 4.7 KB

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