| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.pm.mes.BOMStep', {
- extend: 'Ext.app.Controller',
- FormUtil: Ext.create('erp.util.FormUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- GridUtil: Ext.create('erp.util.GridUtil'),
- views:[
- 'pm.mes.BOMStep','core.form.Panel','core.grid.Panel2','core.button.Query','core.button.Load',
- 'core.button.Add','core.button.Save','core.button.Close','core.button.Update','core.trigger.SearchField',
- 'core.form.YnField','core.grid.YnColumn', 'core.grid.TfColumn','pm.mes.BOMStepTree','core.button.LoadMake',
- 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.trigger.MultiDbfindTrigger','core.button.CopyByConfigs',
- 'core.button.CleanDetail'
- ],
- init:function(){
- var me = this;
- this.control({
- 'erpFormPanel': {
- afterload: function(form) {
- var items = form.items.items;
- Ext.each(items, function() {
- var val = getUrlParam(this.name);
- if(!Ext.isEmpty(val)) {
- this.setValue(val);
- //autoQuery = true;
- /*if(this.xtype == 'dbfindtrigger') {
- this.autoDbfind('form', caller, this.name, this.name + " like '%" + val + "%'");
- }*/
- }
- });
- },
-
- },
- 'erpGridPanel2': {
- itemclick: function(view,record){
- me.itemclick(view,record,me);
- }
- },
- 'erpAddButton': {
- click: function(){
- var code = Ext.getCmp("pr_code").value;
- var cr_code = Ext.getCmp("cr_code").value;
- me.FormUtil.onAdd('addMakeBase', '新增工序BOM', 'jsps/pm/mes/BOMStep.jsp?whoami=' + caller + '&pr_code='+code+'&cr_code='+cr_code );
- }
- },
- 'bomsteptree': {
- itemmousedown: function(selModel, record){
- me.loadTab(selModel, record);
- me.lastSelected = record;
- }
- },
-
- 'dbfindtrigger[name=sb_bomversion]': {
- afterrender: function(f){
- var sb_id = Ext.getCmp('sb_id');
- if(sb_id && sb_id.value!=null && sb_id.value!='' &&sb_id.value!=0){
- f.setEditable(false);
- f.setReadOnly(true);
- }
- },
- beforetrigger: function(t) {
- t.autoDbfind = true;
- t.setHideTrigger(false);
- t.setReadOnly(false);
- var cr_code = Ext.getCmp('cr_code');
- var pr_code = Ext.getCmp('pr_code');
- if(cr_code){
- t.dbBaseCondition = "sb_craftcode='"+cr_code.value+"' and sb_prodcode='"+ pr_code.value+"'";
- }
- },
- change: function(t){
- var prodcode = Ext.getCmp('pr_code').value;
- var cr_code = Ext.getCmp('cr_code').value;
- if(t.value!=''){
- me.FormUtil.getFieldValue('stepBom', 'sb_id', "sb_bomversion='" + t.value + "' and sb_prodcode = '"+prodcode+"' and sb_craftcode = '"+cr_code+"'", 'sb_id');
- var sb_id = Ext.getCmp('sb_id');
- if(sb_id && sb_id.value!=null && sb_id.value!='' &&sb_id.value!=0){
- t.setEditable(false);
- t.setReadOnly(true);
- this.query();
- }
- }
- t.autoDbfind = false;
- t.setHideTrigger(false);
- t.setReadOnly(false);
- var cr_code = Ext.getCmp('cr_code');
- var pr_code = Ext.getCmp('pr_code');
- if(cr_code){
- t.dbBaseCondition = "sb_craftcode='"+cr_code.value+"' and sb_prodcode='"+ pr_code.value+"'";
- }
- },
- focus: function(t){
- t.autoDbfind = false;
- t.setHideTrigger(false);
- t.setReadOnly(false);
- },
- /*aftertrigger: function(t){
- if(t.value!=''){
- this.query();
- }
- }*/
- },
- 'dbfindtrigger[name=cr_code]': {
- beforetrigger: function(t){
- var pr_code = Ext.getCmp('pr_code');
- if(cr_code){
- t.dbBaseCondition = " cr_prodcode='"+ pr_code.value+"'";
- }
- }
- },
- 'dbfindtrigger[name=sp_stepcode]': {
- beforetrigger: function(t) {
- t.autoDbfind = false;
- t.setHideTrigger(false);
- t.setReadOnly(false);
- var cr_code = Ext.getCmp('cr_code');
- var pr_code = Ext.getCmp('pr_code');
- t.dbBaseCondition = "cr_code='"+cr_code.value+"' and cr_prodcode='"+ pr_code.value+"'";
- }
- },
- 'erpQueryButton': {
- click: function(btn){
- this.query();
- }
- },
- 'erpCleanDetailButton':{
- click : function(btn) {
- me.cleanDetail();
- }
- },
- 'erpLoadButton': {
- afterrender: function(btn){
- btn.setWidth(130);
- btn.setText('载入标准BOM');
- },
- click: function(btn){
- var pr_code = Ext.getCmp("pr_code").value;
- var dbwin = new Ext.window.Window({
- id : 'ddbwin',
- title: 'BOM载入',
- height: "90%",
- width: "75%",
- maximizable : true,
- buttonAlign : 'center',
- layout : 'anchor',
- items: []
- });
- dbwin.show();
- var iframe = dbwin.getEl().down('iframe');
- if(!iframe) {
- dbwin.add({
- tag : 'iframe',
- frame : true,
- anchor : '100% 100%',
- layout : 'fit',
- html : '<iframe src="#" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
- });
- iframe = dbwin.getEl().down('iframe');
- }
- iframe.dom.src = basePath+'jsps/pm/mes/BOMStepLoad.jsp?whoami=BOMStep!load&gridCondition=bo_mothercodeIS'+"'"+pr_code+"'";
- }
- },
- 'erpLoadMakeButton': {
- afterrender: function(btn){
- btn.setText('载入工单BOM');
- btn.setWidth(120);
- },
- click: function(btn){
- var sp_bomversion = Ext.getCmp("sb_bomversion").value;
- var sb_prodcode = Ext.getCmp("pr_code").value;
- /*if(sp_bomversion == ''){
- showError('请先选择BOM版本编号!');
- return;
- }*/
- var dbwin = new Ext.window.Window({
- id : 'adbwin',
- title: '工单BOM载入',
- height: "90%",
- width: "75%",
- maximizable : true,
- buttonAlign : 'center',
- layout : 'anchor',
- items: []
- });
- dbwin.show();
- var iframe = dbwin.getEl().down('iframe');
- if(!iframe) {
- dbwin.add({
- tag : 'iframe',
- frame : true,
- anchor : '100% 100%',
- layout : 'fit',
- html : '<iframe src="#" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
- });
- iframe = dbwin.getEl().down('iframe');
- }
- iframe.dom.src = basePath+'jsps/pm/mes/BOMStepLoadMake.jsp?whoami=BOMStep!loadmake&gridCondition=ma_codeIS'+"'"+sp_bomversion+"' and ma_prodcodeIS'"+sb_prodcode+"'";
- }
- },
- 'erpUpdateButton': {
- afterrender: function(btn){
- btn.setText('保存');
- },
- click: function(btn){
- var cr_code = Ext.getCmp('cr_code').value;
- /*var st_code = Ext.getCmp('cr_name').value;*/
- var sp_bomversion = Ext.getCmp('sb_bomversion').value;
- if(cr_code == ''){
- showError("未填写途程!");
- return;
- }else if(sp_bomversion == ''){
- showError("未填写BOM版本编号!");
- return;
- }
- this.onUpdate();
- }
- }
- });
- },
- query: function(cr_value, st_value){
- var pr_code = Ext.getCmp('pr_code').value;
- var cr_code = Ext.getCmp('cr_code');
- var st_code = Ext.getCmp('cr_name');
- var sp_bomversion = Ext.getCmp('sb_bomversion');
- var grid = Ext.getCmp('grid');
- var condition = "sb_prodcode='"+pr_code+"'";
- if(cr_code&&cr_code.value != ""&&cr_code.value != null){
- condition += "and sb_craftcode='"+cr_code.value+"'";
- }else{
- showError("未填写途程!");
- return;
- }
- if(sp_bomversion&&sp_bomversion.value != ""&&sp_bomversion.value != null){
- condition += "and sb_bomversion='"+sp_bomversion.value+"'";
- }else{
- showError("未填写BOM版本编号!");
- return;
- }
- var param = {
- caller : caller,
- condition : condition
- };
- grid.GridUtil.loadNewStore(grid, param);
- },
- getForm: function(btn){
- return btn.ownerCt.ownerCt;
- },
- onUpdate: function(){
- var form = Ext.getCmp('form');
- var me = this, params = new Object();
- if(form.codeField && (Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == '')){
- showError('编号不能为空.');
- return;
- }
- var s1 = me.checkFormDirty(form);
- var s2 = '';
- var grids = Ext.ComponentQuery.query('gridpanel');
- if(grids.length > 0 && !grids[0].ignore){//check所有grid是否已修改
- Ext.each(grids, function(grid, index){
- if(grid.GridUtil){
- var msg = grid.GridUtil.checkGridDirty(grid);
- if(msg.length > 0){
- s2 = s2 + '<br/>' + msg;
- }
- }
- });
- }
- if(s1 == '' && (s2 == '' || s2 == '<br/>')){
- showError('还未添加或修改数据.');
- return;
- }
- if(form && form.getForm().isValid()){
- //form里面数据
- var r = form.getValues();
- //去除ignore字段
- var keys = Ext.Object.getKeys(r), f;
- Ext.each(keys, function(k){
- f = form.down('#' + k);
- if(f && f.logic == 'ignore') {
- delete r[k];
- }
- });
- if(!me.contains(form.updateUrl, '?caller=', true)){
- form.updateUrl = form.updateUrl + "?caller=" + caller;
- }
- var params = [];
- var grid = Ext.getCmp("grid");
- var count = 0;
- var count1 = 0;
- Ext.Array.each(grid.getStore().data.items,function(item){
- if(item.data['sp_tracekind'] != null && item.data['sp_tracekind'] != '' ){
- count++;
- }
- if(item.data['sp_soncode'] != null && item.data['sp_soncode'] != '' ){
- count1++;
- }
- });
- if(count != count1){
- showError('管控类型不允许为空');
- return;
- }
- if(grids.length > 0 && grids[0].columns.length > 0 && !grids[0].ignore){
- if(grids[0].GridUtil.isEmpty(grids[0])) {
- showError("明细还未录入数据,请添加明细行数据!");
- return;
- } else if(grids[0].GridUtil.isDirty(grids[0])) {
- var param = grids[0].GridUtil.getGridStore();
- if(grids[0].necessaryField && grids[0].necessaryField.length > 0 && (param == null || param.length == 0 || param == '')){
- warnMsg('明细表有必填项未填写,是否继续保存?', function(btn){
- if(btn == 'yes' || btn == 'ok'){
- params = unescape("[" + param.toString() + "]");
- me.update();
- } else {
- return;
- }
- });
- }else{
- me.update();
- }
- }else{
- me.update();
- }
- }else{
- me.update();
- }
- }
- },
- update: function(){
- var me =this,form = Ext.getCmp('form'), url = form.updateUrl;
- var r = form.getValues();
- var formStore = unescape(escape(Ext.JSON.encode(r)));
- var grids = Ext.ComponentQuery.query('gridpanel');
- var cr_code = Ext.getCmp('cr_code');
- var pr_code = Ext.getCmp('pr_code');
- var sb_bomversion = Ext.getCmp('sb_bomversion');
- /*var st_code = Ext.getCmp('cr_name');*/
- var cr_value = cr_code.value;
- /*var st_value = st_code.value;*/
- if(url.indexOf('caller=') == -1){
- url = url + "?caller=" + caller;
- }
- var gridStore = unescape("[" + grids[0].GridUtil.getGridStore() + "]");
- me.setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + url,
- params: {
- formStore : formStore,
- gridStore : gridStore
- },
- method : 'post',
- callback : function(options,success,response){
- me.setLoading(false);
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- /*me.query();*/
- var formCondition = 'sb_bomversionIS'+"'"+sb_bomversion.value+"'"+'and pr_codeIS'+"'"+pr_code.value+"'"+'and cr_codeIS'+"'"+cr_code.value+"'";
- var sb_id = Ext.getCmp('sb_id');
- if(sb_id.value == '' || sb_id.value == null || sb_id.value == 0){
- me.FormUtil.getFieldValue('stepBom', 'sb_id', "sb_bomversion='" + sb_bomversion.value + "' and sb_prodcode = '"+pr_code.value+"' and sb_craftcode = '"+cr_code.value+"'", 'sb_id');
- }
- if(sb_id != '' && sb_id != null && sb_id != 0){
- window.location.href=basePath+'jsps/pm/mes/BOMStep.jsp?whoami=BOMStep&formCondition='+formCondition+'&gridCondition=sp_sbidIS'+sb_id.value;
- }
- } else if(localJson.exceptionInfo){
- var str = localJson.exceptionInfo;
- if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
- me.query();
- }
- showError(str);return;
- } else {
- updateFailure();
- }
- }
- });
- },
- /**
- * 检查表单是否被修改,并返回被修改的内容
- */
- checkFormDirty: function(){
- var form = Ext.getCmp('form');
- var s = '';
- form.getForm().getFields().each(function (item,index, length){
- if(item.logic!='ignore'){
- var value = item.value == null ? "" : item.value;
- if(item.xtype == 'htmleditor') {
- value = item.getValue();
- }
- item.originalValue = item.originalValue == null ? "" : item.originalValue;
- if(Ext.typeOf(item.originalValue) != 'object'){
- if(item.originalValue.toString() != value.toString()){//isDirty、wasDirty、dirty一直都是true,没办法判断,所以直接用item.originalValue,原理是一样的
- var label = item.fieldLabel || item.ownerCt.fieldLabel ||
- item.boxLabel || item.ownerCt.title;//针对fieldContainer、radio、fieldset等
- if(label){
- s = s + ' ' + label.replace(/ /g,'');
- }
- }
- }
- }
- });
- return (s == '') ? s : ('表单字段(<font color=green>'+s+'</font>)已修改');
- },
- /**
- * string:原始字符串
- * substr:子字符串
- * isIgnoreCase:忽略大小写
- */
- contains: function(string, substr, isIgnoreCase){
- if (string == null || substr == null) return false;
- if (isIgnoreCase === undefined || isIgnoreCase === true) {
- string = string.toLowerCase();
- substr = substr.toLowerCase();
- }
- return string.indexOf(substr) > -1;
- },
- setLoading : function(b) {// 原this.getActiveTab().setLoading()换成此方法,解决Window模式下无loading问题
- var mask = this.mask;
- if (!mask) {
- this.mask = mask = new Ext.LoadMask(Ext.getBody(), {
- msg : "处理中,请稍后...",
- msgCls : 'z-index:10000;'
- });
- }
- if (b)
- mask.show();
- else
- mask.hide();
- },
- loadNewStore: function(pr_id){
- var me = this;
- var grid = Ext.getCmp('grid');
- grid.setLoading(true);//loading...
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + "pm/mes/queryBOMStep.action",
- params: {
- id : pr_id
- },
- method : 'post',
- callback : function(options,success,response){
- grid.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- var data = res.data;
- if(!data || data.length == 0){
- grid.store.removeAll();
- grid.GridUtil.add10EmptyItems(grid);
- } else {
- if(grid.buffered) {
- var ln = data.length, records = [], i = 0;
- for (; i < ln; i++) {
- records.push(Ext.create(grid.store.model.getName(), data[i]));
- }
- grid.store.purgeRecords();
- grid.store.cacheRecords(records);
- grid.store.totalCount = ln;
- grid.store.guaranteedStart = -1;
- grid.store.guaranteedEnd = -1;
- var a = grid.store.pageSize - 1;
- a = a > ln - 1 ? ln - 1 : a;
- grid.store.guaranteeRange(0, a);
- } else {
- grid.store.loadData(data);
- }
- }
- //自定义event
- grid.addEvents({
- storeloaded: true
- });
- grid.fireEvent('storeloaded', grid, data);
- }
- });
- },
- cleanDetail : function() {
- var grid = Ext.getCmp('grid');
- var pr_code = Ext.getCmp('pr_code').value;
- var sp_bomversion = Ext.getCmp('sb_bomversion').value;
- var sb_id = Ext.getCmp('sb_id').value;
- var cr_code = Ext.getCmp('cr_code').value //途程
- if(pr_code == null || pr_code ==''){
- showError("产品编号不允许为空");
- return;
- }else if(sp_bomversion == null || sp_bomversion == ''){
- showError("BOM版本不允许为空");
- return;
- }else if(cr_code == '' || cr_code == null){
- showError("途程不允许为空");
- return;
- }
- grid.setLoading(true);
- Ext.Ajax.request({
- url : basePath + 'pm/mes/cleanBomStep.action',
- params : {
- caller:caller,
- pr_code : pr_code,
- sp_bomversion:sp_bomversion, //BOM版本编号
- cr_code:cr_code , //途程
- sb_id : sb_id
- },
- method : 'post',
- callback : function(options, success, response) {
- grid.setLoading(false);
- var localJson = new Ext.decode(response.responseText);
- if (localJson.success) {
- showMessage('提示', '清除明细成功!', 1000);
- //update成功后刷新页面进入可编辑的页面
- window.location.reload();
- } else if (localJson.exceptionInfo) {
- showError(localJson.exceptionInfo);
- return;
- }
- }
- });
- },
- itemclick:function(view,record,me){
- me.GridUtil.onGridItemClick(view,record);
- },
- loadTab: function(selModel, record){
- var me = this;
- var cr_code = Ext.getCmp('cr_code');
- var cr_stepcode = Ext.getCmp('cr_name');
- if(!record.data['leaf']){
- cr_code.setValue(record.data['text']);
- cr_stepcode.setValue('');
- }else{
- cr_stepcode.setValue(record.data['text']);
- }
- var tree = Ext.getCmp('tree-panel');
- if (!record.get('leaf')) {
- if(record.isExpanded() && record.childNodes.length > 0){//是根节点,且已展开
- record.collapse(true,true);//收拢
- } else {//未展开
- //看是否加载了其children
- if(record.childNodes.length == 0){
- //从后台加载
- tree.setLoading(true, tree.body);
- Ext.Ajax.request({//拿到tree数据
- url : basePath + 'pm/mes/getBOMStepTree.action',
- params: {
- caller:caller,
- cr_id: record.data['id'],
- pr_id:0
- },
- async: false,
- callback : function(options,success,response){
- tree.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if(res.tree){
- record.appendChild(res.tree);
- record.expand(false,true);//展开
- } else if(res.exceptionInfo){
- showError(res.exceptionInfo);
- }
- }
- });
- } else {
- record.expand(false,true);//展开
- }
- }
- }
- tree.getExpandedItems(record);
- var choose = '';
- Ext.each(tree.expandedNodes, function(){
- me.lastCode += this.data['qtip'];
- choose += '»' + this.data['text'];
- });
- Ext.getCmp('form').setTitle("<font color=blue>" + choose + "</font>");
- }
- });
|