123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- Ext.define('erp.view.oa.meeting.Showapply',{
- extend: 'Ext.grid.Panel',
- alias: 'widget.erpBatchDealGridPanel',
- id: 'batchDealGridPanel',
- columnLines : true,
- autoScroll : true,
- store: [],
- region: 'south',
- layout : 'fit',
- columns: new Array(),
- height:height,
- GridUtil: Ext.create('erp.util.GridUtil'),
- bodyStyle:'background-color:#f1f1f1;',
- selModel: Ext.create('Ext.selection.CheckboxModel',{
- headerWidth: 0
- }),
- /*enableLocking:true,*/
- /*lockable: true,*/
- GridUtil: Ext.create('erp.util.GridUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1,
- listeners:{
- 'edit':function(editor,e,Opts){
- var record=e.record,data=null,qty=0;
- if(record){
- data=record.data;
- for(var property in data){
- if(!/^[a-zA-Z]/.test(property)){
- qty+=data[property];
- }
- }
- }
- }
- }
- })],
- initComponent : function(){
- var condition = this.condition;
- if(!condition){
- var urlCondition = this.BaseUtil.getUrlParam('gridCondition');
- urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition;
- gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
- gridCondition = gridCondition + urlCondition;
- gridCondition = gridCondition.replace(/IS/g, "=");
- if(gridCondition.search(/!/) != -1){
- gridCondition = gridCondition.substring(0, gridCondition.length - 4);
- }
- condition = gridCondition;
- }
- var gridParam = {caller: this.caller || caller, condition: condition};
- this.getGridColumnsAndStore(this, 'oa/meeting/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
- this.callParent(arguments);
- },
- loadNewStore:function(grid, url, param, no){
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + url,
- params: param,
- method : 'post',
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
- var data2 = Ext.decode(res.data2.replace(/,}/g, '}').replace(/,]/g, ']'));
- Ext.Array.each(data,function(item){
- Ext.Array.each(data2,function(item2){
- if(item.mr_code==item2.mamrcode){
- item[item2.name]=item2.result;
- }
-
- });
-
- });
- grid.store.loadData(data);
- }
- });
- },
- getGridColumnsAndStore: function(grid, url, param, no){
- var me = this;
- patchurl=basePath+url;
- grid.setLoading(true);
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + url,
- params: param,
- async:false,
- method : 'post',
- callback : function(options,success,response){
- grid.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- if(res.columns){
- var limits = res.limits, limitArr = new Array();
- if(limits != null && limits.length > 0) {//权限外字段
- limitArr = Ext.Array.pluck(limits, 'lf_field');
- }
- var data = [];
- var gridfields=res.fields;
- var gridcolumns=res.columns;
- var hasadd=false,basecode=null;
- if(!res.data || res.data.length == 2){
- me.add10EmptyData(grid.detno, data);
- me.add10EmptyData(grid.detno, data);//添加20条空白数据
- } else {
- data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
- var data2=Ext.decode(res.data2.replace(/,}/g, '}').replace(/,]/g, ']'));
- Ext.Array.each(data,function(item){
- Ext.Array.each(data2,function(item2){
- if(item.mr_code==item2.mamrcode){
- item[item2.name]=item2.result;
- }
- basecode=basecode==null?item2.mamrcode:basecode;
- if(item2.mamrcode==basecode&&hasadd==false){
- gridcolumns.push({
- readOnly:false,
- header:item2.name,
- cls: "x-grid-header-1",
- dataIndex:item2.name,
- width : 120,
- align:'right',
- format:'0',
- renderer:'oameeting'
- });
- gridfields.push({
- name:item2.name,
- type:'string'
- });
- }
- });
- hasadd=true;
- });
- Ext.each(res.columns, function(column, y){
- //power
- if(limitArr.length > 0 && Ext.Array.contains(limitArr, column.dataIndex)) {
- column.hidden = true;
- }
- //renderer
- me.setRenderer(grid, column);
- //logictype
- me.setLogicType(grid, column);
- });
- }
- //store
-
- //view
- if(grid.selModel.views == null){
- grid.selModel.views = [];
- }
- //dbfind
- if(res.dbfinds&&res.dbfinds.length > 0){
- grid.dbfinds = res.dbfinds;
- }
- //toolbar
- me.setToolbar(grid, res.columns, res.necessaryField, limitArr);
-
- var store = me.setStore(gridfields, data, grid.groupField, grid.necessaryField);
- grid.store=store;
- grid.columns=gridcolumns;
- var form = Ext.ComponentQuery.query('form')[0];
- if(form){
- if(form.readOnly){
- grid.readOnly = true;//grid不可编辑
- }
- }
- } else {
- grid.hide();
- var form = Ext.ComponentQuery.query('form')[0];
- me.updateFormPosition(form);//字段较少时,修改form布局
- }
- }
- });
- },
- setRenderer: function(grid, column){
- if(!column.haveRendered && column.renderer != null && column.renderer != ""){
- if(!grid.RenderUtil){
- grid.RenderUtil = Ext.create('erp.util.RenderUtil');
- }
- var renderName = column.renderer;
- if(contains(column.renderer, ':', true)){
- var args = new Array();
- Ext.each(column.renderer.split(':'), function(a, index){
- if(index == 0){
- renderName = a;
- } else {
- args.push(a);
- }
- });
- if(!grid.RenderUtil.args[renderName]){
- grid.RenderUtil.args[renderName] = new Object();
- }
- grid.RenderUtil.args[renderName][column.dataIndex] = args;
- }
- column.renderer = grid.RenderUtil[renderName];
- column.haveRendered = true;
- }
- },
- setLogicType: function(grid, column){
- var logic = column.logic;
- if(logic != null){
- if(logic == 'detno'){
- grid.detno = column.dataIndex;
- column.width = 40;
- column.renderer = function(val, meta) {
- meta.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
- return val;
- };
- } else if(logic == 'keyField'){
- grid.keyField = column.dataIndex;
- } else if(logic == 'mainField'){
- grid.mainField = column.dataIndex;
- } else if(logic == 'necessaryField'){
- grid.necessaryField = column.dataIndex;
- if(!grid.necessaryFields){
- grid.necessaryFields = new Array();
- }
- grid.necessaryFields.push(column.dataIndex);
- if(!column.haveRendered){
- column.renderer = function(val, meta, record, x, y, store, view){
- var c = this.columns[y];
- if(val != null && val.toString().trim() != ''){
- if(c.xtype == 'datecolumn'){
- val = Ext.Date.format(val, 'Y-m-d');
- }
- return val;
- } else {
- if(c.xtype == 'datecolumn'){
- val = '';
- }
- return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
- '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
- }
- };
- }
- } else if(logic == 'groupField'){
- grid.groupField = column.dataIndex;
- }
- }
- },
- setStore: function(fields, data, groupField, necessaryField){
- griddata=data;
- if(!Ext.isChrome){
- Ext.each(fields, function(f){
- if(f.type == 'date'){
- f.dateFormat = 'Y-m-d H:m:s';
- }
- });
- }
- return Ext.create('Ext.data.Store', {
- fields: fields,
- data: data,
- groupField: groupField,
- getSum: function(records, field) {
- if (arguments.length < 2) {
- return 0;
- }
- var total = 0,
- i = 0,
- len = records.length;
- if(necessaryField) {
- for (; i < len; ++i) {//重写getSum,grid在合计时,只合计填写了必要信息的行
- var necessary = records[i].get(necessaryField);
- if(necessary != null && necessary != ''){
- total += records[i].get(field);
- }
- }
- } else {
- for (; i < len; ++i) {
- total += records[i].get(field);
- }
- }
- return total;
- },
- getCount: function() {
- if(necessaryField) {
- var count = 0;
- Ext.each(this.data.items, function(item){//重写getCount,grid在合计时,只合计填写了必要信息的行
- if(item.data[necessaryField] != null && item.data[necessaryField] != ''){
- count++;
- }
- });
- return count;
- }
- return this.data.items.length;
- }
- });
- },
- setToolbar: function(grid, columns, necessaryField, limitArr){
- var items = [];
- var bool = true;
- if(!grid.dockedItems)
- return;
- Ext.each(grid.dockedItems.items, function(item){
- if(item.dock == 'bottom' && item.items){//bbar已存在
- bool = false;
- }
- });
- if(bool){
- Ext.each(columns, function(column){
- if(limitArr.length == 0 || !Ext.Array.contains(limitArr, column.dataIndex)) {
- if(column.summaryType == 'sum'){
- items.push('-',{
- id: column.dataIndex + '_sum',
- itemId: column.dataIndex,
- xtype: 'tbtext',
- text: column.header + '(sum):0'
- });
- } else if(column.summaryType == 'average') {
- items.push('-',{
- id: column.dataIndex + '_average',
- itemId: column.dataIndex,
- xtype: 'tbtext',
- text: column.header + '(average):0'
- });
- } else if(column.summaryType == 'count') {
- items.push('-',{
- id: column.dataIndex + '_count',
- itemId: column.dataIndex,
- xtype: 'tbtext',
- text: column.header + '(count):0'
- });
- }
- }
- if(column.dataIndex == necessaryField){
- column.renderer = function(val){
- if(val != null && val.toString().trim() != ''){
- return val;
- } else {
- return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
- '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
- }
- };
- }
- });
- grid.addDocked({
- xtype: 'toolbar',
- dock: 'bottom',
- items: items
- });
- } else {
- var bars = Ext.ComponentQuery.query('erpToolbar');
- if(bars.length > 0){
- Ext.each(columns, function(column){
- if(column.summaryType == 'sum'){
- bars[0].add('-');
- bars[0].add({
- id: column.dataIndex + '_sum',
- itemId: column.dataIndex,
- xtype: 'tbtext',
- text: column.header + '(sum):0'
- });
- } else if(column.summaryType == 'average') {
- bars[0].add('-');
- bars[0].add({
- id: column.dataIndex + '_average',
- itemId: column.dataIndex,
- xtype: 'tbtext',
- text: column.header + '(average):0'
- });
- } else if(column.summaryType == 'count') {
- bars[0].add('-');
- bars[0].add({
- id: column.dataIndex + '_count',
- itemId: column.dataIndex,
- xtype: 'tbtext',
- text: column.header + '(count):0'
- });
- }
- });
- }
- }
- },
- add10EmptyData: function(detno, data){
- if(detno){
- var index = data.length == 0 ? 0 : Number(data[data.length-1][detno]);
- for(var i=0;i<10;i++){
- var o = new Object();
- o[detno] = index + i + 1;
- data.push(o);
- }
- } else {
- for(var i=0;i<10;i++){
- var o = new Object();
- data.push(o);
- }
- }
- },
- checkGridDirty: function(grid){
- var s = grid.getStore().data.items;//获取store里面的数据
- var msg = '';
- for(var i=0;i<s.length;i++){
- if(s[i].dirty){//明细行被修改过哦
- msg = msg + '第' + (i+1) + '行:';
- var changed = Ext.Object.getKeys(s[i].modified);//拿到被修改了的字段
- for(var j = 0;j < changed.length;j++){
- Ext.each(grid.columns, function(c, index){
- if(index == 0){
- return;
- }
- if(c.dataIndex == changed[j] && c.logic != 'ignore'){//由字段dataindex匹配其text
- msg = msg + '<font color=blue>' + c.text + '</font> ';
- }
- });
- }
- msg = msg + ";";
- }
- }
- if(msg != '' && msg != ';'){//明细行被修改过哦
- msg = "明细行<font color=green>" + msg.substring(0, msg.length-1) + "</font>已编辑过";
- }
- return msg;
- },
- getGridStore: function(grid){
- if(grid == null){
- grid = Ext.getCmp('grid');
- }
- var me = this,
- jsonGridData = new Array();
- var form = Ext.getCmp('form');
- var s = grid.getStore().data.items;//获取store里面的数据
- var dd;
- for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
- var data = s[i].data;
- dd = new Object();
-
- if(s[i].dirty && !me.isBlank(grid, data)){
- Ext.each(gridcolumns, function(c){
- if(c.logic != 'ignore'){//只需显示,无需后台操作的字段,自动略去
- if(c.dataIndex=='wd_date'){
- Ext.Array.each(c.columns,function(column){
- dd[column.dataIndex]=data[column.dataIndex];
- });
-
- }else {
- if(c.xtype == 'datecolumn'){
- c.format = c.format || 'Y-m-d';
- if(Ext.isDate(data[c.dataIndex])){
- dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], c.format);
- } else {
- if(c.editor){
- dd[c.dataIndex] = Ext.Date.format(new Date(), c.format);//如果用户没输入日期,或输入有误,就给个默认日期,
- }
- }
- } else if(c.xtype == 'datetimecolumn'){
- if(Ext.isDate(data[c.dataIndex])){
- dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], 'Y-m-d H:i:s');//在这里把GMT日期转化成Y-m-d H:i:s格式日期
- } else {
- if(c.editor){
- dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');//默认日期,
- }
- }
- } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
- if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
- dd[c.dataIndex] = '0';//也可以从data里面去掉这些字段
- } else {
- dd[c.dataIndex] = s[i].data[c.dataIndex];
- }
- } else {
- dd[c.dataIndex] = s[i].data[c.dataIndex];
- }
- }
- }
- });
- if(grid.mainField && form && form.keyField){//例如,将pu_id的值赋给pd_puid
- dd[grid.mainField] = Ext.getCmp(form.keyField).value;
- }
- jsonGridData.push(Ext.JSON.encode(dd));
- }
- }
- return jsonGridData;
- },
- isBlank: function(grid, data) {
- var ff = grid.necessaryFields,bool = true;
- if(ff) {
- Ext.each(ff, function(f) {
- if(!Ext.isEmpty(data[f]) && data[f] != 0) {
- bool = false;
- }else {
- bool=true;
- return
- }
- });
- } else {
- if(!grid.necessaryField || !Ext.isEmpty(data[grid.necessaryField])) {
- bool = false;
- }
- }
- return bool;
- },
- });
|