Search.js 123 KB

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