custom-query.vue 23 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
<template>
    <div class="customQueryBody">
        <!--查询页签区域,包括:高级查询、表格等-->
        <query-tabs
            :queryHandler="queryHandler"
            :seniorQuery="seniorQuery"
            :dynamicSeniorQueryCondition='dynamicSeniorQueryCondition'
            :isShowTabCountZero='isShowTabCountZero'
            :contentIcon='contentIcon'
            :noDataObject='noDataObject'
            ref='queryTabs'
            :extrCondition='extrCondition'
            :queryBus="queryBus"
            :defaultGroup='defaultGroup'
            :groups="groups"
            :content="content"
            @innerSceneQuery='innerSceneQuery'
            @senior-query-data-change="handleSeniorQueryDataChange"
            :groupCount="groupCount"
            :extraActionObject="extraActionObject"
            :tableHeight="tableHeight"
        />
    </div>
</template>

<script>
import QueryTabs from "./query-tabs.vue";
import helper from "./helper/index.js";
import QueryUtil from "./queryUtil.js";
export default {
    name: "CustomQuery",
    data() {
        return {
            contentIcon: "", //查询内容图标
            isShowNoticeLine: false, //是否展示提示信息
            isOpenDrawer: false, //是否打开已标记资产卡片
            showMark: false, //配置是否展示已标记资产
            clicked: false, //点击配置时打开已标记资产卡片
            queryBus: helper.generateQueryBusObject(), //默认查询列表配置信息
            groups: [], //查询配置中页签数组配置集合
            isShowTabCountZero: true, //控制展示页签
            content: {}, //查询元数据配置内容
            groupCount: null, //自定义查询页签
            titleBar: { //查询标题工具栏
                title: "",
                description: "",
                fuzzySearch: [],
                actions: [],
                mark: {}
            },
            remind: [], //提醒信息数组
            text: "", //默认第一条提醒信息内容
            showUseListDrawer: false, //控制展示领用选择组件
            dataconfig: {}, //资产个性化代码,关于领用组件
            queryHandler: {}, //操作表格数据的方法对象
        };
    },
    watch: {
        remind() {
            this.text = this.remind && this.remind.length > 0 ? this.remind[0].describe : "";
        },
        groups(newVal, oldVal) {
            if (newVal) {
                this.getGroup(this.defaultGroup);
            }
        },
        //监听templateName改变时获取查询元数据配置
        // templateName(val) {
        //     if (val) {
        //         console.log(123123, val)
        //         this.initTemplate(val);
        //     }
        // },
        //监听查询元数据配置变化时
        config(val) {
            if (val && !this.templateName) {
                this.initConfig(JSON.parse(val));
            }
        },
        queryBus: {
            deep: true,
            handler(v) {
                this.$emit('query-bus-change', v)
            },
        },
    },
    methods: {
        handleSeniorQueryDataChange(v) {
            this.$emit('senior-query-data-change', v)
        },
        //获取相关通知信息,确认是否展示通知区域
        getNotice() {
            let obj = {
                datasource: this.remind[0].datasource
            };
            //@king GMS中拿$http
            window.GMS.$http.post(
                QueryUtil.api.count,
                JSON.stringify(obj),
                {
                    contentType: "application/json"
                }
            ).then((response) => {
                let data = response.data;
                if (data > 0) {
                    this.isShowNoticeLine = true;
                } else {
                    this.isShowNoticeLine = false;
                }
            }).catch((error) => {
                this.isShowNoticeLine = false;
            });
        },
        //关闭通知区域
        closeLine() {
            this.isShowNoticeLine = false;
        },
        //选择内置查询方案时触发(个性化)
        innerSceneQuery(data) {
            let currentGroup = this.queryBus.currGroup;
            this.forItemAndGroup(data, currentGroup);
        },
        //通知信息点击处理时触发(个性化)
        clickHandle() {
            let handleGroup = this.remind[0].handle.group;
            let handleScene = this.remind[0].handle.scene;
            let group = this.getGroup(handleGroup);
            let item = this.getScene(group, handleScene);
            if (!item) {
                return;
            }
            this.forItemAndGroup(item, group);
        },
        //通过name值得到对应页签数组groups中的页签配置对象group
        getGroup(groupName) {
            if (!groupName) {
                return null;
            }
            let group = {};
            for (let i = 0; i < this.groups.length; i++) {
                let item = this.groups[i];
                if (groupName == item.name) {
                    this.$refs.queryTabs.tabOnClick(i);
                    this.$refs.queryTabs.labelStr = String(i);
                    group = item;
                    break;
                }
            }
            group.content = group.content ? group.content : this.content
            group.content.scenes = group.content.scenes ? group.content.scenes : this.content.scenes;
            group.content.arguments = group.content.arguments ? group.content.arguments : this.content.arguments;
            return group;
        },
        //通过name值得到对应页签内查询方案数组配置的查询方案
        getScene(group, sceneName) {
            if (!group || !group.content) {
                return
            }
            //得到group中content中scenes中items项
            let scenes = group.content.scenes;
            if (!scenes || !scenes.items || scenes.items.length == 0) {
                return null;
            }
            let items = scenes.items;
            for (let i = 0; i < items.length; i++) {
                let item = items[i];
                if (sceneName == item.name) {
                    return item;
                }
            }
            return null;
        },
        //针对当前查询页签配置group和查询方案item配置关联?
        forItemAndGroup(item, group) {
            let result = [];
            let obj = {};
            for (let i = 0; i < item.conditions.length; i++) {
                let iItem = item.conditions[i];
                obj = {};
                if (iItem.argsId) {
                    obj.name = iItem.name;
                    obj.value = iItem.values;
                    obj.dataType = iItem.dataType;
                    result.push(obj);
                } else {
                    let args = group.content.arguments;
                    if (!args || !args.items || args.items.length == 0) {
                        return;
                    }
                    for (let j = 0; j < args.items.length; j++) {
                        let jItem = args.items[j];
                        for (let k = 0; k < jItem.length; k++) {
                            let kItem = jItem[k];
                            if (iItem.argsId == kItem.id) {
                                obj = {
                                    id: iItem.argsId,
                                    title: kItem.title,
                                    name: iItem.name,
                                    value: iItem.values,
                                    dataType: kItem.dataType,
                                    text: iItem.text
                                };
                                if (kItem.type == "INPUT") {
                                    obj.text = iItem.values;
                                    if (kItem.dataType == "STRING") {
                                        obj.type = "strInput";
                                        obj.fuzzySearch = kItem.fuzzySearch == false ? false : true;
                                    }
                                    if (kItem.dataType == "NUMBER") {
                                        obj.type = "numInput";
                                    }
                                    result.push(obj);
                                    break;
                                } else if (kItem.type == "PERSON") {
                                    obj.type = "person";
                                    result.push(obj);
                                    break;
                                } else if (kItem.type == "DEPARTMENT") {
                                    obj.type = "department";
                                    result.push(obj);
                                    break;
                                } else if (kItem.type == "DEPOSITARY") {
                                    obj.type = "depositary";
                                    result.push(obj);
                                    break;
                                } else if (kItem.type == "DATE") {
                                    obj.text = this.toTimeStr(iItem.values);
                                    obj.type = "DATE";
                                    result.push(obj);
                                    break;
                                } else if (kItem.type == "SELECT") {
                                    if (kItem.config.isMulti) {
                                        obj.isMulti = true;
                                        obj._index = [];
                                        obj.text = [];
                                        for (let i = 0; i < kItem.config.values.length; i++) {
                                            obj._index.push(-1);
                                        }
                                        for (let i = 0; i < iItem.values.length; i++) {
                                            for (let j = 0; j < kItem.config.values.length; j++) {
                                                if (iItem.values[i] == kItem.config.values[j].value) {
                                                    this.$set(obj._index, j, j);
                                                    obj.text.push(kItem.config.values[j].title);
                                                    break;
                                                }
                                            }
                                        }
                                    } else {
                                        obj._index = "";
                                        obj.text = "";
                                        for (let i = 0; i < iItem.values.length; i++) {
                                            for (let j = 0; j < kItem.config.values.length; j++) {
                                                if (iItem.values[i] == kItem.config.values[j].value) {
                                                    obj._index = j;
                                                    obj.text = kItem.config.values[j].title;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    obj.type = "select";
                                    result.push(obj);
                                    break;
                                } else if (kItem.type == "RANGE") {
                                    if (kItem.dataType == "DATE") {
                                        obj.type = "dateRange";
                                        obj._index = -1;
                                        obj.text = this.toTimeStr(obj.value.min) + " - " + this.toTimeStr(obj.value.max);
                                        if (kItem.config.values && kItem.config.values.length != 0) {
                                            for (let i = 0; i < kItem.config.values.length; i++) {
                                                if (obj.value.min == kItem.config.values[i].min && obj.value.max == kItem.config.values[i].max) {
                                                    obj.isChoseEnum = true;
                                                    obj._index = i;
                                                    obj.text = kItem.config.values[i].title;
                                                    break;
                                                }
                                            }
                                        }
                                        result.push(obj);
                                        break;
                                    }
                                    if (kItem.dataType == "NUMBER") {
                                        obj.type = "numRange";
                                        obj._index = -1;
                                        obj.text = obj.value.min + "-" + obj.value.max;
                                        if (kItem.config.values && kItem.config.values.length != 0) {
                                            for (let i = 0; i < kItem.config.values.length; i++) {
                                                if (obj.value.min == kItem.config.values[i].min && obj.value.max == kItem.config.values[i].max) {
                                                    obj.text = kItem.config.values[i].title;
                                                    obj.isChoseEnum = true;
                                                    obj._index = i;
                                                    break;
                                                }
                                            }
                                        }
                                        result.push(obj);
                                        break;
                                    }
                                } else if (kItem.type == "DROPDOWN") {
                                    if (kItem.config.isMulti == true) {
                                        obj.text = [];
                                        for (let i = 0; i < iItem.values.length; i++) {
                                            for (let j = 0; j < kItem.config.values.length; j++) {
                                                if (iItem.values[i] == kItem.config.values[j].value) {
                                                    obj.text.push(
                                                        kItem.config.values[j].title
                                                    );
                                                    break;
                                                }
                                            }
                                        }
                                    } else {
                                        obj.text = "";
                                        for (let k = 0; k < kItem.config.values.length; k++) {
                                            if (iItem.values == kItem.config.values[k].value) {
                                                obj.text = kItem.config.values[k].title;
                                                break;
                                            }
                                        }
                                    }
                                    obj.type = "dropdown";
                                    result.push(obj);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            let conditions = JSON.parse(JSON.stringify(result));
            window.GMS.vbus.$emit("getQueryPlanData", conditions);
        },
        //打开标记资产卡片
        openDrawer() {
            this.clicked = true;
            this.$nextTick(function () {
                if (this.titleBar.mark.type == "platform") {
                    this.showUseListDrawer = true;
                    this.dataconfig = {
                        types: 1
                    };
                } else {
                    this.isOpenDrawer = true;
                    this.$refs.markfund.refreshFirstEnterData();
                }
            });
        },
        //资产个性化,关闭资产领用组件触发
        closeUseListDrawer() {
            this.showUseListDrawer = false;
        },
        //关闭已标记资产
        closeDrawer() {
            this.isOpenDrawer = false;
        },
        //模糊搜索时触发
        fuzzySearch() {
            this.$refs.queryTabs.buttonRefreshData();
        },
        //日期格式转为年-月-日
        toTimeStr(timeStamp) {
            var timeDate = new Date(timeStamp);
            var year = timeDate.getFullYear(); //当前年份
            var month = timeDate.getMonth() + 1; //当前月份
            var date = timeDate.getDate(); //天
            var timeStr = year + "-" + month + "-" + date;
            return timeStr;
        },
        //对于页签数组进行初始化,使页签下功能进行完善,包括:表格(table)、场景(scenes)、动作(actions)、datasource和高级查询(arguments)等
        initMeta(groups, config) {
            for (let i = 0; i < groups.length; i++) {
                let item = groups[i];
                if (!item.content) {
                    item.content = JSON.parse(JSON.stringify(config.content));
                } else {
                    let content = item.content;
                    content.datasource = content.datasource ? content.datasource : config.content.datasource;
                    content.actions = content.actions ? content.actions : JSON.parse(JSON.stringify(config.content.actions));
                    content.table = content.table ? content.table : JSON.parse(JSON.stringify(config.content.table));
                    content.arguments = content.arguments ? content.arguments : JSON.parse(JSON.stringify(config.content.arguments));
                    if (!content.scenes && config.content.scenes) {
                        content.scenes = JSON.parse(JSON.stringify(config.content.scenes));
                    }
                    if (!content.page && config.content.page) {
                        content.page = JSON.parse(JSON.stringify(config.content.page));
                    }
                }
            }
            return config;
        },
        //初始化查询元数据主页签(外层)配置,此时config为整体的查询配置content
        initConfig(config) {
            //this.noDataObject = config.noDataObject;//针对从设计期元数据配置查询无数据内容时的配置信息,包括:提示信息与字体图标
            this.contentIcon = config.contentIcon ? "#icon-_" + config.contentIcon : "";
            this.queryBus.config = this.initMeta(config.groups ? config.groups : [{}], config);
            this.titleBar = {
                title: config.title,
                description: config.description,
                name: config.name,
                fuzzySearch: config.fuzzySearch ? config.fuzzySearch : [],
                actions: config.actions ? config.actions : [],
                mark: config.mark ? config.mark : {}
            };
            this.isShowTabCountZero = config.isShowTabCountZero == false ? false : true;
            this.groups = config.groups ? config.groups : [{}];
            this.content = config.content;
            this.groupCount = config.groupCount;
            this.remind = config.remind ? config.remind : [];
            if (this.remind.length == 0) {
                this.isShowNoticeLine = false;
            } else {
                this.getNotice();
            }
            if (config.mark) {
                this.showMark = true;
            }
        },
        //通过查询templateName获取元数据配置
        initTemplate(templateName) {
            let url = `/bcp/query/advance/view/${templateName}`;
            window.GMS.$http.get(url).then(
                function(response) {
                    if (response.data) {
                        this.initConfig(response.data);
                    }
                }.bind(this)
            ).catch(
                function(error) {
                    console.log("获取配置文件错误");
                }.bind(this)
            )
        }
    },
    props: {
        templateName: {
            type: String,
            default: ""
        },
        config: {
            type: String,
            default: "",
            require: true
        },
        //默认页签,推测是资产在元数据自定义的默认页签,这里传的值为默认页签名称,但在实现中并没有特别处理,疑问?
        defaultGroup: {
            type: String,
            default: ""
        },
        extrCondition: {
            type: Array,
            default: function () {
                return new Array();
            }
        },
        dynamicSeniorQueryCondition: {
            type: Array,
            default: function () {
                return new Array();
            }
        },
        title: {
            type: String,
            default: ""
        },
        //查询增加额外属性,用来处理额外的动作触发传值
        extraActionObject: {
            type: [Object, Array]
        },
        tableHeight: {
            type: Number,
            default: function () {
                return window.innerHeight - 380;
            }
        },
        noDataObject: {
            type: Object,
            default() {
                return {
                    text: '暂无业务数据',
                    icon: '#icon-_zanwuyewushuju'
                }
            }
        },
        seniorQuery: {
            type: Array,
            default() {
                return []
            }
        }
    },
    mounted() {
        var that = this;
        this.queryHandler.getTemplate = function () {
            return that.templateName;
        };
        this.queryHandler.getTitle = function () {
            return that.titleBar.title;
        };
        if (this.templateName) {
            this.initTemplate(this.templateName);
        } else {
            this.initConfig(JSON.parse(this.config));
        }
    },
    components: {
        QueryTabs,
    },
    created() {
        //@king  关注下这里,还没有处理defaultGroup
        // if (this.$route.query.defaultGroup) { //获取默认页签
        // 	this.defaultGroup = this.$route.query.defaultGroup
        // }
    }
};
</script>
<style lang='less' scoped>
.circle {
    font-weight: bold;
    padding: 10px 30px;
    color: #565555;

    b {
        height: 4px;
        width: 4px;
        margin: 4px 4px 3px 10px;
        display: inline-block;
        border-radius: 50%;
        background-color: #565555;
    }
}

.customQueryBody {
    padding: 0px;
    position: relative;
    box-sizing: border-box;
    height: 100%;
}

.height15 {
    height: 15px;
}

.tips {
    position: absolute;
    left: 120px;
    top: 18px;
    width: 14px;
    height: 14px;
    text-align: center;
    line-height: 14px;
    background-color: #828fa0;
    border-radius: 50%;
    color: #fff;
}
</style>