SchoolInfo.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. layout: 'column',
  12. autoScroll: true,
  13. bodyPadding: '8 12 8 12',
  14. fieldDefaults: {
  15. margin: '0 0 10 0',
  16. labelAlign: 'right',
  17. labelWidth: 90,
  18. columnWidth: 0.25,
  19. },
  20. initComponent: function () {
  21. var me = this;
  22. Ext.apply(this, {
  23. dockedItems: [{
  24. xtype: 'toolbar',
  25. dock: 'top',
  26. items: ['->', {
  27. xtype: 'button',
  28. text: '更新',
  29. bind: {
  30. disabled: '{!formValid}'
  31. },
  32. handler: function() {
  33. me.onSave();
  34. }
  35. }],
  36. }],
  37. items: [{
  38. xtype: 'hidden',
  39. name: 'school_id',
  40. bind: '{schoolId}',
  41. fieldLabel: 'id'
  42. }, {
  43. xtype: "textfield",
  44. name: "school_name",
  45. bind: '{schoolName}',
  46. fieldLabel: "学校名称",
  47. allowBlank: false,
  48. columnWidth: 0.5
  49. }, {
  50. xtype: 'textfield',
  51. name: 'school_status',
  52. bind: '{schoolStatus}',
  53. fieldLabel: '状态',
  54. }, {
  55. xtype: "textfield",
  56. name: "school_address",
  57. bind: '{schoolAddress}',
  58. fieldLabel: "学校地址",
  59. allowBlank: true,
  60. columnWidth: 1
  61. }, {
  62. xtype: "textfield",
  63. name: 'school_phone',
  64. bind: '{schoolPhone}',
  65. fieldLabel: '联系电话'
  66. }, {
  67. xtype: 'textfield',
  68. name: 'school_appid',
  69. bind: '{schoolAppId}',
  70. fieldLabel: '绑定微信号'
  71. }, {
  72. xtype: 'textfield',
  73. name: 'school_remarks',
  74. bind: '{schoolRemarks}',
  75. fieldLabel: '备注',
  76. columnWidth: 1
  77. }]
  78. });
  79. this.callParent();
  80. },
  81. onSave: function() {
  82. let me = this,
  83. values = me.getValues();
  84. me.setLoading(true);
  85. school.util.BaseUtil.request({
  86. url: 'http://10.1.80.35:9560/school/save',
  87. method: 'POST',
  88. params: JSON.stringify(values)
  89. })
  90. .then(function() {
  91. me.setLoading(false);
  92. school.util.BaseUtil.showSuccessToast('资料更新成功');
  93. me.clearDirty();
  94. })
  95. .catch(function(e) {
  96. me.setLoading(false);
  97. school.util.BaseUtil.showErrorToast('资料更新失败: ' + e.message);
  98. });
  99. },
  100. clearDirty: function() {
  101. let me = this;
  102. let fields = me.getForm().getFields().items;
  103. Ext.Array.each(fields, function(f) {
  104. f.resetOriginalValue ? f.resetOriginalValue() : '';
  105. });
  106. },
  107. //overriders
  108. isValid: function() {
  109. let me = this;
  110. let viewModel = me.getViewModel();
  111. let formItems = me.getForm().getFields().items;
  112. let valid = !Ext.Array.findBy(formItems, function(f) {
  113. return !f.isValid();
  114. });
  115. viewModel.set('formValid', valid);
  116. return valid;
  117. },
  118. });