| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- Ext.define('saas.view.sys.config.FormPanelController', {
- extend: 'Ext.app.ViewController',
- alias: 'controller.sys-config-formpanel',
- BaseUtil: Ext.create('saas.util.BaseUtil'),
- FormUtil: Ext.create('saas.util.FormUtil'),
- auditBtnClick: function() {
- var me = this,
- form = me.getView(),
- statusCodeField = form._statusCodeField,
- viewModel = me.getViewModel(),
- status = viewModel.get(statusCodeField);
- status == 'AUDITED' ? me.unAudit() : me.audit();
- },
- add: function(){
- var form = this.getView();
- var id = form.xtype + '-add';
- openTab(form.xtype,'新增' + form._title, id);
- },
-
- delete: function(){
- var me = this;
- var form = this.getView();
- var viewModel = me.getViewModel();
- var id = viewModel.get(form._idField);
- var code = viewModel.get(form._codeField);
- if(id&&id.value!=0){
- me.BaseUtil.request({
- url: form._deleteUrl+id,
- method: 'POST',
- })
- .then(function(localJson) {
- if(localJson.success){
- var mainTab = Ext.getCmp('main-tab-panel');
- mainTab.getActiveTab().close();
- //解析参数
- showToast('删除成功');
- }
- })
- .catch(function(res) {
- console.error(res);
- showToast('删除失败: ' + res.message);
- });
- }
- },
- onSave: function() {
- var me = this,
- form = this.getView();
- var valid = form.isValid();
- if(!valid) {
- showToast('表单校验有误,请检查');
- return false;
- }
- if(form.getForm().wasDirty==false){
- showToast('未修改数据,请修改后保存');
- return false;
- }
- //form里面数据
- var formData = form.getFormData();
-
- me.save(formData);
- },
- save:function(formData){
- var me = this,
- form = this.getView(),
- detailCount = form.detailCount,
- viewModel = me.getViewModel(),
- modelData = viewModel.getData();
- var params = {
- main:formData.main
- };
- for(var i = 0; i < detailCount; i++) {
- params['items' + ( i + 1)] = formData['detail' + i];
- }
- // 只有一个从表时从表字段改为items
- if(detailCount == 1) {
- params.items = params.items1;
- delete params.items1;
- }
- me.BaseUtil.request({
- url: form._saveUrl,
- params: JSON.stringify(params),
- method: 'POST',
- })
- .then(function(localJson) {
- if(localJson.success){
- var id = localJson.data.id;
- var code = localJson.data.code;
- form.initId = id;
- form.FormUtil.loadData(form);
- showToast('保存成功');
- var newId = form.xtype + '-' + id;
- var newTitle = form._title + '(' + code + ')';
- refreshTabTitle(newId, newTitle);
- }
- })
- .catch(function(res) {
- console.error(res);
- showToast('保存失败: ' + res.message);
- });
- },
- audit: function(){
- var me = this,
- form = this.getView(),
- detailCount = form.detailCount,
- viewModel = me.getViewModel(),
- modelData = viewModel.getData();
- var valid = form.isValid();
- if(!valid) {
- showToast('表单校验有误,请检查');
- return false;
- }
-
- if(form.getForm().wasDirty==false){
- showToast('未修改数据,请修改后保存');
- return false;
- }
- //form里面数据
- var formData = form.getFormData();
- var params = {
- main: formData.main
- };
- for(var i = 0; i < detailCount; i++) {
- params['items' + ( i + 1)] = formData['detail' + i];
- }
- // 只有一个从表时从表字段改为items
- if(detailCount == 1) {
- params.items = params.items1;
- delete params.items1;
- }
- me.BaseUtil.request({
- url: form._auditUrl,
- params: JSON.stringify(params),
- method: 'POST',
- })
- .then(function(localJson) {
- if(localJson.success){
- // 未保存直接审核会返回id
- if(localJson.data) {
- var id = localJson.data.id;
- var code = localJson.data.code;
-
- form.initId = id;
- var newId = form.xtype + '-' + id;
- var newTitle = form._title + '(' + code + ')';
- refreshTabTitle(newId, newTitle);
- }
- form.FormUtil.loadData(form);
- form.setEditable(false);
- showToast('审核成功');
- }
- })
- .catch(function(res) {
- console.error(res);
- showToast('审核失败: ' + res.message);
- });
- },
- unAudit: function() {
- var me = this;
- var form = this.getView();
- var viewModel = me.getViewModel();
- var id = viewModel.get(form._idField);
- var code = viewModel.get(form._codeField);
- if(id&&id.value!=0){
- me.BaseUtil.request({
- url: form._unAuditUrl+id,
- method: 'POST',
- })
- .then(function(localJson) {
- if(localJson.success){
- //解析参数
- showToast('反审核成功');
- form.FormUtil.loadData(form);
- }
- })
- .catch(function(res) {
- console.error(res);
- showToast('反审核失败: ' + res.message);
- });
- }
- },
- codeEditorBlur: function(e) {
- var me = this,
- viewModel = me.getViewModel(),
- targetEl = event.target,
- faEl = targetEl.getElementsByClassName('fa')[0];
- if(faEl && faEl.classList.contains('fa-check-circle')) {
- // 处理重复触发事件
- // viewModel.set('base.codeEditable', false);
- }else {
- viewModel.set('base.codeEditable', false);
- }
- },
- codeEditorClick: function() {
- var me = this,
- viewModel = me.getViewModel(),
- codeEditable = viewModel.get('base.codeEditable');
- viewModel.set('base.codeEditable', !codeEditable);
- }
- });
|