You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.2 KiB

define(function (require, exports, module) {
function QueryPanelAdapter(id, args) {
this.id = id;
this.vmodel = {};
this.actions = args.actions || {}
this.source = args.source
this.data = {}
_init(this, args.data);
}
function _init(self, data) {
if (self.source.isDataSource) {
if (data) {
data.master.forEach(q => {
if (q.queryschemetype === 'fixed' && q.masteruiobjcode === self.source.uiObjCode) {
self.data.fixed = _.extend({}, q)
self.data.fixed.items = _.where(data.detail, { queryschemeid: q.queryschemeid })
}
if (q.queryschemetype === 'default' && q.masteruiobjcode === self.source.uiObjCode) {
self.data.default = _.extend({}, q)
self.data.default.items = _.where(data.detail, { queryschemeid: q.queryschemeid })
}
})
}
self.source.on('onBeforeSearch', function (ds, params) {
if (!self.checkEditorsRequired()) {
params.isCancel = true;
return false;
}
});
self.source.on('onGetQueryParams', function (ds, params) {
//如果查询方案有必填项字段 不加下方代码会报错
if (ds.linkQuery) {
return;
}
var values = self.getValues();
if (ds.dataObjType == Store.Enums['DataObjType'].STOREDPROC) {
for (var key in self.vmodel.$editors) {
var col = ds.getColumn(key);
if (col) {
col.paraValue = values[key] || null;
}
}
return
}
if (Object.keys(values).length > 0) {
var projectQuery = {};
var relations = ds.getDetailRelations();
var relationArray = [];
for (var i = 0; i < relations.length; i += 1) {
var relation = relations[i];
relationArray.push({
detailDatasetName: relation.detail.datasetName,
detailKey: relation.detailColumns.join(','),
masterKey: relation.masterColunms.join(',')
});
}
projectQuery.querySchemeId = self.getCurrentSchemeId();
projectQuery.inputInfo = values;
projectQuery.detailRelation = relationArray;
projectQuery.funcCode = ds.funcCode;
projectQuery.uiObjCode = ds.uiObjCode;
params.projectQuery = projectQuery;
return
}
params.keywordQuery = {
keyword: self.getKeyword()
}
});
}
}
/**
* avalon初始化组件时调用
* @return {[type]} [description]
*/
QueryPanelAdapter.prototype.init = function () {
};
QueryPanelAdapter.prototype.getValues = function () {
if (this.vmodel.$getValues) {
return this.vmodel.$getValues();
}
return {};
};
QueryPanelAdapter.prototype.getKeyword = function () {
if (this.vmodel.$getKeyword) {
return this.vmodel.$getKeyword();
}
return '';
};
QueryPanelAdapter.prototype.getCurrentSchemeId = function () {
if (this.vmodel.$getSchemeId) {
return this.vmodel.$getSchemeId();
}
};
QueryPanelAdapter.prototype.checkEditorsRequired = function () {
if (this.vmodel.$checkEditorsRequired) {
return this.vmodel.$checkEditorsRequired();
}
};
QueryPanelAdapter.prototype.getValueByFieldName = function (fieldname) {
if (this.vmodel.$getValueByFieldName) {
return this.vmodel.$getValueByFieldName(fieldname);
}
};
return QueryPanelAdapter;
})