123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.common.Template', {
- extend: 'Ext.app.Controller',
- requires: ['erp.util.BaseUtil','erp.util.GridUtil'],
- views: ['common.init.Template', 'core.button.UpExcel', 'core.trigger.DbfindTrigger', 'core.trigger.MultiDbfindTrigger',
- 'core.toolbar.Toolbar'],
- init: function(){
- var me = this;
- me.BaseUtil = Ext.create('erp.util.BaseUtil');
- me.GridUtil = Ext.create('erp.util.GridUtil');
- this.control({
- 'panel[id="tree"]': {
- afterrender: function(p){
- me.getParentNodes(p);
- }
- },
- 'form[id=upexcel]': {
- afterrender: function(btn){
- btn.upexcel = function(field){
- if(btn.grid){
- btn.getForm().submit({
- url: basePath + 'system/initImport.action?caller=' + btn.grid.caller,
- waitMsg: "正在解析Excel",
- success: function(fp, o){
- field.reset();
- btn.grid.ilid = o.result.ilid;
- btn.grid.down('pagingtoolbar').dataCount = o.result.count;
- btn.grid.down('pagingtoolbar').onLoad();
- btn.grid.getGridData(1);
- Ext.getCmp('check').show();
- },
- failure: function(fp, o){
- if(o.result.size){
- showError(o.result.error + " " + Ext.util.Format.fileSize(o.result.size));
- field.reset();
- } else {
- showError(o.result.error);
- field.reset();
- }
- }
- });
-
- }
- };
- }
- },
- 'button[id=export]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt.down('gridpanel');
- if(grid){
- window.location = basePath + 'system/initTemplate.xls?caller=' + grid.caller +
- '&title=' + (grid.ownerCt.title.replace(/»/g, '/'));
- }
- }
- },
- 'button[id=rule]': {
- click: function(btn){
- me.showRule(btn.ownerCt.ownerCt.down('gridpanel'));
- }
- },
- 'button[id=check]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt.down('gridpanel');
- if(grid){
- me.checkdata(grid);
- }
- }
- },
- 'button[id=history]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt.down('gridpanel');
- if(grid){
- me.showHistory(grid.caller);
- }
- }
- },
- 'checkbox[id=onlyerror]': {
- change: function(f){
- var grid = f.ownerCt.ownerCt.down('gridpanel');
- if(grid) {
- if(f.checked) {
- grid.store.filterBy(function(item) {
- return !Ext.isEmpty(item.get('log'));
- });
- } else {
- grid.store.filterBy(function(item) {
- return true;
- });
- }
- }
- }
- },
- 'button[id=toformal]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt.down('gridpanel');
- if(grid && grid.ilid > 0) {
- if(grid.errorNodes && grid.errorNodes.length > 0) {
- showMessage('提示', '测试未通过,无法转入正式');
- } else {
- me.toformal(grid);
- }
- }
- }
- },
- 'button[id=errdelete]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt.down('gridpanel');
- if(grid && grid.ilid > 0) {
- me.deleteErrors(grid);
- }
- }
- },
- 'button[id=saveupdates]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt.down('gridpanel');
- if(grid && grid.ilid > 0) {
- me.saveUpdates(grid);
- }
- }
- },
- 'button[id=errdownload]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt.down('gridpanel');
- if(grid && grid.ilid > 0) {
- window.location = basePath + 'system/initError.xls?caller=' + grid.caller +
- '&title=ERR_' + (grid.ownerCt.title.replace(/»/g, '/') + '&id=' + grid.ilid);
- }
- }
- }
- });
- },
- getParentNodes: function(p){
- var me = this;
- Ext.Ajax.request({// 拿到tree数据
- url : basePath + 'system/initTree.action',
- params: {
- pid: 0
- },
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.tree){
- Ext.each(res.tree, function(t){
- p.add({
- title: t.in_desc,
- autoScroll: true,
- caller: t.in_caller,
- id: t.in_id,
- listeners: {
- expand: function(n){
- if(n.items.items.length == 0){
- me.getTreeNode(n);
- }
- }
- }
- });
- });
- var n = p.items.items[0];
- if(n && n.items.items.length == 0) {
- me.getTreeNode(n);
- }
- } else if(res.exceptionInfo){
- showError(res.exceptionInfo);
- }
- }
- });
- },
- getTreeNode: function(node){
- var me = this;
- Ext.Ajax.request({// 拿到tree数据
- url : basePath + 'system/initTree.action',
- params: {
- pid: node.id
- },
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.tree){
- var tree = me.parseTree(res.tree);
- node.add({
- xtype: 'treepanel',
- height: '100%',
- rootVisible: false,
- containerScroll : true,
- autoScroll: false,
- store: Ext.create('Ext.data.TreeStore', {
- root: {
- text: 'root',
- id: 'root',
- expanded: true,
- children: tree
- }
- }),
- listeners: {
- itemmousedown: function(selModel, record){
- Ext.getCmp('template').setTitle(me.getPathString(selModel.ownerCt, record));
- me.getNode(record);
- }
- }
- });
- } else if(res.exceptionInfo){
- showError(res.exceptionInfo);
- }
- }
- });
- },
- parseTree: function(arr){
- var tree = new Array(),t;
- Ext.each(arr, function(r){
- t = new Object();
- t.id = r.in_id;
- t.text = r.in_desc;
- t.caller = r.in_caller;
- t.img = r.in_img;
- t.parentId = r.in_pid;
- t.leaf = r.in_leaf == 1;
- tree.push(t);
- });
- return tree;
- },
- getNode: function(record){
- var me = this,
- p = Ext.getCmp('template');
- me.getDetails(p, record.raw.caller, false);
- },
- getDetails: function(p, caller, isReload){
- if(caller != p.caller || isReload){
- p.caller = caller;
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'system/initDetails.action',
- params: {
- caller: caller
- },
- method: 'post',
- callback: function(options, success, response){
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo != null){
- Ext.getCmp('upexcel').hide();
- showError(res.exceptionInfo);return;
- } else {
- p.removeAll();
- var store = me.emptyData(res.data);
- p.add({
- xtype: 'grid',
- id: 'template-data',
- anchor: "100% 100%",
- cls: 'custom',
- caller: caller,
- ilid: -1,
- cfg: res.data,// 当前导入项的配置信息
- columnLines: true,
- columns: me.parseInitDetails(res.data),
- store: store,
- dockedItems: [me.getDockedItems(store)],
- getGridData: function(page){
- me.loadInitData(this, page);
- },
- loadData: function(ilid, count, page){
- this.ilid = ilid;
- this.down('pagingtoolbar').dataCount = count;
- this.down('pagingtoolbar').onLoad();
- this.getGridData(page);
- Ext.getCmp('errdownload').show();
- Ext.getCmp('onlyerror').show();
- Ext.getCmp('toformal').show();
- Ext.getCmp('errdelete').show();
- Ext.getCmp('saveupdates').show();
- Ext.getCmp('check').show();
- },
- deleteData: function(ilid){
- me.ondelete(ilid);
- },
- reset: function(){
- this.ilid = -1;
- this.down('pagingtoolbar').dataCount = 25;
- this.down('pagingtoolbar').onLoad();
- this.store.removeAll(true);
- this.store.loadData([{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]);
- },
- showErrors: function(){
- var grid = this,items = grid.store.data.items,
- columns = grid.columns,d,nodes = grid.errorNodes,log = '';
- if(nodes && nodes.length > 0) {
- Ext.each(items, function(item, index){
- d = item.data;
- log = '';
- Ext.each(columns, function(c, idx){
- if(idx > 0 && c.logic && c.renderer){
- if(Ext.Array.contains(nodes, d.id_id + ':' + c.dataIndex)) {
- if(log == '') {
- log = '<table border="1" class="custom-log">';
- log += '<tr class="custom-tr"><td>字段</td><td>值</td>' +
- '<td>规则</td><td>数据类型</td>' +
- '<td>是否必填</td>' +
- '<td>逻辑</td>' +
- '</tr>';
- }
- log += '<tr><td>' + c.text + '</td><td><font color=red>'
- + d[c.dataIndex] + '</td><td><font color=blue>'
- + (c.rule || '') + '</font></td><td><font color=blue>'
- + c.dataType + '</font></td><td><font color=blue>'
- + c.isNeed + '</font></td><td><font color=red>'
- + c.logicdesc +'</font></td></tr>';
- }
- }
- });
- if(log != '') {
- log += '</table>';
- }
- item.set('log', log);
- });
- }
- },
- plugins: [{
- ptype: 'rowexpander',
- rowBodyTpl : [
- '<p><b>校验状态:</b> {log}</p><br>'
- ]
- }, Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1
- })]
- });
- Ext.getCmp('upexcel').show();
- Ext.getCmp('upexcel').grid = p.down('gridpanel');
- }
- }
- });
- }
- },
- parseInitDetails: function(arr){
- var me = this, d = new Array(),o;
- d.push({xtype: 'rownumberer', width: 35});
- d.push({
- text: '导入日志',
- dataIndex: 'log',
- hidden: true,
- renderer: function(val, meta){
- meta.style = 'height:0px;';
- }
- });
- d.push({
- text: 'ID',
- dataIndex: 'id_id',
- hidden: true
- });
- Ext.each(arr, function(a){
- o = new Object();
- o.text = a.id_caption;
- o.dataIndex = a.id_field;
- o.hidden = a.id_visible == 0;
- o.width = a.id_width;
- o.rule = a.id_rule;
- o.dataType = a.id_type;
- o.isNeed = a.id_need == 1 ? '是' : '否';
- o.logic = a.id_logic;
- o.logicdesc = me.parseLogic(o.logic);
- o.editor = {
- xtype: 'textfield'
- };
- if(/combo(.)/.test(o.logic)){
- var s = o.logic.substring(6, o.logic.lastIndexOf(')')).split(','),
- da = new Array();
- Ext.each(s, function(t){
- da.push({
- display: t,
- value: t
- });
- });
- o.editor = {
- xtype: 'combobox',
- displayField: 'display',
- valueField: 'value',
- queryMode: 'local',
- editable: false,
- store: Ext.create('Ext.data.Store', {
- fields: ['display', 'value'],
- data : da
- })
- };
- }
- o.renderer = function(val, meta, record, x, y, store, view){
- if(view) {
- var grid = view.ownerCt,errNodes = grid.errorNodes,cm = grid.columns[y];
- if(errNodes && y > 0 && Ext.Array.contains(errNodes, record.data['id_id'] + ':' + cm.dataIndex)){
- meta.tdCls = 'x-td-warn';
- meta.tdAttr = 'data-qtip="' + cm.rule + '"';
- }
- }
- return val;
- };
- d.push(o);
- });
- return d;
- },
- emptyData: function(arr){
- var fields = new Array();
- Ext.each(arr, function(a){
- fields.push(a.id_field);
- });
- return new Ext.data.Store({
- fields: fields,
- data: [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
- });
- },
- getDockedItems: function(store){
- return {
- xtype: 'pagingtoolbar',
- store: store,
- pageSize: 100,
- dataCount: store.data.items.length,
- page: 1,
- dock: 'bottom',
- displayInfo: true,
- updateInfo : function(){
- var page = this.child('#inputItem').getValue() || 1;
- var me = this,
- pageSize = me.pageSize || 100,
- dataCount = me.dataCount || 20;
- var displayItem = me.child('#displayItem'),
- pageData = me.getPageData();
- pageData.fromRecord = (page-1)*pageSize+1;
- pageData.toRecord = page*pageSize > dataCount ? dataCount : page*pageSize;
- pageData.total = dataCount;
- var msg;
- if (displayItem) {
- if (me.dataCount === 0) {
- msg = me.emptyMsg;
- } else {
- msg = Ext.String.format(
- me.displayMsg,
- pageData.fromRecord,
- pageData.toRecord,
- pageData.total
- );
- }
- displayItem.setText(msg);
- me.doComponentLayout();
- }
- },
- getPageData : function(){
- var me = this,
- totalCount = me.dataCount;
- return {
- total : totalCount,
- currentPage : me.page,
- pageCount: Math.ceil(me.dataCount / me.pageSize),
- fromRecord: ((me.page - 1) * me.pageSize) + 1,
- toRecord: Math.min(me.page * me.pageSize, totalCount)
- };
- },
- doRefresh:function(){
- this.moveFirst();
- },
- onPagingKeyDown : function(field, e){
- var me = this,
- k = e.getKey(),
- pageData = me.getPageData(),
- increment = e.shiftKey ? 10 : 1,
- pageNum = 0;
- if (k == e.RETURN) {
- e.stopEvent();
- pageNum = me.readPageFromInput(pageData);
- if (pageNum !== false) {
- pageNum = Math.min(Math.max(1, pageNum), pageData.pageCount);
- me.child('#inputItem').setValue(pageNum);
- if(me.fireEvent('beforechange', me, pageNum) !== false){
- me.page = pageNum;
- me.ownerCt.getGridData(me.page);
- }
-
- }
- } else if (k == e.HOME || k == e.END) {
- e.stopEvent();
- pageNum = k == e.HOME ? 1 : pageData.pageCount;
- field.setValue(pageNum);
- } else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN) {
- e.stopEvent();
- pageNum = me.readPageFromInput(pageData);
- if (pageNum) {
- if (k == e.DOWN || k == e.PAGEDOWN) {
- increment *= -1;
- }
- pageNum += increment;
- if (pageNum >= 1 && pageNum <= pageData.pages) {
- field.setValue(pageNum);
- }
- }
- }
- me.updateInfo();
- me.resetTool(value);
- },
- moveFirst : function(){
- var me = this;
- me.child('#inputItem').setValue(1);
- value = 1;
- me.page = value;
- me.ownerCt.getGridData(value);
- me.updateInfo();
- me.resetTool(value);
- },
- movePrevious : function(){
- var me = this;
- me.child('#inputItem').setValue(me.child('#inputItem').getValue() - 1);
- value = me.child('#inputItem').getValue();
- me.page = value;
- me.ownerCt.getGridData(value);
- me.updateInfo();
- me.resetTool(value);
- },
- moveNext : function(){
- var me = this,
- last = me.getPageData().pageCount;
- total = last;
- me.child('#inputItem').setValue(me.child('#inputItem').getValue() + 1);
- value = me.child('#inputItem').getValue();
- me.page = value;
- me.ownerCt.getGridData(value);
- me.updateInfo();
- me.resetTool(value);
- },
- moveLast : function(){
- var me = this,
- last = me.getPageData().pageCount;
- total = last;
- me.child('#inputItem').setValue(last);
- value = me.child('#inputItem').getValue();
- me.page = value;
- me.ownerCt.getGridData(value);
- me.updateInfo();
- me.resetTool(value);
- },
- onLoad : function() {
- var e = this, d, b, c, a;
- if (!e.rendered) {
- return
- }
- d = e.getPageData();
- b = d.currentPage;
- c = Math.ceil(e.dataCount / e.pageSize);
- a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
- e.child("#afterTextItem").setText(a);
- e.child("#inputItem").setValue(b);
- e.child("#first").setDisabled(b === 1);
- e.child("#prev").setDisabled(b === 1);
- e.child("#next").setDisabled(b === c || c===1);//
- e.child("#last").setDisabled(b === c || c===1);
- e.child("#refresh").enable();
- e.updateInfo();
- e.fireEvent("change", e, d);
- },
- resetTool: function(value){
- var pageCount = this.getPageData().pageCount;
- this.child('#last').setDisabled(value == pageCount || pageCount == 1);
- this.child('#next').setDisabled(value == pageCount || pageCount == 1);
- this.child('#first').setDisabled(value <= 1);
- this.child('#prev').setDisabled(value <= 1);
- }
- };
- },
- getPathString: function(tree, record){// path:/root/5/12
- var str = tree.ownerCt.title;
- return record.getPath('text', '»').replace('root', str);
- },
- showHistory: function(caller){
- var w = Ext.create('Ext.Window', {
- width: '60%',
- height: '80%',
- id: 'history-win',
- title: '导入数据历史记录',
- autoShow: true,
- layout: 'anchor',
- items: [{
- xtype: 'gridpanel',
- anchor: '100% 100%',
- columnLines: true,
- columns: [{dataIndex: 'il_id', hidden: true},{dataIndex: 'il_caller', hidden: true},{dataIndex: 'il_date', text: '日期', flex: 2},
- {dataIndex: 'il_sequence', text: '次数', flex: 1},{dataIndex: 'il_count', text: '数据量(条)', flex: 1},
- {dataIndex: 'il_checked', text: '是否已校验', flex: 1, renderer: function(val, m){
- if(val == '否') {
- m.style = 'float:right';
- }
- return val;
- }},{dataIndex: 'il_success',text:'是否校验通过', flex: 1, renderer: function(val, m){
- if(val == '否') {
- m.style = 'float:right';
- }
- return val;
- }},
- {dataIndex: 'il_toformal', text: '是否转正式', flex: 1, renderer: function(val, m){
- if(val == '否') {
- m.style = 'float:right';
- }
- return val;
- }}, {text: '', flex: 1, renderer: function(val, m, r){
- return '<a href="javascript:Ext.getCmp(\'template-data\').loadData(' + r.get('il_id') + ','
- + r.get('il_count') + ',1);Ext.getCmp(\'history-win\').close();">载入</a> <a href="javascript:Ext.getCmp(\'template-data\').deleteData(' +
- r.get('il_id') + ');Ext.getCmp(\'history-win\').close();">删除</a>';
- }}],
- store: Ext.create('Ext.data.Store', {
- fields: ['il_id', 'il_caller', 'il_date', 'il_sequence', 'il_count', 'il_checked', 'il_success', 'il_toformal'],
- data: [{},{},{},{},{},{},{},{},{},{}]
- })
- }]
- });
- this.getInitLog(w.down('gridpanel'), caller);
- },
- getInitLog: function(g, c){
- Ext.Ajax.request({
- url: basePath + 'system/initHistory.action',
- params: {
- caller: c
- },
- method: 'post',
- callback: function(opt, s, r){
- var res = new Ext.decode(r.responseText);
- var dd = res.data;
- Ext.each(dd, function(d){
- d.il_date = Ext.Date.format(new Date(d.il_date), 'Y-m-d H:i:s');
- d.il_checked = d.il_checked == 1 ? '是' : '否';
- d.il_success = d.il_success == 1 ? '是' : '否';
- d.il_toformal = d.il_toformal == 1 ? '是' : '否';
- });
- g.store.loadData(dd);
- }
- });
- },
- loadInitData: function(grid, page){
- var f = (page-1) * 100 + 1,
- t = page*100;
- grid.setLoading(true);
- Ext.Ajax.request({
- url: basePath + 'system/getInitData.action',
- timeout: 10000,
- params: {
- condition: "id_ilid=" + grid.ilid +
- " AND id_detno between " + f + " AND " + t
- },
- method: 'post',
- callback: function(options, success, response){
- grid.setLoading(false);
- if(!success) {
- alert('系统繁忙,请稍后再试!');
- return;
- }
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo != null){
- showError(res.exceptionInfo);return;
- } else {
- var datas = new Array(), o;
- Ext.each(res.data, function(d){
- o = Ext.decode(d.id_data);
- o.id_id = d.id_id;
- datas.push(o);
- });
- grid.store.loadData(datas);
- grid.showErrors();
- var f = Ext.getCmp('onlyerror');
- if(f.checked) {
- grid.store.filterBy(function(item) {
- return !Ext.isEmpty(item.get('log'));
- });
- }
- }
- }
- });
- },
- ondelete: function(id){
- var grid = Ext.getCmp('template-data');
- grid.setLoading(true);
- Ext.Ajax.request({
- url: basePath + 'system/deleteInitData.action',
- params: {
- id: id
- },
- method: 'post',
- timeout: 20000,
- callback: function(options, success, response){
- grid.setLoading(false);
- if(!success) {
- alert('系统繁忙,请稍后再试!');
- return;
- }
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo != null){
- showError(res.exceptionInfo);return;
- } else {
- if(id == grid.ilid) {// 如果删除的是当前显示的数据,要清除当前grid的数据
- grid.reset();
- }
- }
- }
- });
- },
- showRule: function(grid){
- if(grid){
- var me = this,data = me.getRules(grid);
- Ext.create('Ext.window.Window', {
- width: '100%',
- height: '100%',
- autoShow: 'true',
- closeAction: 'destroy',
- title: '导入配置',
- layout: 'anchor',
- tbar: ['->',{
- text: '保存',
- width: 80,
- cls: 'x-btn-bar-s',
- handler: function(b){
- me.saveInitDetails(b.ownerCt.ownerCt.down('gridpanel'), grid.caller);
- }
- },{
- text: '取消',
- width: 80,
- cls: 'x-btn-bar-s',
- handler: function(b) {
- b.ownerCt.ownerCt.close();
- }
- },'->'],
- items: [{
- xtype: 'gridpanel',
- id: 'initdetails',
- anchor: '100% 100%',
- plugins: Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1
- }),
- columnLines: true,
- keyField: 'id_id',
- detno: 'id_detno',
- bbar: {xtype: 'erpToolbar'},
- dbfinds: [{
- field: 'id_table',
- dbGridField: 'dd_tablename;ddd_tablename'
- },{
- field: 'id_field',
- dbGridField: 'ddd_fieldname'
- },{
- field: 'id_caption',
- dbGridField: 'ddd_description'
- },{
- field: 'id_type',
- dbGridField: 'ddd_fieldtype'
- }],
- columns: [{
- dataIndex: 'id_id',
- hidden: true
- },{
- dataIndex: 'id_caller',
- hidden: true,
- renderer: function(v, m, r, x, y, s, w){
- var grid = w.ownerCt;
- if(Ext.isEmpty(v) && !Ext.isEmpty(grid.caller)) {
- v = grid.caller;
- r.set('id_caller', v);
- }
- return v;
- }
- },{
- dataIndex: 'id_detno',
- text: '序号',
- width: 40,
- renderer: function(val, meta) {
- meta.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
- return val;
- }
- },{
- text: '导入表',
- dataIndex: 'id_table',
- width: 90,
- editor: {
- xtype: 'dbfindtrigger'
- },
- dbfind: 'DataDictionary|dd_tablename'
- },{
- text: '导入项',
- dataIndex: 'id_field',
- width: 100,
- editor: {
- xtype: 'multidbfindtrigger'
- },
- dbfind: 'DataDictionaryDetail|ddd_fieldname'
- },{
- text: '描述',
- dataIndex: 'id_caption',
- width: 105,
- renderer: function(v){
- if(Ext.isEmpty(v)) {
- return '<font color=gray>无</font>';
- }
- return v;
- },
- editor: {
- xtype: 'textfield'
- }
- },{
- text: '逻辑表达式',
- dataIndex: 'id_logic',
- width: 250,
- renderer: function(v){
- if(Ext.isEmpty(v)) {
- return '<font color=gray>无</font>';
- }
- return v;
- },
- editor: {
- xtype: 'trigger',
- editable: false,
- triggerCls: 'x-form-search-trigger',
- onTriggerClick: function(){
- me.logicTypes(this, Ext.getCmp('initdetails').selModel.lastSelected);
- }
- }
- },{
- text: '逻辑描述',
- dataIndex: 'id_rule',
- width: 500,
- renderer: function(v){
- if(Ext.isEmpty(v)) {
- return '<font color=gray>无</font>';
- }
- return v;
- },
- editor: {
- xtype: 'textfield'
- }
- },{
- text: '类型',
- dataIndex: 'id_type',
- width: 105,
- renderer: function(v, meta, record){
- if(Ext.isEmpty(v)) {
- return '<font color=gray>无</font>';
- } else {
- v = v.toLowerCase();
- if(contains(v, 'varchar2')) {
- v = v.replace(/byte/g, '').trim();
- }
- if(record.data['id_type'] != v) {
- record.set('id_type', v);
- }
- }
- return v;
- },
- editor: {
- xtype: 'trigger',
- editable: false,
- triggerCls: 'x-form-search-trigger',
- onTriggerClick: function(){
- me.dataTypes(this, Ext.getCmp('initdetails').selModel.lastSelected);
- }
- }
- },{
- text: '默认值',
- dataIndex: 'id_default',
- wdith: 80,
- renderer: function(v){
- if(Ext.isEmpty(v)) {
- return '<font color=gray>无</font>';
- }
- return v;
- },
- editor: {
- xtype: 'trigger',
- editable: false,
- triggerCls: 'x-form-search-trigger',
- onTriggerClick: function(){
- me.fieldTypes(this, Ext.getCmp('initdetails').selModel.lastSelected);
- }
- }
- },{
- text: '是否显示',
- dataIndex: 'id_visible',
- xtype: 'checkcolumn',
- width: 75,
- editor: {
- xtype: 'checkbox'
- }
- },{
- text: '是否必填',
- dataIndex: 'id_need',
- xtype: 'checkcolumn',
- width: 75,
- editor: {
- xtype: 'checkbox'
- }
- },{
- text: '列宽度',
- dataIndex: 'id_width',
- xtype: 'numbercolumn',
- format: '0',
- width: 75,
- editor: {
- xtype: 'numberfield',
- hideTrigger: true,
- format: '0'
- }
- }],
- store: Ext.create('Ext.data.Store', {
- fields: ['id_id', 'id_caller', 'id_detno', 'id_table', 'id_field', 'id_caption', 'id_logic', 'id_rule',
- 'id_type', {name: 'id_visible', type: 'bool'}, {name: 'id_need', type: 'bool'}, 'id_default',
- 'id_width'],
- data: data
- }),
- listeners: {
- itemclick: function(selModel, record){
- me.GridUtil.onGridItemClick(selModel, record);
- }
- }
- }]
- });
- me.control('field[name=id_field]', {
- focus: function(t){
- var record = Ext.getCmp('initdetails').selModel.lastSelected;
- var dd = record.data['id_table'];
- if(!Ext.isEmpty(dd)) {
- t.dbBaseCondition = 'ddd_tablename=\'' + dd + '\'';
- } else {
- t.dbBaseCondition = '';
- }
- }
- });
- }
- },
- saveInitDetails: function(grid, caller){
- var me = this,datas = [],items = grid.store.data.items,d;
- Ext.each(items, function(i){
- if(i.dirty) {
- d = i.data;
- if(!Ext.isEmpty(d.id_field) && !Ext.isEmpty(d.id_table)) {
- d.id_need = d.id_need ? 1 : 0;
- d.id_visible = d.id_visible ? 1 : 0;
- d.id_caller = caller;
- d.id_width = Ext.isEmpty(d.id_width) ? 0 : d.id_width;
- datas.push(d);
- }
- }
- });
- Ext.Ajax.request({
- url: basePath + 'system/saveInitDetail.action',
- method: 'post',
- params: {
- data: unescape(Ext.encode(datas).replace(/\\/g,"%"))
- },
- callback: function(opt, s, r) {
- if(r.exceptionInfo) {
- showError(r.exceptionInfo);
- } else {
- alert('保存成功!');
- grid.ownerCt.destroy();
- me.getDetails(Ext.getCmp('template'), caller, true);
- }
- }
- });
- },
- fieldTypes: function(f, record){
- var g = Ext.getCmp('initdetails'), dd = g.store.data.items,ff = [];
- Ext.each(dd, function(i){
- if(i.data.id_field != record.data.id_field) {
- ff.push({
- display: i.data.id_caption,
- value: i.data.id_field
- });
- }
- });
- var ww = Ext.create('Ext.Window', {
- autoShow: true,
- modal: true,
- title: '默认值',
- width: '55%',
- height: '50%',
- layout: 'column',
- items: [{
- xtype: 'fieldcontainer',
- name: 'keyField',
- columnWidth: 1,
- items: [{
- xtype: 'radio',
- columnWidth: 1,
- boxLabel: '自动取ID',
- name: 'default'
- }],
- getValue: function(){
- return 'keyField';
- },
- setValue: function(){
- this.down('radio').setValue(true);
- }
- },{
- xtype: 'fieldcontainer',
- name: 'codeField',
- columnWidth: 1,
- items: [{
- xtype: 'radio',
- columnWidth: 1,
- boxLabel: '自动取编号',
- name: 'default'
- }],
- getValue: function(){
- return 'codeField';
- },
- setValue: function(){
- this.down('radio').setValue(true);
- }
- },{
- xtype: 'fieldcontainer',
- name: 'date',
- columnWidth: 1,
- layout: 'hbox',
- items: [{
- xtype: 'radio',
- boxLabel: '当前时间',
- name: 'default'
- },{
- xtype: 'checkbox',
- inputValue: 'yy-MM-dd',
- separator: ' ',
- boxLabel: '年月日'
- },{
- xtype: 'checkbox',
- inputValue: 'HH:mm:ss',
- separator: '',
- boxLabel: '时分秒'
- }],
- getValue: function(){
- var rr = this.query('checkbox[checked=true]'), vv = '', len = rr.length;
- Ext.each(rr, function(r, idx){
- if(r.xtype == 'checkbox' && r.inputValue) {
- vv += r.inputValue;
- if(idx < len - 1) {
- vv += r.separator;
- }
- }
- });
- if(vv == '') {
- return '';
- }
- return 'date(' + vv + ')';
- },
- setValue: function(v){
- this.down('radio').setValue(true);
- v = v.substring(v.indexOf('(') + 1, v.indexOf(')'));
- var y = v.split(' '),arr,me = this;
- Ext.each(y, function(i){
- if(i.indexOf('-') != -1) {
- arr = i.split('-');
- } else {
- arr = i.split(':');
- }
- var ch;
- Ext.each(arr, function(j){
- ch = me.down('checkbox[inputValue=' + j + ']');
- if(ch)
- ch.setValue(true);
- });
- });
- }
- },{
- xtype: 'fieldcontainer',
- name: 'replace',
- columnWidth: 1,
- layout: 'hbox',
- items: [{
- xtype: 'radio',
- name: 'default',
- boxLabel: '替代值'
- },{
- xtype: 'fieldcontainer',
- items: [{
- xtype: 'textfield',
- emptyText: '显示值'
- },{
- xtype: 'textfield',
- emptyText: '实际值'
- }],
- getValue: function(){
- var val = this.items.items[0],dis = this.items.items[1];
- if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
- return val.value + ':' + dis.value;
- }
- return '';
- },
- setValue: function(v) {
- if(!Ext.isEmpty(v)) {
- this.items.items[0].setValue(v.split(':')[0]);
- this.items.items[1].setValue(v.split(':')[1] || '');
- }
- }
- },{
- xtype: 'button',
- iconCls: 'x-button-icon-add',
- cls: 'x-btn-tb',
- handler: function(b){
- b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
- xtype: 'fieldcontainer',
- items: [{
- xtype: 'textfield',
- emptyText: '显示值'
- },{
- xtype: 'textfield',
- emptyText: '实际值'
- }],
- getValue: function(){
- var val = this.items.items[0],dis = this.items.items[1];
- if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
- return val.value + ':' + dis.value;
- }
- return '';
- },
- setValue: function(v) {
- if(!Ext.isEmpty(v)) {
- this.items.items[0].setValue(v.split(':')[0]);
- this.items.items[1].setValue(v.split(':')[1] || '');
- }
- }
- });
- }
- }],
- getValue: function(){
- var tx = this.query('fieldcontainer'),val = '';
- Ext.each(tx, function(t){
- if(!Ext.isEmpty(t.getValue())) {
- if(val == '') {
- val = t.getValue();
- } else {
- val += ',' + t.getValue();
- }
- }
- });
- if(val == '') {
- return null;
- }
- return 'replace(' +val + ')';
- },
- setValue: function(v){
- var m = this;
- this.down('radio').setValue(true);
- var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
- Ext.each(t, function(r, i){
- if(i == 0) {
- m.down('fieldcontainer').setValue(r);
- } else {
- var f = Ext.create('Ext.form.FieldContainer', {
- items: [{
- xtype: 'textfield',
- emptyText: '显示值'
- },{
- xtype: 'textfield',
- emptyText: '实际值'
- }],
- getValue: function(){
- var val = this.items.items[0],dis = this.items.items[1];
- if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
- return val.value + ':' + dis.value;
- }
- return '';
- },
- setValue: function(v) {
- if(!Ext.isEmpty(v)) {
- this.items.items[0].setValue(v.split(':')[0]);
- this.items.items[1].setValue(v.split(':')[1] || '');
- }
- }
- });
- m.insert(m.items.items.length - 1, f);
- f.setValue(r);
- }
- });
- }
- },{
- xtype: 'fieldcontainer',
- name: 'copy',
- columnWidth: 1,
- layout: 'hbox',
- items: [{
- xtype: 'radio',
- boxLabel: '等于字段',
- name: 'default'
- },{
- xtype: 'combo',
- displayField: 'display',
- valueField: 'value',
- queryMode: 'local',
- editable: false,
- store: Ext.create('Ext.data.Store', {
- fields: ['display','value'],
- data: ff
- })
- },{
- xtype: 'radio',
- name: 'condition',
- inputValue: 'if',
- boxLabel: '只在值为空时'
- },{
- xtype: 'radio',
- name: 'condition',
- inputValue: 'of',
- boxLabel: '任何情况下',
- checked: true
- }],
- getValue: function(){
- var rr = this.query('radio[name=condition]'), vv = '';
- Ext.each(rr, function(){
- if(this.checked) {
- vv = this.inputValue;
- }
- });
- return 'copy' + vv + '(' + this.down('combo').value + ')';
- },
- setValue: function(v) {
- this.down('radio').setValue(true);
- this.down('combo').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
- var ff = v.substring(4, v.indexOf('('));
- this.down('radio[inputValue=' + ff + ']').setValue(true);
- }
- },{
- xtype: 'fieldcontainer',
- name: 'others',
- columnWidth: 1,
- layout: 'hbox',
- items: [{
- xtype: 'radio',
- boxLabel: '其它',
- name: 'default'
- },{
- xtype: 'textfield'
- }],
- getValue: function() {
- return this.down('textfield').value;
- },
- setValue: function(v) {
- this.down('radio').setValue(true);
- this.down('textfield').setValue(v);
- }
- }],
- buttonAlign: 'center',
- buttons: [{
- text: '确定',
- handler: function(b){
- var w = b.ownerCt.ownerCt;
- var val = '',ch = w.query('radio[name="default"]'),cc = null;
- Ext.each(ch, function(){
- if(this.checked) {
- cc = this;
- }
- });
- if(cc) {
- v = cc.ownerCt.getValue();
- if(v != null) {
- val = v;
- }
- }
- f.setValue(val);
- record.set('id_default', val);
- w.close();
- }
- },{
- text: '取消',
- handler: function(b){
- b.ownerCt.ownerCt.close();
- }
- }]
- });
- var fc = ww.query('fieldcontainer');
- if(!Ext.isEmpty(f.value)) {
- var vv = f.value,bool = false;
- Ext.each(fc, function(r){
- if(contains(vv, r.name, true)) {
- bool = true;
- r.setValue(vv);
- }
- });
- if(!bool) {
- ww.down('fieldcontainer[name=others]').setValue(vv);
- }
- }
- },
- logicTypes: function(f, record){
- var g = Ext.getCmp('initdetails'), dd = g.store.data.items,ff = [];
- Ext.each(dd, function(i){
- if(i.data.id_field != record.data.id_field) {
- ff.push({
- display: i.data.id_caption,
- value: i.data.id_field
- });
- }
- });
- var ww = Ext.create('Ext.Window', {
- autoShow: true,
- modal: true,
- title: '逻辑表达式',
- width: '60%',
- height: '60%',
- layout: 'column',
- padding: 15,
- items: [{
- xtype: 'fieldcontainer',
- name: 'unique',
- columnWidth: 1,
- items: [{
- xtype: 'checkbox',
- boxLabel: '唯一性'
- }],
- getValue: function(){
- return 'unique(' + record.data.id_table + '|' + record.data.id_field + ')';
- },
- setValue: function(v){
- this.down('checkbox').setValue(true);
- }
- },{
- xtype: 'fieldcontainer',
- name: 'trim',
- columnWidth: 1,
- layout: 'column',
- items: [{
- xtype: 'checkbox',
- columnWidth: 0.1,
- boxLabel: '禁用字符'
- },{
- xtype: 'textfield',
- columnWidth: 0.1
- },{
- xtype: 'button',
- iconCls: 'x-button-icon-add',
- cls: 'x-btn-tb',
- handler: function(b){
- b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
- xtype: 'textfield',
- columnWidth: 0.1
- });
- }
- }],
- getValue: function(){
- var tx = this.query('textfield'),val = '';
- Ext.each(tx, function(t){
- if(!Ext.isEmpty(t.value)) {
- if(val == '') {
- val = t.value;
- } else {
- val += ',' + t.value;
- }
- }
- });
- if(val == '') {
- return null;
- }
- return 'trim(' +val + ')';
- },
- setValue: function(v){
- var m = this;
- m.down('checkbox').setValue(true);
- var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
- Ext.each(t, function(r, i){
- if(i == 0) {
- m.down('textfield').setValue(r);
- } else {
- m.insert(m.items.items.length - 1, {
- xtype: 'textfield',
- columnWidth: 0.1,
- value: r
- });
- }
- });
- }
- },{
- xtype: 'fieldcontainer',
- name: 'combo',
- columnWidth: 1,
- layout: 'column',
- items: [{
- xtype: 'checkbox',
- columnWidth: 0.1,
- boxLabel: '可选范围'
- },{
- xtype: 'textfield',
- columnWidth: 0.1
- },{
- xtype: 'button',
- iconCls: 'x-button-icon-add',
- cls: 'x-btn-tb',
- handler: function(b){
- b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
- xtype: 'textfield',
- columnWidth: 0.1
- });
- }
- }],
- getValue: function(){
- var tx = this.query('textfield'),val = '';
- Ext.each(tx, function(t){
- if(!Ext.isEmpty(t.value)) {
- if(val == '') {
- val = t.value;
- } else {
- val += ',' + t.value;
- }
- }
- });
- if(val == '') {
- return null;
- }
- return 'combo(' +val + ')';
- },
- setValue: function(v){
- var m = this;
- m.down('checkbox').setValue(true);
- var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
- Ext.each(t, function(r, i){
- if(i == 0) {
- m.down('textfield').setValue(r);
- } else {
- m.insert(m.items.items.length - 1, {
- xtype: 'textfield',
- columnWidth: 0.1,
- value: r
- });
- }
- });
- }
- },{
- xtype: 'fieldcontainer',
- name: 'accord',
- columnWidth: 1,
- layout: 'column',
- items: [{
- xtype: 'checkbox',
- columnWidth: 0.1,
- boxLabel: '关联'
- },{
- columnWidth: 0.3,
- emptyText: '表',
- id: 'accord_table',
- name: 'accord_table',
- xtype: 'dbfindtrigger'
- },{
- columnWidth: 0.3,
- emptyText: '字段',
- id: 'accord_field',
- name: 'accord_field',
- dbKey: 'accord_table',
- mappingKey: 'ddd_tablename',
- dbMessage: '请选择表名',
- xtype: 'dbfindtrigger'
- }],
- getValue: function(){
- var at = this.down('dbfindtrigger[name=accord_table]'),
- af = this.down('dbfindtrigger[name=accord_field]');
- if(!Ext.isEmpty(at.value) && !Ext.isEmpty(af.value)) {
- return 'accord(' + at.value + '|' + af.value + ')';
- }
- return null;
- },
- setValue: function(v){
- this.down('checkbox').setValue(true);
- var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split('|');
- this.down('dbfindtrigger[name=accord_table]').setValue(t[0]);
- this.down('dbfindtrigger[name=accord_field]').setValue(t[1]);
- }
- },{
- xtype: 'fieldcontainer',
- name: 'diffence',
- columnWidth: 1,
- layout: 'column',
- items: [{
- xtype: 'checkbox',
- columnWidth: 0.1,
- boxLabel: '不同于'
- },{
- columnWidth: 0.3,
- xtype: 'combo',
- displayField: 'display',
- valueField: 'value',
- queryMode: 'local',
- editable: false,
- store: Ext.create('Ext.data.Store', {
- fields: ['display','value'],
- data: ff
- })
- }],
- getValue: function(){
- var c = this.down('combo');
- if(!Ext.isEmpty(c.value)) {
- return 'diffence(' + c.value + ')';
- }
- return null;
- },
- setValue: function(v){
- this.down('checkbox').setValue(true);
- this.down('combo').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
- }
- },{
- xtype: 'fieldcontainer',
- name: 'minValue',
- columnWidth: 1,
- layout: 'column',
- items: [{
- xtype: 'checkbox',
- columnWidth: 0.1,
- boxLabel: '最小值'
- },{
- columnWidth: 0.3,
- xtype: 'numberfield'
- }],
- getValue: function(){
- var c = this.down('numberfield');
- if(!Ext.isEmpty(c.value)) {
- return 'minValue(' + c.value + ')';
- }
- return null;
- },
- setValue: function(v){
- this.down('checkbox').setValue(true);
- this.down('minValue').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
- }
- }],
- buttonAlign: 'center',
- buttons: [{
- text: '确定',
- handler: function(b){
- var w = b.ownerCt.ownerCt;
- var val = '',ch = w.query('checkbox[checked=true]'),v;
- Ext.each(ch, function(c){
- v = c.ownerCt.getValue();
- if(v != null) {
- if(val != '') {
- val += ';';
- }
- val += v;
- }
- });
- f.setValue(val);
- record.set('id_logic', val);
- w.close();
- }
- },{
- text: '取消',
- handler: function(b){
- b.ownerCt.ownerCt.close();
- }
- }]
- });
- var fc = ww.query('fieldcontainer');
- if(!Ext.isEmpty(f.value)) {
- var vv = f.value.split(';');
- Ext.each(vv, function(s){
- Ext.each(fc, function(r){
- if(contains(s, r.name, true)) {
- r.setValue(s);
- }
- });
- });
- }
- },
- dataTypes: function(f, record){
- var v = f.value,a = v.substring(v.indexOf('(') + 1, v.indexOf(')')),x = 30,y = 0;
- if(a) {
- x = a.split(',')[0];
- y = a.split(',')[1];
- }
- var isDate = contains(f.value, 'date', true), isStr = contains(f.value, 'varchar2', true);
- Ext.create('Ext.Window', {
- autoShow: true,
- modal: true,
- title: '数据类型',
- width: '40%',
- height: '30%',
- items: [{
- xtype: 'container',
- padding: '10 5 5 10',
- items: [{
- xtype: 'radio',
- boxLabel: '日期',
- name: 'type',
- checked: isDate,
- inputValue: 'date()',
- listeners: {
- change : function(){
- if(this.checked) {
- this.ownerCt.down('numberfield[name=length_y]').hide();
- this.ownerCt.down('numberfield[name=length_x]').hide();
- } else {
- this.ownerCt.down('numberfield[name=length_x]').show();
- }
- }
- }
- },{
- xtype: 'radio',
- boxLabel: '字符串',
- name: 'type',
- checked: isStr,
- inputValue: 'varchar2'
- },{
- xtype: 'radio',
- boxLabel: '数字',
- name: 'type',
- checked: !isDate && !isStr,
- inputValue: 'number',
- listeners: {
- change : function(){
- if(this.checked) {
- this.ownerCt.down('numberfield[name=length_y]').show();
- this.ownerCt.down('numberfield[name=length_x]').setMaxValue(38);
- this.ownerCt.down('numberfield[name=length_x]').validate();
- } else {
- this.ownerCt.down('numberfield[name=length_y]').hide();
- this.ownerCt.down('numberfield[name=length_x]').setMaxValue(2000);
- }
- }
- }
- },{
- xtype: 'numberfield',
- fieldLabel: '长度',
- name: 'length_x',
- format: '0',
- value: x,
- hidden: isDate,
- maxText: '超过最大长度',
- listeners: {
- change: function(f){
- var a = f.ownerCt.down('radio[checked=true]').inputValue;
- if(a == 'number') {
- f.setMaxValue(38);
- } else {
- f.setMaxValue(2000);
- }
- }
- }
- },{
- xtype: 'numberfield',
- fieldLabel: '小数位数',
- name: 'length_y',
- hidden: isDate || isStr,
- format: '0',
- maxValue: 57,
- maxText: '超过最大数57',
- value: y
- }]
- }],
- buttonAlign: 'center',
- buttons: [{
- text: '确定',
- handler: function(b){
- var w = b.ownerCt.ownerCt;
- v = w.down('radio[checked=true]').inputValue;
- x = w.down('numberfield[name=length_x]').value || 0;
- y = w.down('numberfield[name=length_y]').value || 0;
- if(v == 'varchar2') {
- v += '(' + x + ')';
- } else if (v == 'number') {
- v += '(' + x + ',' + y + ')';
- }
- f.setValue(v);
- record.set(f.name, v);
- w.close();
- }
- },{
- text: '取消',
- handler: function(b){
- b.ownerCt.ownerCt.close();
- }
- }]
- });
- },
- getRules: function(grid){
- var datas = new Array();
- if(grid.cfg && grid.cfg.length > 0) {
- datas = grid.cfg;
- var keys;
- Ext.each(datas, function(d){
- keys = Ext.Object.getKeys(d);
- Ext.each(keys, function(k){
- d[k] = d[k] == null ? '' : d[k];
- });
- d.id_visible = d.id_visible == 1;
- d.id_need = d.id_need == 1;
- });
- } else {
- datas = [{id_detno:1,id_width:100},{id_detno:2,id_width:100},{id_detno:3,id_width:100},
- {id_detno:4,id_width:100},{id_detno:5,id_width:100},{id_detno:6,id_width:100},
- {id_detno:7,id_width:100},{id_detno:8,id_width:100},{id_detno:9,id_width:100},
- {id_detno:10,id_width:100}];
- }
- return datas;
- },
- /**
- * 数据校验
- */
- checkdata: function(grid){
- var me = this, count = grid.down('pagingtoolbar').dataCount, pageSize = 5000, page = 0, a, b,
- len = Math.ceil(count/pageSize), index = 0;
- var p = Ext.create('Ext.ProgressBar', {
- width: '60%',
- text: '准备校验中...',
- floating: true,
- renderTo: Ext.getBody()
- }).show();
- grid.setLoading(true);
- // 先删除上次校验记录
- Ext.Ajax.request({
- url: basePath + 'system/beforeCheckLog.action',
- params: {
- id: grid.ilid
- },
- method: 'post',
- callback: function(opt, s, r){
- var res = Ext.decode(r.responseText);
- if(res.success) {
- while (page*pageSize < count) {
- a = page * pageSize + 1;
- b = (page + 1) * pageSize;
- Ext.Ajax.request({
- url: basePath + 'system/checkInitData.action',
- timeout: 30000,
- async: false,
- method: 'post',
- params: {
- id: grid.ilid,
- start: a,
- end: b
- },
- callback: function(opt, s, r){
- var rs = Ext.decode(r.responseText);
- if(rs.exceptionInfo) {
- grid.setLoading(false);
- p.destroy();
- Ext.Msg.alert('发现错误', rs.exceptionInfo);return;
- }
- index++;
- p.updateProgress(index/len, '完成' + index/len*100 + '%', true);
- if(index == len) {
- p.updateProgress(0.4, '准备完毕,正在校验...', true);
- Ext.Ajax.request({
- url: basePath + 'system/afterCheckLog.action',
- timeout: (5000 + count*50),
- params: {
- id: grid.ilid
- },
- method: 'post',
- callback: function(opt, s, r){
- grid.setLoading(false);
- var res = Ext.decode(r.responseText);
- if(res.success) {
- p.updateProgress(0.8, '校验完成,正在获取校验结果...', true);
- // 刷新grid.renderer
- me.getCheckResult(grid, p);
- } else {
- p.updateProgress(0.8, '校验过程中出现错误,请向管理员反馈...', true);
- alert(res.exceptionInfo);
- }
- }
- });
- }
- }
- });
- page++;
- }
- } else {
- alert('系统错误,准备校验失败!');
- }
- }
- });
- },
- /**
- * 从数据库取校验结果
- */
- getCheckResult: function(grid, p){
- grid.setLoading(true);
- Ext.Ajax.request({
- url: basePath + 'system/getCheckResult.action',
- timeout: 15000,
- params: {
- id: grid.ilid
- },
- method: 'post',
- callback: function(opt, s, r){
- p.destroy();
- grid.setLoading(false);
- var rs = r.responseText;
- if(rs != null && rs != '') {
- grid.errorNodes = rs.replace(/\s/g, '').split(',').filter(function(a){
- return a != '' && a != ' ';
- });
- } else {
- grid.errorNodes = [];
- alert('系统错误,未找到校验结果.');
- }
- grid.showErrors();
- Ext.getCmp('errdownload').show();
- Ext.getCmp('onlyerror').show();
- Ext.getCmp('toformal').show();
- Ext.getCmp('errdelete').show();
- Ext.getCmp('saveupdates').show();
- }
- });
- },
- toformal: function(grid){
- var count = grid.down('pagingtoolbar').dataCount, pageSize = 2000, page = 0, a, b,
- len = Math.ceil(count/pageSize), index = 0;
- if ('Purchase' == grid.caller || 'Sale' == grid.caller ||
- 'PurchasePrice' == grid.caller || 'SalePrice' == grid.caller ||
- 'ProdInOut' == grid.caller || 'Estimate' == grid.caller ||
- 'Make' == grid.caller || 'SaleForecast' == grid.caller
- || 'GoodsSend' == grid.caller|| 'ARBill'==grid.caller||'APBill'==grid.caller||
- 'ProdInOut!ExchangeIn'==grid.caller||'ProdInOut!SaleBorrow'==grid.caller||
- 'ProdInOut!OtherPurcIn'==grid.caller) {
- pageSize = count;
- len = 1;
- }
- var p = Ext.create('Ext.ProgressBar', {
- width: '60%',
- text: '准备中...',
- floating: true,
- renderTo: Ext.getBody()
- }).show();
- grid.setLoading(true);
- Ext.Ajax.request({
- url: basePath + 'system/beforeToFormal.action',
- params: {
- id: grid.ilid
- },
- callback: function(opt, s, r){
- if (!s) {
- grid.setLoading(false);
- p.destroy();
- showError('网络或系统错误!');return;
- }
- var res = Ext.decode(r.responseText);
- if(res.success) {
- while (page*pageSize < count) {
- a = page * pageSize + 1;
- b = (page + 1) * pageSize;
- p.updateProgress(index/len, '开始导入' + index/len*100 + '%', true);
- Ext.Ajax.request({
- url: basePath + 'system/toFormalData.action',
- timeout: 30000,
- method: 'post',
- async: false,
- params: {
- id: grid.ilid,
- start: a,
- end: b
- },
- callback: function(_opt, _s, _r){
- var rs = Ext.decode(_r.responseText);
- if(rs.exceptionInfo) {
- grid.setLoading(false);
- p.destroy();
- showError(rs.exceptionInfo);return;
- } else if(_s){
- index++;
- p.updateProgress(index/len, '完成' + index/len*100 + '%', true);
- if(index == len) {
- grid.setLoading(false);
- p.destroy();
- alert('转入成功!');
- Ext.Ajax.request({
- url: basePath + 'system/afterToFormal.action',
- params: {
- id: grid.ilid
- },
- callback: function(){
-
- }
- });
- }
- } else
- return;
- }
- });
- page++;
- }
- } else {
- grid.setLoading(false);
- p.destroy();
- showError(res.exceptionInfo);
- }
- }
- });
- },
- /**
- * 保存已修改的数据
- */
- saveUpdates: function(grid){
- var items = grid.store.data.items,arr = new Array();
- Ext.each(items, function(item){
- if(item.dirty) {
- arr.push(item.data);
- }
- });
- Ext.Ajax.request({
- url: basePath + 'system/updateInitData.action',
- method: 'post',
- params: {
- data: Ext.encode(arr)
- },
- callback: function(opt, s, r) {
- var res = Ext.decode(r.responseText);
- if(res.success) {
- alert('保存成功!');
- grid.getGridData(1);
- }
- }
- });
- },
- /**
- * 删除校验错误数据
- */
- deleteErrors: function(grid) {
- Ext.Msg.alert('提示', '确定删除?', function(btn){
- if(btn == 'ok' || btn == 'yes') {
- Ext.Ajax.request({
- url: basePath + 'system/init/errdelete.action',
- params: {
- id: grid.ilid
- },
- callback: function(opt, s, r) {
- var rs = Ext.decode(r.responseText);
- if(rs.success) {
- alert('删除成功!');
- grid.getGridData(1);
- }
- }
- });
- }
- });
- },
- parseLogic: function(logic) {
- if(logic != null) {
- var gc = logic.split(';'), str = '';
- for(var i in gc) {
- var s = gc[i];
- if(s != null) {
- if(s.indexOf('unique') > -1) {
- str += '唯一性;';
- } else if(s.indexOf('trim') > -1) {
- str += '不能包含' + s.replace('trim', '') + ';';
- } else if(s.indexOf('combo') > -1) {
- str += '只能是' + s.replace('combo', '') + '之一;';
- } else if(s.indexOf('accord') > -1) {
- str += '必须存在于' + s.replace('accord', '') + '中;';
- } else if(s.indexOf('diffence') > -1) {
- str += '必须与' + s.replace('diffence', '') + '不同;';
- } else if(s.indexOf('minValue') > -1) {
- str += '必须大于' + s.replace('minValue', '') + ';';
- }
- }
- }
- return str;
- }
- return null;
- }
- });
|