Search.js 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.Search', {
  3. extend : 'Ext.app.Controller',
  4. requires : ['erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views : [ 'common.search.Viewport', 'core.trigger.DbfindTrigger', 'core.form.FtField',
  6. 'core.form.ConDateField', 'core.form.YnField','core.button.Sync',
  7. 'core.form.FtDateField', 'core.form.YearDateField',
  8. 'core.form.MonthDateField', 'core.form.FtFindField', 'core.form.FtNumberField',
  9. 'core.grid.YnColumn', 'core.grid.TfColumn',
  10. 'core.form.ConMonthDateField', 'core.trigger.TextAreaTrigger' ],
  11. models : ['SearchTemplate'],
  12. refs : [ {
  13. ref : 'grid',
  14. selector : '#querygrid'
  15. }, {
  16. ref: 'dataCount',
  17. selector: '#dataCount'
  18. } ],
  19. init : function() {
  20. var me = this;
  21. me.GridUtil = Ext.create('erp.util.GridUtil');
  22. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  23. this.control({
  24. 'button[name=find]' : {
  25. click : function(btn) {
  26. this.onQueryClick();
  27. },
  28. afterrender : function() {
  29. Ext.defer(function(){
  30. me.onQueryClick();
  31. }, 500);
  32. }
  33. },
  34. 'button[name=group]' : {
  35. click : function(btn) {
  36. this.onGroupClick();
  37. }
  38. },
  39. 'button[name=close]' : {
  40. click : function() {
  41. if (parent.Ext && parent.Ext.getCmp('content-panel')) {
  42. parent.Ext.getCmp('content-panel').getActiveTab().close();
  43. } else {
  44. window.close();
  45. }
  46. }
  47. },
  48. 'button[name=clearcondition]' : {
  49. click : function() {
  50. if (this.querywin) {
  51. var g = this.querywin.down('grid');
  52. g.store.removeAll();
  53. g.loadEmptyData();
  54. }
  55. }
  56. },
  57. 'button[name=filter]' : {
  58. click : function() {
  59. }
  60. },
  61. 'button[name=sort]' : {
  62. click : function() {
  63. var items = this.searchTemplate ? this.searchTemplate.items : [],
  64. sorts = this.searchTemplate ? this.searchTemplate.st_sorts : null;
  65. this.onSortClick(items, sorts, function(sortSql, newSorts){
  66. me.getGrid().normalGrid.store.sort(newSorts);
  67. me.searchTemplate.st_sorts = sortSql;
  68. });
  69. }
  70. },
  71. 'button[name=temp]' : {
  72. click : function() {
  73. warnMsg('保存当前设置到方案?', function(b){
  74. if(b == 'ok' || b == 'yes') {
  75. me.updateTemp();
  76. }
  77. });
  78. }
  79. },
  80. 'menuitem[name=exportexcel]' : {
  81. click : function() {
  82. /*this.BaseUtil.exportGrid(this.getGrid().normalGrid);*/
  83. var temp =Ext.getCmp('temp');
  84. me.exportExcel(me.getGrid(), temp.selModel.getSelection(),me.getGrid().queryCondition);
  85. }
  86. },
  87. 'menuitem[name=exportpdf]' : {
  88. click : function() {
  89. this.BaseUtil.exportPdf(this.getGrid().normalGrid);
  90. }
  91. },
  92. 'button[name=lock]' : {
  93. click : function() {
  94. this.onLockClick();
  95. }
  96. },
  97. 'menuitem[name=sum]' : {
  98. click : function() {
  99. }
  100. },
  101. 'menuitem[name=average]' : {
  102. click : function() {
  103. }
  104. },
  105. 'menuitem[name=max]' : {
  106. click : function() {
  107. window.open(window.location.href);
  108. }
  109. },
  110. 'menuitem[name=webexcel]' : {
  111. click : function() {
  112. window.open(basePath + 'jsps/Excel/sheet/index.jsp');
  113. }
  114. },
  115. 'button[name=removeformat]' : {
  116. click : function() {
  117. this.onClear();
  118. }
  119. },
  120. 'button[name=clearall]' : {
  121. click : function() {
  122. this.getGrid().normalGrid.store.loadData([{},{},{},{},{},{},{},{},{},{}]);
  123. }
  124. },
  125. 'menuitem[name=template-copy]': {
  126. click: function(item) {
  127. var record = item.ownerCt.record;
  128. if (record) {
  129. var t = record.get('st_title');
  130. me.addTemp(t + '(新)', function(title){
  131. me.copyTemp(title, record.get('st_id'));
  132. });
  133. }
  134. }
  135. },
  136. 'menuitem[name=template-title]': {
  137. click: function(item) {
  138. var record = item.ownerCt.record;
  139. if (record) {
  140. me.addTemp(record.get('st_title'), function(title){
  141. me.onTempTitleChange(title, record.get('st_id'), function(){
  142. record.set('st_title', title);
  143. });
  144. });
  145. }
  146. }
  147. },
  148. 'menuitem[name=template-set]': {
  149. click: function(item) {
  150. var record = item.ownerCt.record;
  151. if (record) {
  152. me.onTempSet(record, record.get('items'), record.get('st_id'));
  153. }
  154. }
  155. },
  156. 'menuitem[name=template-del]': {
  157. click: function(item) {
  158. var grid = item.ownerCt.grid, record = item.ownerCt.record;
  159. if (record) {
  160. warnMsg('确定删除 ' + record.get('st_title') + ' ?', function(k){
  161. if(k == 'ok' || k == 'yes') {
  162. me.onTempDel(record.get('st_id'), function(){
  163. Ext.example.msg('info', '提示', record.get('st_title') + ' 删除成功', 2000);
  164. grid.store.remove(record);
  165. record = grid.store.first();
  166. if(record) {
  167. grid.selModel.select(record);
  168. }
  169. });
  170. }
  171. });
  172. }
  173. }
  174. }
  175. });
  176. if(!window.onLinkClick)
  177. window.onLinkClick = function(l, t, f, arg1, arg2){
  178. me.onLinkClick(l, t, f, arg1, arg2);
  179. };
  180. },
  181. onQueryClick : function() {
  182. var me = this, win = me.querywin;
  183. if (!win) {
  184. var form = me.createQueryForm(), temp = me.createTempGrid();
  185. win = me.querywin = Ext.create('Ext.window.Window', {
  186. closeAction : 'hide',
  187. title : '筛选',
  188. height: 500,
  189. width: 550,
  190. layout: 'anchor',
  191. items : [form, temp],
  192. buttonAlign : 'center',
  193. buttons : [{
  194. text : $I18N.common.button.erpQueryButton,
  195. height : 26,
  196. handler : function(b) {
  197. var items = temp.selModel.getSelection();
  198. if(items.length > 0) {
  199. me.onQuery(items[0].data);
  200. }
  201. b.ownerCt.ownerCt.hide();
  202. }
  203. },{
  204. text : '直接导出',
  205. iconCls: 'icon-xls',
  206. height : 26,
  207. handler : function(b) {
  208. me.exportExcel(me.getGrid().normalGrid, temp.selModel.getSelection(), form.getCondition());
  209. b.ownerCt.ownerCt.hide();
  210. }
  211. },{
  212. text : '复制方案到...',
  213. iconCls: '',
  214. height : 26,
  215. handler : function(b) {
  216. var items = temp.selModel.getSelection();
  217. if(items.length > 0) {
  218. console.log(items);
  219. me.duplicateTemp(items[0].data);
  220. }
  221. }
  222. },{
  223. height : 26,
  224. iconCls: '',
  225. xtype: 'erpSyncButton',
  226. itemId : 'sync',
  227. caller:'Search!Post',
  228. style : {
  229. marginLeft : '0px'
  230. },
  231. autoClearCache: true
  232. },{
  233. text : $I18N.common.button.erpCloseButton,
  234. height : 26,
  235. handler : function(b) {
  236. b.ownerCt.ownerCt.hide();
  237. }
  238. }]
  239. });
  240. me.onTempLoad(function(data, lastId){
  241. temp.store.loadData(data);
  242. if(data.length > 0) {
  243. var r = (lastId && temp.store.findRecord('st_id', lastId)) || temp.store.first();
  244. temp.selModel.select(r);
  245. form.setTitle(r.get('st_title'));
  246. }
  247. });
  248. }
  249. win.show();
  250. },
  251. createTempGrid : function() {
  252. var me = this;
  253. return Ext.create('Ext.grid.Panel', {
  254. id: 'temp',
  255. cls: 'custom-grid',
  256. title: '自定义方案',
  257. region: 'south',
  258. anchor: '100% 40%',
  259. autoScroll: true,
  260. tools: [{
  261. type: 'plus',
  262. tooltip: '添加方案',
  263. handler: function(e, el, tb, tool) {
  264. me.addTemp();
  265. }
  266. }],
  267. columns: [{
  268. text: '日期',
  269. dataIndex: 'st_date',
  270. renderer: function(v) {
  271. return Ext.Date.format(new Date(v), 'Y-m-d');
  272. },
  273. flex: 1
  274. },{
  275. text: '创建人',
  276. dataIndex: 'st_man',
  277. flex: 0.8
  278. },{
  279. text: '描述',
  280. dataIndex: 'st_title',
  281. flex: 3
  282. },{
  283. xtype: 'actioncolumn',
  284. flex: .6,
  285. align: 'center',
  286. items: [{
  287. icon: basePath + 'resource/images/16/edit.png',
  288. tooltip: '设置',
  289. handler: function(grid, rIdx, cIdx) {
  290. var record = grid.store.getAt(rIdx);
  291. me.onTempSet(record, record.get('items'), record.get('st_id'));
  292. }
  293. },{
  294. icon: basePath + 'resource/images/16/delete.png',
  295. tooltip: '删除',
  296. handler: function(grid, rIdx, cIdx) {
  297. var record = grid.store.getAt(rIdx);
  298. warnMsg('确定删除 ' + record.get('st_title') + ' ?', function(k){
  299. if(k == 'ok' || k == 'yes') {
  300. me.onTempDel(record.get('st_id'), function(){
  301. Ext.example.msg('info', '提示', record.get('st_title') + ' 删除成功', 2000);
  302. grid.store.remove(record);
  303. record = grid.store.first();
  304. if(record) {
  305. grid.selModel.select(record);
  306. }
  307. });
  308. }
  309. });
  310. }
  311. }]
  312. }],
  313. selModel: Ext.create('Ext.selection.CheckboxModel',{
  314. mode: 'SINGLE',
  315. listeners: {
  316. select : function(sm, record, idx) {
  317. var items = record.get('items');
  318. if(items) {
  319. me.formatTempSet(items, record.get('properties'), true);
  320. }
  321. me.querywin.down('erpSyncButton[itemId=sync]').syncdatas = record.get('st_id');
  322. me.defaultCondition = record.get('st_condition');
  323. me.searchTemplate = record.data;
  324. }
  325. }
  326. }),
  327. columnLines: true,
  328. store: new Ext.data.Store({
  329. fields: ['st_date', 'st_man', 'st_title', 'items', 'properties', 'st_id','st_condition','st_usedtable','st_tablesql','st_sorts', 'st_limits']
  330. }),
  331. viewConfig: {
  332. listeners: {
  333. itemcontextmenu: function(view, record, item, index, e) {
  334. me.onTempContextmenu(view, record, e);
  335. }
  336. }
  337. }
  338. });
  339. },
  340. /**
  341. * 方案grid,右键菜单
  342. */
  343. onTempContextmenu: function(view, record, e) {
  344. e.preventDefault();
  345. var menu = view.contextMenu;
  346. if (!menu) {
  347. menu = view.contextMenu = new Ext.menu.Menu({
  348. items: [{
  349. text : '复制方案',
  350. name: 'template-copy'
  351. },{
  352. text : '修改描述',
  353. name: 'template-title'
  354. },{
  355. text : '编辑方案',
  356. name: 'template-set'
  357. },{
  358. iconCls: 'icon-remove',
  359. text : '删除',
  360. name: 'template-del'
  361. }]
  362. });
  363. menu.grid = view.ownerCt;
  364. }
  365. menu.showAt(e.getXY());
  366. menu.record = record;
  367. },
  368. formatTempSet : function(items, properties, load) {
  369. var me = this, grid = this.getGrid();
  370. var datas = new Array(), columns = new Array(), alias = new Array(),
  371. group = null, locks = new Array(), temp = new Array(), v, w = 0.5;
  372. Ext.Array.each(items, function(i){
  373. var modeItems = [];
  374. if(1 === i.stg_query) {
  375. if (i.stg_mode && i.stg_mode != '' && properties) {// multi properties field
  376. Ext.Array.each(properties, function(p){
  377. if(p.stg_field == i.stg_field) {
  378. modeItems.push({
  379. display: p.display,
  380. value: p.value
  381. });
  382. }
  383. });
  384. if(i.stg_mode == 'checkboxgroup' || i.stg_mode == 'radiogroup') {
  385. var items = [];
  386. Ext.Array.each(properties, function(p){
  387. if(p.stg_field == i.stg_field) {
  388. items.push({
  389. boxLabel: p.display,
  390. inputValue: p.value,
  391. name: i.stg_field,
  392. checked: (i.stg_value && (i.stg_value == p.value || i.stg_value == '$ALL'))
  393. });
  394. }
  395. });
  396. datas.push({
  397. xtype: i.stg_mode,
  398. fieldLabel: i.stg_text,
  399. relativeTable: i.stg_table,
  400. columnWidth: 1,
  401. columns: 3,
  402. vertical: true,
  403. items: items
  404. });
  405. } else if (i.stg_mode == 'combobox') {
  406. var store = new Ext.data.Store({
  407. fields: ['display', 'value'],
  408. data: Ext.Array.merge([{
  409. display: '全部',
  410. value: '$ALL'
  411. },{
  412. display: '无',
  413. value: '$NULL'
  414. }], modeItems)
  415. });
  416. datas.push({
  417. xtype: i.stg_mode,
  418. name: i.stg_field,
  419. fieldLabel: i.stg_text,
  420. relativeTable: i.stg_table,
  421. columnWidth: .5,
  422. store: store,
  423. queryMode: 'local',
  424. displayField: 'display',
  425. valueField: 'value',
  426. value: i.stg_value
  427. });
  428. }
  429. } else {
  430. w = .5;
  431. v = i.stg_value;
  432. var t = 'textfield', type = i.stg_type.toUpperCase();
  433. if(/(DATE|TIMESTAMP)(\(\d+\)){0,1}/.test(type)) {
  434. t = 'datefield';
  435. if(!Ext.isEmpty(v)) {
  436. w = 1;
  437. switch(v) {
  438. case '今天':
  439. t = 'condatefield';v = 1;break;
  440. case '昨天':
  441. t = 'condatefield';v = 2;break;
  442. case '本月':
  443. t = 'condatefield';v = 3;break;
  444. case '上个月':
  445. t = 'condatefield';v = 4;break;
  446. case '本年度':
  447. t = 'condatefield';v = 5;break;
  448. case '上年度':
  449. t = 'condatefield';v = 6;break;
  450. case '自定义':
  451. t = 'condatefield';v = 7;break;
  452. default:
  453. if(!Ext.isDate(v) && /\d{4}-\d{2}-\d{2}/.test(v)) {
  454. v = Ext.Date.parse(v, 'Y-m-d');
  455. }
  456. break;
  457. }
  458. }
  459. } else if(/(NUMBER|FLOAT|INT)(\(\d+\)){0,1}/.test(type)) {
  460. t = 'numberfield';
  461. }
  462. if(1 == i.stg_dbfind) {
  463. t = 'dbfindtrigger';
  464. }
  465. if(1 == i.stg_double) {
  466. w = 1;
  467. if(t == 'numberfield') {
  468. t = 'erpFtNumberField';
  469. } else if (t == 'dbfindtrigger') {
  470. t = 'ftfindfield';
  471. } else if (t == 'datefield') {
  472. t = 'ftdatefield';
  473. } else if (t == 'textfield'){
  474. t = 'erpFtField';
  475. }
  476. if(i.stg_format == 'Ym') {
  477. t = 'conmonthdatefield';
  478. }
  479. }
  480. datas.push({
  481. fieldLabel: i.stg_text,
  482. relativeTable: i.stg_table,
  483. labelWidth: 100,
  484. xtype: t,
  485. name: i.stg_field,
  486. id: i.stg_field,
  487. value: v,
  488. columnWidth: w
  489. });
  490. }
  491. }
  492. if(1 === i.stg_group) {
  493. group = i.stg_alias;
  494. }
  495. if(1 === i.stg_lock) {
  496. locks.push(i.stg_alias);
  497. }
  498. var xtype = me.getTypeByStg(i.stg_type);
  499. if(1 === i.stg_use) {
  500. var col = {
  501. text: i.stg_text,
  502. xtype: xtype,
  503. dataIndex: i.stg_alias,
  504. dataField: i.stg_field,
  505. dataTable: i.stg_table,
  506. format: (i.stg_format == 'Ym') ? null : i.stg_format,
  507. width: i.stg_width,
  508. summaryType: i.stg_sum == 1 ? 'sum' : null,
  509. align: xtype == 'numbercolumn' ? 'right' : 'left'
  510. };
  511. if(i.stg_link) {
  512. col.renderer = function(value, p, record) {
  513. if(value) {
  514. return Ext.String.format(
  515. '<a href="javascript:void(0)" onclick="onLinkClick(\'' + i.stg_link + '\',\'{2}\',\'{3}\',\'{0}\',\'{1}\')">{2}</a>',
  516. record.get(i.stg_tokencol1),
  517. record.get(i.stg_tokencol2),
  518. value,
  519. i.stg_field
  520. );
  521. return null;
  522. };
  523. };
  524. }
  525. columns.push(col);
  526. }
  527. temp.push({
  528. stg_text: i.stg_text,
  529. stg_use: i.stg_use,
  530. stg_field: i.stg_field,
  531. stg_value: i.stg_value,
  532. stg_lock: i.stg_lock == 1,
  533. stg_group: i.stg_group == 1,
  534. stg_sum: i.stg_sum == 1,
  535. stg_dbfind: i.stg_dbfind == 1,
  536. stg_double: i.stg_double == 1,
  537. stg_query: i.stg_query == 1,
  538. stg_width: i.stg_width,
  539. stg_type: i.stg_type,
  540. stg_table: i.stg_table,
  541. stg_format: i.stg_format,
  542. stg_formula: i.stg_formula,
  543. stg_mode: i.stg_mode,
  544. modeItems: i.stg_mode ? (modeItems || [{dispay:null,value:null}]) : modeItems,
  545. type: xtype,
  546. links: i.links,
  547. stg_link: i.stg_link,
  548. stg_tokentab1: i.stg_tokentab1,
  549. stg_tokencol1: i.stg_tokencol1,
  550. stg_tokentab2: i.stg_tokentab2,
  551. stg_tokencol2: i.stg_tokencol2
  552. });
  553. });
  554. // 加载筛选条件
  555. if(load) {
  556. var f = this.querywin.down('form');
  557. f.removeAll();
  558. f.add(datas);
  559. var alias = Ext.Array.pluck(columns, 'dataIndex');
  560. Ext.Array.each(temp, function(t){
  561. if(t.stg_tokencol1 && !Ext.Array.contains(alias, t.stg_tokencol1)) {
  562. alias.push(t.stg_tokencol1);
  563. }
  564. if(t.stg_tokencol2 && !Ext.Array.contains(alias, t.stg_tokencol2)) {
  565. alias.push(t.stg_tokencol2);
  566. }
  567. });
  568. Ext.suspendLayouts();
  569. grid.reconfigure(new Ext.data.Store({
  570. fields: alias
  571. }), columns);
  572. Ext.resumeLayouts(true);
  573. // 加载分组条件
  574. this.groupfield = group;
  575. this.toogleGroup(group, true);
  576. // 固定列
  577. this.lockfields = locks;
  578. if(locks.length > 0) {
  579. var normal = grid.getView().normalGrid;
  580. Ext.Array.each(locks, function(){
  581. var column = normal.down('gridcolumn[dataIndex=' + this + ']');
  582. if (column.locked) {
  583. grid.unlock(column);
  584. } else {
  585. grid.lock(column);
  586. }
  587. });
  588. }
  589. // 加载合计
  590. }
  591. return temp;
  592. },
  593. onTempSet : function(record, items, sId) {
  594. var me = this, win = me.tempwin, temp = me.formatTempSet(items, record.get('properties'), false);
  595. if (!win) {
  596. var sGrid = me.getSettingGrid();
  597. Ext.define("Post", {
  598. extend: 'Ext.data.Model',
  599. proxy: {
  600. type: 'ajax',
  601. url : basePath + 'ma/dataDictionary/search.action',
  602. reader: {
  603. type: 'json',
  604. root: 'datas',
  605. totalProperty: 'totalCount'
  606. },
  607. headers: {
  608. 'Content-Type': 'application/json;charset=utf-8'
  609. }
  610. },
  611. fields: [
  612. {name: 'desc', mapping: 'comments'},
  613. {name: 'table', mapping: 'table_name'}
  614. ]
  615. });
  616. ds = Ext.create('Ext.data.Store', {
  617. pageSize: 10,
  618. model: 'Post'
  619. });
  620. win = me.tempwin = Ext.create('Ext.window.Window', {
  621. header: {
  622. items: [{
  623. xtype: 'tbtext',
  624. id: 'set-title',
  625. text: '方案设置',
  626. style: 'font-weight: 700;'
  627. }, {
  628. xtype: 'tbtext',
  629. id: 'set-info',
  630. tpl: Ext.create('Ext.XTemplate',
  631. '共 <strong>{tableCount}</strong> 个表关联,' +
  632. '可选 <strong>{columnCount}</strong> 列 ' +
  633. '已选 <strong>{usedCount}</strong> 列')
  634. }]
  635. },
  636. closeAction : 'hide',
  637. width : '100%',
  638. height : '80%',
  639. layout: 'border',
  640. items : [{
  641. region: 'west',
  642. width: 400,
  643. layout: 'accordion',
  644. id: 'dictionary',
  645. tbar: [{
  646. xtype: 'combo',
  647. store: ds,
  648. width: 360,
  649. displayField: 'desc',
  650. emptyText: '查找数据字典',
  651. typeAhead: false,
  652. hideLabel: true,
  653. hideTrigger:true,
  654. minChars: 3,
  655. listConfig: {
  656. minHeight: 360,
  657. maxHeight: 360,
  658. loadingText: '查找中...',
  659. emptyText: '<h3>没有找到您需要的数据字典.</h3>',
  660. getInnerTpl: function() {
  661. return '<div style="padding: 5px 10px;">' +
  662. '<span style="font-weight:bold;font-size:120%;">' +
  663. '<tpl if="desc">{desc}<tpl else>{table}</tpl>' +
  664. '</span>' +
  665. '<span style="float:right;">{table}</span>' +
  666. '</div>';
  667. }
  668. },
  669. pageSize: 10,
  670. listeners: {
  671. select: function(combo, records, opts) {
  672. me.addDictionary(win, records[0].get('table'));
  673. combo.reset();
  674. }
  675. },
  676. getParams: function(queryString) {
  677. var params = {},
  678. param = this.queryParam;
  679. if (param) {
  680. params[param] = escape(queryString);
  681. }
  682. return params;
  683. }
  684. },'->', {
  685. xtype: 'tool',
  686. type: 'left',
  687. style: {
  688. marginRight: '5px'
  689. },
  690. tooltip: '收拢',
  691. handler: function(e, el, tb, tool) {
  692. tb.ownerCt.collapse(Ext.Component.DIRECTION_LEFT, true);
  693. }
  694. }]
  695. },{
  696. region: 'center',
  697. layout: 'anchor',
  698. items: [sGrid]
  699. }],
  700. buttonAlign : 'center',
  701. buttons : [{
  702. text : '保存到方案',
  703. height : 26,
  704. handler : function(b) {
  705. var w = b.ownerCt.ownerCt;
  706. me.updateTemp(function(){
  707. w.hide();
  708. });
  709. }
  710. },{
  711. text : '作为新方案保存',
  712. id: 'new_temp_btn',
  713. height : 26,
  714. hidden : (sId <= 0),
  715. handler : function(b) {
  716. var t = win.relativeRecord.get('st_title');
  717. me.addTemp(t + '(新)', function(title){
  718. var w = b.ownerCt.ownerCt;
  719. w.hide();
  720. me.copyTemp(title);
  721. });
  722. }
  723. }, {
  724. text : $I18N.common.button.erpCloseButton,
  725. height : 26,
  726. handler : function(b) {
  727. b.ownerCt.ownerCt.hide();
  728. }
  729. }]
  730. });
  731. }
  732. win.show();
  733. if(sId <= 0) {
  734. win.down('#new_temp_btn').hide();
  735. } else {
  736. win.down('#new_temp_btn').show();
  737. }
  738. var g = win.down('#grid-setting');
  739. g.store.loadData(temp);
  740. g.sorts = record.get('st_sorts');
  741. g.limits = record.get('st_limits');
  742. g.down('#st_condition').setValue(record.get('st_condition'));
  743. // 加载数据字典
  744. var dic = win.down('#dictionary'),
  745. usedTabs = record.get('st_usedtable'), tabSql = record.get('st_tablesql');
  746. if(dic.tables != usedTabs || win.relativeId != sId) {
  747. g.down('#set-tab-info').setTooltip(me.getCodeTip({
  748. usedTabs: usedTabs.split(','),
  749. tabSql: tabSql,
  750. condSql: record.get('st_condition'),
  751. sortSql: g.sorts,
  752. data: temp
  753. }));
  754. me.getDictionary(usedTabs, function(datas){
  755. dic.tables = usedTabs;
  756. dic.removeAll();
  757. var c = 0;
  758. for(var i in datas) {
  759. dic.add(me.createDictionaryGrid(datas[i]));
  760. c += datas[i].dataDictionaryDetails.length;
  761. }
  762. win.down('#set-info').update({
  763. tableCount: datas.length,
  764. columnCount: c,
  765. usedCount: temp.length
  766. });
  767. });
  768. }
  769. if(win.relativeId != sId) {
  770. win.down('#set-title').setText(record.get('st_title'));
  771. win.relativeRecord = record;
  772. win.relativeId = sId;
  773. }
  774. },
  775. /**
  776. * 显示方案sql的tip
  777. */
  778. getCodeTip: function(config) {
  779. var me = this, oldConf = me.templateConfig;
  780. if(!oldConf)
  781. oldConf = {};
  782. me.templateConfig = config = Ext.Object.merge(oldConf, config);
  783. return new Ext.tip.ToolTip({
  784. target: 'set-tab-info',
  785. cls: 'tip-custom',
  786. autoHide: false,
  787. hideDelay: 0,
  788. html: me.getCodeHtml(config)
  789. });
  790. },
  791. /**
  792. * 代码html
  793. */
  794. getCodeHtml: function(datas) {
  795. return new Ext.XTemplate(
  796. '<strong class="code-title">数据字典:</strong>' +
  797. '<tpl for="usedTabs">' +
  798. '<label class="label label-info">{.}</label>' +
  799. '</tpl>' +
  800. '<strong class="code-title">关联SQL:</strong>' +
  801. '<div class="code-body">{tabSql:this.format}</div>' +
  802. '<strong class="code-title">排序SQL:</strong>' +
  803. '<div class="code-body">{sortSql:this.orderBy}</div>' +
  804. '<strong class="code-title">条件SQL:</strong>' +
  805. '<div class="code-body">{condSql:this.format}</div>' +
  806. '<strong class="code-title">查询SQL:</strong>' +
  807. '<div class="code-body">{[this.getSearchSql(values)]}</div>', {
  808. keywords : ['SELECT ', ' FROM ', ' WHERE ', ' LEFT JOIN ', ' ON ', 'ORDER BY ', ' AND ', ' DESC', ' ASC', 'TO_CHAR'],
  809. format: function(sql) {
  810. if(!sql) return null;
  811. var kw = this.keywords;
  812. for(var i in kw) {
  813. var reg = new RegExp(kw[i], 'g');
  814. sql = sql.replace(reg, '<span class="code-key">' + kw[i] + '</span>');
  815. }
  816. sql = this.replaceQuot(sql);
  817. return sql;
  818. },
  819. replaceQuot: function(sql) {
  820. var index = 0, length = sql.length, s, e = -1, c = 0, htm = '';
  821. while(index < length) {
  822. if((s = sql.indexOf('\'', index)) != -1 && (e = sql.indexOf('\'', s + 1)) != -1) {
  823. c = 1;
  824. while(sql.substring(e + c, e + c + 1) == '\'' || c%2 == 0){
  825. e++;
  826. c++;
  827. }
  828. htm += sql.substring(index, s) + '<span class="code-quot">' + sql.substring(s, e+1) +'</span>';
  829. index = e + 1;
  830. } else {
  831. htm += sql.substring(e + 1);
  832. break;
  833. }
  834. }
  835. return htm.length > 0 ? htm : sql;
  836. },
  837. orderBy: function(sql) {
  838. if(!sql) return null;
  839. return this.format('ORDER BY ' + sql);
  840. },
  841. getSearchSql: function(values) {
  842. var fs = [];
  843. Ext.Array.each(values.data, function(d){
  844. if(d.stg_type.toLowerCase() == 'date')
  845. fs.push('TO_CHAR(' + d.stg_table + '.' + d.stg_field +
  846. ', \'yyyy-mm-dd hh24:mi:ss\') ' + d.stg_field);
  847. else
  848. fs.push(d.stg_table + '.' + d.stg_field + ' ' + d.stg_field);
  849. });
  850. return this.format('SELECT ' + fs.join(',') + ' FROM ' + values.tabSql +
  851. (values.condSql ? (' WHERE (' + values.condSql + ')') : '') +
  852. (values.sortSql ? (' ORDER BY ' + values.sortSql) : ''));
  853. }
  854. }).apply(datas);
  855. },
  856. /**
  857. * 添加数据字典
  858. */
  859. addDictionary: function(win, table) {
  860. var me = this, dic = win.down('#dictionary');
  861. if(dic.tables && Ext.Array.indexOf(dic.tables.split(','), table) > -1) {
  862. Ext.example.msg('warning', '警告', '不能添加已经存在的表', 4000);
  863. return;
  864. }
  865. var newTabs = dic.tables ? dic.tables + ',' + table : table;
  866. me.getTabSql(newTabs, function(sql){
  867. me.getDictionary(table, function(datas){
  868. dic.tables = newTabs;
  869. var c = 0;
  870. for(var i in datas) {
  871. dic.add(me.createDictionaryGrid(datas[i]));
  872. c += datas[i].dataDictionaryDetails.length;
  873. }
  874. Ext.each(dic.items.items, function(g){
  875. c += g.store.getCount();
  876. });
  877. win.down('#set-info').update({
  878. tableCount: dic.items.items.length,
  879. columnCount: c
  880. });
  881. win.down('#set-tab-info').setTooltip(me.getCodeTip({
  882. usedTabs: dic.tables.split(','),
  883. tabSql: sql
  884. }));
  885. });
  886. });
  887. },
  888. getTypeByStg: function(t) {
  889. t = t.toUpperCase();
  890. if(/(NUMBER|FLOAT|INT)(\(\d+\)){0,1}/.test(t))
  891. return 'numbercolumn';
  892. if(/(DATE|TIMESTAMP)(\(\d+\)){0,1}/.test(t))
  893. return 'datecolumn';
  894. return null;
  895. },
  896. /**
  897. * 显示数据字典的grid
  898. */
  899. createDictionaryGrid: function(dic) {
  900. var id = 'grid-' + dic.table_name, datas = [], me = this;
  901. Ext.Array.each(dic.dataDictionaryDetails, function(d){
  902. var nl = {
  903. text: d.comments,
  904. type: me.getTypeByStg(d.data_type),
  905. stg_width: 100,
  906. stg_text: d.comments,
  907. stg_use: 1,
  908. stg_field: d.column_name.toUpperCase(),
  909. stg_table: d.table_name.toUpperCase(),
  910. stg_type: d.data_type.toUpperCase(),
  911. modeItems: [],
  912. links: d.links
  913. };
  914. if(d.links && d.links.length > 0) {
  915. nl.stg_link = d.links[0].dl_link;
  916. nl.stg_tokentab1 = d.links[0].dl_tokentab1;
  917. nl.stg_tokencol1 = d.links[0].dl_tokencol1;
  918. nl.stg_tokentab2 = d.links[0].dl_tokentab2;
  919. nl.stg_tokencol2 = d.links[0].dl_tokencol2;
  920. }
  921. datas.push(nl);
  922. });
  923. return new Ext.grid.Panel({
  924. title: dic.comments,
  925. cls: 'custom-grid',
  926. id: id,
  927. columns: [{
  928. text: '代码',
  929. dataIndex: 'stg_field',
  930. flex: 1,
  931. filter: {
  932. xtype : 'textfield'
  933. }
  934. },{
  935. text: '描述',
  936. dataIndex: 'stg_text',
  937. flex: 1,
  938. filter: {
  939. xtype : 'textfield'
  940. }
  941. }],
  942. plugins: [Ext.create('erp.view.core.grid.HeaderFilter')],
  943. viewConfig: {
  944. plugins: {
  945. ptype: 'gridviewdragdrop',
  946. dragGroup: 'grid-setting',
  947. dropGroup: 'grid-setting'
  948. },
  949. listeners: {
  950. drop: function(node, data) {
  951. // 从配置里面拖过来的,表示删除
  952. // 重新加载数据,防止出现checkcolumn的勾选错位情况
  953. var newData = [];
  954. data.view.store.each(function(record){
  955. newData.push(record.data);
  956. });
  957. data.view.store.loadData(newData);
  958. }
  959. }
  960. },
  961. selModel: new Ext.selection.RowModel({
  962. mode: 'MULTI'
  963. }),
  964. store: new Ext.data.Store({
  965. model: erp.model.SearchTemplate,
  966. data: datas,
  967. sorters: [{
  968. property: 'stg_field',
  969. direction: 'ASC'
  970. }]
  971. })
  972. });
  973. },
  974. createQueryForm : function() {
  975. var me = this;
  976. var form = Ext.create('Ext.form.Panel', {
  977. region: 'center',
  978. anchor: '100% 60%',
  979. title: '(未选择方案)',
  980. layout: 'column',
  981. autoScroll: true,
  982. defaults: {
  983. columnWidth: 1,
  984. margin: '4 8 4 8'
  985. },
  986. bodyStyle: 'background:#f1f2f5;',
  987. getCondition: function() {
  988. var s = me.defaultCondition ? '(' + me.defaultCondition + ')' : '';
  989. Ext.each(this.items.items, function(){
  990. var v = this.getValue(), b = this.relativeTable, n = this.name, _n = b + '.' + n, t;
  991. if(!Ext.isEmpty(v) && v != '$ALL') {
  992. switch(this.xtype) {
  993. case 'datefield':
  994. t = "to_char(" + _n + ",'yyyy-mm-dd')='" + Ext.Date.format(v,'Y-m-d') + "'";break;
  995. case 'condatefield':
  996. t = _n + ' ' + v;break;
  997. case 'ftdatefield':
  998. t = _n + ' ' + this.value;break;
  999. case 'ftfindfield':
  1000. t = _n + ' ' + this.value;break;
  1001. case 'erpFtNumberField':
  1002. t = _n + ' ' + this.value;break;
  1003. case 'checkboxgroup':
  1004. if(!Ext.Object.isEmpty(v)) {
  1005. var ks = Ext.Object.getKeys(v), k = ks[0], vs = [];
  1006. Ext.Array.each(v[k], function(c){
  1007. vs.push(k + '=\'' + c + '\'');
  1008. });
  1009. t = vs.join(' OR ');
  1010. }
  1011. break;
  1012. case 'radiogroup':
  1013. if(!Ext.Object.isEmpty(v)) {
  1014. var ks = Ext.Object.getKeys(v), k = ks[0];
  1015. t = k + '=\'' + v[k] + '\'';
  1016. }
  1017. break;
  1018. case 'conmonthdatefield':
  1019. if(!Ext.Object.isEmpty(v)) {
  1020. if(n.toUpperCase().indexOf('YM_VIEW_PARAM') > -1) {
  1021. t = ' ' + this.value;
  1022. } else {
  1023. t = _n + ' ' + this.value;
  1024. }
  1025. }
  1026. break;
  1027. default:
  1028. v = String(v);
  1029. if(v.charAt(0) == '%' || v.charAt(v.length - 1) == '%') {
  1030. t = _n + " like '" + v + "'";
  1031. } else if (v == '$NULL') {
  1032. t = "nvl(" + _n + ",' ')=' '";
  1033. } else {
  1034. t = _n + "='" + v + "'";
  1035. }
  1036. break;
  1037. }
  1038. if(t) {
  1039. t = '(' + t + ')';
  1040. s += s.length > 0 ? (' and ' + t ) : t;
  1041. }
  1042. }
  1043. });
  1044. return s.length > 0 ? s : '0=0';
  1045. }
  1046. });
  1047. return form;
  1048. },
  1049. onQuery : function(data) {
  1050. var g = this.getGrid(), q = this.querywin.down('form'), end = g.maxDataSize || 10000;
  1051. this.loadNewStore(g, {
  1052. sId: data ? data.st_id : this.$sid,
  1053. condition: q.getCondition(),
  1054. sorts: data ? data.st_sorts : this.templateConfig.sorts,
  1055. start: 1,
  1056. end: end
  1057. });
  1058. this.querywin.hide();
  1059. this.log();//记录本次选择的方案
  1060. },
  1061. onGroupClick : function() {
  1062. var me = this, win = me.groupwin;
  1063. if (!win) {
  1064. var form = me.getAliaForm();
  1065. win = me.groupwin = Ext.create('Ext.window.Window', {
  1066. title : '分组设置',
  1067. closeAction : 'hide',
  1068. width : 500,
  1069. maxHeight : 400,
  1070. items : [form],
  1071. buttonAlign : 'center',
  1072. buttons : [{
  1073. text : '取消分组',
  1074. flag : 'cancel',
  1075. height : 26,
  1076. disabled : true,
  1077. handler : function(b) {
  1078. var w = b.ownerCt.ownerCt;
  1079. me.toogleGroup(w.down('form'), false);
  1080. w.hide();
  1081. }
  1082. },{
  1083. text : $I18N.common.button.erpConfirmButton,
  1084. height : 26,
  1085. handler : function(b) {
  1086. var w = b.ownerCt.ownerCt;
  1087. me.toogleGroup(w.down('form'), true);
  1088. w.hide();
  1089. }
  1090. }, {
  1091. text : $I18N.common.button.erpCloseButton,
  1092. height : 26,
  1093. handler : function(b) {
  1094. b.ownerCt.ownerCt.hide();
  1095. }
  1096. }]
  1097. });
  1098. if(this.groupfield) {
  1099. var f = win.down('radio[inputValue=' + this.groupfield + ']');
  1100. if(f) {
  1101. f.setValue(true);
  1102. }
  1103. }
  1104. }
  1105. win.show();
  1106. var f = win.down('radio[value=true]'), b = win.down('button[flag=cancel]');
  1107. b.setDisabled(!f);
  1108. },
  1109. onLockClick : function() {
  1110. var me = this, win = me.lockwin;
  1111. if (!win) {
  1112. var form = me.getAliaForm('checkbox');
  1113. win = me.lockwin = Ext.create('Ext.window.Window', {
  1114. title : '固定列设置',
  1115. closeAction : 'hide',
  1116. width : 500,
  1117. maxHeight : 400,
  1118. items : [form],
  1119. buttonAlign : 'center',
  1120. buttons : [{
  1121. text : $I18N.common.button.erpConfirmButton,
  1122. height : 26,
  1123. handler : function(b) {
  1124. var w = b.ownerCt.ownerCt;
  1125. me.onLock(w.down('form'));
  1126. w.hide();
  1127. }
  1128. }, {
  1129. text : $I18N.common.button.erpCloseButton,
  1130. height : 26,
  1131. handler : function(b) {
  1132. b.ownerCt.ownerCt.hide();
  1133. }
  1134. }]
  1135. });
  1136. if(this.lockfields) {
  1137. Ext.Array.each(this.lockfields, function(l){
  1138. var f = win.down('checkbox[inputValue=' + l + ']');
  1139. if(f) {
  1140. f.setValue(true);
  1141. }
  1142. });
  1143. }
  1144. }
  1145. win.show();
  1146. },
  1147. onSortClick : function(source, oldSorts, callback) {
  1148. var me = this, win = me.sortwin;
  1149. var oldData = [], oldProp = [];
  1150. if(oldSorts) {
  1151. Ext.Array.each(oldSorts.split(','), function(s, i){
  1152. var p = s.split(' '), t = null, f = p[0], tx = '';
  1153. if(f.indexOf('.') > 0) {// table.field
  1154. t = f.substr(0, f.indexOf('.'));
  1155. f = f.substr(f.indexOf('.') + 1);
  1156. }
  1157. if(Ext.isArray(source)) {
  1158. var obj = Ext.Array.findBy(source, function(i){
  1159. return i.stg_field == f;
  1160. });
  1161. if (obj) tx = obj.stg_text;
  1162. } else {
  1163. tx = source.findRecord('stg_field', f).get('stg_text');
  1164. }
  1165. oldData.push({property: f, direction: p[1], number: i+1, description: tx, table: t});
  1166. oldProp.push(f);
  1167. });
  1168. }
  1169. if (!win) {
  1170. var form = me.getGridForm('checkbox', null, source, oldProp),
  1171. view = me.getSortingView(oldData);
  1172. win = me.sortwin = Ext.create('Ext.window.Window', {
  1173. title : '排序设置',
  1174. closeAction : 'hide',
  1175. width : 800,
  1176. layout: 'hbox',
  1177. defaults: {flex: 1},
  1178. items : [form, view],
  1179. buttonAlign : 'center',
  1180. buttons : [{
  1181. text : $I18N.common.button.erpConfirmButton,
  1182. height : 26,
  1183. handler : function(b) {
  1184. var w = b.ownerCt.ownerCt, sorts = [], sortSql = [], desc = '';
  1185. view.getStore().each(function(i){
  1186. desc = i.get('property') + ' ' + i.get('direction');
  1187. if(i.get('table'))
  1188. desc = i.get('table') + '.' + desc;
  1189. sortSql.push(desc);
  1190. sorts.push({
  1191. property: i.get('alias'),
  1192. direction: i.get('direction')
  1193. });
  1194. });
  1195. callback.call(me, sortSql.join(','), sorts);
  1196. w.hide();
  1197. }
  1198. }, {
  1199. text : $I18N.common.button.erpCloseButton,
  1200. height : 26,
  1201. handler : function(b) {
  1202. b.ownerCt.ownerCt.hide();
  1203. }
  1204. }]
  1205. });
  1206. } else {
  1207. var form = win.down('form'), view = win.down('dataview');
  1208. form.removeAll();
  1209. form.add(me.createFormItems(source, oldProp));
  1210. view.store.loadData(oldData);
  1211. }
  1212. win.show();
  1213. me.onSortChange(win.down('form'), win.down('dataview'));
  1214. },
  1215. /**
  1216. * 排序设置,监听字段变化
  1217. */
  1218. onSortChange: function(form, view) {
  1219. var me = this, onDirectionChange = function() {
  1220. var d = Ext.select("td.sort-value input"), e = d.elements;
  1221. Ext.each(e, function(m) {
  1222. Ext.EventManager.on(m, {
  1223. change : function(e, el){
  1224. var record = view.getStore().findRecord('property', el.name);
  1225. record.set('direction', el.value);
  1226. },
  1227. buffer : 100
  1228. });
  1229. });
  1230. };
  1231. form.getForm().getFields().each(function(field){
  1232. field.on('change', function(scope){
  1233. view.getStore().loadData(me.getSortProperties(scope.ownerCt, view.getStore()));
  1234. onDirectionChange();
  1235. });
  1236. });
  1237. Ext.defer(onDirectionChange, 100);
  1238. },
  1239. /**
  1240. * 选中的排序字段view
  1241. */
  1242. getSortingView: function(oldData) {
  1243. var sortStore = new Ext.data.Store({
  1244. fields: ['property', 'description', 'direction', 'number', 'table', 'alias'],
  1245. sorters: [{
  1246. property: 'number',
  1247. direction: 'ASC'
  1248. }],
  1249. data: oldData
  1250. });
  1251. return Ext.create('Ext.view.View', {
  1252. cls: 'sort-view',
  1253. tpl: '<tpl for=".">' +
  1254. '<div class="sort"><table><tbody>' +
  1255. '<tr><td class="sort-name">{description}</td></tr>' +
  1256. '<tr><td class="sort-value">' +
  1257. '<em>升序 </em><input type="radio" name="{property}" value="ASC" ' +
  1258. '<tpl if="direction == &quot;ASC&quot;"> checked="checked"</tpl>' +
  1259. '/>' +
  1260. '</td></tr>' +
  1261. '<tr><td class="sort-value">' +
  1262. '<em>降序 </em><input type="radio" name="{property}" value="DESC" ' +
  1263. '<tpl if="direction == &quot;DESC&quot;"> checked="checked"</tpl>' +
  1264. '/>' +
  1265. '</td></tr>' +
  1266. '</tbody></table></div>' +
  1267. '</tpl>' +
  1268. '<ol class="sort-note">' +
  1269. '<li>如果直接点击列抬头来排序,将不会使用到本次排序设置</li>' +
  1270. '<li>可以拖放选中的字段来改变排序的优先顺序</li>' +
  1271. '</ol>',
  1272. itemSelector: 'div.sort',
  1273. overItemCls: 'sort-over',
  1274. selectedItemClass: 'sort-selected',
  1275. singleSelect: true,
  1276. ddGroup: 'sort',
  1277. store: sortStore,
  1278. listeners: {
  1279. render: function(v) {
  1280. v.dragZone = new Ext.dd.DragZone(v.ownerCt.el, {
  1281. ddGroup: 'sort',
  1282. getDragData: function(e) {
  1283. var sourceEl = e.getTarget(v.itemSelector, 10), d;
  1284. if (sourceEl) {
  1285. d = sourceEl.cloneNode(true);
  1286. d.id = Ext.id();
  1287. return (v.dragData = {
  1288. sourceEl: sourceEl,
  1289. repairXY: Ext.fly(sourceEl).getXY(),
  1290. ddel: d,
  1291. record: v.getRecord(sourceEl)
  1292. });
  1293. }
  1294. },
  1295. getRepairXY: function() {
  1296. return this.dragData.repairXY;
  1297. }
  1298. });
  1299. v.dropZone = new Ext.dd.DropZone(v.ownerCt.el, {
  1300. ddGroup: 'sort',
  1301. getTargetFromEvent: function(e) {
  1302. return e.getTarget('.sort .sort-over');
  1303. },
  1304. onNodeEnter: function(target, dd, e, data){
  1305. var fly = Ext.fly(target);
  1306. if(fly && typeof fly.addClass === 'function')
  1307. fly.addClass('sort-target-hover');
  1308. },
  1309. onNodeOut: function(target, dd, e, data){
  1310. var fly = Ext.fly(target);
  1311. if(fly && typeof fly.removeClass === 'function')
  1312. fly.removeClass('sort-target-hover');
  1313. },
  1314. onNodeOver: function(target, dd, e, data){
  1315. return Ext.dd.DropZone.prototype.dropAllowed;
  1316. },
  1317. onNodeDrop : function(target, dd, e, data){
  1318. var dragRec = dd.dragData.record,
  1319. dropRec = v.getRecord(target);
  1320. var i = dragRec.get('number'), j = dropRec.get('number');
  1321. dragRec.set('number', j);
  1322. dropRec.set('number', i);
  1323. v.getStore().sort('number', 'ASC');
  1324. return true;
  1325. }
  1326. });
  1327. }
  1328. }
  1329. });
  1330. },
  1331. newComboConfig: function(data) {
  1332. return {
  1333. store: Ext.create('Ext.data.Store', {
  1334. fields: ['display', 'value'],
  1335. data : data
  1336. }),
  1337. displayField: 'display',
  1338. valueField: 'value',
  1339. queryMode: 'local'
  1340. };
  1341. },
  1342. getSettingGrid : function() {
  1343. var me = this, config = {
  1344. store: Ext.create('Ext.data.Store', {
  1345. fields: ['display', 'value'],
  1346. data : [
  1347. {"display": '今天', "value": '今天'},
  1348. {"display": '昨天', "value": '昨天'},
  1349. {"display": '本月', "value": '本月'},
  1350. {"display": '上个月', "value": '上个月'},
  1351. {"display": '本年度', "value": '本年度'},
  1352. {"display": '上年度', "value": '上年度'},
  1353. {"display": '自定义', "value": '自定义'}
  1354. ]
  1355. }),
  1356. displayField: 'display',
  1357. valueField: 'value',
  1358. queryMode: 'local'
  1359. };
  1360. var formatStore = new Ext.data.Store({
  1361. fields: ['display', 'value', 'type'],
  1362. data: [{
  1363. display: '0,000.00',
  1364. value: '0,000.00',
  1365. type: 'numbercolumn'
  1366. },{
  1367. display: '0,000.0000',
  1368. value: '0,000.0000',
  1369. type: 'numbercolumn'
  1370. },{
  1371. display: '0,000.000000',
  1372. value: '0,000.000000',
  1373. type: 'numbercolumn'
  1374. },{
  1375. display: '整数',
  1376. value: '0,000',
  1377. type: 'numbercolumn'
  1378. },{
  1379. display: '年-月-日',
  1380. value: 'Y-m-d',
  1381. type: 'datecolumn'
  1382. },{
  1383. display: '年-月-日 时:分:秒',
  1384. value: 'Y-m-d H:i:s',
  1385. type: 'datecolumn'
  1386. },{
  1387. display: '年-月',
  1388. value: 'Y-m',
  1389. type: 'datecolumn'
  1390. },{
  1391. display: '月-日 时:分',
  1392. value: 'm-d H:i',
  1393. type: 'datecolumn'
  1394. }]
  1395. });
  1396. return Ext.create('Ext.grid.Panel', {
  1397. id: 'grid-setting',
  1398. anchor: '100% 100%',
  1399. autoScroll : true,
  1400. cls: 'custom-grid',
  1401. border: false,
  1402. columnLines: true,
  1403. tbar: [{
  1404. text: '自定义公式',
  1405. iconCls: 'icon-fx',
  1406. handler: function(t) {
  1407. var g = t.ownerCt.ownerCt;
  1408. me.onFormulaClick(g.getStore(), null, function(formula){
  1409. var isN = formula.indexOf("'") == -1;
  1410. g.store.add({
  1411. stg_text: '输入公式名称',
  1412. stg_use: true,
  1413. stg_field: 'COL_' + new Date().getTime(),
  1414. stg_formula: formula,
  1415. stg_width: 100,
  1416. stg_type: isN ? 'NUMBER' : 'VARCHAR2(100)',
  1417. stg_format: isN ? '0,000.00' : null,
  1418. modeItems: []
  1419. });
  1420. g.selModel.select(g.store.last());
  1421. });
  1422. }
  1423. },{
  1424. text: '权限约束',
  1425. iconCls: 'icon-limit',
  1426. handler: function(t) {
  1427. var g = t.ownerCt.ownerCt;
  1428. me.onLimitClick(g.getStore(), g.limits, function(val){
  1429. g.limits = val;
  1430. });
  1431. }
  1432. },{
  1433. text: '排序设置',
  1434. iconCls: 'icon-sort',
  1435. handler: function(t) {
  1436. var g = t.ownerCt.ownerCt;
  1437. me.onSortClick(g.getStore(), g.sorts, function(sortSql){
  1438. g.sorts = sortSql;
  1439. g.down('#set-tab-info').setTooltip(me.getCodeTip({
  1440. sortSql: g.sorts
  1441. }));
  1442. });
  1443. }
  1444. },'->',{
  1445. xtype: 'textfield',
  1446. emptyText: 'SQL条件',
  1447. width: '66%',
  1448. id: 'st_condition'
  1449. }],
  1450. bbar: ['提示:1. 可以拖动数据字典的字段到右边;2. 字段可以拖放来调整顺序;3. 行展开设置特殊选项', '->', {
  1451. icon: basePath + 'resource/images/16/question.png',
  1452. cls: 'x-btn-icon',
  1453. text: '查看方案代码',
  1454. tooltip: '',
  1455. id: 'set-tab-info'
  1456. }],
  1457. viewConfig: {
  1458. plugins: {
  1459. ptype: 'gridviewdragdrop',
  1460. dragGroup: 'grid-setting',
  1461. dropGroup: 'grid-setting'
  1462. },
  1463. listeners: {
  1464. drop: function(node, data, over) {
  1465. // 重新加载数据,防止出现checkcolumn的勾选错位情况
  1466. var newData = [];
  1467. if(over) {
  1468. over.store.each(function(record){
  1469. newData.push(record.data);
  1470. });
  1471. over.store.loadData(newData);
  1472. }
  1473. }
  1474. }
  1475. },
  1476. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  1477. clicksToEdit: 1,
  1478. listeners: {
  1479. beforeedit: function(editor, e, opts) {
  1480. if(e.column.dataIndex == 'stg_value') {
  1481. var isDate = ['datecolumn','datetimecolumn'].indexOf(e.record.get('type')) > -1,
  1482. isRadio = e.record.get('stg_mode') == 'radiogroup',
  1483. isMulti = ['checkboxgroup','combobox'].indexOf(e.record.get('stg_mode')) > -1,
  1484. items = e.record.get('modeItems');
  1485. if(isDate) {
  1486. e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(config, {
  1487. value: e.value
  1488. })));
  1489. } else if(isRadio) {
  1490. e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(me.newComboConfig(items), {
  1491. value: e.value
  1492. })));
  1493. } else if(isMulti) {
  1494. var _items = Ext.Array.merge([{display: '全选', value: '$ALL'}], items);
  1495. e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(me.newComboConfig(_items), {
  1496. value: e.value
  1497. })));
  1498. } else {
  1499. e.column.setEditor(new Ext.form.field.Text({
  1500. value: e.value
  1501. }));
  1502. }
  1503. } else if(e.column.dataIndex == 'stg_format') {
  1504. formatStore.clearFilter(true);
  1505. formatStore.filter('type', e.record.get('type'));
  1506. }
  1507. }
  1508. }
  1509. }), {
  1510. ptype: 'rowexpander',
  1511. pluginId: 'rowexpander',
  1512. expandOnDblClick: false,
  1513. rowBodyTpl : [
  1514. '<tpl if="stg_formula">' +
  1515. '<div class="row">' +
  1516. '<label class="radio-inline text-info col-xs-2">' +
  1517. '表达式:' +
  1518. '</label>' +
  1519. '<div class="col-xs-8">{stg_formula:this.formatFormula}</div>' +
  1520. '<div class="col-xs-1">' +
  1521. '<button id="{[this.linkEvent(\'onFormulaEdit\')]}" class="x-btn" data-bind="{stg_field}">编辑</button>' +
  1522. '</div>' +
  1523. '</div><br>' +
  1524. '</tpl>'+
  1525. '<tpl if="stg_link">' +
  1526. '<div class="links row">' +
  1527. '<label class="radio-inline text-info col-xs-2">' +
  1528. '链接:' +
  1529. '</label>' +
  1530. '<div class="col-xs-10">' +
  1531. '<tpl for="links">' +
  1532. '<label class="radio-inline">' +
  1533. '<input type="radio" id="{[this.linkEvent(\'onLinkChange\')]}" name="{dl_fieldname}-link" data-bind="{dl_fieldname}" value="{[xindex]}" ' +
  1534. '<tpl if="dl_link == parent.stg_link"> checked="checked"</tpl>' +
  1535. ' /> {dl_title}' +
  1536. '</label>' +
  1537. '</tpl>' +
  1538. '</div>' +
  1539. '</div>' +
  1540. '</tpl>' +
  1541. '<tpl if="stg_table">' +
  1542. '<div class="mode-type row" data-bind="{stg_field}">' +
  1543. '<label class="radio-inline text-info col-xs-2">' +
  1544. '查询格式:' +
  1545. '</label>' +
  1546. '<div class="col-xs-10">' +
  1547. '<label class="radio-inline">' +
  1548. '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="" ' +
  1549. '<tpl if="!stg_mode || stg_mode == &quot;&quot;"> checked="checked"</tpl>' +
  1550. ' /> 无' +
  1551. '</label>' +
  1552. '<label class="radio-inline">' +
  1553. '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="checkboxgroup" ' +
  1554. '<tpl if="stg_mode == &quot;checkboxgroup&quot;"> checked="checked"</tpl>' +
  1555. ' /> 勾选框' +
  1556. '</label>' +
  1557. '<label class="radio-inline">' +
  1558. '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="radiogroup" ' +
  1559. '<tpl if="stg_mode == &quot;radiogroup&quot;"> checked="checked"</tpl>' +
  1560. ' /> 单选框' +
  1561. '</label>' +
  1562. '<label class="radio-inline">' +
  1563. '<input type="radio" id="{[this.linkEvent(\'onModeChange\')]}" name="{stg_field}" value="combobox" ' +
  1564. '<tpl if="stg_mode == &quot;combobox&quot;"> checked="checked"</tpl>' +
  1565. ' /> 下拉框' +
  1566. '</label>' +
  1567. '</div>' +
  1568. '</div>' +
  1569. '</tpl>' +
  1570. '<tpl if="stg_mode">' +
  1571. '<div class="mode-items" data-bind="{stg_field}">' +
  1572. '<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>' +
  1573. '<tpl for="modeItems">' +
  1574. '<div class="mode-item">' +
  1575. '<input type="text" id="{[this.linkEvent(\'onModeItemFocus\')]}" name="display" value="{display}" placeholder="显示属性" />' +
  1576. '<input type="text" id="{[this.linkEvent(\'onModeItemFocus\')]}" name="value" value="{value}" placeholder="实际属性" />' +
  1577. '<input type="button" id="{[this.linkEvent(\'onModeItemDel\')]}" data-index="{[xindex]}" value="&times;" title="删除"/>' +
  1578. '</div>' +
  1579. '</tpl>' +
  1580. '</div>' +
  1581. '</tpl>',
  1582. {
  1583. formatFormula: function(formula) {
  1584. // 数据库格式的表达式转化为界面显示的表达式
  1585. var units = formula.replace(/>=/g,'≥').replace(/<=/g,'≤').replace(/<>/g,'≠').replace(/(\|\|)/g,'‖')._split(/[\+\-\*=><\/%,\(\)\s]/), text = '', scope = this;
  1586. Ext.Array.each(units, function(unit){
  1587. if(!isNumber(unit) && (unit.indexOf('.') > 0 || unit.indexOf('COL_') == 0))
  1588. text += scope.getDesc(unit);
  1589. else
  1590. text += unit;
  1591. });
  1592. return text;
  1593. },
  1594. onFormulaEdit: function(elm) {
  1595. var store = this.owner.view.store, grid = this.owner.grid;
  1596. Ext.EventManager.on(elm, {
  1597. click: function(event, el) {
  1598. var record = grid.store.findRecord('stg_field', el.getAttribute('data-bind'));
  1599. me.onFormulaClick(store, record.get('stg_formula').replace(/>=/g,'≥').replace(/<=/g,'≤').replace(/<>/g,'≠').replace(/(\|\|)/g,'‖'), function(formula){
  1600. record.set('stg_formula', formula);
  1601. });
  1602. Ext.EventManager.stopEvent(event);
  1603. },
  1604. buffer: 50
  1605. });
  1606. },
  1607. getDesc: function(unit) {
  1608. var table = null, field = unit;
  1609. if(unit.indexOf('.') > 0) {
  1610. table = unit.substring(0, unit.indexOf('.'));
  1611. field = unit.substr(unit.indexOf('.')+1);
  1612. }
  1613. var res = this.owner.view.store.queryBy(function(record){
  1614. return record.get('stg_table') == table && record.get('stg_field') == field;
  1615. }), item = res.first();
  1616. if(item)
  1617. return item.get('stg_text');
  1618. return '';
  1619. },
  1620. linkEvent: function(eventName) {
  1621. var result = Ext.id();
  1622. Ext.defer(this.addListener, 1, this, [result, eventName]);
  1623. return result;
  1624. },
  1625. addListener: function(id, eventName) {
  1626. var elm = Ext.get(id);
  1627. elm && this[eventName].call(this, elm);
  1628. },
  1629. onModeChange: function(elm) {
  1630. var grid = this.owner.grid;
  1631. Ext.EventManager.on(elm, {
  1632. change: function(event, el) {
  1633. var record = grid.store.findRecord('stg_field', el.name);
  1634. record.set('stg_mode', el.value);
  1635. if(el.value && el.value != '') {
  1636. var items = record.get('modeItems');
  1637. if(!items || items.length == 0) {
  1638. record.set('modeItems', [{display: null,value:null}]);
  1639. }
  1640. }
  1641. Ext.EventManager.stopEvent(event);
  1642. },
  1643. buffer: 100
  1644. });
  1645. },
  1646. getViewItems: function(el) {
  1647. var p = el.parentNode.parentNode;
  1648. if(p) {
  1649. var gps = Ext.query('.mode-item', el.parentNode.parentNode), items = [];
  1650. Ext.Array.each(gps, function(els){
  1651. var e = els.childNodes, d = e[0].value, v = e[1].value;
  1652. v = (!v || v == '') ? d : v;
  1653. v = (!d || d == '') ? null : v;
  1654. items.push({display: d, value: v});
  1655. });
  1656. return items;
  1657. }
  1658. return null;
  1659. },
  1660. onModeItemAdd: function(elm) {
  1661. var grid = this.owner.grid, me = this;
  1662. Ext.EventManager.on(elm, {
  1663. click: function(event, el) {
  1664. var p = el.parentNode.parentNode;
  1665. if(p) {
  1666. var field = p.getAttribute('data-bind'),
  1667. record = grid.store.findRecord('stg_field', field),
  1668. items = me.getViewItems(el) || [];
  1669. items.push({
  1670. display: null,
  1671. value: null
  1672. });
  1673. record.set('modeItems', items);
  1674. }
  1675. Ext.EventManager.stopEvent(event);
  1676. },
  1677. buffer: 50
  1678. });
  1679. },
  1680. onModeItemDel: function(elm) {
  1681. var grid = this.owner.grid;
  1682. Ext.EventManager.on(elm, {
  1683. click: function(event, el) {
  1684. var p = el.parentNode.parentNode;
  1685. if(p) {
  1686. var field = p.getAttribute('data-bind'),
  1687. record = grid.store.findRecord('stg_field', field),
  1688. items = record.get('modeItems'), idx = Number(el.getAttribute('data-index')) - 1;
  1689. items.splice(idx, 1);
  1690. Ext.get(el.parentNode).remove();
  1691. record.set('modeItems', items);
  1692. }
  1693. Ext.EventManager.stopEvent(event);
  1694. }
  1695. });
  1696. },
  1697. onModeItemFocus: function(elm) {
  1698. var me = this;
  1699. Ext.EventManager.on(elm, {
  1700. mousedown: function(event, el) {
  1701. el.focus();
  1702. Ext.EventManager.stopEvent(event);
  1703. },
  1704. buffer: 100
  1705. });
  1706. Ext.EventManager.on(elm, {
  1707. blur: function(event, el) {
  1708. if(el.name == 'display') {
  1709. var nextEl = el.nextSibling;
  1710. if(Ext.isEmpty(el.value) || el.value == '') {
  1711. nextEl.value = null;
  1712. } else {
  1713. if(Ext.isEmpty(nextEl.value) || nextEl.value == '') {
  1714. nextEl.value = el.value;
  1715. }
  1716. }
  1717. }
  1718. },
  1719. change: function(event, el) {
  1720. var items = me.getViewItems(el);
  1721. if (items) {
  1722. var field = el.parentNode.parentNode.getAttribute('data-bind'),
  1723. grid = me.owner.grid,
  1724. record = grid.store.findRecord('stg_field', field);
  1725. record.set('modeItems', items);
  1726. }
  1727. },
  1728. buffer: 10
  1729. });
  1730. },
  1731. onLinkChange: function(elm) {
  1732. var grid = this.owner.grid;
  1733. Ext.EventManager.on(elm, {
  1734. change: function(event, el) {
  1735. var record = grid.store.findRecord('stg_field', el.getAttribute('data-bind')),
  1736. links = record.get('links'), dl = links[el.value - 1];
  1737. record.set('stg_link', dl.dl_link);
  1738. record.set('stg_tokentab1', dl.dl_tokentab1);
  1739. record.set('stg_tokencol1', dl.dl_tokencol1);
  1740. record.set('stg_tokentab2', dl.dl_tokentab1);
  1741. record.set('stg_tokencol2', dl.dl_tokencol2);
  1742. Ext.EventManager.stopEvent(event);
  1743. },
  1744. buffer: 100
  1745. });
  1746. }
  1747. }]
  1748. }],
  1749. store: new Ext.data.Store({
  1750. model: erp.model.SearchTemplate
  1751. }),
  1752. columns: [{
  1753. text: '列',
  1754. flex: 1,
  1755. columns: [{
  1756. text: '名称',
  1757. dataIndex: 'stg_text',
  1758. width: 180,
  1759. editor: {
  1760. xtype: 'textfield'
  1761. },
  1762. sortable: false,
  1763. renderer: function(val, meta, record){
  1764. var a = record.get('stg_table'), b = record.get('stg_field'),
  1765. c = record.get('stg_formula'), text = '';
  1766. a && (text += '表:' + a);
  1767. b && (text += ' 字段:' + b);
  1768. c && (text += ' 公式:' + c);
  1769. return '<span title="' + text + '">' + val + '</span>';
  1770. }
  1771. },{
  1772. text: '是否<br>显示',
  1773. xtype: 'checkcolumn',
  1774. dataIndex: 'stg_use',
  1775. align: 'center',
  1776. headerCheckable: false,
  1777. width: 45,
  1778. sortable: false
  1779. },{
  1780. text: '宽度',
  1781. xtype: 'numbercolumn',
  1782. dataIndex: 'stg_width',
  1783. align: 'center',
  1784. width: 50,
  1785. format: '0,00',
  1786. editor: {
  1787. xtype: 'numberfield',
  1788. hideTrigger: true
  1789. },
  1790. sortable: false
  1791. },{
  1792. text: '格式转换',
  1793. dataIndex: 'stg_format',
  1794. align: 'center',
  1795. width: 90,
  1796. editor: {
  1797. xtype: 'combo',
  1798. store: formatStore,
  1799. displayField: 'display',
  1800. valueField: 'value',
  1801. queryMode: 'local'
  1802. },
  1803. sortable: false
  1804. }],
  1805. sortable: false
  1806. },{
  1807. text: '查询',
  1808. columns: [{
  1809. text: '用于<br>查询',
  1810. xtype: 'checkcolumn',
  1811. dataIndex: 'stg_query',
  1812. align: 'center',
  1813. width: 45,
  1814. sortable: false
  1815. },{
  1816. text: '多输<br>入框',
  1817. dataIndex: 'stg_double',
  1818. xtype: 'checkcolumn',
  1819. align: 'center',
  1820. width: 45,
  1821. sortable: false
  1822. },{
  1823. text: '带放<br>大镜',
  1824. dataIndex: 'stg_dbfind',
  1825. xtype: 'checkcolumn',
  1826. align: 'center',
  1827. width: 45,
  1828. sortable: false
  1829. },{
  1830. text: '默认值',
  1831. dataIndex: 'stg_value',
  1832. align: 'center',
  1833. flex: 1,
  1834. sortable: false,
  1835. editor: {
  1836. xtype: 'textfield'
  1837. }
  1838. }],
  1839. sortable: false
  1840. },{
  1841. text: '锁列',
  1842. dataIndex: 'stg_lock',
  1843. xtype: 'checkcolumn',
  1844. width: 40,
  1845. sortable: false
  1846. },{
  1847. text: '分组',
  1848. dataIndex: 'stg_group',
  1849. xtype: 'checkcolumn',
  1850. singleChecked: true,
  1851. width: 40,
  1852. sortable: false
  1853. },{
  1854. text: '合计',
  1855. dataIndex: 'stg_sum',
  1856. xtype: 'checkcolumn',
  1857. width: 40,
  1858. sortable: false
  1859. }]
  1860. });
  1861. },
  1862. getLimitForm: function(combo) {
  1863. return Ext.create('Ext.form.Panel', {
  1864. title: '选择字段,建立约束关系',
  1865. bodyStyle : 'background:#f1f2f5;padding:5px 5px 0',
  1866. items: [{
  1867. xtype:'fieldset',
  1868. title: '客户分配',
  1869. padding: '0 5 10 10',
  1870. name: '_L',
  1871. checkboxToggle: true,
  1872. collapsible: true,
  1873. collapsed: true,
  1874. defaultType: 'combobox',
  1875. defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
  1876. layout: 'column',
  1877. items :[Ext.Object.merge({
  1878. fieldLabel: '客户编号',
  1879. name: '_L_CU_1'
  1880. }, combo), {
  1881. xtype: 'displayfield',
  1882. value: '调取分配给你的客户的所有数据'
  1883. }, Ext.Object.merge({
  1884. fieldLabel: '业务员编号',
  1885. name: '_L_CU_2'
  1886. }, combo), {
  1887. xtype: 'displayfield',
  1888. value: '调取业务员是你的所有数据'
  1889. }],
  1890. getValue: function() {
  1891. var a = this.down('combo[name=_L_CU_1]').getValue(),
  1892. b = this.down('combo[name=_L_CU_2]').getValue();
  1893. return a ? 'CU(' + a + (b ? (',' + b) : '') + ')' : null;
  1894. }
  1895. }, {
  1896. xtype:'fieldset',
  1897. title: '供应商分配',
  1898. padding: '0 5 10 10',
  1899. name: '_L',
  1900. checkboxToggle: true,
  1901. collapsible: true,
  1902. collapsed: true,
  1903. defaultType: 'combobox',
  1904. defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
  1905. layout: 'column',
  1906. items :[Ext.Object.merge({
  1907. fieldLabel: '供应商编号',
  1908. name: '_L_VE_1'
  1909. }, combo), {
  1910. xtype: 'displayfield',
  1911. value: '调取分配给你的供应商的所有数据'
  1912. }, Ext.Object.merge({
  1913. fieldLabel: '采购员编号',
  1914. name: '_L_VE_2'
  1915. }, combo), {
  1916. xtype: 'displayfield',
  1917. value: '调取采购员是你的所有数据'
  1918. }],
  1919. getValue: function() {
  1920. var a = this.down('combo[name=_L_VE_1]').getValue(),
  1921. b = this.down('combo[name=_L_VE_2]').getValue();
  1922. return a && b ? 'VE(' + a + (b ? (',' + b) : '') + ')' : null;
  1923. }
  1924. }, {
  1925. xtype:'fieldset',
  1926. title: '个人',
  1927. padding: '0 5 10 10',
  1928. name: '_L',
  1929. checkboxToggle: true,
  1930. collapsible: true,
  1931. collapsed: true,
  1932. defaultType: 'combobox',
  1933. defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
  1934. layout: 'column',
  1935. items :[Ext.Object.merge({
  1936. fieldLabel: '个人编号',
  1937. name: '_L_EM_1'
  1938. }, combo)],
  1939. getValue: function() {
  1940. var a = this.down('combo[name=_L_EM_1]').getValue();
  1941. return a ? 'EM(' + a + ')' : null;
  1942. }
  1943. }]
  1944. });
  1945. },
  1946. /**
  1947. * 权限约束设置
  1948. */
  1949. onLimitClick: function(source, oldLimits, callback) {
  1950. var me = this, win = me.limitwin, datas = [{display: '(无)', value: null}];
  1951. source.each(function(item){
  1952. if(item.get('stg_type').indexOf('VARCHAR2') == 0) {
  1953. datas.push({
  1954. display: item.get('stg_text'),
  1955. value: item.get('stg_table') + '.' + item.get('stg_field')
  1956. });
  1957. }
  1958. });
  1959. var combo = me.newComboConfig(datas);
  1960. if (!win) {
  1961. win = me.limitwin = Ext.create('Ext.window.Window', {
  1962. title : '权限约束设置',
  1963. closeAction : 'hide',
  1964. width : 500,
  1965. items : [me.getLimitForm(combo)],
  1966. buttonAlign : 'center',
  1967. buttons : [{
  1968. text : $I18N.common.button.erpConfirmButton,
  1969. height : 26,
  1970. handler : function(b) {
  1971. var w = b.ownerCt.ownerCt,
  1972. fs = w.down('form').down('fieldset[collapsed=false]'),
  1973. value = fs ? fs.getValue() : null;
  1974. callback && callback.call(me, value);
  1975. w.hide();
  1976. }
  1977. }, {
  1978. text : $I18N.common.button.erpCloseButton,
  1979. height : 26,
  1980. handler : function(b) {
  1981. b.ownerCt.ownerCt.hide();
  1982. }
  1983. }]
  1984. });
  1985. } else {
  1986. var coms = win.down('form').query('combobox');
  1987. Ext.Array.each(coms, function(com){
  1988. com.getStore().loadData(datas);
  1989. });
  1990. }
  1991. win.show();
  1992. var form = win.down('form');
  1993. if(oldLimits) {
  1994. if(oldLimits.indexOf('CU') == 0) {// 客户分配
  1995. var col1 = null, col2 = null;
  1996. if(oldLimits.indexOf(",") > -1) {
  1997. col1 = oldLimits.substring(3, oldLimits.indexOf(','));
  1998. col2 = oldLimits.substring(oldLimits.indexOf(',') + 1, oldLimits.lastIndexOf(')'));
  1999. } else {
  2000. col1 = oldLimits.substring(3, oldLimits.indexOf(')'));
  2001. }
  2002. form.down('combobox[name=_L_CU_1]').setValue(col1);
  2003. form.down('combobox[name=_L_CU_2]').setValue(col2);
  2004. form.down('combobox[name=_L_CU_1]').ownerCt.setExpanded(true);
  2005. } else if(oldLimits.indexOf('VE') == 0) {// 供应商分配
  2006. var col1 = null, col2 = null;
  2007. if(oldLimits.indexOf(",") > -1) {
  2008. col1 = oldLimits.substring(3, oldLimits.indexOf(','));
  2009. col2 = oldLimits.substring(oldLimits.indexOf(',') + 1, oldLimits.lastIndexOf(')'));
  2010. } else {
  2011. col1 = oldLimits.substring(3, oldLimits.indexOf(')'));
  2012. }
  2013. form.down('combobox[name=_L_VE_1]').setValue(col1);
  2014. form.down('combobox[name=_L_VE_2]').setValue(col2);
  2015. form.down('combobox[name=_L_VE_1]').ownerCt.setExpanded(true);
  2016. } else if(oldLimits.indexOf('EM') == 0) {// 个人
  2017. var col1 = oldLimits.substring(3, oldLimits.lastIndexOf(')'));
  2018. form.down('combobox[name=_L_EM_1]').setValue(col1);
  2019. form.down('combobox[name=_L_EM_1]').ownerCt.setExpanded(true);
  2020. }
  2021. } else {
  2022. var fs = form.down('fieldset[collapsed=false]');
  2023. fs && fs.setExpanded(false);
  2024. }
  2025. },
  2026. /**
  2027. * 公式设置用到的函数
  2028. */
  2029. formula: function() {
  2030. var me = this;
  2031. me.formula_operator = [];
  2032. return {
  2033. log: function(oper, text, data, isfn) {
  2034. me.formula_operator.push({oper: oper, text: text, data: data, isfn: isfn});
  2035. },
  2036. getContainer: function(scope) {
  2037. return scope.up('form').down('fieldcontainer[cls~=x-screen]');
  2038. },
  2039. add: function(scope, parentScope) {
  2040. var f = this.getContainer(parentScope || scope);
  2041. f.add({text: scope.text, data: scope.data, isfn: scope.isfn});
  2042. if(scope.isfn) {
  2043. f.add({text: '('});
  2044. this.log(1, scope.text, null, true);
  2045. this.log(2, '(');
  2046. } else {
  2047. this.log(1, scope.text, scope.data);
  2048. }
  2049. },
  2050. del: function(scope) {
  2051. var f = this.getContainer(scope), l = f.down('button:last');
  2052. if (l) {
  2053. f.remove(l);
  2054. this.log(0, l.text, l.data, l.isfn);
  2055. }
  2056. },
  2057. back: function(scope) {
  2058. var f = this.getContainer(scope), len = me.formula_operator.length;
  2059. if(len > 0) {
  2060. var i = len - 1, o = me.formula_operator[i], oper = o.oper;
  2061. switch(oper) {
  2062. case 0:
  2063. f.add({text: o.text, data: o.data, isfn: o.isfn});
  2064. break;
  2065. case 1:
  2066. var b = f.down('button:last');
  2067. if(b && b.text == o.text)
  2068. f.remove(b);
  2069. break;
  2070. case 2:
  2071. var b = f.down('button:last');
  2072. if(b && b.text == o.text) {
  2073. f.remove(b);
  2074. f.remove(f.down('button:last'));
  2075. }
  2076. break;
  2077. case 3:
  2078. var j = 0;
  2079. for(;i > 0;i-- ) {
  2080. if(me.formula_operator[i].oper == 3) {
  2081. j = i;
  2082. } else {
  2083. break;
  2084. }
  2085. }
  2086. for(;j < len;j++ ) {
  2087. o = me.formula_operator[j];
  2088. f.add({text: o.text, data: o.data, isfn: o.isfn});
  2089. }
  2090. i++;
  2091. break;
  2092. }
  2093. me.formula_operator.splice(i);
  2094. }
  2095. },
  2096. clear: function(scope) {
  2097. var m = this, f = m.getContainer(scope), btns = f.query('button');
  2098. f.removeAll();
  2099. Ext.Array.each(btns, function(b){
  2100. m.log(3, b.text, b.data, b.isfn);
  2101. });
  2102. },
  2103. reset: function(scope, source, oldData) {
  2104. var f = this.getContainer(scope);
  2105. if(me.formula_operator.length > 0) {
  2106. f.removeAll();
  2107. f.add(f.initItems);
  2108. }
  2109. me.formula_operator = [];
  2110. }
  2111. };
  2112. },
  2113. getFormulaForm: function(source, oldData) {
  2114. var defItems = [], defBtns = "789/%456*(123-)0.+=><≥≤≠".split(""),
  2115. colItems = [], me = this, formula = me.formula();
  2116. defItems.push({
  2117. text: '←',
  2118. tooltip: '删除',
  2119. handler: function(btn) {
  2120. formula.del(btn);
  2121. }
  2122. });
  2123. defItems.push({
  2124. text: '→',
  2125. tooltip: '回退',
  2126. handler: function(btn) {
  2127. formula.back(btn);
  2128. }
  2129. });
  2130. defItems.push({text: ','});
  2131. defItems.push({
  2132. text: 'RE',
  2133. tooltip: '重置',
  2134. handler: function(btn) {
  2135. formula.reset(btn);
  2136. }
  2137. });
  2138. defItems.push({
  2139. text: 'CE',
  2140. tooltip: '清除',
  2141. handler: function(btn) {
  2142. formula.clear(btn);
  2143. }
  2144. });
  2145. Ext.Array.each(defBtns, function(b){
  2146. var o = {text: b};
  2147. if(b == '0')
  2148. o.width = 88;
  2149. defItems.push(o);
  2150. });
  2151. defItems.push({text: 'nvl', isfn: true, tooltip: 'nvl(x,y),如果x不为空,返回x,否则返回y'});
  2152. defItems.push({text: 'round', isfn: true, tooltip: 'round(x,y),返回四舍五入到小数点右边y位的x值'});
  2153. defItems.push({text: 'floor', isfn: true, tooltip: 'floor(x),返回小于或等于x的最大整数'});
  2154. defItems.push({text: 'ceil', isfn: true, tooltip: 'ceil(x),返回大于或等于x的最小整数'});
  2155. defItems.push({text: 'abs', isfn: true, tooltip: 'abs(x),返回x的绝对值'});
  2156. defItems.push({text: 'nvl2', isfn: true, tooltip: 'nvl2(x,y,z),如果x不为空,返回y,否则返回z'});
  2157. defItems.push({text: 'trim', isfn: true, tooltip: 'trim(x),去除x前后空格'});
  2158. defItems.push({text: 'lpad', isfn: true, tooltip: 'lpad(x,y,z),如果x的长度小于y,左边填充z'});
  2159. defItems.push({text: 'rpad', isfn: true, tooltip: 'rpad(x,y,z),如果x的长度小于y,右边填充z'});
  2160. defItems.push({text: '‖', tooltip: '字符串连接符'});
  2161. defItems.push({text: 'sysdate', tooltip: 'sysdate,当前时间', width: 88});
  2162. defItems.push({text: 'to_char', isfn: true, tooltip: 'to_char(x,y),日期x按格式y转化成字符串', width: 88});
  2163. defItems.push({text: 'trunc', isfn: true, tooltip: 'trunc(x,y),日期截断。清除时分秒:trunc(sysdate);年初:trunc(sysdate,\'y\');月初:trunc(sysdate,\'mm\')'});
  2164. // case when
  2165. Ext.Array.each('case,when,then,else,end'.split(','), function(b){
  2166. var o = {text: b, tooltip: '判断语句case when..then..when..then..else..end'};
  2167. defItems.push(o);
  2168. });
  2169. defItems.push({
  2170. width: 229,
  2171. text: '添加自定义内容',
  2172. handler: function(btn) {
  2173. me.onUserDefinedClick(function(text){
  2174. formula.add({text: "'" + text + "'"}, btn);// 当字符串处理
  2175. });
  2176. }
  2177. });
  2178. source.each(function(item){
  2179. if(/(NUMBER|FLOAT|INT|DATE|TIMESTAMP)(\(\d+\)){0,1}/.test(item.get('stg_type')) && item.get('stg_table')) {
  2180. colItems.push({
  2181. text: item.get('stg_text'),
  2182. data: item.data
  2183. });
  2184. }
  2185. });
  2186. var form = Ext.create('Ext.form.Panel', {
  2187. bodyStyle : 'background:#f1f2f5;padding:5px',
  2188. layout: 'vbox',
  2189. minHeight : 490,
  2190. items: [{
  2191. xtype: 'fieldcontainer',
  2192. margin: '0 3 8 3',
  2193. width: '100%',
  2194. minHeight: 50,
  2195. cls: 'x-form-text x-screen',
  2196. defaultType: 'button',
  2197. defaults: {
  2198. margin: '0 0 3 0',
  2199. cls: 'x-btn-clear'
  2200. }
  2201. },{
  2202. xtype: 'container',
  2203. layout: 'hbox',
  2204. width: '100%',
  2205. defaultType: 'fieldcontainer',
  2206. defaults: {flex: 1},
  2207. items: [{
  2208. defaultType: 'button',
  2209. defaults: {
  2210. width: 41,
  2211. height: 30,
  2212. margin: '3 3 3 3'
  2213. },
  2214. items: defItems
  2215. },{
  2216. layout: 'column',
  2217. defaultType: 'button',
  2218. defaults: {
  2219. columnWidth: .5,
  2220. height: 30,
  2221. margin: '3 3 3 3'
  2222. },
  2223. items: colItems
  2224. }]
  2225. }]
  2226. });
  2227. var btns = form.query('button');
  2228. Ext.Array.each(btns, function(btn){
  2229. if(!btn.handler) {
  2230. btn.handler = function() {
  2231. formula.add(btn);
  2232. };
  2233. }
  2234. });
  2235. if(oldData) {
  2236. var container = form.down('fieldcontainer[cls~=x-screen]'),
  2237. items = me.getItemsFromFormula(source, oldData);
  2238. container.initItems = items;
  2239. container.add(items);
  2240. }
  2241. return form;
  2242. },
  2243. /**
  2244. * 解析表达式
  2245. */
  2246. getItemsFromFormula: function(source, oldData) {
  2247. var sign = /[\+\-\*=\/%,\(\)\s]/, units = oldData._split(sign), items = [],
  2248. fns = ['abs', 'ceil', 'floor', 'round', 'nvl', 'nvl2', 'lpad', 'rpad', 'trim', 'trunc', 'to_char'],
  2249. cw = ['case', 'when', 'then', 'else', 'end', 'sysdate', '||'];
  2250. Ext.Array.each(units, function(unit){
  2251. if(isNumber(unit)) {
  2252. Ext.Array.each(unit.split(""), function(u){
  2253. items.push({text: u});
  2254. });
  2255. } else if(fns.indexOf(unit) > -1){
  2256. items.push({
  2257. text: unit,
  2258. isfn: true
  2259. });
  2260. } else if(sign.test(unit) || cw.indexOf(unit) > -1) {
  2261. if(unit != ' ')
  2262. items.push({text: unit});
  2263. } else {
  2264. var table = null, field = unit, type = null;
  2265. if(unit.indexOf('.') > 0) {
  2266. table = unit.substring(0, unit.indexOf('.'));
  2267. field = unit.substr(unit.indexOf('.')+1);
  2268. }
  2269. var res = source.queryBy(function(record){
  2270. return record.get('stg_table') == table && record.get('stg_field') == field;
  2271. }), item = res.first();
  2272. if (item) {
  2273. unit = item.get('stg_text');
  2274. type = item.get('stg_type');
  2275. }
  2276. items.push({
  2277. text: unit,
  2278. data: {stg_table: table, stg_field: field, stg_type: type}
  2279. });
  2280. }
  2281. });
  2282. return items;
  2283. },
  2284. onUserDefinedClick: function(callback) {
  2285. var me = this;
  2286. var win = Ext.create('Ext.window.Window', {
  2287. title : '自定义内容',
  2288. closeAction: 'destroy',
  2289. width : 300,
  2290. items : [{
  2291. xtype : 'textfield',
  2292. emptyText : '输入除单引号外任意字符',
  2293. width: '100%'
  2294. }],
  2295. buttons : [{
  2296. text : $I18N.common.button.erpConfirmButton,
  2297. height : 26,
  2298. handler : function(b) {
  2299. var w = b.ownerCt.ownerCt, f = w.down('textfield'), v = f.getValue();
  2300. v && (callback.call(me, v));
  2301. w.close();
  2302. }
  2303. }, {
  2304. text : $I18N.common.button.erpCloseButton,
  2305. height : 26,
  2306. handler : function(b) {
  2307. var w = b.ownerCt.ownerCt;
  2308. w.close();
  2309. }
  2310. }]
  2311. });
  2312. win.show();
  2313. },
  2314. /**
  2315. * 自定义公式
  2316. */
  2317. onFormulaClick: function(source, oldData, callback) {
  2318. var me = this;
  2319. var win = Ext.create('Ext.window.Window', {
  2320. title : '自定义公式',
  2321. closeAction: 'destroy',
  2322. width : 540,
  2323. items : [me.getFormulaForm(source, oldData)],
  2324. buttonAlign : 'center',
  2325. buttons : [{
  2326. text : $I18N.common.button.erpConfirmButton,
  2327. height : 26,
  2328. handler : function(b) {
  2329. var w = b.ownerCt.ownerCt,
  2330. items = w.query('fieldcontainer[cls~=x-screen] > button'),
  2331. text = '', test = '', c, h;
  2332. Ext.Array.each(items, function(item){
  2333. if(item.data) {
  2334. text += item.data.stg_table + '.' + item.data.stg_field;
  2335. var type = me.getTypeByStg(item.data.stg_type);
  2336. // 生成随机测试数据
  2337. if("datecolumn" == type) {
  2338. test += 'randomDate()';
  2339. } else if("numbercolumn" == type) {
  2340. test += 'randomNum()';
  2341. } else {
  2342. test += 'randomStr()';
  2343. }
  2344. } else {
  2345. if(item.text == 'sysdate'){
  2346. text += 'sysdate';
  2347. test += 'new Date()';
  2348. } else if(item.text == 'case'){
  2349. c = true;
  2350. text += item.text + ' ';
  2351. } else if(item.text == 'when') {
  2352. h = true;
  2353. if(c) {
  2354. c = false;
  2355. test += 'if(';
  2356. } else
  2357. test += '}else if(';
  2358. text += ' ' + item.text + ' ';
  2359. } else if(item.text == 'then') {
  2360. h = false;
  2361. test += '){';
  2362. text += ' ' + item.text + ' ';
  2363. } else if(item.text == 'else') {
  2364. test += '}else{';
  2365. text += ' ' + item.text + ' ';
  2366. } else if(item.text == '>') {
  2367. test += '>';
  2368. text += ' > ';
  2369. } else if(item.text == '<') {
  2370. test += '<';
  2371. text += ' < ';
  2372. } else if(item.text == '≥') {
  2373. test += '>=';
  2374. text += ' >= ';
  2375. } else if(item.text == '≤') {
  2376. test += '<=';
  2377. text += ' <= ';
  2378. } else if(item.text == '≠') {
  2379. test += '!=';
  2380. text += ' <> ';
  2381. } else if(item.text == '‖') {
  2382. test += '+';
  2383. text += ' || ';
  2384. } else if(item.text == 'end') {
  2385. test += '}';
  2386. text += ' ' + item.text + ' ';
  2387. } else {
  2388. if(h && item.text == '=') {
  2389. test += '==';
  2390. } else
  2391. test += item.text;
  2392. text += item.text;
  2393. }
  2394. }
  2395. });
  2396. try {
  2397. Ext.eval(test);
  2398. callback && callback.call(me, text);
  2399. w.close();
  2400. } catch(e) {
  2401. Ext.example.msg('error', '错误', '您的公式有误,请检查并修改正确' +
  2402. '<p><strong>' +e + '</strong></p>', 5000);
  2403. }
  2404. }
  2405. }, {
  2406. text : $I18N.common.button.erpCloseButton,
  2407. height : 26,
  2408. handler : function(b) {
  2409. var w = b.ownerCt.ownerCt;
  2410. w.close();
  2411. }
  2412. }]
  2413. });
  2414. win.show();
  2415. },
  2416. /**
  2417. * 生成form的字段<br>
  2418. * 勾选、单选框
  2419. */
  2420. createFormItems: function(source, oldData) {
  2421. var fields = [];
  2422. if(source) {
  2423. if(Ext.isArray(source)) {
  2424. Ext.Array.each(source, function(i){
  2425. if(i.stg_use == 1) {
  2426. var obj = {boxLabel : i.stg_text, inputValue : i.stg_field, table: i.stg_table, alias: i.stg_alias};
  2427. if(oldData && Ext.Array.indexOf(oldData, i.stg_field) > -1)
  2428. obj.checked = true;
  2429. fields.push(obj);
  2430. }
  2431. });
  2432. } else {
  2433. source.each(function(i){
  2434. if(i.get('stg_use') == 1) {
  2435. var obj = {boxLabel : i.get('stg_text'), inputValue : i.get('stg_field'), table: i.get('stg_table'), alias: i.get('stg_alias')};
  2436. if(oldData && Ext.Array.indexOf(oldData, i.get('stg_field')) > -1)
  2437. obj.checked = true;
  2438. fields.push(obj);
  2439. }
  2440. });
  2441. }
  2442. } else {
  2443. var grid = this.getGrid().getView().normalGrid, columns = grid.headerCt.getGridColumns();
  2444. Ext.each(columns, function(){
  2445. if(!this.hidden && this.getWidth() > 0 && this.dataIndex) {
  2446. var obj = {boxLabel : this.text, inputValue : this.dataField, table: this.dataTable, alias: this.dataIndex};
  2447. if(oldData && Ext.Array.indexOf(oldData, this.dataIndex) > -1)
  2448. obj.checked = true;
  2449. fields.push(obj);
  2450. }
  2451. });
  2452. }
  2453. return fields;
  2454. },
  2455. /**
  2456. * 生成form的字段<br>
  2457. * 勾选、单选框<br>使用别名
  2458. */
  2459. createAliaItems: function(oldData) {
  2460. var fields = [];
  2461. var grid = this.getGrid().getView().normalGrid, columns = grid.headerCt.getGridColumns();
  2462. Ext.each(columns, function(){
  2463. if(!this.hidden && this.getWidth() > 0 && this.dataIndex) {
  2464. var obj = {boxLabel : this.text, inputValue : this.dataIndex};
  2465. if(oldData && Ext.Array.indexOf(oldData, this.dataIndex) > -1)
  2466. obj.checked = true;
  2467. fields.push(obj);
  2468. }
  2469. });
  2470. return fields;
  2471. },
  2472. /**
  2473. *
  2474. */
  2475. getAliaForm : function(type, itemId, oldData) {
  2476. var me = this;
  2477. return Ext.create('Ext.form.Panel', {
  2478. itemId : itemId,
  2479. autoScroll : true,
  2480. layout : 'column',
  2481. bodyStyle : 'background:#f1f2f5;',
  2482. defaults : {
  2483. xtype : type || 'radio',
  2484. name : 'gridfield',
  2485. columnWidth : .33,
  2486. margin : '3 3 3 10'
  2487. },
  2488. items : me.createAliaItems(oldData)
  2489. });
  2490. },
  2491. getGridForm : function(type, itemId, source, oldData) {
  2492. var me = this;
  2493. return Ext.create('Ext.form.Panel', {
  2494. itemId : itemId,
  2495. autoScroll : true,
  2496. layout : 'column',
  2497. bodyStyle : 'background:#f1f2f5;',
  2498. defaults : {
  2499. xtype : type || 'radio',
  2500. name : 'gridfield',
  2501. columnWidth : .33,
  2502. margin : '3 3 3 10'
  2503. },
  2504. items : me.createFormItems(source, oldData)
  2505. });
  2506. },
  2507. toogleGroup : function(f, b) {
  2508. if (!f) return;
  2509. var dx = null;
  2510. if (typeof f === 'string') {
  2511. dx = f;
  2512. } else {
  2513. var r = f.down('radio[value=true]');
  2514. if (r) {
  2515. dx = r.inputValue;
  2516. }
  2517. }
  2518. if (dx) {
  2519. var grid = this.getGrid(), c = grid.down('gridcolumn[dataIndex=' + dx + ']');
  2520. if(b) {
  2521. if(grid.store.groupField) {
  2522. var m = grid.down('gridcolumn[dataIndex=' + grid.store.groupField + ']');
  2523. if(m) {
  2524. m.summaryType = m.lastSummaryType;
  2525. m.summaryRenderer = m.lastSummaryRenderer;
  2526. }
  2527. }
  2528. if(typeof c.lastSummaryType === 'undefined') {
  2529. c.lastSummaryType = c.summaryType;
  2530. }
  2531. if(typeof c.lastSummaryRenderer === 'undefined') {
  2532. c.lastSummaryRenderer = c.summaryRenderer;
  2533. }
  2534. c.summaryType = 'count';
  2535. c.summaryRenderer = function(v) {
  2536. return '共(' + v + ')条';
  2537. };
  2538. grid.store.groupField = dx;
  2539. grid.store.group(dx, 'ASC');
  2540. // 先筛选数据,再选择分组字段时,不出现分组合计行的问题
  2541. if (grid.store.getTotalCount() > 0) {
  2542. var grouper = grid.view.normalView.getFeature('group');
  2543. grouper.enable();
  2544. }
  2545. } else {
  2546. c.summaryType = c.lastSummaryType;
  2547. c.summaryRenderer = c.lastSummaryRenderer;
  2548. var view = grid.lockedGrid.getView(), fe = view.getFeature('group');
  2549. if(fe) {
  2550. fe.disable();
  2551. view.refresh();
  2552. }
  2553. view = grid.normalGrid.getView(), fe = view.getFeature('group');
  2554. if(fe) {
  2555. fe.disable();
  2556. view.refresh();
  2557. }
  2558. var r = f.down('radio[value=true]');
  2559. if (r) {
  2560. r.setValue(false);
  2561. }
  2562. grid.store.groupField = null;
  2563. }
  2564. }
  2565. },
  2566. /**
  2567. * 锁定列
  2568. */
  2569. onLock : function(form) {
  2570. var r = form.query('checkbox[value=true]'),
  2571. checked = Ext.Array.pluck(r, 'inputValue');
  2572. var grid = this.getGrid(), locked = grid.getView().lockedGrid,
  2573. normal = grid.getView().normalGrid;
  2574. var lockedCols = locked.headerCt.getGridColumns();
  2575. Ext.Array.each(lockedCols, function(column){
  2576. if(!Ext.Array.contains(checked, column.dataIndex)) {
  2577. grid.unlock(column);
  2578. }
  2579. });
  2580. Ext.Array.each(r, function(){
  2581. var column = normal.down('gridcolumn[dataIndex=' + this.inputValue + ']');
  2582. if(column && !column.locked) {
  2583. grid.lock(column);
  2584. }
  2585. });
  2586. },
  2587. /**
  2588. * 取出排序设置
  2589. */
  2590. getSortProperties : function(form, store) {
  2591. var r = form.query('checkbox[value=true]'), prop = [];
  2592. Ext.Array.each(r, function(c, i){
  2593. var obj = {
  2594. property: c.inputValue,
  2595. direction: 'ASC',
  2596. description: c.boxLabel,
  2597. alias: c.alias,
  2598. number: i + 1,
  2599. table: c.table
  2600. };
  2601. if (store) {
  2602. var item = store.findRecord('property', c.inputValue);
  2603. if (item) {
  2604. obj.direction = item.get('direction');
  2605. }
  2606. }
  2607. prop.push(obj);
  2608. });
  2609. return prop;
  2610. },
  2611. /**
  2612. * 后台排序
  2613. */
  2614. onSort : function(sorts) {
  2615. // var grid = this.getGrid().getView().normalGrid;
  2616. // grid.store.sort(this.getSortProperties(form));
  2617. },
  2618. /**
  2619. * 清除排序、分组等
  2620. */
  2621. onClear : function() {
  2622. var grid = this.getGrid().getView().normalGrid;
  2623. grid.store.clearGrouping();
  2624. grid.store.clearFilter();
  2625. },
  2626. onTempLoad : function(fn) {
  2627. Ext.Ajax.request({
  2628. url: basePath + 'ma/search/temp/g.action',
  2629. params: {
  2630. caller: caller
  2631. },
  2632. callback: function(opt, s, res) {
  2633. var r = Ext.decode(res.responseText);
  2634. if(r.success && r.data) {
  2635. fn.call(null, r.data, r.lastId);
  2636. } else if(r.exceptionInfo) {
  2637. Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
  2638. }
  2639. }
  2640. });
  2641. },
  2642. duplicateTemp:function(data){
  2643. var me = this;
  2644. var w=Ext.getCmp('duplicateTemp');
  2645. if(w)w.data=data;
  2646. else{
  2647. w = Ext.create('Ext.window.Window', {
  2648. width: 300,
  2649. height: 97,
  2650. data:data,
  2651. title: '请输入导航栏CALLER',
  2652. id:'duplicateTemp',
  2653. layout: 'anchor',
  2654. items: [{
  2655. xtype: 'textfield',
  2656. allowBlank: false,
  2657. anchor: '100% 100%',
  2658. value:'New'+caller
  2659. }],
  2660. buttonAlign: 'center',
  2661. closeAction:'hide',
  2662. buttons: [{
  2663. text : $I18N.common.button.erpConfirmButton,
  2664. height : 26,
  2665. handler : function(b) {
  2666. var w = b.ownerCt.ownerCt, f = w.down('textfield');
  2667. if(!Ext.isEmpty(f.getValue())) {
  2668. me.checkCaller(f.getValue(),w.data);
  2669. }
  2670. w.close();
  2671. }
  2672. }, {
  2673. text : $I18N.common.button.erpCloseButton,
  2674. height : 26,
  2675. handler : function(b) {
  2676. b.ownerCt.ownerCt.hide();
  2677. }
  2678. }]
  2679. });}
  2680. w.show();
  2681. },
  2682. checkCaller:function(newCaller,data){
  2683. var me = this;
  2684. Ext.Ajax.request({
  2685. url: basePath + 'ma/search/temp/checkCaller.action',
  2686. params: {
  2687. caller: newCaller,
  2688. title: newCaller+data.st_title
  2689. },
  2690. callback: function(opt, s, res) {
  2691. var r = Ext.decode(res.responseText);
  2692. if(r.result) {
  2693. Ext.MessageBox.confirm('提示', r.result, function(but) {
  2694. if(but=='yes')me.onDuplicateTemp(newCaller,data);
  2695. });
  2696. } else if(r.exceptionInfo) {
  2697. Ext.example.msg('error', '提示', r.exceptionInfo, 5000);
  2698. }else me.onDuplicateTemp(newCaller,data);
  2699. }
  2700. });
  2701. },
  2702. onDuplicateTemp:function(newCaller,data){
  2703. var me = this;
  2704. Ext.Ajax.request({
  2705. url: basePath + 'ma/search/temp/duplTemp.action',
  2706. params: {
  2707. caller: newCaller,
  2708. sId: data.st_id,
  2709. title:newCaller+data.st_title
  2710. },
  2711. callback: function(opt, s, res) {
  2712. var r = Ext.decode(res.responseText);
  2713. if(r.success) {
  2714. Ext.example.msg('info', '提示', '复制方案到新导航栏成功', 2000);
  2715. } else if(r.exceptionInfo) {
  2716. Ext.example.msg('error', '提示', r.exceptionInfo, 5000);
  2717. }
  2718. }
  2719. });
  2720. },
  2721. addTemp : function(title, fn) {
  2722. var me = this;
  2723. var t = title || (me.BaseUtil.getActiveTab().title + '(' + em_name + ')' + Ext.Date.format(new Date(),'Y-m-d'));
  2724. var w = Ext.create('Ext.window.Window', {
  2725. width: 300,
  2726. height: 97,
  2727. title: '为方案命名',
  2728. layout: 'anchor',
  2729. items: [{
  2730. xtype: 'textfield',
  2731. allowBlank: false,
  2732. anchor: '100% 100%',
  2733. value: t
  2734. }],
  2735. buttonAlign: 'center',
  2736. buttons: [{
  2737. text : $I18N.common.button.erpConfirmButton,
  2738. height : 26,
  2739. handler : function(b) {
  2740. var w = b.ownerCt.ownerCt, f = w.down('textfield');
  2741. if(!Ext.isEmpty(f.getValue())) {
  2742. if(fn) {
  2743. fn.call(me, f.getValue());
  2744. } else {
  2745. var g = me.querywin.down('grid');
  2746. var r = g.store.add({st_id: 0, st_date: new Date().getTime(), st_man: em_name, st_title: f.getValue(), st_caller: caller});
  2747. if(r.length > 0) {
  2748. g.selModel.select(r[0]);
  2749. me.onTempSet(r[0], [], 0);
  2750. }
  2751. }
  2752. }
  2753. w.close();
  2754. }
  2755. }, {
  2756. text : $I18N.common.button.erpCloseButton,
  2757. height : 26,
  2758. handler : function(b) {
  2759. b.ownerCt.ownerCt.hide();
  2760. }
  2761. }]
  2762. });
  2763. w.show();
  2764. },
  2765. updateTemp : function(callback) {
  2766. var me = this, win = this.tempwin, g = win.down('#grid-setting'),
  2767. datas = new Array(), d, s = win.relativeId, i = 1,
  2768. c = g.down('#st_condition').getValue(),
  2769. sorts = g.sorts, limits = g.limits;
  2770. g.store.each(function(r){
  2771. d = r.data;
  2772. if(d.stg_use || d.stg_query || d.stg_group || d.stg_lock) {
  2773. d.stg_use = d.stg_use ? 1 : 0;
  2774. d.stg_query = d.stg_query ? 1 : 0;
  2775. d.stg_group = d.stg_group ? 1 : 0;
  2776. d.stg_lock = d.stg_lock ? 1 : 0;
  2777. d.stg_sum = d.stg_sum ? 1 : 0;
  2778. d.stg_double = d.stg_double ? 1 : 0;
  2779. d.stg_dbfind = d.stg_dbfind ? 1 : 0;
  2780. d.stg_stid = s;
  2781. d.stg_detno = i++;
  2782. delete d.text;
  2783. delete d.type;
  2784. delete d.links;
  2785. delete d.stg_alias;
  2786. if (d.modeItems) {
  2787. var validItems = [];
  2788. Ext.Array.each(d.modeItems, function(item, i){
  2789. if(item.display && item.display != '') {
  2790. item.num = validItems.length + 1;
  2791. item.st_id = s;
  2792. item.stg_field = d.stg_field;
  2793. item.value = (item.value == null || item.value == '') ?
  2794. item.display : item.value;
  2795. validItems.push(item);
  2796. }
  2797. });
  2798. d.modeItems = validItems;
  2799. }
  2800. datas.push(d);
  2801. }
  2802. });
  2803. var e = me.getRepeats(datas);
  2804. if(e) {
  2805. Ext.example.msg('error', '有重复选择的字段', e, 5000);
  2806. return;
  2807. }
  2808. if(s > 0) {
  2809. me.onTempUpdate(datas, c, sorts, limits, s, callback);
  2810. } else {
  2811. me.onTempSave(win.relativeRecord.get('st_title'), datas, c, sorts, limits, callback);
  2812. }
  2813. },
  2814. /**
  2815. * 判断是否有重复拖放过来的字段或重复的公式
  2816. */
  2817. getRepeats: function(datas) {
  2818. var p = {}, k = null, e = '';
  2819. Ext.Array.each(datas, function(d, i){
  2820. k = d.stg_table + '.' + d.stg_field;
  2821. if(d.stg_formula)
  2822. k = d.stg_formula;
  2823. if(p[k])
  2824. e += '行' + (i + 1) + '的' + d.stg_text;
  2825. else
  2826. p[k] = true;
  2827. });
  2828. if(e.length > 0)
  2829. return e;
  2830. return null;
  2831. },
  2832. copyTemp: function(title, sourceId) {
  2833. if(sourceId) {
  2834. this.onTempCopy(title, sourceId);
  2835. } else {
  2836. var me = this, win = this.tempwin, g = win.down('#grid-setting'),
  2837. datas = new Array(), d, i = 1,
  2838. c = g.down('#st_condition').getValue(), sorts = g.sorts, limits = g.limits;
  2839. g.store.each(function(r){
  2840. d = r.data;
  2841. if(d.stg_use || d.stg_query || d.stg_group || d.stg_lock) {
  2842. d.stg_use = d.stg_use ? 1 : 0;
  2843. d.stg_query = d.stg_query ? 1 : 0;
  2844. d.stg_group = d.stg_group ? 1 : 0;
  2845. d.stg_lock = d.stg_lock ? 1 : 0;
  2846. d.stg_sum = d.stg_sum ? 1 : 0;
  2847. d.stg_double = d.stg_double ? 1 : 0;
  2848. d.stg_dbfind = d.stg_dbfind ? 1 : 0;
  2849. d.stg_stid = 0;
  2850. d.stg_detno = i++;
  2851. delete d.text;
  2852. delete d.type;
  2853. delete d.links;
  2854. delete d.stg_alias;
  2855. if (d.modeItems) {
  2856. var validItems = [];
  2857. Ext.Array.each(d.modeItems, function(item, i){
  2858. if(item.display && item.display != '') {
  2859. item.num = validItems.length + 1;
  2860. item.stg_field = d.stg_field;
  2861. item.value = (item.value == null || item.value == '') ?
  2862. item.display : item.value;
  2863. validItems.push(item);
  2864. }
  2865. });
  2866. d.modeItems = validItems;
  2867. }
  2868. datas.push(d);
  2869. }
  2870. });
  2871. me.onTempSave(title, datas, c, sorts, limits);
  2872. }
  2873. },
  2874. onTempUpdate : function(datas, condition, sorts, limits, id, callback) {
  2875. var me = this;
  2876. Ext.Ajax.request({
  2877. url: basePath + 'ma/search/temp/u.action',
  2878. params: {
  2879. sId: id,
  2880. caller: caller,
  2881. datas: Ext.encode(datas),
  2882. condition: condition,
  2883. sorts: sorts,
  2884. limits: limits
  2885. },
  2886. callback: function(opt, s, res) {
  2887. var r = Ext.decode(res.responseText);
  2888. if(r.success) {
  2889. callback && callback.call(me);
  2890. Ext.example.msg('info', '提示', '方案修改成功', 2000);
  2891. me.onTempLoad(function(data){
  2892. var temp = me.querywin.down('gridpanel[id=temp]'),
  2893. grid = me.querywin.down('grid');
  2894. temp.store.loadData(data);
  2895. if(data.length > 0) {
  2896. var r = temp.store.findRecord('st_id', id) || temp.store.last();
  2897. temp.selModel.select(r);
  2898. grid.setTitle(r.get('st_title'));
  2899. }
  2900. });
  2901. } else if(r.exceptionInfo) {
  2902. Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
  2903. }
  2904. }
  2905. });
  2906. },
  2907. onTempSave : function(title, datas, condition, sorts, limits, callback) {
  2908. var me = this;
  2909. Ext.Ajax.request({
  2910. url: basePath + 'ma/search/temp/s.action',
  2911. params: {
  2912. caller: caller,
  2913. title: title,
  2914. datas: Ext.encode(datas),
  2915. condition: condition,
  2916. sorts: sorts,
  2917. limits: limits
  2918. },
  2919. callback: function(opt, s, res) {
  2920. var r = Ext.decode(res.responseText);
  2921. if(r.success) {
  2922. callback && callback.call(me);
  2923. Ext.example.msg('info', '提示', '方案保存成功', 2000);
  2924. me.onTempLoad(function(data){
  2925. var temp = me.querywin.down('gridpanel[id=temp]'),
  2926. grid = me.querywin.down('grid');
  2927. temp.store.loadData(data);
  2928. if(data.length > 0) {
  2929. var r = temp.store.last();
  2930. temp.selModel.select(r);
  2931. grid.setTitle(r.get('st_title'));
  2932. }
  2933. });
  2934. } else if(r.exceptionInfo) {
  2935. Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
  2936. }
  2937. }
  2938. });
  2939. },
  2940. onTempCopy : function(title, id) {
  2941. var me = this;
  2942. Ext.Ajax.request({
  2943. url: basePath + 'ma/search/temp/c.action',
  2944. params: {
  2945. title: title,
  2946. sId: id
  2947. },
  2948. callback: function(opt, s, res) {
  2949. var r = Ext.decode(res.responseText);
  2950. if(r.success) {
  2951. Ext.example.msg('info', '提示', '方案复制成功', 2000);
  2952. me.onTempLoad(function(data){
  2953. var temp = me.querywin.down('gridpanel[id=temp]'),
  2954. grid = me.querywin.down('grid');
  2955. temp.store.loadData(data);
  2956. if(data.length > 0) {
  2957. var r = temp.store.last();
  2958. temp.selModel.select(r);
  2959. grid.setTitle(r.get('st_title'));
  2960. }
  2961. });
  2962. } else if(r.exceptionInfo) {
  2963. Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
  2964. }
  2965. }
  2966. });
  2967. },
  2968. onTempTitleChange: function(title, id, callback) {
  2969. var me = this;
  2970. Ext.Ajax.request({
  2971. url: basePath + 'ma/search/temp/t.action',
  2972. params: {
  2973. title: title,
  2974. sId: id
  2975. },
  2976. callback: function(opt, s, res) {
  2977. var r = Ext.decode(res.responseText);
  2978. if(r.success) {
  2979. Ext.example.msg('info', '提示', '修改成功', 2000);
  2980. callback && callback.call(me);
  2981. } else if(r.exceptionInfo) {
  2982. Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
  2983. }
  2984. }
  2985. });
  2986. },
  2987. onTempDel : function(id, fn) {
  2988. if(id > 0) {
  2989. Ext.Ajax.request({
  2990. url: basePath + 'ma/search/temp/d.action',
  2991. params: {
  2992. caller: caller,
  2993. sId: id
  2994. },
  2995. callback: function(opt, s, res) {
  2996. var r = Ext.decode(res.responseText);
  2997. if(r.success) {
  2998. fn.call();
  2999. } else if(r.exceptionInfo) {
  3000. Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
  3001. }
  3002. }
  3003. });
  3004. } else {
  3005. fn.call();
  3006. }
  3007. },
  3008. /**
  3009. * 记录选择方案
  3010. */
  3011. log : function() {
  3012. var grid = this.querywin.down('grid'), record = grid.selModel.lastSelected;
  3013. if (record) {
  3014. var id = record.get('st_id');
  3015. if(id && id > 0 ) {
  3016. Ext.Ajax.request({
  3017. url: basePath + 'ma/search/log.action',
  3018. params: {
  3019. caller: caller,
  3020. sId: id
  3021. },
  3022. callback: function(opt, s, res) {
  3023. var r = Ext.decode(res.responseText);
  3024. if(r.exceptionInfo) {
  3025. Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
  3026. }
  3027. }
  3028. });
  3029. }
  3030. }
  3031. },
  3032. /**
  3033. * 数据字典
  3034. */
  3035. getDictionary: function(tableNames, callback) {
  3036. if(tableNames && tableNames != '') {
  3037. var me = this;
  3038. Ext.Ajax.request({
  3039. url: basePath + 'ma/getDataDictionaries.action',
  3040. params: {
  3041. tables: tableNames
  3042. },
  3043. callback: function(opt, s, res) {
  3044. var r = Ext.decode(res.responseText);
  3045. if(r.exceptionInfo) {
  3046. Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
  3047. } else if(r.datas) {
  3048. callback.call(me, r.datas);
  3049. }
  3050. }
  3051. });
  3052. } else {
  3053. callback.call(me, []);
  3054. }
  3055. },
  3056. /**
  3057. * 重新加载数据
  3058. */
  3059. loadNewStore : function(grid, params) {
  3060. var me = this;
  3061. grid.setLoading(true);
  3062. Ext.Ajax.request({
  3063. url : basePath + "common/search.action",
  3064. params: params,
  3065. timeout: 60000,
  3066. method : 'post',
  3067. callback : function(opt, s, res){
  3068. grid.setLoading(false);
  3069. grid.queryCondition=params.condition;
  3070. var r = Ext.decode(res.responseText);
  3071. if(r.datas) {
  3072. grid.store.totalCount = r.datas.length;
  3073. grid.store.loadData(r.datas);
  3074. me.getDataCount().update({count: r.datas.length});
  3075. me.getDataCount().show();
  3076. }
  3077. }
  3078. });
  3079. },
  3080. /**
  3081. * 导出excel
  3082. */
  3083. exportExcel : function(grid, records, condition) {
  3084. var columns = grid.headerCt.getGridColumns(),
  3085. cm = new Array(), gf = grid.store.groupField;
  3086. Ext.Array.each(columns, function(c){
  3087. if(!c.hidden && (c.width > 0 || c.flex > 0) && !c.isCheckerHd) {
  3088. cm.push({
  3089. text: (Ext.isEmpty(c.text) ? ' ' : c.text.replace(/<br>/g, '\n')),
  3090. dataIndex: c.dataIndex,
  3091. width: c.width,
  3092. xtype: c.xtype,
  3093. format: c.format,
  3094. locked: c.locked,
  3095. summary: c.summaryType == 'sum',
  3096. group: c.dataIndex == gf
  3097. });
  3098. }
  3099. });
  3100. if (!Ext.fly('ext-grid-excel')) {
  3101. var frm = document.createElement('form');
  3102. frm.id = 'ext-grid-excel';
  3103. frm.name = frm.id;
  3104. frm.className = 'x-hidden';
  3105. document.body.appendChild(frm);
  3106. }
  3107. var record = records[0];
  3108. Ext.Ajax.request({
  3109. url: basePath + 'common/search/excel.xls',
  3110. method: 'post',
  3111. form: Ext.fly('ext-grid-excel'),
  3112. isUpload: true,
  3113. params: {
  3114. sId: record.get('st_id'),
  3115. condition: condition,
  3116. columns: unescape(Ext.encode(cm).replace(/\\/g,"%")),
  3117. sorts: record.get('st_sorts'),
  3118. title: record.get('st_title') + '----' + Ext.Date.format(new Date(), 'Y-m-d H:i:s')
  3119. }
  3120. });
  3121. },
  3122. /**
  3123. * 传入表名,获得表的关联sql
  3124. */
  3125. getTabSql: function(tables, callback) {
  3126. var me = this;
  3127. Ext.Ajax.request({
  3128. url: basePath + 'ma/search/relation.action',
  3129. method : 'post',
  3130. params: {
  3131. tables: tables
  3132. },
  3133. callback : function(opt, s, res){
  3134. var r = Ext.decode(res.responseText);
  3135. if(r.data) {
  3136. callback && callback.call(me, r.data);
  3137. } else {
  3138. Ext.example.msg('error', '错误', '您选择的数据字典 ' + tables +
  3139. ' 暂时还没有建立关联关系', 5000);
  3140. }
  3141. }
  3142. });
  3143. },
  3144. /**
  3145. * 行点击链接,打开单据界面
  3146. */
  3147. onLinkClick: function(link, title, field) {
  3148. var args = encodeURI(Ext.Array.toArray(arguments, 3).join('-')).replace(/%/g,'-');
  3149. var tabPanel = this.getTabPanel(),
  3150. panel = tabPanel.down('#' + args);
  3151. link += '&_noc=1';// no control
  3152. // 出入库单据、工单、等按类型来获取caller,统一类型标志class
  3153. // 用于jsp页面一致,caller不同的
  3154. if(link.indexOf('class=') > -1) {
  3155. var cls = this.getUrlParam(link, 'class');
  3156. link += '&whoami=' + this.getCaller(cls, field);
  3157. // 无法直接配置,需要按类型来匹配具体链接的
  3158. if(link.indexOf('{url}') > -1) {
  3159. link = link.replace('{url}', this.getUrl(cls, field));
  3160. }
  3161. }
  3162. if (!panel) {
  3163. panel = tabPanel.add({
  3164. id : args,
  3165. title : title,
  3166. tag : 'iframe',
  3167. border : false,
  3168. layout : 'fit',
  3169. iconCls : 'x-tree-icon-tab-tab1',
  3170. html : '<iframe src="' + link + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  3171. closable : true
  3172. });
  3173. }
  3174. tabPanel.setActiveTab(panel);
  3175. },
  3176. /**
  3177. * 主界面的tabPanel
  3178. */
  3179. getTabPanel: function() {
  3180. var main = parent.Ext.getCmp("content-panel");
  3181. if (!main) {
  3182. main = parent.parent.Ext.getCmp("content-panel");
  3183. }
  3184. return main;
  3185. },
  3186. /**
  3187. * URL里面解析出参数值
  3188. */
  3189. getUrlParam: function(url, param) {
  3190. var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)"),
  3191. matchs = url.substr(url.indexOf('?') + 1).match(reg);
  3192. if (matchs)
  3193. return decodeURI(matchs[2]);
  3194. return null;
  3195. },
  3196. /**
  3197. * 按类型获取caller。用于出入库单等
  3198. */
  3199. getCaller: function(cls, field) {
  3200. var call = null;
  3201. switch (cls) {
  3202. case '采购验收单':
  3203. call = 'ProdInOut!PurcCheckin';
  3204. break;
  3205. case '采购验退单':
  3206. call = 'ProdInOut!PurcCheckout';
  3207. break;
  3208. case '出货单':
  3209. call = 'ProdInOut!Sale';
  3210. break;
  3211. case '拨入单':
  3212. call = 'ProdInOut!AppropriationIn';
  3213. break;
  3214. case '销售拨出单':
  3215. call = 'ProdInOut!SaleAppropriationOut';
  3216. break;
  3217. case '销售退货单':
  3218. call = 'ProdInOut!SaleReturn';
  3219. break;
  3220. case '拨出单':
  3221. call = 'ProdInOut!AppropriationOut';
  3222. break;
  3223. case '不良品入库单':
  3224. call = 'ProdInOut!DefectIn';
  3225. break;
  3226. case '不良品出库单':
  3227. call = 'ProdInOut!DefectOut';
  3228. break;
  3229. case '委外领料单':
  3230. call = 'ProdInOut!OutsidePicking';
  3231. break;
  3232. case '委外退料单':
  3233. call = 'ProdInOut!OutsideReturn';
  3234. break;
  3235. case '委外验收单':
  3236. call = 'ProdInOut!OutsideCheckIn';
  3237. break;
  3238. case '委外验退单':
  3239. call = 'ProdInOut!OutesideCheckReturn';
  3240. break;
  3241. case '借货归还单':
  3242. call = 'ProdInOut!OutReturn';
  3243. break;
  3244. case '研发采购验收单':
  3245. call = 'ProdInOut!PurcCheckin!PLM';
  3246. break;
  3247. case '研发采购验退单':
  3248. call = 'ProdInOut!PurcCheckout!PLM';
  3249. break;
  3250. case '换货入库单':
  3251. call = 'ProdInOut!ExchangeIn';
  3252. break;
  3253. case '换货出库单':
  3254. call = 'ProdInOut!ExchangeOut';
  3255. break;
  3256. case '生产补料单':
  3257. call = 'ProdInOut!Make!Give';
  3258. break;
  3259. case '完工入库单':
  3260. call = 'ProdInOut!Make!In';
  3261. break;
  3262. case '生产退料单':
  3263. call = 'ProdInOut!Make!Return';
  3264. break;
  3265. case '生产报废单':
  3266. call = 'ProdInOut!Make!Useless';
  3267. break;
  3268. case '无订单出货单':
  3269. call = 'ProdInOut!NoSale';
  3270. break;
  3271. case '委外补料单':
  3272. call = 'ProdInOut!OSMake!Give';
  3273. break;
  3274. case '其它入库单':
  3275. call = 'ProdInOut!OtherIn';
  3276. break;
  3277. case '其它出库单':
  3278. call = 'ProdInOut!OtherOut';
  3279. break;
  3280. case '其它采购入库单':
  3281. call = 'ProdInOut!OtherPurcIn';
  3282. break;
  3283. case '其它采购出库单':
  3284. call = 'ProdInOut!OtherPurcOut';
  3285. break;
  3286. case '拆件入库单':
  3287. call = 'ProdInOut!PartitionStockIn';
  3288. break;
  3289. case '生产领料单':
  3290. call = 'ProdInOut!Picking';
  3291. break;
  3292. case '库存初始化':
  3293. call = 'ProdInOut!ReserveInitialize';
  3294. break;
  3295. case '借货出货单':
  3296. call = 'ProdInOut!SaleBorrow';
  3297. break;
  3298. case '销售拨入单':
  3299. call = 'ProdInOut!SalePutIn';
  3300. break;
  3301. case '盘亏调整单':
  3302. call = 'ProdInOut!StockLoss';
  3303. break;
  3304. case '盘盈调整单':
  3305. call = 'ProdInOut!StockProfit';
  3306. break;
  3307. case '报废单':
  3308. call = 'ProdInOut!StockScrap';
  3309. break;
  3310. case '研发退料单':
  3311. call = 'ProdInOut!YFIN';
  3312. break;
  3313. case '研发领料单':
  3314. call = 'ProdInOut!YFOUT';
  3315. break;
  3316. case 'MAKE':
  3317. call = 'Make!Base';
  3318. break;
  3319. case 'OS':
  3320. call = 'Make';
  3321. break;
  3322. case '采购收料单':
  3323. call = 'VerifyApply';
  3324. break;
  3325. case '委外收料单':
  3326. call = 'VerifyApply!OS';
  3327. break;
  3328. case '采购入库申请单':
  3329. call = 'VerifyApply';
  3330. break;
  3331. case '委外入库申请单':
  3332. call = 'VerifyApply!OS';
  3333. break;
  3334. case '应收发票':
  3335. call = 'ARBill!IRMA';
  3336. break;
  3337. case '应收款转销':
  3338. call = field == 'AB_CODE' ? 'ARBill!IRMA' : 'RecBalance!ARRM';
  3339. break;
  3340. case '其它应收单':
  3341. call = 'ARBill!OTRS';
  3342. break;
  3343. case '收款单':
  3344. call = 'RecBalance!PBIL';
  3345. break;
  3346. case '冲应收款':
  3347. call = 'RecBalance!IMRE';
  3348. break;
  3349. case '应收冲应付':
  3350. call = field == 'RB_CODE' ? 'RecBalance!RRCW' : 'PayBalance';
  3351. break;
  3352. case '预收冲应收':
  3353. call = 'RecBalance!PTAR';
  3354. break;
  3355. case '应收退款单':
  3356. call = 'RecBalance!TK';
  3357. break;
  3358. case '预收款':
  3359. call = 'PreRec!Ars!DERE';
  3360. break;
  3361. case '预收退款':
  3362. call = 'PreRec!Ars!DEPR';
  3363. break;
  3364. case '应付发票':
  3365. call = 'APBill!CWIM';
  3366. break;
  3367. case '其它应付单':
  3368. call = 'APBill!OTDW';
  3369. break;
  3370. case '付款单':
  3371. call = 'PayBalance';
  3372. break;
  3373. case '应付款转销':
  3374. call = 'PayBalance!APRM';
  3375. break;
  3376. case '冲应付款':
  3377. call = 'PayBalance!CAID';
  3378. break;
  3379. case '预付冲应付':
  3380. call = 'PayBalance!Arp!PADW';
  3381. break;
  3382. case '应付退款单':
  3383. call = 'PayBalance!TK';
  3384. break;
  3385. case '预付款':
  3386. call = 'PrePay!Arp!PAMT';
  3387. break;
  3388. case '预付退款':
  3389. call = 'PrePay!Arp!PAPR';
  3390. break;
  3391. }
  3392. return call;
  3393. },
  3394. /**
  3395. * 存在同一table,同一链接不同caller情况;同一table,不同界面,不同caller的情况
  3396. * 直接按类型取链接
  3397. */
  3398. getUrl: function(cls, field) {
  3399. var url = null;
  3400. switch (cls) {
  3401. case '应收发票':
  3402. url = 'jsps/fa/ars/arbill.jsp';
  3403. break;
  3404. case '应收款转销':
  3405. url = field == 'AB_CODE' ? 'jsps/fa/ars/arbill.jsp' : 'jsps/fa/ars/recBalance.jsp';
  3406. break;
  3407. case '其它应收单':
  3408. url = 'jsps/fa/ars/arbill.jsp';
  3409. break;
  3410. case '收款单':
  3411. url = 'jsps/fa/ars/recBalance.jsp';
  3412. break;
  3413. case '冲应收款':
  3414. url = 'jsps/fa/ars/recBalance.jsp';
  3415. break;
  3416. case '应收冲应付':
  3417. url = field == 'RB_CODE' ? 'jsps/fa/ars/recBalanceAP.jsp' : 'jsps/fa/arp/paybalance.jsp';
  3418. break;
  3419. case '预收冲应收':
  3420. url = 'jsps/fa/ars/recBalancePRDetail.jsp';
  3421. break;
  3422. case '应收退款单':
  3423. url = 'jsps/fa/ars/recBalanceTK.jsp';
  3424. break;
  3425. case '预收款':
  3426. url = 'jsps/fa/ars/preRec.jsp';
  3427. break;
  3428. case '预收退款':
  3429. url = 'jsps/fa/ars/preRec.jsp';
  3430. break;
  3431. case '应付发票':
  3432. url = 'jsps/fa/ars/apbill.jsp';
  3433. break;
  3434. case '其它应付单':
  3435. url = 'jsps/fa/ars/apbill.jsp';
  3436. break;
  3437. case '付款单':
  3438. url = 'jsps/fa/arp/paybalance.jsp';
  3439. break;
  3440. case '应付款转销':
  3441. url = 'jsps/fa/arp/paybalance.jsp';
  3442. break;
  3443. case '冲应付款':
  3444. url = 'jsps/fa/arp/paybalance.jsp';
  3445. break;
  3446. case '预付冲应付':
  3447. url = 'jsps/fa/arp/payBalancePRDetail.jsp';
  3448. break;
  3449. case '应付退款单':
  3450. url = 'jsps/fa/arp/paybalanceTK.jsp';
  3451. break;
  3452. case '预付款':
  3453. url = 'jsps/fa/arp/prepay.jsp';
  3454. break;
  3455. case '预付退款':
  3456. url = 'jsps/fa/arp/prepay.jsp';
  3457. break;
  3458. }
  3459. return url;
  3460. }
  3461. });