Skip to content

Instantly share code, notes, and snippets.

@vikingmute
Last active August 29, 2015 13:57
Show Gist options
  • Save vikingmute/9481510 to your computer and use it in GitHub Desktop.
Save vikingmute/9481510 to your computer and use it in GitHub Desktop.
simple er esui workflow
//start action.js
/**
* 关键字报表Action
* @author zhangxuan06
*/
define(function (require) {
//get the shit together
var Action = require('common/list/List');
var util = require('er/util');
var accountTree = require('common/accountTree');
var updateQuery = require('biz/updateQuery');
var actionDialog = require('biz/actionDialog');
function ListAction() {
Action.apply(this, arguments);
}
//inherits from common list
util.inherits(ListAction, Action);
util.mix(ListAction.prototype, {
modelType: require('./ListModel'),
viewType: require('./ListView')
});
ListAction.prototype.initBehavior = function () {
var me = this;
var view = me.view;
var model = me.model;
//event for enable or disable modBudgetButton
Action.prototype.initBehavior.apply(me, arguments);
view.on('selectMaterial', function (params) {
var selectedIndex = params.evt.selectedIndex;
var modBudgetButton = view.get('modBudgetButton');
if (selectedIndex.length) {
modBudgetButton.enable();
} else {
modBudgetButton.disable();
}
});
view.on('changeTab', function (params) {
updateQuery(me, {
path: params.evt.tab.path,
pageNum: 1
});
});
};
return ListAction;
});
//listModel file
/**
* @file 关键字列表的model文件
* @author zhangxuan06
*/
define(function (require) {
//from common
var Model = require('common/list/ListModel');
var datasource = require('common/datasource');
var url = require('biz/url');
var getQuery = require('biz/getQuery');
//base shit
function ReportListModel() {
var model = this;
Model.apply(model, arguments);
var options = getQuery();
var params = {
pageNum: options.pageNum - 1,
pageSize: options.pageSize,
unitId: options.id
/*dateStart: options.dateStart,
dateEnd: options.dateEnd,
level: options.level,
levelId: options.id*/
};
//the datasource baby~
model.datasource = [
{
retrieve: datasource.constant(options),
dump: 1
},
{
retrieve: datasource.remote(url.GET_KEYWORD_LIST, {
method: 'GET',
data: params
}),
dump: 1
},
{
total: datasource.remote(url.GET_REPORT_TOTAL, {
method: 'GET',
data: {
level: options.level,
id: options.id,
dateStart: options.dateStart,
dateEnd: options.dateEnd
}
})
}
];
}
//you can add some spicy when model is ready
ReportListModel.prototype.prepare = function () {
var model = this;
Model.prototype.prepare.apply(model, arguments);
//overwrite tabIndex
model.set('tabIndex', 1);
};
var util = require('er/util');
//babymaker
util.inherits(ReportListModel, Model);
return ReportListModel;
});
//listView.js
/**
* @file 关键词列表view
* @author zhangxuan06
*/
define(function (require) {
var UIView = require('common/list/ListView');
require('er/tpl!./list.tpl.html');
function ReportListView() {
UIView.apply(this, arguments);
}
var util = require('er/util');
util.inherits(ReportListView, UIView);
var buildUrl = require('biz/buildUrl');
var config = require('biz/lang/unit');
var tableFields = [
{
title: '关键词',
field: 'keyword',
width: 100,
content: function (item) {
return item.word || '--';
}
},
{
title: '推广计划',
field: 'plan',
width: 100,
content: function (item) {
return item.planName || '--';
}
},
{
title: '推广单元',
field: 'unit',
width: 100,
content: function (item) {
return item.unitName || '--';
}
},
{
title: '竞价',
field: 'bid',
width: 100,
content: function (item) {
return item.bid || '--';
}
}
];
util.mix(ReportListView.prototype, {
template: 'keywordList',
uiProperties: {
ListTable: {
datasource: '@list',
editable: 1,
columnResizable: 1,
select: 'multi',
fields: tableFields
},
modBudgetButton: {
disabled: 1
}
},
uiEvents: {
},
enterDocument: function () {
var view = this;
UIView.prototype.enterDocument.apply(view, arguments);
}
});
return ReportListView;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment