|
|
@@ -0,0 +1,246 @@
|
|
|
+Ext.define('saas.util.QueryUtil', {
|
|
|
+
|
|
|
+ BaseUtil: Ext.create('saas.util.BaseUtil'),
|
|
|
+
|
|
|
+ // 请求页面组件接口模板
|
|
|
+ baseUrl: 'http://192.168.0.181:8560/api/ui/co_view/config?name={xtype}',
|
|
|
+ // 模板替换正则
|
|
|
+ urlRe: /(.*){xtype}(.*)/g,
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得form的字段配置
|
|
|
+ * @param form: form组件
|
|
|
+ */
|
|
|
+ setItems: function(form) {
|
|
|
+ var me = this;
|
|
|
+ debuggre;
|
|
|
+ Ext.each(form.items.items, function(f){
|
|
|
+ if(f.xtype=='core-query-queryformpanel'){
|
|
|
+
|
|
|
+ }else if(f.xtype=='core-query-gridpanel'){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ // xtype = form.xtype,
|
|
|
+ // url = me.baseUrl.replace(me.urlRe, '$1' + xtype);
|
|
|
+ // me.BaseUtil.request({url})
|
|
|
+ // .then(function(response) {
|
|
|
+ // var res = Ext.decode(response.responseText);
|
|
|
+ // if(res.success) {
|
|
|
+ // var config = res.data, items = [];
|
|
|
+ // if(config) {
|
|
|
+ // items = config.items;
|
|
|
+ // //_baseItems
|
|
|
+ // // _BaseColumn: '',
|
|
|
+ // // _RelativeColumn: '',
|
|
|
+ // form.add(items);
|
|
|
+ // }
|
|
|
+ // form.fireEvent('afterSetItems', form, items);
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // .catch(function(response) {
|
|
|
+ // console.error(response);
|
|
|
+ // });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 获得form的字段查询条件
|
|
|
+ * @param form: form组件
|
|
|
+ * @returns Mode: 字段模式,默认MAIN 当f.fieldMode = "DETAIL",Mode->"DETAIL"
|
|
|
+ */
|
|
|
+ getStoreMode: function(form){
|
|
|
+ var Mode = "MAIN";
|
|
|
+ Ext.each(form.items.items, function(f){
|
|
|
+ if(!Ext.isEmpty(f.value)&&f.fieldMode == "DETAIL") {
|
|
|
+ Mode = "DETAIL";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return Mode;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 获得form的字段查询条件
|
|
|
+ * @param form: form组件
|
|
|
+ */
|
|
|
+ getFormCondition: function(form){
|
|
|
+ var condition = "",
|
|
|
+ me = this;
|
|
|
+ Ext.each(form.items.items, function(f){
|
|
|
+ if((f.xtype == 'checkbox' || f.xtype == 'radio')&&f.logic){
|
|
|
+ if(f.value == true) {
|
|
|
+ if(condition == ''){
|
|
|
+ condition += "("+f.logic+")";
|
|
|
+ } else {
|
|
|
+ condition += ' AND (' + f.logic+')';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if(f.xtype == 'datefield' && f.value != null && f.value != '' ){
|
|
|
+ var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
|
|
|
+ if(condition == ''){
|
|
|
+ condition += "to_char("+f.name+",'yyyy-MM-dd')='"+v+"'";
|
|
|
+ } else {
|
|
|
+ condition += " AND to_char("+f.name+",'yyyy-MM-dd')='"+v+"'";
|
|
|
+ }
|
|
|
+ } else if(f.xtype == 'datetimefield' && f.value != null){
|
|
|
+ var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
|
|
|
+ if(condition == ''){
|
|
|
+ condition += f.name + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
|
|
|
+ } else {
|
|
|
+ condition += ' AND ' + f.name + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
|
|
|
+ }
|
|
|
+ } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
|
|
|
+ var endChar = '=';
|
|
|
+ if(condition == ''){
|
|
|
+ condition += f.name + endChar + f.value;
|
|
|
+ } else {
|
|
|
+ condition += ' AND ' + f.name + endChar + f.value;
|
|
|
+ }
|
|
|
+ } else if(f.xtype == 'combo' && f.value == '$ALL'){
|
|
|
+ if(f.store.data.length > 1) {
|
|
|
+ if(condition == ''){
|
|
|
+ condition += '(';
|
|
|
+ } else {
|
|
|
+ condition += ' AND (';
|
|
|
+ }
|
|
|
+ var _a = '';
|
|
|
+ f.store.each(function(d, idx){
|
|
|
+ if(d.data.value != '$ALL') {
|
|
|
+ if(_a == ''){
|
|
|
+ _a += f.name + "='" + d.data.value + "'";
|
|
|
+ } else {
|
|
|
+ _a += ' OR ' + f.name + "='" + d.data.value + "'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ condition += _a + ')';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(!Ext.isEmpty(f.value)){
|
|
|
+ if(me.contains(f.value.toString(), 'BETWEEN', true) && me.contains(f.value.toString(), 'AND', true)){
|
|
|
+ if(condition == ''){
|
|
|
+ condition += f.name + " " + f.value;
|
|
|
+ } else {
|
|
|
+ condition += ' AND (' + f.name + " " + f.value + ")";
|
|
|
+ }
|
|
|
+ } else if(me.contains(f.value.toString(), '||', true)){
|
|
|
+ var str = '';
|
|
|
+ Ext.each(f.value.split('||'), function(v){
|
|
|
+ if(v != null && v != ''){
|
|
|
+ if(str == ''){
|
|
|
+ str += f.name + "='" + v + "'";
|
|
|
+ } else {
|
|
|
+ str += ' OR ' + f.name + "='" + v + "'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(condition == ''){
|
|
|
+ condition += "(" + str + ")";
|
|
|
+ } else {
|
|
|
+ condition += ' AND (' + str + ")";
|
|
|
+ }
|
|
|
+ } else if(f.value.toString().charAt(0) == '!'){
|
|
|
+ if(condition == ''){
|
|
|
+ condition += 'nvl(' + f.name + ",' ')<>'" + f.value.substr(1) + "'";
|
|
|
+ } else {
|
|
|
+ condition += ' AND (nvl(' + f.name + ",' ')<>'" + f.value.substr(1) + "')";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(f.value.toString().indexOf('%') >= 0) {
|
|
|
+ if(condition == ''){
|
|
|
+ condition += f.name + " like '" + f.value + "'";
|
|
|
+ } else {
|
|
|
+ condition += ' AND (' + f.name + " like '" + f.value + "')";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(condition == ''){
|
|
|
+ condition += '('+f.name + "='" + f.value + "')";
|
|
|
+ } else {
|
|
|
+ condition += ' AND (' + f.name + "='" + f.value + "')";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return condition;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * string:原始字符串
|
|
|
+ * substr:子字符串
|
|
|
+ * isIgnoreCase:忽略大小写
|
|
|
+ */
|
|
|
+ contains: function(string, substr, isIgnoreCase){
|
|
|
+ if (string == null || substr == null) return false;
|
|
|
+ if (isIgnoreCase === undefined || isIgnoreCase === true) {
|
|
|
+ string = string.toLowerCase();
|
|
|
+ substr = substr.toLowerCase();
|
|
|
+ }
|
|
|
+ return string.indexOf(substr) > -1;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ queryData: function(grid,condition){
|
|
|
+ var me = this;
|
|
|
+ //判断是否加载数据
|
|
|
+ // url = config.url,
|
|
|
+ // params = config.params,
|
|
|
+ // async = config.async || true,
|
|
|
+ // method = config.method || 'GET',
|
|
|
+ // timeout = config.timeout || 8000;
|
|
|
+ if(Ext.isEmpty(condition)){
|
|
|
+ condition ="1=1";
|
|
|
+ }
|
|
|
+ var params = { keyword: condition,number:1,size:15 };
|
|
|
+ var dataRes = {
|
|
|
+ url :grid.listUrl,
|
|
|
+ async:false,
|
|
|
+ params:params
|
|
|
+ };
|
|
|
+ me.BaseUtil.request(dataRes)
|
|
|
+ .then(function(response) {
|
|
|
+ var res = Ext.decode(response.responseText);
|
|
|
+ if(res.success) {
|
|
|
+ var data = res.data;
|
|
|
+ console.log(data);
|
|
|
+ grid.getStore().loadData(data.list);
|
|
|
+ grid.fireEvent('afterLoadData', grid, data.list);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(response) {
|
|
|
+ console.log(response);
|
|
|
+ // something...
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onQuery: function(parentForm,queryMoreForm){
|
|
|
+ var grid = parentForm.down('grid'),
|
|
|
+ condition = me.QueryUtil.getFormCondition(queryForm),
|
|
|
+ Mode = me.QueryUtil.getStoreMode(queryForm);
|
|
|
+ if(queryMoreForm){//更多查询
|
|
|
+ if(!Ext.isEmpty(condition)){
|
|
|
+ condition = " and ( "+me.QueryUtil.getStoreMode(queryMoreForm)+" ) ";
|
|
|
+ }else{
|
|
|
+ condition = me.QueryUtil.getStoreMode(queryMoreForm);
|
|
|
+ }
|
|
|
+ if(Mode=="MAIN"){
|
|
|
+ me.QueryUtil.getStoreMode(queryMoreForm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log("condition:"+condition);
|
|
|
+ condition = " 1=1 ";
|
|
|
+ if(Mode=="MAIN"){
|
|
|
+ console.log("Mode:"+Mode+",查询当前列表");
|
|
|
+ me.queryData(grid,condition);
|
|
|
+ }else{
|
|
|
+ console.log("Mode:"+Mode+",查询当前关联列表");
|
|
|
+ //若明细字段含明细字段注意切换数据源 grid.reconfigure(store, columns);
|
|
|
+ //关联viewName = 关联viewName+"-RelativeGrid"
|
|
|
+ var viewName = parentForm.viewName+"-RelativeGrid";
|
|
|
+ console.log("grid:");
|
|
|
+ console.log(grid);
|
|
|
+ me.GridUtil.setColumns(grid,"http://192.168.0.181:8560/api/ui/co_view/config?name="+viewName);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+});
|