FormPanelController.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. Ext.define('saas.view.sys.config.FormPanelController', {
  2. extend: 'Ext.app.ViewController',
  3. alias: 'controller.sys-config-formpanel',
  4. BaseUtil: Ext.create('saas.util.BaseUtil'),
  5. FormUtil: Ext.create('saas.util.FormUtil'),
  6. auditBtnClick: function() {
  7. var me = this,
  8. form = me.getView(),
  9. statusCodeField = form._statusCodeField,
  10. viewModel = me.getViewModel(),
  11. status = viewModel.get(statusCodeField);
  12. status == 'AUDITED' ? me.unAudit() : me.audit();
  13. },
  14. add: function(){
  15. var form = this.getView();
  16. var id = form.xtype + '-add';
  17. openTab(form.xtype,'新增' + form._title, id);
  18. },
  19. delete: function(){
  20. var me = this;
  21. var form = this.getView();
  22. var viewModel = me.getViewModel();
  23. var id = viewModel.get(form._idField);
  24. var code = viewModel.get(form._codeField);
  25. if(id&&id.value!=0){
  26. me.BaseUtil.request({
  27. url: form._deleteUrl+id,
  28. method: 'POST',
  29. })
  30. .then(function(localJson) {
  31. if(localJson.success){
  32. var mainTab = Ext.getCmp('main-tab-panel');
  33. mainTab.getActiveTab().close();
  34. //解析参数
  35. showToast('删除成功');
  36. }
  37. })
  38. .catch(function(res) {
  39. console.error(res);
  40. showToast('删除失败: ' + res.message);
  41. });
  42. }
  43. },
  44. onSave: function() {
  45. var me = this,
  46. form = this.getView();
  47. var valid = form.isValid();
  48. if(!valid) {
  49. showToast('表单校验有误,请检查');
  50. return false;
  51. }
  52. if(form.getForm().wasDirty==false){
  53. showToast('未修改数据,请修改后保存');
  54. return false;
  55. }
  56. //form里面数据
  57. var formData = form.getFormData();
  58. me.save(formData);
  59. },
  60. save:function(formData){
  61. var me = this,
  62. form = this.getView(),
  63. detailCount = form.detailCount,
  64. viewModel = me.getViewModel(),
  65. modelData = viewModel.getData();
  66. var params = {
  67. main:formData.main
  68. };
  69. for(var i = 0; i < detailCount; i++) {
  70. params['items' + ( i + 1)] = formData['detail' + i];
  71. }
  72. // 只有一个从表时从表字段改为items
  73. if(detailCount == 1) {
  74. params.items = params.items1;
  75. delete params.items1;
  76. }
  77. me.BaseUtil.request({
  78. url: form._saveUrl,
  79. params: JSON.stringify(params),
  80. method: 'POST',
  81. })
  82. .then(function(localJson) {
  83. if(localJson.success){
  84. var id = localJson.data.id;
  85. var code = localJson.data.code;
  86. form.initId = id;
  87. form.FormUtil.loadData(form);
  88. showToast('保存成功');
  89. var newId = form.xtype + '-' + id;
  90. var newTitle = form._title + '(' + code + ')';
  91. refreshTabTitle(newId, newTitle);
  92. }
  93. })
  94. .catch(function(res) {
  95. console.error(res);
  96. showToast('保存失败: ' + res.message);
  97. });
  98. },
  99. audit: function(){
  100. var me = this,
  101. form = this.getView(),
  102. detailCount = form.detailCount,
  103. viewModel = me.getViewModel(),
  104. modelData = viewModel.getData();
  105. var valid = form.isValid();
  106. if(!valid) {
  107. showToast('表单校验有误,请检查');
  108. return false;
  109. }
  110. if(form.getForm().wasDirty==false){
  111. showToast('未修改数据,请修改后保存');
  112. return false;
  113. }
  114. //form里面数据
  115. var formData = form.getFormData();
  116. var params = {
  117. main: formData.main
  118. };
  119. for(var i = 0; i < detailCount; i++) {
  120. params['items' + ( i + 1)] = formData['detail' + i];
  121. }
  122. // 只有一个从表时从表字段改为items
  123. if(detailCount == 1) {
  124. params.items = params.items1;
  125. delete params.items1;
  126. }
  127. me.BaseUtil.request({
  128. url: form._auditUrl,
  129. params: JSON.stringify(params),
  130. method: 'POST',
  131. })
  132. .then(function(localJson) {
  133. if(localJson.success){
  134. // 未保存直接审核会返回id
  135. if(localJson.data) {
  136. var id = localJson.data.id;
  137. var code = localJson.data.code;
  138. form.initId = id;
  139. var newId = form.xtype + '-' + id;
  140. var newTitle = form._title + '(' + code + ')';
  141. refreshTabTitle(newId, newTitle);
  142. }
  143. form.FormUtil.loadData(form);
  144. form.setEditable(false);
  145. showToast('审核成功');
  146. }
  147. })
  148. .catch(function(res) {
  149. console.error(res);
  150. showToast('审核失败: ' + res.message);
  151. });
  152. },
  153. unAudit: function() {
  154. var me = this;
  155. var form = this.getView();
  156. var viewModel = me.getViewModel();
  157. var id = viewModel.get(form._idField);
  158. var code = viewModel.get(form._codeField);
  159. if(id&&id.value!=0){
  160. me.BaseUtil.request({
  161. url: form._unAuditUrl+id,
  162. method: 'POST',
  163. })
  164. .then(function(localJson) {
  165. if(localJson.success){
  166. //解析参数
  167. showToast('反审核成功');
  168. form.FormUtil.loadData(form);
  169. }
  170. })
  171. .catch(function(res) {
  172. console.error(res);
  173. showToast('反审核失败: ' + res.message);
  174. });
  175. }
  176. },
  177. codeEditorBlur: function(e) {
  178. var me = this,
  179. viewModel = me.getViewModel(),
  180. targetEl = event.target,
  181. faEl = targetEl.getElementsByClassName('fa')[0];
  182. if(faEl && faEl.classList.contains('fa-check-circle')) {
  183. // 处理重复触发事件
  184. // viewModel.set('base.codeEditable', false);
  185. }else {
  186. viewModel.set('base.codeEditable', false);
  187. }
  188. },
  189. codeEditorClick: function() {
  190. var me = this,
  191. viewModel = me.getViewModel(),
  192. codeEditable = viewModel.get('base.codeEditable');
  193. viewModel.set('base.codeEditable', !codeEditable);
  194. }
  195. });