| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.common.Search', {
- extend : 'Ext.app.Controller',
- requires : ['erp.util.GridUtil', 'erp.util.BaseUtil'],
- views : [ 'common.search.Viewport', 'core.trigger.DbfindTrigger', 'core.form.FtField',
- 'core.form.ConDateField', 'core.form.YnField','core.button.Sync',
- 'core.form.FtDateField', 'core.form.YearDateField',
- 'core.form.MonthDateField', 'core.form.FtFindField', 'core.form.FtNumberField',
- 'core.grid.YnColumn', 'core.grid.TfColumn',
- 'core.form.ConMonthDateField', 'core.trigger.TextAreaTrigger' ],
- models : ['SearchTemplate'],
- refs : [ {
- ref : 'grid',
- selector : '#querygrid'
- }, {
- ref: 'dataCount',
- selector: '#dataCount'
- } ],
- init : function() {
- var me = this;
- me.GridUtil = Ext.create('erp.util.GridUtil');
- me.BaseUtil = Ext.create('erp.util.BaseUtil');
- this.control({
- 'button[name=find]' : {
- click : function(btn) {
- this.onQueryClick();
- },
- afterrender : function() {
- Ext.defer(function(){
- me.onQueryClick();
- }, 500);
- }
- },
- 'button[name=group]' : {
- click : function(btn) {
- this.onGroupClick();
- }
- },
- 'button[name=close]' : {
- click : function() {
- if (parent.Ext && parent.Ext.getCmp('content-panel')) {
- parent.Ext.getCmp('content-panel').getActiveTab().close();
- } else {
- window.close();
- }
- }
- },
- 'button[name=clearcondition]' : {
- click : function() {
- if (this.querywin) {
- var g = this.querywin.down('grid');
- g.store.removeAll();
- g.loadEmptyData();
- }
- }
- },
- 'button[name=filter]' : {
- click : function() {
-
- }
- },
- 'button[name=sort]' : {
- click : function() {
- var items = this.searchTemplate ? this.searchTemplate.items : [],
- sorts = this.searchTemplate ? this.searchTemplate.st_sorts : null;
- this.onSortClick(items, sorts, function(sortSql, newSorts){
- me.getGrid().normalGrid.store.sort(newSorts);
- me.searchTemplate.st_sorts = sortSql;
- });
- }
- },
- 'button[name=temp]' : {
- click : function() {
- warnMsg('保存当前设置到方案?', function(b){
- if(b == 'ok' || b == 'yes') {
- me.updateTemp();
- }
- });
- }
- },
- 'menuitem[name=exportexcel]' : {
- click : function() {
- /*this.BaseUtil.exportGrid(this.getGrid().normalGrid);*/
- var temp =Ext.getCmp('temp');
- me.exportExcel(me.getGrid(), temp.selModel.getSelection(),me.getGrid().queryCondition);
- }
- },
- 'menuitem[name=exportpdf]' : {
- click : function() {
- this.BaseUtil.exportPdf(this.getGrid().normalGrid);
- }
- },
- 'button[name=lock]' : {
- click : function() {
- this.onLockClick();
- }
- },
- 'menuitem[name=sum]' : {
- click : function() {
-
- }
- },
- 'menuitem[name=average]' : {
- click : function() {
-
- }
- },
- 'menuitem[name=max]' : {
- click : function() {
- window.open(window.location.href);
- }
- },
- 'menuitem[name=webexcel]' : {
- click : function() {
- window.open(basePath + 'jsps/Excel/sheet/index.jsp');
- }
- },
- 'button[name=removeformat]' : {
- click : function() {
- this.onClear();
- }
- },
- 'button[name=clearall]' : {
- click : function() {
- this.getGrid().normalGrid.store.loadData([{},{},{},{},{},{},{},{},{},{}]);
- }
- },
- 'menuitem[name=template-copy]': {
- click: function(item) {
- var record = item.ownerCt.record;
- if (record) {
- var t = record.get('st_title');
- me.addTemp(t + '(新)', function(title){
- me.copyTemp(title, record.get('st_id'));
- });
- }
- }
- },
- 'menuitem[name=template-title]': {
- click: function(item) {
- var record = item.ownerCt.record;
- if (record) {
- me.addTemp(record.get('st_title'), function(title){
- me.onTempTitleChange(title, record.get('st_id'), function(){
- record.set('st_title', title);
- });
- });
- }
- }
- },
- 'menuitem[name=template-set]': {
- click: function(item) {
- var record = item.ownerCt.record;
- if (record) {
- me.onTempSet(record, record.get('items'), record.get('st_id'));
- }
- }
- },
- 'menuitem[name=template-del]': {
- click: function(item) {
- var grid = item.ownerCt.grid, record = item.ownerCt.record;
- if (record) {
- warnMsg('确定删除 ' + record.get('st_title') + ' ?', function(k){
- if(k == 'ok' || k == 'yes') {
- me.onTempDel(record.get('st_id'), function(){
- Ext.example.msg('info', '提示', record.get('st_title') + ' 删除成功', 2000);
- grid.store.remove(record);
- record = grid.store.first();
- if(record) {
- grid.selModel.select(record);
- }
- });
- }
- });
- }
- }
- }
- });
- if(!window.onLinkClick)
- window.onLinkClick = function(l, t, f, arg1, arg2){
- me.onLinkClick(l, t, f, arg1, arg2);
- };
- },
- onQueryClick : function() {
- var me = this, win = me.querywin;
- if (!win) {
- var form = me.createQueryForm(), temp = me.createTempGrid();
- win = me.querywin = Ext.create('Ext.window.Window', {
- closeAction : 'hide',
- title : '筛选',
- height: 500,
- width: 550,
- layout: 'anchor',
- items : [form, temp],
- buttonAlign : 'center',
- buttons : [{
- text : $I18N.common.button.erpQueryButton,
- height : 26,
- handler : function(b) {
- var items = temp.selModel.getSelection();
- if(items.length > 0) {
- me.onQuery(items[0].data);
- }
- b.ownerCt.ownerCt.hide();
- }
- },{
- text : '直接导出',
- iconCls: 'icon-xls',
- height : 26,
- handler : function(b) {
- me.exportExcel(me.getGrid().normalGrid, temp.selModel.getSelection(), form.getCondition());
- b.ownerCt.ownerCt.hide();
- }
- },{
- text : '复制方案到...',
- iconCls: '',
- height : 26,
- handler : function(b) {
- var items = temp.selModel.getSelection();
- if(items.length > 0) {
- console.log(items);
- me.duplicateTemp(items[0].data);
- }
- }
- },{
- height : 26,
- iconCls: '',
- xtype: 'erpSyncButton',
- itemId : 'sync',
- caller:'Search!Post',
- style : {
- marginLeft : '0px'
- },
- autoClearCache: true
- },{
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });
- me.onTempLoad(function(data, lastId){
- temp.store.loadData(data);
- if(data.length > 0) {
- var r = (lastId && temp.store.findRecord('st_id', lastId)) || temp.store.first();
- temp.selModel.select(r);
- form.setTitle(r.get('st_title'));
- }
- });
- }
- win.show();
- },
- createTempGrid : function() {
- var me = this;
- return Ext.create('Ext.grid.Panel', {
- id: 'temp',
- cls: 'custom-grid',
- title: '自定义方案',
- region: 'south',
- anchor: '100% 40%',
- autoScroll: true,
- tools: [{
- type: 'plus',
- tooltip: '添加方案',
- handler: function(e, el, tb, tool) {
- me.addTemp();
- }
- }],
- columns: [{
- text: '日期',
- dataIndex: 'st_date',
- renderer: function(v) {
- return Ext.Date.format(new Date(v), 'Y-m-d');
- },
- flex: 1
- },{
- text: '创建人',
- dataIndex: 'st_man',
- flex: 0.8
- },{
- text: '描述',
- dataIndex: 'st_title',
- flex: 3
- },{
- xtype: 'actioncolumn',
- flex: .6,
- align: 'center',
- items: [{
- icon: basePath + 'resource/images/16/edit.png',
- tooltip: '设置',
- handler: function(grid, rIdx, cIdx) {
- var record = grid.store.getAt(rIdx);
- me.onTempSet(record, record.get('items'), record.get('st_id'));
- }
- },{
- icon: basePath + 'resource/images/16/delete.png',
- tooltip: '删除',
- handler: function(grid, rIdx, cIdx) {
- var record = grid.store.getAt(rIdx);
- warnMsg('确定删除 ' + record.get('st_title') + ' ?', function(k){
- if(k == 'ok' || k == 'yes') {
- me.onTempDel(record.get('st_id'), function(){
- Ext.example.msg('info', '提示', record.get('st_title') + ' 删除成功', 2000);
- grid.store.remove(record);
- record = grid.store.first();
- if(record) {
- grid.selModel.select(record);
- }
- });
- }
- });
- }
- }]
- }],
- selModel: Ext.create('Ext.selection.CheckboxModel',{
- mode: 'SINGLE',
- listeners: {
- select : function(sm, record, idx) {
- var items = record.get('items');
- if(items) {
- me.formatTempSet(items, record.get('properties'), true);
- }
- me.querywin.down('erpSyncButton[itemId=sync]').syncdatas = record.get('st_id');
- me.defaultCondition = record.get('st_condition');
- me.searchTemplate = record.data;
- }
- }
- }),
- columnLines: true,
- store: new Ext.data.Store({
- fields: ['st_date', 'st_man', 'st_title', 'items', 'properties', 'st_id','st_condition','st_usedtable','st_tablesql','st_sorts', 'st_limits']
- }),
- viewConfig: {
- listeners: {
- itemcontextmenu: function(view, record, item, index, e) {
- me.onTempContextmenu(view, record, e);
- }
- }
- }
- });
- },
- /**
- * 方案grid,右键菜单
- */
- onTempContextmenu: function(view, record, e) {
- e.preventDefault();
- var menu = view.contextMenu;
- if (!menu) {
- menu = view.contextMenu = new Ext.menu.Menu({
- items: [{
- text : '复制方案',
- name: 'template-copy'
- },{
- text : '修改描述',
- name: 'template-title'
- },{
- text : '编辑方案',
- name: 'template-set'
- },{
- iconCls: 'icon-remove',
- text : '删除',
- name: 'template-del'
- }]
- });
- menu.grid = view.ownerCt;
- }
- menu.showAt(e.getXY());
- menu.record = record;
- },
- formatTempSet : function(items, properties, load) {
- var me = this, grid = this.getGrid();
- var datas = new Array(), columns = new Array(), alias = new Array(),
- group = null, locks = new Array(), temp = new Array(), v, w = 0.5;
- Ext.Array.each(items, function(i){
- var modeItems = [];
- if(1 === i.stg_query) {
- if (i.stg_mode && i.stg_mode != '' && properties) {// multi properties field
- Ext.Array.each(properties, function(p){
- if(p.stg_field == i.stg_field) {
- modeItems.push({
- display: p.display,
- value: p.value
- });
- }
- });
- if(i.stg_mode == 'checkboxgroup' || i.stg_mode == 'radiogroup') {
- var items = [];
- Ext.Array.each(properties, function(p){
- if(p.stg_field == i.stg_field) {
- items.push({
- boxLabel: p.display,
- inputValue: p.value,
- name: i.stg_field,
- checked: (i.stg_value && (i.stg_value == p.value || i.stg_value == '$ALL'))
- });
- }
- });
- datas.push({
- xtype: i.stg_mode,
- fieldLabel: i.stg_text,
- relativeTable: i.stg_table,
- columnWidth: 1,
- columns: 3,
- vertical: true,
- items: items
- });
- } else if (i.stg_mode == 'combobox') {
- var store = new Ext.data.Store({
- fields: ['display', 'value'],
- data: Ext.Array.merge([{
- display: '全部',
- value: '$ALL'
- },{
- display: '无',
- value: '$NULL'
- }], modeItems)
- });
- datas.push({
- xtype: i.stg_mode,
- name: i.stg_field,
- fieldLabel: i.stg_text,
- relativeTable: i.stg_table,
- columnWidth: .5,
- store: store,
- queryMode: 'local',
- displayField: 'display',
- valueField: 'value',
- value: i.stg_value
- });
- }
- } else {
- w = .5;
- v = i.stg_value;
- var t = 'textfield', type = i.stg_type.toUpperCase();
- if(/(DATE|TIMESTAMP)(\(\d+\)){0,1}/.test(type)) {
- t = 'datefield';
- if(!Ext.isEmpty(v)) {
- w = 1;
- switch(v) {
- case '今天':
- t = 'condatefield';v = 1;break;
- case '昨天':
- t = 'condatefield';v = 2;break;
- case '本月':
- t = 'condatefield';v = 3;break;
- case '上个月':
- t = 'condatefield';v = 4;break;
- case '本年度':
- t = 'condatefield';v = 5;break;
- case '上年度':
- t = 'condatefield';v = 6;break;
- case '自定义':
- t = 'condatefield';v = 7;break;
- default:
- if(!Ext.isDate(v) && /\d{4}-\d{2}-\d{2}/.test(v)) {
- v = Ext.Date.parse(v, 'Y-m-d');
- }
- break;
- }
- }
- } else if(/(NUMBER|FLOAT|INT)(\(\d+\)){0,1}/.test(type)) {
- t = 'numberfield';
- }
- if(1 == i.stg_dbfind) {
- t = 'dbfindtrigger';
- }
- if(1 == i.stg_double) {
- w = 1;
- if(t == 'numberfield') {
- t = 'erpFtNumberField';
- } else if (t == 'dbfindtrigger') {
- t = 'ftfindfield';
- } else if (t == 'datefield') {
- t = 'ftdatefield';
- } else if (t == 'textfield'){
- t = 'erpFtField';
- }
- if(i.stg_format == 'Ym') {
- t = 'conmonthdatefield';
- }
- }
- datas.push({
- fieldLabel: i.stg_text,
- relativeTable: i.stg_table,
- labelWidth: 100,
- xtype: t,
- name: i.stg_field,
- id: i.stg_field,
- value: v,
- columnWidth: w
- });
- }
- }
- if(1 === i.stg_group) {
- group = i.stg_alias;
- }
- if(1 === i.stg_lock) {
- locks.push(i.stg_alias);
- }
- var xtype = me.getTypeByStg(i.stg_type);
- if(1 === i.stg_use) {
- var col = {
- text: i.stg_text,
- xtype: xtype,
- dataIndex: i.stg_alias,
- dataField: i.stg_field,
- dataTable: i.stg_table,
- format: (i.stg_format == 'Ym') ? null : i.stg_format,
- width: i.stg_width,
- summaryType: i.stg_sum == 1 ? 'sum' : null,
- align: xtype == 'numbercolumn' ? 'right' : 'left'
- };
- if(i.stg_link) {
- col.renderer = function(value, p, record) {
- if(value) {
- return Ext.String.format(
- '<a href="javascript:void(0)" onclick="onLinkClick(\'' + i.stg_link + '\',\'{2}\',\'{3}\',\'{0}\',\'{1}\')">{2}</a>',
- record.get(i.stg_tokencol1),
- record.get(i.stg_tokencol2),
- value,
- i.stg_field
- );
- return null;
- };
- };
- }
- columns.push(col);
- }
- temp.push({
- stg_text: i.stg_text,
- stg_use: i.stg_use,
- stg_field: i.stg_field,
- stg_value: i.stg_value,
- stg_lock: i.stg_lock == 1,
- stg_group: i.stg_group == 1,
- stg_sum: i.stg_sum == 1,
- stg_dbfind: i.stg_dbfind == 1,
- stg_double: i.stg_double == 1,
- stg_query: i.stg_query == 1,
- stg_width: i.stg_width,
- stg_type: i.stg_type,
- stg_table: i.stg_table,
- stg_format: i.stg_format,
- stg_formula: i.stg_formula,
- stg_mode: i.stg_mode,
- modeItems: i.stg_mode ? (modeItems || [{dispay:null,value:null}]) : modeItems,
- type: xtype,
- links: i.links,
- stg_link: i.stg_link,
- stg_tokentab1: i.stg_tokentab1,
- stg_tokencol1: i.stg_tokencol1,
- stg_tokentab2: i.stg_tokentab2,
- stg_tokencol2: i.stg_tokencol2
- });
- });
- // 加载筛选条件
- if(load) {
- var f = this.querywin.down('form');
- f.removeAll();
- f.add(datas);
- var alias = Ext.Array.pluck(columns, 'dataIndex');
- Ext.Array.each(temp, function(t){
- if(t.stg_tokencol1 && !Ext.Array.contains(alias, t.stg_tokencol1)) {
- alias.push(t.stg_tokencol1);
- }
- if(t.stg_tokencol2 && !Ext.Array.contains(alias, t.stg_tokencol2)) {
- alias.push(t.stg_tokencol2);
- }
- });
- Ext.suspendLayouts();
- grid.reconfigure(new Ext.data.Store({
- fields: alias
- }), columns);
- Ext.resumeLayouts(true);
- // 加载分组条件
- this.groupfield = group;
- this.toogleGroup(group, true);
- // 固定列
- this.lockfields = locks;
- if(locks.length > 0) {
- var normal = grid.getView().normalGrid;
- Ext.Array.each(locks, function(){
- var column = normal.down('gridcolumn[dataIndex=' + this + ']');
- if (column.locked) {
- grid.unlock(column);
- } else {
- grid.lock(column);
- }
- });
- }
- // 加载合计
- }
- return temp;
- },
- onTempSet : function(record, items, sId) {
- var me = this, win = me.tempwin, temp = me.formatTempSet(items, record.get('properties'), false);
- if (!win) {
- var sGrid = me.getSettingGrid();
- Ext.define("Post", {
- extend: 'Ext.data.Model',
- proxy: {
- type: 'ajax',
- url : basePath + 'ma/dataDictionary/search.action',
- reader: {
- type: 'json',
- root: 'datas',
- totalProperty: 'totalCount'
- },
- headers: {
- 'Content-Type': 'application/json;charset=utf-8'
- }
- },
- fields: [
- {name: 'desc', mapping: 'comments'},
- {name: 'table', mapping: 'table_name'}
- ]
- });
- ds = Ext.create('Ext.data.Store', {
- pageSize: 10,
- model: 'Post'
- });
- win = me.tempwin = Ext.create('Ext.window.Window', {
- header: {
- items: [{
- xtype: 'tbtext',
- id: 'set-title',
- text: '方案设置',
- style: 'font-weight: 700;'
- }, {
- xtype: 'tbtext',
- id: 'set-info',
- tpl: Ext.create('Ext.XTemplate',
- '共 <strong>{tableCount}</strong> 个表关联,' +
- '可选 <strong>{columnCount}</strong> 列 ' +
- '已选 <strong>{usedCount}</strong> 列')
- }]
- },
- closeAction : 'hide',
- width : '100%',
- height : '80%',
- layout: 'border',
- items : [{
- region: 'west',
- width: 400,
- layout: 'accordion',
- id: 'dictionary',
- tbar: [{
- xtype: 'combo',
- store: ds,
- width: 360,
- displayField: 'desc',
- emptyText: '查找数据字典',
- typeAhead: false,
- hideLabel: true,
- hideTrigger:true,
- minChars: 3,
- listConfig: {
- minHeight: 360,
- maxHeight: 360,
- loadingText: '查找中...',
- emptyText: '<h3>没有找到您需要的数据字典.</h3>',
- getInnerTpl: function() {
- return '<div style="padding: 5px 10px;">' +
- '<span style="font-weight:bold;font-size:120%;">' +
- '<tpl if="desc">{desc}<tpl else>{table}</tpl>' +
- '</span>' +
- '<span style="float:right;">{table}</span>' +
- '</div>';
- }
- },
- pageSize: 10,
- listeners: {
- select: function(combo, records, opts) {
- me.addDictionary(win, records[0].get('table'));
- combo.reset();
- }
- },
- getParams: function(queryString) {
- var params = {},
- param = this.queryParam;
- if (param) {
- params[param] = escape(queryString);
- }
- return params;
- }
- },'->', {
- xtype: 'tool',
- type: 'left',
- style: {
- marginRight: '5px'
- },
- tooltip: '收拢',
- handler: function(e, el, tb, tool) {
- tb.ownerCt.collapse(Ext.Component.DIRECTION_LEFT, true);
- }
- }]
- },{
- region: 'center',
- layout: 'anchor',
- items: [sGrid]
- }],
- buttonAlign : 'center',
- buttons : [{
- text : '保存到方案',
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt;
- me.updateTemp(function(){
- w.hide();
- });
- }
- },{
- text : '作为新方案保存',
- id: 'new_temp_btn',
- height : 26,
- hidden : (sId <= 0),
- handler : function(b) {
- var t = win.relativeRecord.get('st_title');
- me.addTemp(t + '(新)', function(title){
- var w = b.ownerCt.ownerCt;
- w.hide();
- me.copyTemp(title);
- });
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });
- }
- win.show();
- if(sId <= 0) {
- win.down('#new_temp_btn').hide();
- } else {
- win.down('#new_temp_btn').show();
- }
- var g = win.down('#grid-setting');
- g.store.loadData(temp);
- g.sorts = record.get('st_sorts');
- g.limits = record.get('st_limits');
- g.down('#st_condition').setValue(record.get('st_condition'));
- // 加载数据字典
- var dic = win.down('#dictionary'),
- usedTabs = record.get('st_usedtable'), tabSql = record.get('st_tablesql');
- if(dic.tables != usedTabs || win.relativeId != sId) {
- g.down('#set-tab-info').setTooltip(me.getCodeTip({
- usedTabs: usedTabs.split(','),
- tabSql: tabSql,
- condSql: record.get('st_condition'),
- sortSql: g.sorts,
- data: temp
- }));
- me.getDictionary(usedTabs, function(datas){
- dic.tables = usedTabs;
- dic.removeAll();
- var c = 0;
- for(var i in datas) {
- dic.add(me.createDictionaryGrid(datas[i]));
- c += datas[i].dataDictionaryDetails.length;
- }
- win.down('#set-info').update({
- tableCount: datas.length,
- columnCount: c,
- usedCount: temp.length
- });
- });
- }
- if(win.relativeId != sId) {
- win.down('#set-title').setText(record.get('st_title'));
- win.relativeRecord = record;
- win.relativeId = sId;
- }
- },
- /**
- * 显示方案sql的tip
- */
- getCodeTip: function(config) {
- var me = this, oldConf = me.templateConfig;
- if(!oldConf)
- oldConf = {};
- me.templateConfig = config = Ext.Object.merge(oldConf, config);
- return new Ext.tip.ToolTip({
- target: 'set-tab-info',
- cls: 'tip-custom',
- autoHide: false,
- hideDelay: 0,
- html: me.getCodeHtml(config)
- });
- },
- /**
- * 代码html
- */
- getCodeHtml: function(datas) {
- return new Ext.XTemplate(
- '<strong class="code-title">数据字典:</strong>' +
- '<tpl for="usedTabs">' +
- '<label class="label label-info">{.}</label>' +
- '</tpl>' +
- '<strong class="code-title">关联SQL:</strong>' +
- '<div class="code-body">{tabSql:this.format}</div>' +
- '<strong class="code-title">排序SQL:</strong>' +
- '<div class="code-body">{sortSql:this.orderBy}</div>' +
- '<strong class="code-title">条件SQL:</strong>' +
- '<div class="code-body">{condSql:this.format}</div>' +
- '<strong class="code-title">查询SQL:</strong>' +
- '<div class="code-body">{[this.getSearchSql(values)]}</div>', {
- keywords : ['SELECT ', ' FROM ', ' WHERE ', ' LEFT JOIN ', ' ON ', 'ORDER BY ', ' AND ', ' DESC', ' ASC', 'TO_CHAR'],
- format: function(sql) {
- if(!sql) return null;
- var kw = this.keywords;
- for(var i in kw) {
- var reg = new RegExp(kw[i], 'g');
- sql = sql.replace(reg, '<span class="code-key">' + kw[i] + '</span>');
- }
- sql = this.replaceQuot(sql);
- return sql;
- },
- replaceQuot: function(sql) {
- var index = 0, length = sql.length, s, e = -1, c = 0, htm = '';
- while(index < length) {
- if((s = sql.indexOf('\'', index)) != -1 && (e = sql.indexOf('\'', s + 1)) != -1) {
- c = 1;
- while(sql.substring(e + c, e + c + 1) == '\'' || c%2 == 0){
- e++;
- c++;
- }
- htm += sql.substring(index, s) + '<span class="code-quot">' + sql.substring(s, e+1) +'</span>';
- index = e + 1;
- } else {
- htm += sql.substring(e + 1);
- break;
- }
- }
- return htm.length > 0 ? htm : sql;
- },
- orderBy: function(sql) {
- if(!sql) return null;
- return this.format('ORDER BY ' + sql);
- },
- getSearchSql: function(values) {
- var fs = [];
- Ext.Array.each(values.data, function(d){
- if(d.stg_type.toLowerCase() == 'date')
- fs.push('TO_CHAR(' + d.stg_table + '.' + d.stg_field +
- ', \'yyyy-mm-dd hh24:mi:ss\') ' + d.stg_field);
- else
- fs.push(d.stg_table + '.' + d.stg_field + ' ' + d.stg_field);
-
- });
- return this.format('SELECT ' + fs.join(',') + ' FROM ' + values.tabSql +
- (values.condSql ? (' WHERE (' + values.condSql + ')') : '') +
- (values.sortSql ? (' ORDER BY ' + values.sortSql) : ''));
- }
- }).apply(datas);
- },
- /**
- * 添加数据字典
- */
- addDictionary: function(win, table) {
- var me = this, dic = win.down('#dictionary');
- if(dic.tables && Ext.Array.indexOf(dic.tables.split(','), table) > -1) {
- Ext.example.msg('warning', '警告', '不能添加已经存在的表', 4000);
- return;
- }
- var newTabs = dic.tables ? dic.tables + ',' + table : table;
- me.getTabSql(newTabs, function(sql){
- me.getDictionary(table, function(datas){
- dic.tables = newTabs;
- var c = 0;
- for(var i in datas) {
- dic.add(me.createDictionaryGrid(datas[i]));
- c += datas[i].dataDictionaryDetails.length;
- }
- Ext.each(dic.items.items, function(g){
- c += g.store.getCount();
- });
- win.down('#set-info').update({
- tableCount: dic.items.items.length,
- columnCount: c
- });
- win.down('#set-tab-info').setTooltip(me.getCodeTip({
- usedTabs: dic.tables.split(','),
- tabSql: sql
- }));
- });
- });
- },
- getTypeByStg: function(t) {
- t = t.toUpperCase();
- if(/(NUMBER|FLOAT|INT)(\(\d+\)){0,1}/.test(t))
- return 'numbercolumn';
- if(/(DATE|TIMESTAMP)(\(\d+\)){0,1}/.test(t))
- return 'datecolumn';
- return null;
- },
- /**
- * 显示数据字典的grid
- */
- createDictionaryGrid: function(dic) {
- var id = 'grid-' + dic.table_name, datas = [], me = this;
- Ext.Array.each(dic.dataDictionaryDetails, function(d){
- var nl = {
- text: d.comments,
- type: me.getTypeByStg(d.data_type),
- stg_width: 100,
- stg_text: d.comments,
- stg_use: 1,
- stg_field: d.column_name.toUpperCase(),
- stg_table: d.table_name.toUpperCase(),
- stg_type: d.data_type.toUpperCase(),
- modeItems: [],
- links: d.links
- };
- if(d.links && d.links.length > 0) {
- nl.stg_link = d.links[0].dl_link;
- nl.stg_tokentab1 = d.links[0].dl_tokentab1;
- nl.stg_tokencol1 = d.links[0].dl_tokencol1;
- nl.stg_tokentab2 = d.links[0].dl_tokentab2;
- nl.stg_tokencol2 = d.links[0].dl_tokencol2;
- }
- datas.push(nl);
- });
- return new Ext.grid.Panel({
- title: dic.comments,
- cls: 'custom-grid',
- id: id,
- columns: [{
- text: '代码',
- dataIndex: 'stg_field',
- flex: 1,
- filter: {
- xtype : 'textfield'
- }
- },{
- text: '描述',
- dataIndex: 'stg_text',
- flex: 1,
- filter: {
- xtype : 'textfield'
- }
- }],
- plugins: [Ext.create('erp.view.core.grid.HeaderFilter')],
- viewConfig: {
- plugins: {
- ptype: 'gridviewdragdrop',
- dragGroup: 'grid-setting',
- dropGroup: 'grid-setting'
- },
- listeners: {
- drop: function(node, data) {
- // 从配置里面拖过来的,表示删除
- // 重新加载数据,防止出现checkcolumn的勾选错位情况
- var newData = [];
- data.view.store.each(function(record){
- newData.push(record.data);
- });
- data.view.store.loadData(newData);
- }
- }
- },
- selModel: new Ext.selection.RowModel({
- mode: 'MULTI'
- }),
- store: new Ext.data.Store({
- model: erp.model.SearchTemplate,
- data: datas,
- sorters: [{
- property: 'stg_field',
- direction: 'ASC'
- }]
- })
- });
- },
- createQueryForm : function() {
- var me = this;
- var form = Ext.create('Ext.form.Panel', {
- region: 'center',
- anchor: '100% 60%',
- title: '(未选择方案)',
- layout: 'column',
- autoScroll: true,
- defaults: {
- columnWidth: 1,
- margin: '4 8 4 8'
- },
- bodyStyle: 'background:#f1f2f5;',
- getCondition: function() {
- var s = me.defaultCondition ? '(' + me.defaultCondition + ')' : '';
- Ext.each(this.items.items, function(){
- var v = this.getValue(), b = this.relativeTable, n = this.name, _n = b + '.' + n, t;
- if(!Ext.isEmpty(v) && v != '$ALL') {
- switch(this.xtype) {
- case 'datefield':
- t = "to_char(" + _n + ",'yyyy-mm-dd')='" + Ext.Date.format(v,'Y-m-d') + "'";break;
- case 'condatefield':
- t = _n + ' ' + v;break;
- case 'ftdatefield':
- t = _n + ' ' + this.value;break;
- case 'ftfindfield':
- t = _n + ' ' + this.value;break;
- case 'erpFtNumberField':
- t = _n + ' ' + this.value;break;
- case 'checkboxgroup':
- if(!Ext.Object.isEmpty(v)) {
- var ks = Ext.Object.getKeys(v), k = ks[0], vs = [];
- Ext.Array.each(v[k], function(c){
- vs.push(k + '=\'' + c + '\'');
- });
- t = vs.join(' OR ');
- }
- break;
- case 'radiogroup':
- if(!Ext.Object.isEmpty(v)) {
- var ks = Ext.Object.getKeys(v), k = ks[0];
- t = k + '=\'' + v[k] + '\'';
- }
- break;
- case 'conmonthdatefield':
- if(!Ext.Object.isEmpty(v)) {
- if(n.toUpperCase().indexOf('YM_VIEW_PARAM') > -1) {
- t = ' ' + this.value;
- } else {
- t = _n + ' ' + this.value;
- }
- }
- break;
- default:
- v = String(v);
- if(v.charAt(0) == '%' || v.charAt(v.length - 1) == '%') {
- t = _n + " like '" + v + "'";
- } else if (v == '$NULL') {
- t = "nvl(" + _n + ",' ')=' '";
- } else {
- t = _n + "='" + v + "'";
- }
- break;
- }
- if(t) {
- t = '(' + t + ')';
- s += s.length > 0 ? (' and ' + t ) : t;
- }
- }
- });
- return s.length > 0 ? s : '0=0';
- }
- });
- return form;
- },
- onQuery : function(data) {
- var g = this.getGrid(), q = this.querywin.down('form'), end = g.maxDataSize || 10000;
- this.loadNewStore(g, {
- sId: data ? data.st_id : this.$sid,
- condition: q.getCondition(),
- sorts: data ? data.st_sorts : this.templateConfig.sorts,
- start: 1,
- end: end
- });
- this.querywin.hide();
- this.log();//记录本次选择的方案
- },
- onGroupClick : function() {
- var me = this, win = me.groupwin;
- if (!win) {
- var form = me.getAliaForm();
- win = me.groupwin = Ext.create('Ext.window.Window', {
- title : '分组设置',
- closeAction : 'hide',
- width : 500,
- maxHeight : 400,
- items : [form],
- buttonAlign : 'center',
- buttons : [{
- text : '取消分组',
- flag : 'cancel',
- height : 26,
- disabled : true,
- handler : function(b) {
- var w = b.ownerCt.ownerCt;
- me.toogleGroup(w.down('form'), false);
- w.hide();
- }
- },{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt;
- me.toogleGroup(w.down('form'), true);
- w.hide();
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });
- if(this.groupfield) {
- var f = win.down('radio[inputValue=' + this.groupfield + ']');
- if(f) {
- f.setValue(true);
- }
- }
- }
- win.show();
- var f = win.down('radio[value=true]'), b = win.down('button[flag=cancel]');
- b.setDisabled(!f);
- },
- onLockClick : function() {
- var me = this, win = me.lockwin;
- if (!win) {
- var form = me.getAliaForm('checkbox');
- win = me.lockwin = Ext.create('Ext.window.Window', {
- title : '固定列设置',
- closeAction : 'hide',
- width : 500,
- maxHeight : 400,
- items : [form],
- buttonAlign : 'center',
- buttons : [{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt;
- me.onLock(w.down('form'));
- w.hide();
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });
- if(this.lockfields) {
- Ext.Array.each(this.lockfields, function(l){
- var f = win.down('checkbox[inputValue=' + l + ']');
- if(f) {
- f.setValue(true);
- }
- });
- }
- }
- win.show();
- },
- onSortClick : function(source, oldSorts, callback) {
- var me = this, win = me.sortwin;
- var oldData = [], oldProp = [];
- if(oldSorts) {
- Ext.Array.each(oldSorts.split(','), function(s, i){
- var p = s.split(' '), t = null, f = p[0], tx = '';
- if(f.indexOf('.') > 0) {// table.field
- t = f.substr(0, f.indexOf('.'));
- f = f.substr(f.indexOf('.') + 1);
- }
- if(Ext.isArray(source)) {
- var obj = Ext.Array.findBy(source, function(i){
- return i.stg_field == f;
- });
- if (obj) tx = obj.stg_text;
- } else {
- tx = source.findRecord('stg_field', f).get('stg_text');
- }
- oldData.push({property: f, direction: p[1], number: i+1, description: tx, table: t});
- oldProp.push(f);
- });
- }
- if (!win) {
- var form = me.getGridForm('checkbox', null, source, oldProp),
- view = me.getSortingView(oldData);
- win = me.sortwin = Ext.create('Ext.window.Window', {
- title : '排序设置',
- closeAction : 'hide',
- width : 800,
- layout: 'hbox',
- defaults: {flex: 1},
- items : [form, view],
- buttonAlign : 'center',
- buttons : [{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt, sorts = [], sortSql = [], desc = '';
- view.getStore().each(function(i){
- desc = i.get('property') + ' ' + i.get('direction');
- if(i.get('table'))
- desc = i.get('table') + '.' + desc;
- sortSql.push(desc);
- sorts.push({
- property: i.get('alias'),
- direction: i.get('direction')
- });
- });
- callback.call(me, sortSql.join(','), sorts);
- w.hide();
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });
- } else {
- var form = win.down('form'), view = win.down('dataview');
- form.removeAll();
- form.add(me.createFormItems(source, oldProp));
- view.store.loadData(oldData);
- }
- win.show();
- me.onSortChange(win.down('form'), win.down('dataview'));
- },
- /**
- * 排序设置,监听字段变化
- */
- onSortChange: function(form, view) {
- var me = this, onDirectionChange = function() {
- var d = Ext.select("td.sort-value input"), e = d.elements;
- Ext.each(e, function(m) {
- Ext.EventManager.on(m, {
- change : function(e, el){
- var record = view.getStore().findRecord('property', el.name);
- record.set('direction', el.value);
- },
- buffer : 100
- });
- });
- };
- form.getForm().getFields().each(function(field){
- field.on('change', function(scope){
- view.getStore().loadData(me.getSortProperties(scope.ownerCt, view.getStore()));
- onDirectionChange();
- });
- });
- Ext.defer(onDirectionChange, 100);
- },
- /**
- * 选中的排序字段view
- */
- getSortingView: function(oldData) {
- var sortStore = new Ext.data.Store({
- fields: ['property', 'description', 'direction', 'number', 'table', 'alias'],
- sorters: [{
- property: 'number',
- direction: 'ASC'
- }],
- data: oldData
- });
- return Ext.create('Ext.view.View', {
- cls: 'sort-view',
- tpl: '<tpl for=".">' +
- '<div class="sort"><table><tbody>' +
- '<tr><td class="sort-name">{description}</td></tr>' +
- '<tr><td class="sort-value">' +
- '<em>升序 </em><input type="radio" name="{property}" value="ASC" ' +
- '<tpl if="direction == "ASC""> checked="checked"</tpl>' +
- '/>' +
- '</td></tr>' +
- '<tr><td class="sort-value">' +
- '<em>降序 </em><input type="radio" name="{property}" value="DESC" ' +
- '<tpl if="direction == "DESC""> checked="checked"</tpl>' +
- '/>' +
- '</td></tr>' +
- '</tbody></table></div>' +
- '</tpl>' +
- '<ol class="sort-note">' +
- '<li>如果直接点击列抬头来排序,将不会使用到本次排序设置</li>' +
- '<li>可以拖放选中的字段来改变排序的优先顺序</li>' +
- '</ol>',
- itemSelector: 'div.sort',
- overItemCls: 'sort-over',
- selectedItemClass: 'sort-selected',
- singleSelect: true,
- ddGroup: 'sort',
- store: sortStore,
- listeners: {
- render: function(v) {
- v.dragZone = new Ext.dd.DragZone(v.ownerCt.el, {
- ddGroup: 'sort',
- getDragData: function(e) {
- var sourceEl = e.getTarget(v.itemSelector, 10), d;
- if (sourceEl) {
- d = sourceEl.cloneNode(true);
- d.id = Ext.id();
- return (v.dragData = {
- sourceEl: sourceEl,
- repairXY: Ext.fly(sourceEl).getXY(),
- ddel: d,
- record: v.getRecord(sourceEl)
- });
- }
- },
- getRepairXY: function() {
- return this.dragData.repairXY;
- }
- });
- v.dropZone = new Ext.dd.DropZone(v.ownerCt.el, {
- ddGroup: 'sort',
- getTargetFromEvent: function(e) {
- return e.getTarget('.sort .sort-over');
- },
- onNodeEnter: function(target, dd, e, data){
- var fly = Ext.fly(target);
- if(fly && typeof fly.addClass === 'function')
- fly.addClass('sort-target-hover');
- },
- onNodeOut: function(target, dd, e, data){
- var fly = Ext.fly(target);
- if(fly && typeof fly.removeClass === 'function')
- fly.removeClass('sort-target-hover');
- },
- onNodeOver: function(target, dd, e, data){
- return Ext.dd.DropZone.prototype.dropAllowed;
- },
- onNodeDrop : function(target, dd, e, data){
- var dragRec = dd.dragData.record,
- dropRec = v.getRecord(target);
- var i = dragRec.get('number'), j = dropRec.get('number');
- dragRec.set('number', j);
- dropRec.set('number', i);
- v.getStore().sort('number', 'ASC');
- return true;
- }
- });
- }
- }
- });
- },
- newComboConfig: function(data) {
- return {
- store: Ext.create('Ext.data.Store', {
- fields: ['display', 'value'],
- data : data
- }),
- displayField: 'display',
- valueField: 'value',
- queryMode: 'local'
- };
- },
- getSettingGrid : function() {
- var me = this, config = {
- store: Ext.create('Ext.data.Store', {
- fields: ['display', 'value'],
- data : [
- {"display": '今天', "value": '今天'},
- {"display": '昨天', "value": '昨天'},
- {"display": '本月', "value": '本月'},
- {"display": '上个月', "value": '上个月'},
- {"display": '本年度', "value": '本年度'},
- {"display": '上年度', "value": '上年度'},
- {"display": '自定义', "value": '自定义'}
- ]
- }),
- displayField: 'display',
- valueField: 'value',
- queryMode: 'local'
- };
- var formatStore = new Ext.data.Store({
- fields: ['display', 'value', 'type'],
- data: [{
- display: '0,000.00',
- value: '0,000.00',
- type: 'numbercolumn'
- },{
- display: '0,000.0000',
- value: '0,000.0000',
- type: 'numbercolumn'
- },{
- display: '0,000.000000',
- value: '0,000.000000',
- type: 'numbercolumn'
- },{
- display: '整数',
- value: '0,000',
- type: 'numbercolumn'
- },{
- display: '年-月-日',
- value: 'Y-m-d',
- type: 'datecolumn'
- },{
- display: '年-月-日 时:分:秒',
- value: 'Y-m-d H:i:s',
- type: 'datecolumn'
- },{
- display: '年-月',
- value: 'Y-m',
- type: 'datecolumn'
- },{
- display: '月-日 时:分',
- value: 'm-d H:i',
- type: 'datecolumn'
- }]
- });
- return Ext.create('Ext.grid.Panel', {
- id: 'grid-setting',
- anchor: '100% 100%',
- autoScroll : true,
- cls: 'custom-grid',
- border: false,
- columnLines: true,
- tbar: [{
- text: '自定义公式',
- iconCls: 'icon-fx',
- handler: function(t) {
- var g = t.ownerCt.ownerCt;
- me.onFormulaClick(g.getStore(), null, function(formula){
- var isN = formula.indexOf("'") == -1;
- g.store.add({
- stg_text: '输入公式名称',
- stg_use: true,
- stg_field: 'COL_' + new Date().getTime(),
- stg_formula: formula,
- stg_width: 100,
- stg_type: isN ? 'NUMBER' : 'VARCHAR2(100)',
- stg_format: isN ? '0,000.00' : null,
- modeItems: []
- });
- g.selModel.select(g.store.last());
- });
- }
- },{
- text: '权限约束',
- iconCls: 'icon-limit',
- handler: function(t) {
- var g = t.ownerCt.ownerCt;
- me.onLimitClick(g.getStore(), g.limits, function(val){
- g.limits = val;
- });
- }
- },{
- text: '排序设置',
- iconCls: 'icon-sort',
- handler: function(t) {
- var g = t.ownerCt.ownerCt;
- me.onSortClick(g.getStore(), g.sorts, function(sortSql){
- g.sorts = sortSql;
- g.down('#set-tab-info').setTooltip(me.getCodeTip({
- sortSql: g.sorts
- }));
- });
- }
- },'->',{
- xtype: 'textfield',
- emptyText: 'SQL条件',
- width: '66%',
- id: 'st_condition'
- }],
- bbar: ['提示:1. 可以拖动数据字典的字段到右边;2. 字段可以拖放来调整顺序;3. 行展开设置特殊选项', '->', {
- icon: basePath + 'resource/images/16/question.png',
- cls: 'x-btn-icon',
- text: '查看方案代码',
- tooltip: '',
- id: 'set-tab-info'
- }],
- viewConfig: {
- plugins: {
- ptype: 'gridviewdragdrop',
- dragGroup: 'grid-setting',
- dropGroup: 'grid-setting'
- },
- listeners: {
- drop: function(node, data, over) {
- // 重新加载数据,防止出现checkcolumn的勾选错位情况
- var newData = [];
- if(over) {
- over.store.each(function(record){
- newData.push(record.data);
- });
- over.store.loadData(newData);
- }
- }
- }
- },
- plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1,
- listeners: {
- beforeedit: function(editor, e, opts) {
- if(e.column.dataIndex == 'stg_value') {
- var isDate = ['datecolumn','datetimecolumn'].indexOf(e.record.get('type')) > -1,
- isRadio = e.record.get('stg_mode') == 'radiogroup',
- isMulti = ['checkboxgroup','combobox'].indexOf(e.record.get('stg_mode')) > -1,
- items = e.record.get('modeItems');
- if(isDate) {
- e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(config, {
- value: e.value
- })));
- } else if(isRadio) {
- e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(me.newComboConfig(items), {
- value: e.value
- })));
- } else if(isMulti) {
- var _items = Ext.Array.merge([{display: '全选', value: '$ALL'}], items);
- e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(me.newComboConfig(_items), {
- value: e.value
- })));
- } else {
- e.column.setEditor(new Ext.form.field.Text({
- value: e.value
- }));
- }
- } else if(e.column.dataIndex == 'stg_format') {
- formatStore.clearFilter(true);
- formatStore.filter('type', e.record.get('type'));
- }
- }
- }
- }), {
- ptype: 'rowexpander',
- pluginId: 'rowexpander',
- expandOnDblClick: false,
- rowBodyTpl : [
- '<tpl if="stg_formula">' +
- '<div class="row">' +
- '<label class="radio-inline text-info col-xs-2">' +
- '表达式:' +
- '</label>' +
- '<div class="col-xs-8">{stg_formula:this.formatFormula}</div>' +
- '<div class="col-xs-1">' +
- '<button id="{[this.linkEvent(\'onFormulaEdit\')]}" class="x-btn" data-bind="{stg_field}">编辑</button>' +
- '</div>' +
- '</div><br>' +
- '</tpl>'+
- '<tpl if="stg_link">' +
- '<div class="links row">' +
- '<label class="radio-inline text-info col-xs-2">' +
- '链接:' +
- '</label>' +
- '<div class="col-xs-10">' +
- '<tpl for="links">' +
- '<label class="radio-inline">' +
- '<input type="radio" id="{[this.linkEvent(\'onLinkChange\')]}" name="{dl_fieldname}-link" data-bind="{dl_fieldname}" value="{[xindex]}" ' +
- '<tpl if="dl_link == parent.stg_link"> checked="checked"</tpl>' +
- ' /> {dl_title}' +
- '</label>' +
- '</tpl>' +
- '</div>' +
- '</div>' +
- '</tpl>' +
- '<tpl if="stg_table">' +
- '<div class="mode-type row" data-bind="{stg_field}">' +
- '<label class="radio-inline text-info col-xs-2">' +
- '查询格式:' +
- '</label>' +
- '<div class="col-xs-10">' +
- '<label class="radio-inline">' +
- '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="" ' +
- '<tpl if="!stg_mode || stg_mode == """> checked="checked"</tpl>' +
- ' /> 无' +
- '</label>' +
- '<label class="radio-inline">' +
- '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="checkboxgroup" ' +
- '<tpl if="stg_mode == "checkboxgroup""> checked="checked"</tpl>' +
- ' /> 勾选框' +
- '</label>' +
- '<label class="radio-inline">' +
- '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="radiogroup" ' +
- '<tpl if="stg_mode == "radiogroup""> checked="checked"</tpl>' +
- ' /> 单选框' +
- '</label>' +
- '<label class="radio-inline">' +
- '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="combobox" ' +
- '<tpl if="stg_mode == "combobox""> checked="checked"</tpl>' +
- ' /> 下拉框' +
- '</label>' +
- '</div>' +
- '</div>' +
- '</tpl>' +
- '<tpl if="stg_mode">' +
- '<div class="mode-items" data-bind="{stg_field}">' +
- '<a class="x-btn btn-default" id="{[this.linkEvent(\'onModeItemAdd\')]}"><i class="x-btn-icon-el icon-add"></i><span class="x-btn-text">添加属性</span></a>' +
- '<tpl for="modeItems">' +
- '<div class="mode-item">' +
- '<input type="text" id="{[this.linkEvent(\'onModeItemFocus\')]}" name="display" value="{display}" placeholder="显示属性" />' +
- '<input type="text" id="{[this.linkEvent(\'onModeItemFocus\')]}" name="value" value="{value}" placeholder="实际属性" />' +
- '<input type="button" id="{[this.linkEvent(\'onModeItemDel\')]}" data-index="{[xindex]}" value="×" title="删除"/>' +
- '</div>' +
- '</tpl>' +
- '</div>' +
- '</tpl>',
- {
- formatFormula: function(formula) {
- // 数据库格式的表达式转化为界面显示的表达式
- var units = formula.replace(/>=/g,'≥').replace(/<=/g,'≤').replace(/<>/g,'≠').replace(/(\|\|)/g,'‖')._split(/[\+\-\*=><\/%,\(\)\s]/), text = '', scope = this;
- Ext.Array.each(units, function(unit){
- if(!isNumber(unit) && (unit.indexOf('.') > 0 || unit.indexOf('COL_') == 0))
- text += scope.getDesc(unit);
- else
- text += unit;
- });
- return text;
- },
- onFormulaEdit: function(elm) {
- var store = this.owner.view.store, grid = this.owner.grid;
- Ext.EventManager.on(elm, {
- click: function(event, el) {
- var record = grid.store.findRecord('stg_field', el.getAttribute('data-bind'));
- me.onFormulaClick(store, record.get('stg_formula').replace(/>=/g,'≥').replace(/<=/g,'≤').replace(/<>/g,'≠').replace(/(\|\|)/g,'‖'), function(formula){
- record.set('stg_formula', formula);
- });
- Ext.EventManager.stopEvent(event);
- },
- buffer: 50
- });
- },
- getDesc: function(unit) {
- var table = null, field = unit;
- if(unit.indexOf('.') > 0) {
- table = unit.substring(0, unit.indexOf('.'));
- field = unit.substr(unit.indexOf('.')+1);
- }
- var res = this.owner.view.store.queryBy(function(record){
- return record.get('stg_table') == table && record.get('stg_field') == field;
- }), item = res.first();
- if(item)
- return item.get('stg_text');
- return '';
- },
- linkEvent: function(eventName) {
- var result = Ext.id();
- Ext.defer(this.addListener, 1, this, [result, eventName]);
- return result;
- },
- addListener: function(id, eventName) {
- var elm = Ext.get(id);
- elm && this[eventName].call(this, elm);
- },
- onModeChange: function(elm) {
- var grid = this.owner.grid;
- Ext.EventManager.on(elm, {
- change: function(event, el) {
- var record = grid.store.findRecord('stg_field', el.name);
- record.set('stg_mode', el.value);
- if(el.value && el.value != '') {
- var items = record.get('modeItems');
- if(!items || items.length == 0) {
- record.set('modeItems', [{display: null,value:null}]);
- }
- }
- Ext.EventManager.stopEvent(event);
- },
- buffer: 100
- });
- },
- getViewItems: function(el) {
- var p = el.parentNode.parentNode;
- if(p) {
- var gps = Ext.query('.mode-item', el.parentNode.parentNode), items = [];
- Ext.Array.each(gps, function(els){
- var e = els.childNodes, d = e[0].value, v = e[1].value;
- v = (!v || v == '') ? d : v;
- v = (!d || d == '') ? null : v;
- items.push({display: d, value: v});
- });
- return items;
- }
- return null;
- },
- onModeItemAdd: function(elm) {
- var grid = this.owner.grid, me = this;
- Ext.EventManager.on(elm, {
- click: function(event, el) {
- var p = el.parentNode.parentNode;
- if(p) {
- var field = p.getAttribute('data-bind'),
- record = grid.store.findRecord('stg_field', field),
- items = me.getViewItems(el) || [];
- items.push({
- display: null,
- value: null
- });
- record.set('modeItems', items);
- }
- Ext.EventManager.stopEvent(event);
- },
- buffer: 50
- });
- },
- onModeItemDel: function(elm) {
- var grid = this.owner.grid;
- Ext.EventManager.on(elm, {
- click: function(event, el) {
- var p = el.parentNode.parentNode;
- if(p) {
- var field = p.getAttribute('data-bind'),
- record = grid.store.findRecord('stg_field', field),
- items = record.get('modeItems'), idx = Number(el.getAttribute('data-index')) - 1;
- items.splice(idx, 1);
- Ext.get(el.parentNode).remove();
- record.set('modeItems', items);
- }
- Ext.EventManager.stopEvent(event);
- }
- });
- },
- onModeItemFocus: function(elm) {
- var me = this;
- Ext.EventManager.on(elm, {
- mousedown: function(event, el) {
- el.focus();
- Ext.EventManager.stopEvent(event);
- },
- buffer: 100
- });
- Ext.EventManager.on(elm, {
- blur: function(event, el) {
- if(el.name == 'display') {
- var nextEl = el.nextSibling;
- if(Ext.isEmpty(el.value) || el.value == '') {
- nextEl.value = null;
- } else {
- if(Ext.isEmpty(nextEl.value) || nextEl.value == '') {
- nextEl.value = el.value;
- }
- }
- }
- },
- change: function(event, el) {
- var items = me.getViewItems(el);
- if (items) {
- var field = el.parentNode.parentNode.getAttribute('data-bind'),
- grid = me.owner.grid,
- record = grid.store.findRecord('stg_field', field);
- record.set('modeItems', items);
- }
- },
- buffer: 10
- });
- },
- onLinkChange: function(elm) {
- var grid = this.owner.grid;
- Ext.EventManager.on(elm, {
- change: function(event, el) {
- var record = grid.store.findRecord('stg_field', el.getAttribute('data-bind')),
- links = record.get('links'), dl = links[el.value - 1];
- record.set('stg_link', dl.dl_link);
- record.set('stg_tokentab1', dl.dl_tokentab1);
- record.set('stg_tokencol1', dl.dl_tokencol1);
- record.set('stg_tokentab2', dl.dl_tokentab1);
- record.set('stg_tokencol2', dl.dl_tokencol2);
- Ext.EventManager.stopEvent(event);
- },
- buffer: 100
- });
- }
- }]
- }],
- store: new Ext.data.Store({
- model: erp.model.SearchTemplate
- }),
- columns: [{
- text: '列',
- flex: 1,
- columns: [{
- text: '名称',
- dataIndex: 'stg_text',
- width: 180,
- editor: {
- xtype: 'textfield'
- },
- sortable: false,
- renderer: function(val, meta, record){
- var a = record.get('stg_table'), b = record.get('stg_field'),
- c = record.get('stg_formula'), text = '';
- a && (text += '表:' + a);
- b && (text += ' 字段:' + b);
- c && (text += ' 公式:' + c);
- return '<span title="' + text + '">' + val + '</span>';
- }
- },{
- text: '是否<br>显示',
- xtype: 'checkcolumn',
- dataIndex: 'stg_use',
- align: 'center',
- headerCheckable: false,
- width: 45,
- sortable: false
- },{
- text: '宽度',
- xtype: 'numbercolumn',
- dataIndex: 'stg_width',
- align: 'center',
- width: 50,
- format: '0,00',
- editor: {
- xtype: 'numberfield',
- hideTrigger: true
- },
- sortable: false
- },{
- text: '格式转换',
- dataIndex: 'stg_format',
- align: 'center',
- width: 90,
- editor: {
- xtype: 'combo',
- store: formatStore,
- displayField: 'display',
- valueField: 'value',
- queryMode: 'local'
- },
- sortable: false
- }],
- sortable: false
- },{
- text: '查询',
- columns: [{
- text: '用于<br>查询',
- xtype: 'checkcolumn',
- dataIndex: 'stg_query',
- align: 'center',
- width: 45,
- sortable: false
- },{
- text: '多输<br>入框',
- dataIndex: 'stg_double',
- xtype: 'checkcolumn',
- align: 'center',
- width: 45,
- sortable: false
- },{
- text: '带放<br>大镜',
- dataIndex: 'stg_dbfind',
- xtype: 'checkcolumn',
- align: 'center',
- width: 45,
- sortable: false
- },{
- text: '默认值',
- dataIndex: 'stg_value',
- align: 'center',
- flex: 1,
- sortable: false,
- editor: {
- xtype: 'textfield'
- }
- }],
- sortable: false
- },{
- text: '锁列',
- dataIndex: 'stg_lock',
- xtype: 'checkcolumn',
- width: 40,
- sortable: false
- },{
- text: '分组',
- dataIndex: 'stg_group',
- xtype: 'checkcolumn',
- singleChecked: true,
- width: 40,
- sortable: false
- },{
- text: '合计',
- dataIndex: 'stg_sum',
- xtype: 'checkcolumn',
- width: 40,
- sortable: false
- }]
- });
- },
- getLimitForm: function(combo) {
- return Ext.create('Ext.form.Panel', {
- title: '选择字段,建立约束关系',
- bodyStyle : 'background:#f1f2f5;padding:5px 5px 0',
- items: [{
- xtype:'fieldset',
- title: '客户分配',
- padding: '0 5 10 10',
- name: '_L',
- checkboxToggle: true,
- collapsible: true,
- collapsed: true,
- defaultType: 'combobox',
- defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
- layout: 'column',
- items :[Ext.Object.merge({
- fieldLabel: '客户编号',
- name: '_L_CU_1'
- }, combo), {
- xtype: 'displayfield',
- value: '调取分配给你的客户的所有数据'
- }, Ext.Object.merge({
- fieldLabel: '业务员编号',
- name: '_L_CU_2'
- }, combo), {
- xtype: 'displayfield',
- value: '调取业务员是你的所有数据'
- }],
- getValue: function() {
- var a = this.down('combo[name=_L_CU_1]').getValue(),
- b = this.down('combo[name=_L_CU_2]').getValue();
- return a ? 'CU(' + a + (b ? (',' + b) : '') + ')' : null;
- }
- }, {
- xtype:'fieldset',
- title: '供应商分配',
- padding: '0 5 10 10',
- name: '_L',
- checkboxToggle: true,
- collapsible: true,
- collapsed: true,
- defaultType: 'combobox',
- defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
- layout: 'column',
- items :[Ext.Object.merge({
- fieldLabel: '供应商编号',
- name: '_L_VE_1'
- }, combo), {
- xtype: 'displayfield',
- value: '调取分配给你的供应商的所有数据'
- }, Ext.Object.merge({
- fieldLabel: '采购员编号',
- name: '_L_VE_2'
- }, combo), {
- xtype: 'displayfield',
- value: '调取采购员是你的所有数据'
- }],
- getValue: function() {
- var a = this.down('combo[name=_L_VE_1]').getValue(),
- b = this.down('combo[name=_L_VE_2]').getValue();
- return a && b ? 'VE(' + a + (b ? (',' + b) : '') + ')' : null;
- }
- }, {
- xtype:'fieldset',
- title: '个人',
- padding: '0 5 10 10',
- name: '_L',
- checkboxToggle: true,
- collapsible: true,
- collapsed: true,
- defaultType: 'combobox',
- defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
- layout: 'column',
- items :[Ext.Object.merge({
- fieldLabel: '个人编号',
- name: '_L_EM_1'
- }, combo)],
- getValue: function() {
- var a = this.down('combo[name=_L_EM_1]').getValue();
- return a ? 'EM(' + a + ')' : null;
- }
- }]
- });
- },
- /**
- * 权限约束设置
- */
- onLimitClick: function(source, oldLimits, callback) {
- var me = this, win = me.limitwin, datas = [{display: '(无)', value: null}];
- source.each(function(item){
- if(item.get('stg_type').indexOf('VARCHAR2') == 0) {
- datas.push({
- display: item.get('stg_text'),
- value: item.get('stg_table') + '.' + item.get('stg_field')
- });
- }
- });
- var combo = me.newComboConfig(datas);
- if (!win) {
- win = me.limitwin = Ext.create('Ext.window.Window', {
- title : '权限约束设置',
- closeAction : 'hide',
- width : 500,
- items : [me.getLimitForm(combo)],
- buttonAlign : 'center',
- buttons : [{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt,
- fs = w.down('form').down('fieldset[collapsed=false]'),
- value = fs ? fs.getValue() : null;
- callback && callback.call(me, value);
- w.hide();
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });
- } else {
- var coms = win.down('form').query('combobox');
- Ext.Array.each(coms, function(com){
- com.getStore().loadData(datas);
- });
- }
- win.show();
- var form = win.down('form');
- if(oldLimits) {
- if(oldLimits.indexOf('CU') == 0) {// 客户分配
- var col1 = null, col2 = null;
- if(oldLimits.indexOf(",") > -1) {
- col1 = oldLimits.substring(3, oldLimits.indexOf(','));
- col2 = oldLimits.substring(oldLimits.indexOf(',') + 1, oldLimits.lastIndexOf(')'));
- } else {
- col1 = oldLimits.substring(3, oldLimits.indexOf(')'));
- }
- form.down('combobox[name=_L_CU_1]').setValue(col1);
- form.down('combobox[name=_L_CU_2]').setValue(col2);
- form.down('combobox[name=_L_CU_1]').ownerCt.setExpanded(true);
- } else if(oldLimits.indexOf('VE') == 0) {// 供应商分配
- var col1 = null, col2 = null;
- if(oldLimits.indexOf(",") > -1) {
- col1 = oldLimits.substring(3, oldLimits.indexOf(','));
- col2 = oldLimits.substring(oldLimits.indexOf(',') + 1, oldLimits.lastIndexOf(')'));
- } else {
- col1 = oldLimits.substring(3, oldLimits.indexOf(')'));
- }
- form.down('combobox[name=_L_VE_1]').setValue(col1);
- form.down('combobox[name=_L_VE_2]').setValue(col2);
- form.down('combobox[name=_L_VE_1]').ownerCt.setExpanded(true);
- } else if(oldLimits.indexOf('EM') == 0) {// 个人
- var col1 = oldLimits.substring(3, oldLimits.lastIndexOf(')'));
- form.down('combobox[name=_L_EM_1]').setValue(col1);
- form.down('combobox[name=_L_EM_1]').ownerCt.setExpanded(true);
- }
- } else {
- var fs = form.down('fieldset[collapsed=false]');
- fs && fs.setExpanded(false);
- }
- },
- /**
- * 公式设置用到的函数
- */
- formula: function() {
- var me = this;
- me.formula_operator = [];
- return {
- log: function(oper, text, data, isfn) {
- me.formula_operator.push({oper: oper, text: text, data: data, isfn: isfn});
- },
- getContainer: function(scope) {
- return scope.up('form').down('fieldcontainer[cls~=x-screen]');
- },
- add: function(scope, parentScope) {
- var f = this.getContainer(parentScope || scope);
- f.add({text: scope.text, data: scope.data, isfn: scope.isfn});
- if(scope.isfn) {
- f.add({text: '('});
- this.log(1, scope.text, null, true);
- this.log(2, '(');
- } else {
- this.log(1, scope.text, scope.data);
- }
- },
- del: function(scope) {
- var f = this.getContainer(scope), l = f.down('button:last');
- if (l) {
- f.remove(l);
- this.log(0, l.text, l.data, l.isfn);
- }
- },
- back: function(scope) {
- var f = this.getContainer(scope), len = me.formula_operator.length;
- if(len > 0) {
- var i = len - 1, o = me.formula_operator[i], oper = o.oper;
- switch(oper) {
- case 0:
- f.add({text: o.text, data: o.data, isfn: o.isfn});
- break;
- case 1:
- var b = f.down('button:last');
- if(b && b.text == o.text)
- f.remove(b);
- break;
- case 2:
- var b = f.down('button:last');
- if(b && b.text == o.text) {
- f.remove(b);
- f.remove(f.down('button:last'));
- }
- break;
- case 3:
- var j = 0;
- for(;i > 0;i-- ) {
- if(me.formula_operator[i].oper == 3) {
- j = i;
- } else {
- break;
- }
- }
- for(;j < len;j++ ) {
- o = me.formula_operator[j];
- f.add({text: o.text, data: o.data, isfn: o.isfn});
- }
- i++;
- break;
- }
- me.formula_operator.splice(i);
- }
- },
- clear: function(scope) {
- var m = this, f = m.getContainer(scope), btns = f.query('button');
- f.removeAll();
- Ext.Array.each(btns, function(b){
- m.log(3, b.text, b.data, b.isfn);
- });
- },
- reset: function(scope, source, oldData) {
- var f = this.getContainer(scope);
- if(me.formula_operator.length > 0) {
- f.removeAll();
- f.add(f.initItems);
- }
- me.formula_operator = [];
- }
- };
- },
- getFormulaForm: function(source, oldData) {
- var defItems = [], defBtns = "789/%456*(123-)0.+=><≥≤≠".split(""),
- colItems = [], me = this, formula = me.formula();
- defItems.push({
- text: '←',
- tooltip: '删除',
- handler: function(btn) {
- formula.del(btn);
- }
- });
- defItems.push({
- text: '→',
- tooltip: '回退',
- handler: function(btn) {
- formula.back(btn);
- }
- });
- defItems.push({text: ','});
- defItems.push({
- text: 'RE',
- tooltip: '重置',
- handler: function(btn) {
- formula.reset(btn);
- }
- });
- defItems.push({
- text: 'CE',
- tooltip: '清除',
- handler: function(btn) {
- formula.clear(btn);
- }
- });
- Ext.Array.each(defBtns, function(b){
- var o = {text: b};
- if(b == '0')
- o.width = 88;
- defItems.push(o);
- });
- defItems.push({text: 'nvl', isfn: true, tooltip: 'nvl(x,y),如果x不为空,返回x,否则返回y'});
- defItems.push({text: 'round', isfn: true, tooltip: 'round(x,y),返回四舍五入到小数点右边y位的x值'});
- defItems.push({text: 'floor', isfn: true, tooltip: 'floor(x),返回小于或等于x的最大整数'});
- defItems.push({text: 'ceil', isfn: true, tooltip: 'ceil(x),返回大于或等于x的最小整数'});
- defItems.push({text: 'abs', isfn: true, tooltip: 'abs(x),返回x的绝对值'});
- defItems.push({text: 'nvl2', isfn: true, tooltip: 'nvl2(x,y,z),如果x不为空,返回y,否则返回z'});
- defItems.push({text: 'trim', isfn: true, tooltip: 'trim(x),去除x前后空格'});
- defItems.push({text: 'lpad', isfn: true, tooltip: 'lpad(x,y,z),如果x的长度小于y,左边填充z'});
- defItems.push({text: 'rpad', isfn: true, tooltip: 'rpad(x,y,z),如果x的长度小于y,右边填充z'});
- defItems.push({text: '‖', tooltip: '字符串连接符'});
- defItems.push({text: 'sysdate', tooltip: 'sysdate,当前时间', width: 88});
- defItems.push({text: 'to_char', isfn: true, tooltip: 'to_char(x,y),日期x按格式y转化成字符串', width: 88});
- defItems.push({text: 'trunc', isfn: true, tooltip: 'trunc(x,y),日期截断。清除时分秒:trunc(sysdate);年初:trunc(sysdate,\'y\');月初:trunc(sysdate,\'mm\')'});
- // case when
- Ext.Array.each('case,when,then,else,end'.split(','), function(b){
- var o = {text: b, tooltip: '判断语句case when..then..when..then..else..end'};
- defItems.push(o);
- });
- defItems.push({
- width: 229,
- text: '添加自定义内容',
- handler: function(btn) {
- me.onUserDefinedClick(function(text){
- formula.add({text: "'" + text + "'"}, btn);// 当字符串处理
- });
- }
- });
- source.each(function(item){
- if(/(NUMBER|FLOAT|INT|DATE|TIMESTAMP)(\(\d+\)){0,1}/.test(item.get('stg_type')) && item.get('stg_table')) {
- colItems.push({
- text: item.get('stg_text'),
- data: item.data
- });
- }
- });
- var form = Ext.create('Ext.form.Panel', {
- bodyStyle : 'background:#f1f2f5;padding:5px',
- layout: 'vbox',
- minHeight : 490,
- items: [{
- xtype: 'fieldcontainer',
- margin: '0 3 8 3',
- width: '100%',
- minHeight: 50,
- cls: 'x-form-text x-screen',
- defaultType: 'button',
- defaults: {
- margin: '0 0 3 0',
- cls: 'x-btn-clear'
- }
- },{
- xtype: 'container',
- layout: 'hbox',
- width: '100%',
- defaultType: 'fieldcontainer',
- defaults: {flex: 1},
- items: [{
- defaultType: 'button',
- defaults: {
- width: 41,
- height: 30,
- margin: '3 3 3 3'
- },
- items: defItems
- },{
- layout: 'column',
- defaultType: 'button',
- defaults: {
- columnWidth: .5,
- height: 30,
- margin: '3 3 3 3'
- },
- items: colItems
- }]
- }]
- });
- var btns = form.query('button');
- Ext.Array.each(btns, function(btn){
- if(!btn.handler) {
- btn.handler = function() {
- formula.add(btn);
- };
- }
- });
- if(oldData) {
- var container = form.down('fieldcontainer[cls~=x-screen]'),
- items = me.getItemsFromFormula(source, oldData);
- container.initItems = items;
- container.add(items);
- }
- return form;
- },
- /**
- * 解析表达式
- */
- getItemsFromFormula: function(source, oldData) {
- var sign = /[\+\-\*=\/%,\(\)\s]/, units = oldData._split(sign), items = [],
- fns = ['abs', 'ceil', 'floor', 'round', 'nvl', 'nvl2', 'lpad', 'rpad', 'trim', 'trunc', 'to_char'],
- cw = ['case', 'when', 'then', 'else', 'end', 'sysdate', '||'];
- Ext.Array.each(units, function(unit){
- if(isNumber(unit)) {
- Ext.Array.each(unit.split(""), function(u){
- items.push({text: u});
- });
- } else if(fns.indexOf(unit) > -1){
- items.push({
- text: unit,
- isfn: true
- });
- } else if(sign.test(unit) || cw.indexOf(unit) > -1) {
- if(unit != ' ')
- items.push({text: unit});
- } else {
- var table = null, field = unit, type = null;
- if(unit.indexOf('.') > 0) {
- table = unit.substring(0, unit.indexOf('.'));
- field = unit.substr(unit.indexOf('.')+1);
- }
- var res = source.queryBy(function(record){
- return record.get('stg_table') == table && record.get('stg_field') == field;
- }), item = res.first();
- if (item) {
- unit = item.get('stg_text');
- type = item.get('stg_type');
- }
- items.push({
- text: unit,
- data: {stg_table: table, stg_field: field, stg_type: type}
- });
- }
- });
- return items;
- },
- onUserDefinedClick: function(callback) {
- var me = this;
- var win = Ext.create('Ext.window.Window', {
- title : '自定义内容',
- closeAction: 'destroy',
- width : 300,
- items : [{
- xtype : 'textfield',
- emptyText : '输入除单引号外任意字符',
- width: '100%'
- }],
- buttons : [{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt, f = w.down('textfield'), v = f.getValue();
- v && (callback.call(me, v));
- w.close();
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt;
- w.close();
- }
- }]
- });
- win.show();
- },
- /**
- * 自定义公式
- */
- onFormulaClick: function(source, oldData, callback) {
- var me = this;
- var win = Ext.create('Ext.window.Window', {
- title : '自定义公式',
- closeAction: 'destroy',
- width : 540,
- items : [me.getFormulaForm(source, oldData)],
- buttonAlign : 'center',
- buttons : [{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt,
- items = w.query('fieldcontainer[cls~=x-screen] > button'),
- text = '', test = '', c, h;
- Ext.Array.each(items, function(item){
- if(item.data) {
- text += item.data.stg_table + '.' + item.data.stg_field;
- var type = me.getTypeByStg(item.data.stg_type);
- // 生成随机测试数据
- if("datecolumn" == type) {
- test += 'randomDate()';
- } else if("numbercolumn" == type) {
- test += 'randomNum()';
- } else {
- test += 'randomStr()';
- }
- } else {
- if(item.text == 'sysdate'){
- text += 'sysdate';
- test += 'new Date()';
- } else if(item.text == 'case'){
- c = true;
- text += item.text + ' ';
- } else if(item.text == 'when') {
- h = true;
- if(c) {
- c = false;
- test += 'if(';
- } else
- test += '}else if(';
- text += ' ' + item.text + ' ';
- } else if(item.text == 'then') {
- h = false;
- test += '){';
- text += ' ' + item.text + ' ';
- } else if(item.text == 'else') {
- test += '}else{';
- text += ' ' + item.text + ' ';
- } else if(item.text == '>') {
- test += '>';
- text += ' > ';
- } else if(item.text == '<') {
- test += '<';
- text += ' < ';
- } else if(item.text == '≥') {
- test += '>=';
- text += ' >= ';
- } else if(item.text == '≤') {
- test += '<=';
- text += ' <= ';
- } else if(item.text == '≠') {
- test += '!=';
- text += ' <> ';
- } else if(item.text == '‖') {
- test += '+';
- text += ' || ';
- } else if(item.text == 'end') {
- test += '}';
- text += ' ' + item.text + ' ';
- } else {
- if(h && item.text == '=') {
- test += '==';
- } else
- test += item.text;
- text += item.text;
- }
- }
- });
- try {
- Ext.eval(test);
- callback && callback.call(me, text);
- w.close();
- } catch(e) {
- Ext.example.msg('error', '错误', '您的公式有误,请检查并修改正确' +
- '<p><strong>' +e + '</strong></p>', 5000);
- }
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt;
- w.close();
- }
- }]
- });
- win.show();
- },
- /**
- * 生成form的字段<br>
- * 勾选、单选框
- */
- createFormItems: function(source, oldData) {
- var fields = [];
- if(source) {
- if(Ext.isArray(source)) {
- Ext.Array.each(source, function(i){
- if(i.stg_use == 1) {
- var obj = {boxLabel : i.stg_text, inputValue : i.stg_field, table: i.stg_table, alias: i.stg_alias};
- if(oldData && Ext.Array.indexOf(oldData, i.stg_field) > -1)
- obj.checked = true;
- fields.push(obj);
- }
- });
- } else {
- source.each(function(i){
- if(i.get('stg_use') == 1) {
- var obj = {boxLabel : i.get('stg_text'), inputValue : i.get('stg_field'), table: i.get('stg_table'), alias: i.get('stg_alias')};
- if(oldData && Ext.Array.indexOf(oldData, i.get('stg_field')) > -1)
- obj.checked = true;
- fields.push(obj);
- }
- });
- }
- } else {
- var grid = this.getGrid().getView().normalGrid, columns = grid.headerCt.getGridColumns();
- Ext.each(columns, function(){
- if(!this.hidden && this.getWidth() > 0 && this.dataIndex) {
- var obj = {boxLabel : this.text, inputValue : this.dataField, table: this.dataTable, alias: this.dataIndex};
- if(oldData && Ext.Array.indexOf(oldData, this.dataIndex) > -1)
- obj.checked = true;
- fields.push(obj);
- }
- });
- }
- return fields;
- },
- /**
- * 生成form的字段<br>
- * 勾选、单选框<br>使用别名
- */
- createAliaItems: function(oldData) {
- var fields = [];
- var grid = this.getGrid().getView().normalGrid, columns = grid.headerCt.getGridColumns();
- Ext.each(columns, function(){
- if(!this.hidden && this.getWidth() > 0 && this.dataIndex) {
- var obj = {boxLabel : this.text, inputValue : this.dataIndex};
- if(oldData && Ext.Array.indexOf(oldData, this.dataIndex) > -1)
- obj.checked = true;
- fields.push(obj);
- }
- });
- return fields;
- },
- /**
- *
- */
- getAliaForm : function(type, itemId, oldData) {
- var me = this;
- return Ext.create('Ext.form.Panel', {
- itemId : itemId,
- autoScroll : true,
- layout : 'column',
- bodyStyle : 'background:#f1f2f5;',
- defaults : {
- xtype : type || 'radio',
- name : 'gridfield',
- columnWidth : .33,
- margin : '3 3 3 10'
- },
- items : me.createAliaItems(oldData)
- });
- },
- getGridForm : function(type, itemId, source, oldData) {
- var me = this;
- return Ext.create('Ext.form.Panel', {
- itemId : itemId,
- autoScroll : true,
- layout : 'column',
- bodyStyle : 'background:#f1f2f5;',
- defaults : {
- xtype : type || 'radio',
- name : 'gridfield',
- columnWidth : .33,
- margin : '3 3 3 10'
- },
- items : me.createFormItems(source, oldData)
- });
- },
- toogleGroup : function(f, b) {
- if (!f) return;
- var dx = null;
- if (typeof f === 'string') {
- dx = f;
- } else {
- var r = f.down('radio[value=true]');
- if (r) {
- dx = r.inputValue;
- }
- }
- if (dx) {
- var grid = this.getGrid(), c = grid.down('gridcolumn[dataIndex=' + dx + ']');
- if(b) {
- if(grid.store.groupField) {
- var m = grid.down('gridcolumn[dataIndex=' + grid.store.groupField + ']');
- if(m) {
- m.summaryType = m.lastSummaryType;
- m.summaryRenderer = m.lastSummaryRenderer;
- }
- }
- if(typeof c.lastSummaryType === 'undefined') {
- c.lastSummaryType = c.summaryType;
- }
- if(typeof c.lastSummaryRenderer === 'undefined') {
- c.lastSummaryRenderer = c.summaryRenderer;
- }
- c.summaryType = 'count';
- c.summaryRenderer = function(v) {
- return '共(' + v + ')条';
- };
- grid.store.groupField = dx;
- grid.store.group(dx, 'ASC');
- // 先筛选数据,再选择分组字段时,不出现分组合计行的问题
- if (grid.store.getTotalCount() > 0) {
- var grouper = grid.view.normalView.getFeature('group');
- grouper.enable();
- }
- } else {
- c.summaryType = c.lastSummaryType;
- c.summaryRenderer = c.lastSummaryRenderer;
- var view = grid.lockedGrid.getView(), fe = view.getFeature('group');
- if(fe) {
- fe.disable();
- view.refresh();
- }
- view = grid.normalGrid.getView(), fe = view.getFeature('group');
- if(fe) {
- fe.disable();
- view.refresh();
- }
- var r = f.down('radio[value=true]');
- if (r) {
- r.setValue(false);
- }
- grid.store.groupField = null;
- }
- }
- },
- /**
- * 锁定列
- */
- onLock : function(form) {
- var r = form.query('checkbox[value=true]'),
- checked = Ext.Array.pluck(r, 'inputValue');
- var grid = this.getGrid(), locked = grid.getView().lockedGrid,
- normal = grid.getView().normalGrid;
- var lockedCols = locked.headerCt.getGridColumns();
- Ext.Array.each(lockedCols, function(column){
- if(!Ext.Array.contains(checked, column.dataIndex)) {
- grid.unlock(column);
- }
- });
- Ext.Array.each(r, function(){
- var column = normal.down('gridcolumn[dataIndex=' + this.inputValue + ']');
- if(column && !column.locked) {
- grid.lock(column);
- }
- });
- },
- /**
- * 取出排序设置
- */
- getSortProperties : function(form, store) {
- var r = form.query('checkbox[value=true]'), prop = [];
- Ext.Array.each(r, function(c, i){
- var obj = {
- property: c.inputValue,
- direction: 'ASC',
- description: c.boxLabel,
- alias: c.alias,
- number: i + 1,
- table: c.table
- };
- if (store) {
- var item = store.findRecord('property', c.inputValue);
- if (item) {
- obj.direction = item.get('direction');
- }
- }
- prop.push(obj);
- });
- return prop;
- },
- /**
- * 后台排序
- */
- onSort : function(sorts) {
- // var grid = this.getGrid().getView().normalGrid;
- // grid.store.sort(this.getSortProperties(form));
- },
- /**
- * 清除排序、分组等
- */
- onClear : function() {
- var grid = this.getGrid().getView().normalGrid;
- grid.store.clearGrouping();
- grid.store.clearFilter();
- },
- onTempLoad : function(fn) {
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/g.action',
- params: {
- caller: caller
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.success && r.data) {
- fn.call(null, r.data, r.lastId);
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
- }
- }
- });
- },
- duplicateTemp:function(data){
- var me = this;
- var w=Ext.getCmp('duplicateTemp');
- if(w)w.data=data;
- else{
- w = Ext.create('Ext.window.Window', {
- width: 300,
- height: 97,
- data:data,
- title: '请输入导航栏CALLER',
- id:'duplicateTemp',
- layout: 'anchor',
- items: [{
- xtype: 'textfield',
- allowBlank: false,
- anchor: '100% 100%',
- value:'New'+caller
- }],
- buttonAlign: 'center',
- closeAction:'hide',
- buttons: [{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt, f = w.down('textfield');
- if(!Ext.isEmpty(f.getValue())) {
- me.checkCaller(f.getValue(),w.data);
- }
- w.close();
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });}
- w.show();
- },
- checkCaller:function(newCaller,data){
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/checkCaller.action',
- params: {
- caller: newCaller,
- title: newCaller+data.st_title
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.result) {
- Ext.MessageBox.confirm('提示', r.result, function(but) {
- if(but=='yes')me.onDuplicateTemp(newCaller,data);
- });
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '提示', r.exceptionInfo, 5000);
- }else me.onDuplicateTemp(newCaller,data);
- }
- });
- },
- onDuplicateTemp:function(newCaller,data){
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/duplTemp.action',
- params: {
- caller: newCaller,
- sId: data.st_id,
- title:newCaller+data.st_title
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.success) {
- Ext.example.msg('info', '提示', '复制方案到新导航栏成功', 2000);
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '提示', r.exceptionInfo, 5000);
- }
- }
- });
- },
- addTemp : function(title, fn) {
- var me = this;
- var t = title || (me.BaseUtil.getActiveTab().title + '(' + em_name + ')' + Ext.Date.format(new Date(),'Y-m-d'));
- var w = Ext.create('Ext.window.Window', {
- width: 300,
- height: 97,
- title: '为方案命名',
- layout: 'anchor',
- items: [{
- xtype: 'textfield',
- allowBlank: false,
- anchor: '100% 100%',
- value: t
- }],
- buttonAlign: 'center',
- buttons: [{
- text : $I18N.common.button.erpConfirmButton,
- height : 26,
- handler : function(b) {
- var w = b.ownerCt.ownerCt, f = w.down('textfield');
- if(!Ext.isEmpty(f.getValue())) {
- if(fn) {
- fn.call(me, f.getValue());
- } else {
- var g = me.querywin.down('grid');
- var r = g.store.add({st_id: 0, st_date: new Date().getTime(), st_man: em_name, st_title: f.getValue(), st_caller: caller});
- if(r.length > 0) {
- g.selModel.select(r[0]);
- me.onTempSet(r[0], [], 0);
- }
- }
- }
- w.close();
- }
- }, {
- text : $I18N.common.button.erpCloseButton,
- height : 26,
- handler : function(b) {
- b.ownerCt.ownerCt.hide();
- }
- }]
- });
- w.show();
- },
- updateTemp : function(callback) {
- var me = this, win = this.tempwin, g = win.down('#grid-setting'),
- datas = new Array(), d, s = win.relativeId, i = 1,
- c = g.down('#st_condition').getValue(),
- sorts = g.sorts, limits = g.limits;
- g.store.each(function(r){
- d = r.data;
- if(d.stg_use || d.stg_query || d.stg_group || d.stg_lock) {
- d.stg_use = d.stg_use ? 1 : 0;
- d.stg_query = d.stg_query ? 1 : 0;
- d.stg_group = d.stg_group ? 1 : 0;
- d.stg_lock = d.stg_lock ? 1 : 0;
- d.stg_sum = d.stg_sum ? 1 : 0;
- d.stg_double = d.stg_double ? 1 : 0;
- d.stg_dbfind = d.stg_dbfind ? 1 : 0;
- d.stg_stid = s;
- d.stg_detno = i++;
- delete d.text;
- delete d.type;
- delete d.links;
- delete d.stg_alias;
- if (d.modeItems) {
- var validItems = [];
- Ext.Array.each(d.modeItems, function(item, i){
- if(item.display && item.display != '') {
- item.num = validItems.length + 1;
- item.st_id = s;
- item.stg_field = d.stg_field;
- item.value = (item.value == null || item.value == '') ?
- item.display : item.value;
- validItems.push(item);
- }
- });
- d.modeItems = validItems;
- }
- datas.push(d);
- }
- });
- var e = me.getRepeats(datas);
- if(e) {
- Ext.example.msg('error', '有重复选择的字段', e, 5000);
- return;
- }
- if(s > 0) {
- me.onTempUpdate(datas, c, sorts, limits, s, callback);
- } else {
- me.onTempSave(win.relativeRecord.get('st_title'), datas, c, sorts, limits, callback);
- }
- },
- /**
- * 判断是否有重复拖放过来的字段或重复的公式
- */
- getRepeats: function(datas) {
- var p = {}, k = null, e = '';
- Ext.Array.each(datas, function(d, i){
- k = d.stg_table + '.' + d.stg_field;
- if(d.stg_formula)
- k = d.stg_formula;
- if(p[k])
- e += '行' + (i + 1) + '的' + d.stg_text;
- else
- p[k] = true;
- });
- if(e.length > 0)
- return e;
- return null;
- },
- copyTemp: function(title, sourceId) {
- if(sourceId) {
- this.onTempCopy(title, sourceId);
- } else {
- var me = this, win = this.tempwin, g = win.down('#grid-setting'),
- datas = new Array(), d, i = 1,
- c = g.down('#st_condition').getValue(), sorts = g.sorts, limits = g.limits;
- g.store.each(function(r){
- d = r.data;
- if(d.stg_use || d.stg_query || d.stg_group || d.stg_lock) {
- d.stg_use = d.stg_use ? 1 : 0;
- d.stg_query = d.stg_query ? 1 : 0;
- d.stg_group = d.stg_group ? 1 : 0;
- d.stg_lock = d.stg_lock ? 1 : 0;
- d.stg_sum = d.stg_sum ? 1 : 0;
- d.stg_double = d.stg_double ? 1 : 0;
- d.stg_dbfind = d.stg_dbfind ? 1 : 0;
- d.stg_stid = 0;
- d.stg_detno = i++;
- delete d.text;
- delete d.type;
- delete d.links;
- delete d.stg_alias;
- if (d.modeItems) {
- var validItems = [];
- Ext.Array.each(d.modeItems, function(item, i){
- if(item.display && item.display != '') {
- item.num = validItems.length + 1;
- item.stg_field = d.stg_field;
- item.value = (item.value == null || item.value == '') ?
- item.display : item.value;
- validItems.push(item);
- }
- });
- d.modeItems = validItems;
- }
- datas.push(d);
- }
- });
- me.onTempSave(title, datas, c, sorts, limits);
- }
- },
- onTempUpdate : function(datas, condition, sorts, limits, id, callback) {
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/u.action',
- params: {
- sId: id,
- caller: caller,
- datas: Ext.encode(datas),
- condition: condition,
- sorts: sorts,
- limits: limits
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.success) {
- callback && callback.call(me);
- Ext.example.msg('info', '提示', '方案修改成功', 2000);
- me.onTempLoad(function(data){
- var temp = me.querywin.down('gridpanel[id=temp]'),
- grid = me.querywin.down('grid');
- temp.store.loadData(data);
- if(data.length > 0) {
- var r = temp.store.findRecord('st_id', id) || temp.store.last();
- temp.selModel.select(r);
- grid.setTitle(r.get('st_title'));
- }
- });
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
- }
- }
- });
- },
- onTempSave : function(title, datas, condition, sorts, limits, callback) {
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/s.action',
- params: {
- caller: caller,
- title: title,
- datas: Ext.encode(datas),
- condition: condition,
- sorts: sorts,
- limits: limits
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.success) {
- callback && callback.call(me);
- Ext.example.msg('info', '提示', '方案保存成功', 2000);
- me.onTempLoad(function(data){
- var temp = me.querywin.down('gridpanel[id=temp]'),
- grid = me.querywin.down('grid');
- temp.store.loadData(data);
- if(data.length > 0) {
- var r = temp.store.last();
- temp.selModel.select(r);
- grid.setTitle(r.get('st_title'));
- }
- });
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
- }
- }
- });
- },
- onTempCopy : function(title, id) {
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/c.action',
- params: {
- title: title,
- sId: id
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.success) {
- Ext.example.msg('info', '提示', '方案复制成功', 2000);
- me.onTempLoad(function(data){
- var temp = me.querywin.down('gridpanel[id=temp]'),
- grid = me.querywin.down('grid');
- temp.store.loadData(data);
- if(data.length > 0) {
- var r = temp.store.last();
- temp.selModel.select(r);
- grid.setTitle(r.get('st_title'));
- }
- });
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
- }
- }
- });
- },
- onTempTitleChange: function(title, id, callback) {
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/t.action',
- params: {
- title: title,
- sId: id
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.success) {
- Ext.example.msg('info', '提示', '修改成功', 2000);
- callback && callback.call(me);
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
- }
- }
- });
- },
- onTempDel : function(id, fn) {
- if(id > 0) {
- Ext.Ajax.request({
- url: basePath + 'ma/search/temp/d.action',
- params: {
- caller: caller,
- sId: id
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.success) {
- fn.call();
- } else if(r.exceptionInfo) {
- Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
- }
- }
- });
- } else {
- fn.call();
- }
- },
- /**
- * 记录选择方案
- */
- log : function() {
- var grid = this.querywin.down('grid'), record = grid.selModel.lastSelected;
- if (record) {
- var id = record.get('st_id');
- if(id && id > 0 ) {
- Ext.Ajax.request({
- url: basePath + 'ma/search/log.action',
- params: {
- caller: caller,
- sId: id
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.exceptionInfo) {
- Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
- }
- }
- });
- }
- }
- },
- /**
- * 数据字典
- */
- getDictionary: function(tableNames, callback) {
- if(tableNames && tableNames != '') {
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/getDataDictionaries.action',
- params: {
- tables: tableNames
- },
- callback: function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if(r.exceptionInfo) {
- Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
- } else if(r.datas) {
- callback.call(me, r.datas);
- }
- }
- });
- } else {
- callback.call(me, []);
- }
- },
- /**
- * 重新加载数据
- */
- loadNewStore : function(grid, params) {
- var me = this;
- grid.setLoading(true);
- Ext.Ajax.request({
- url : basePath + "common/search.action",
- params: params,
- timeout: 60000,
- method : 'post',
- callback : function(opt, s, res){
- grid.setLoading(false);
- grid.queryCondition=params.condition;
- var r = Ext.decode(res.responseText);
- if(r.datas) {
- grid.store.totalCount = r.datas.length;
- grid.store.loadData(r.datas);
- me.getDataCount().update({count: r.datas.length});
- me.getDataCount().show();
- }
- }
- });
- },
- /**
- * 导出excel
- */
- exportExcel : function(grid, records, condition) {
- var columns = grid.headerCt.getGridColumns(),
- cm = new Array(), gf = grid.store.groupField;
- Ext.Array.each(columns, function(c){
- if(!c.hidden && (c.width > 0 || c.flex > 0) && !c.isCheckerHd) {
- cm.push({
- text: (Ext.isEmpty(c.text) ? ' ' : c.text.replace(/<br>/g, '\n')),
- dataIndex: c.dataIndex,
- width: c.width,
- xtype: c.xtype,
- format: c.format,
- locked: c.locked,
- summary: c.summaryType == 'sum',
- group: c.dataIndex == gf
- });
- }
- });
- if (!Ext.fly('ext-grid-excel')) {
- var frm = document.createElement('form');
- frm.id = 'ext-grid-excel';
- frm.name = frm.id;
- frm.className = 'x-hidden';
- document.body.appendChild(frm);
- }
- var record = records[0];
- Ext.Ajax.request({
- url: basePath + 'common/search/excel.xls',
- method: 'post',
- form: Ext.fly('ext-grid-excel'),
- isUpload: true,
- params: {
- sId: record.get('st_id'),
- condition: condition,
- columns: unescape(Ext.encode(cm).replace(/\\/g,"%")),
- sorts: record.get('st_sorts'),
- title: record.get('st_title') + '----' + Ext.Date.format(new Date(), 'Y-m-d H:i:s')
- }
- });
- },
- /**
- * 传入表名,获得表的关联sql
- */
- getTabSql: function(tables, callback) {
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'ma/search/relation.action',
- method : 'post',
- params: {
- tables: tables
- },
- callback : function(opt, s, res){
- var r = Ext.decode(res.responseText);
- if(r.data) {
- callback && callback.call(me, r.data);
- } else {
- Ext.example.msg('error', '错误', '您选择的数据字典 ' + tables +
- ' 暂时还没有建立关联关系', 5000);
- }
- }
- });
- },
- /**
- * 行点击链接,打开单据界面
- */
- onLinkClick: function(link, title, field) {
- var args = encodeURI(Ext.Array.toArray(arguments, 3).join('-')).replace(/%/g,'-');
- var tabPanel = this.getTabPanel(),
- panel = tabPanel.down('#' + args);
- link += '&_noc=1';// no control
- // 出入库单据、工单、等按类型来获取caller,统一类型标志class
- // 用于jsp页面一致,caller不同的
- if(link.indexOf('class=') > -1) {
- var cls = this.getUrlParam(link, 'class');
- link += '&whoami=' + this.getCaller(cls, field);
- // 无法直接配置,需要按类型来匹配具体链接的
- if(link.indexOf('{url}') > -1) {
- link = link.replace('{url}', this.getUrl(cls, field));
- }
- }
- if (!panel) {
- panel = tabPanel.add({
- id : args,
- title : title,
- tag : 'iframe',
- border : false,
- layout : 'fit',
- iconCls : 'x-tree-icon-tab-tab1',
- html : '<iframe src="' + link + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
- closable : true
- });
- }
- tabPanel.setActiveTab(panel);
- },
- /**
- * 主界面的tabPanel
- */
- getTabPanel: function() {
- var main = parent.Ext.getCmp("content-panel");
- if (!main) {
- main = parent.parent.Ext.getCmp("content-panel");
- }
- return main;
- },
- /**
- * URL里面解析出参数值
- */
- getUrlParam: function(url, param) {
- var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)"),
- matchs = url.substr(url.indexOf('?') + 1).match(reg);
- if (matchs)
- return decodeURI(matchs[2]);
- return null;
- },
- /**
- * 按类型获取caller。用于出入库单等
- */
- getCaller: function(cls, field) {
- var call = null;
- switch (cls) {
- case '采购验收单':
- call = 'ProdInOut!PurcCheckin';
- break;
- case '采购验退单':
- call = 'ProdInOut!PurcCheckout';
- break;
- case '出货单':
- call = 'ProdInOut!Sale';
- break;
- case '拨入单':
- call = 'ProdInOut!AppropriationIn';
- break;
- case '销售拨出单':
- call = 'ProdInOut!SaleAppropriationOut';
- break;
- case '销售退货单':
- call = 'ProdInOut!SaleReturn';
- break;
- case '拨出单':
- call = 'ProdInOut!AppropriationOut';
- break;
- case '不良品入库单':
- call = 'ProdInOut!DefectIn';
- break;
- case '不良品出库单':
- call = 'ProdInOut!DefectOut';
- break;
- case '委外领料单':
- call = 'ProdInOut!OutsidePicking';
- break;
- case '委外退料单':
- call = 'ProdInOut!OutsideReturn';
- break;
- case '委外验收单':
- call = 'ProdInOut!OutsideCheckIn';
- break;
- case '委外验退单':
- call = 'ProdInOut!OutesideCheckReturn';
- break;
- case '借货归还单':
- call = 'ProdInOut!OutReturn';
- break;
- case '研发采购验收单':
- call = 'ProdInOut!PurcCheckin!PLM';
- break;
- case '研发采购验退单':
- call = 'ProdInOut!PurcCheckout!PLM';
- break;
- case '换货入库单':
- call = 'ProdInOut!ExchangeIn';
- break;
- case '换货出库单':
- call = 'ProdInOut!ExchangeOut';
- break;
- case '生产补料单':
- call = 'ProdInOut!Make!Give';
- break;
- case '完工入库单':
- call = 'ProdInOut!Make!In';
- break;
- case '生产退料单':
- call = 'ProdInOut!Make!Return';
- break;
- case '生产报废单':
- call = 'ProdInOut!Make!Useless';
- break;
- case '无订单出货单':
- call = 'ProdInOut!NoSale';
- break;
- case '委外补料单':
- call = 'ProdInOut!OSMake!Give';
- break;
- case '其它入库单':
- call = 'ProdInOut!OtherIn';
- break;
- case '其它出库单':
- call = 'ProdInOut!OtherOut';
- break;
- case '其它采购入库单':
- call = 'ProdInOut!OtherPurcIn';
- break;
- case '其它采购出库单':
- call = 'ProdInOut!OtherPurcOut';
- break;
- case '拆件入库单':
- call = 'ProdInOut!PartitionStockIn';
- break;
- case '生产领料单':
- call = 'ProdInOut!Picking';
- break;
- case '库存初始化':
- call = 'ProdInOut!ReserveInitialize';
- break;
- case '借货出货单':
- call = 'ProdInOut!SaleBorrow';
- break;
- case '销售拨入单':
- call = 'ProdInOut!SalePutIn';
- break;
- case '盘亏调整单':
- call = 'ProdInOut!StockLoss';
- break;
- case '盘盈调整单':
- call = 'ProdInOut!StockProfit';
- break;
- case '报废单':
- call = 'ProdInOut!StockScrap';
- break;
- case '研发退料单':
- call = 'ProdInOut!YFIN';
- break;
- case '研发领料单':
- call = 'ProdInOut!YFOUT';
- break;
- case 'MAKE':
- call = 'Make!Base';
- break;
- case 'OS':
- call = 'Make';
- break;
- case '采购收料单':
- call = 'VerifyApply';
- break;
- case '委外收料单':
- call = 'VerifyApply!OS';
- break;
- case '采购入库申请单':
- call = 'VerifyApply';
- break;
- case '委外入库申请单':
- call = 'VerifyApply!OS';
- break;
- case '应收发票':
- call = 'ARBill!IRMA';
- break;
- case '应收款转销':
- call = field == 'AB_CODE' ? 'ARBill!IRMA' : 'RecBalance!ARRM';
- break;
- case '其它应收单':
- call = 'ARBill!OTRS';
- break;
- case '收款单':
- call = 'RecBalance!PBIL';
- break;
- case '冲应收款':
- call = 'RecBalance!IMRE';
- break;
- case '应收冲应付':
- call = field == 'RB_CODE' ? 'RecBalance!RRCW' : 'PayBalance';
- break;
- case '预收冲应收':
- call = 'RecBalance!PTAR';
- break;
- case '应收退款单':
- call = 'RecBalance!TK';
- break;
- case '预收款':
- call = 'PreRec!Ars!DERE';
- break;
- case '预收退款':
- call = 'PreRec!Ars!DEPR';
- break;
- case '应付发票':
- call = 'APBill!CWIM';
- break;
- case '其它应付单':
- call = 'APBill!OTDW';
- break;
- case '付款单':
- call = 'PayBalance';
- break;
- case '应付款转销':
- call = 'PayBalance!APRM';
- break;
- case '冲应付款':
- call = 'PayBalance!CAID';
- break;
- case '预付冲应付':
- call = 'PayBalance!Arp!PADW';
- break;
- case '应付退款单':
- call = 'PayBalance!TK';
- break;
- case '预付款':
- call = 'PrePay!Arp!PAMT';
- break;
- case '预付退款':
- call = 'PrePay!Arp!PAPR';
- break;
- }
- return call;
- },
- /**
- * 存在同一table,同一链接不同caller情况;同一table,不同界面,不同caller的情况
- * 直接按类型取链接
- */
- getUrl: function(cls, field) {
- var url = null;
- switch (cls) {
- case '应收发票':
- url = 'jsps/fa/ars/arbill.jsp';
- break;
- case '应收款转销':
- url = field == 'AB_CODE' ? 'jsps/fa/ars/arbill.jsp' : 'jsps/fa/ars/recBalance.jsp';
- break;
- case '其它应收单':
- url = 'jsps/fa/ars/arbill.jsp';
- break;
- case '收款单':
- url = 'jsps/fa/ars/recBalance.jsp';
- break;
- case '冲应收款':
- url = 'jsps/fa/ars/recBalance.jsp';
- break;
- case '应收冲应付':
- url = field == 'RB_CODE' ? 'jsps/fa/ars/recBalanceAP.jsp' : 'jsps/fa/arp/paybalance.jsp';
- break;
- case '预收冲应收':
- url = 'jsps/fa/ars/recBalancePRDetail.jsp';
- break;
- case '应收退款单':
- url = 'jsps/fa/ars/recBalanceTK.jsp';
- break;
- case '预收款':
- url = 'jsps/fa/ars/preRec.jsp';
- break;
- case '预收退款':
- url = 'jsps/fa/ars/preRec.jsp';
- break;
- case '应付发票':
- url = 'jsps/fa/ars/apbill.jsp';
- break;
- case '其它应付单':
- url = 'jsps/fa/ars/apbill.jsp';
- break;
- case '付款单':
- url = 'jsps/fa/arp/paybalance.jsp';
- break;
- case '应付款转销':
- url = 'jsps/fa/arp/paybalance.jsp';
- break;
- case '冲应付款':
- url = 'jsps/fa/arp/paybalance.jsp';
- break;
- case '预付冲应付':
- url = 'jsps/fa/arp/payBalancePRDetail.jsp';
- break;
- case '应付退款单':
- url = 'jsps/fa/arp/paybalanceTK.jsp';
- break;
- case '预付款':
- url = 'jsps/fa/arp/prepay.jsp';
- break;
- case '预付退款':
- url = 'jsps/fa/arp/prepay.jsp';
- break;
- }
- return url;
- }
- });
|