select2根据传入的url参数动态添加option

(function ($) { 
    var FundArchivementsDSHome = function () { };
    //初始化
    FundArchivementsDSHome.load = function () {
        init();
        ResultDSChart();
    };
//根据url动态添加select2的option
    var init = function (callback) {
        let fundName = getUrlParam("fundName", true);
        let fundCode = getUrlParam("fundCode");
        if (fundCode !== "0" && fundCode !== null) {
            var option = new Option(fundName, fundCode, true, true);
            $('#FundListS').append(option);
        } 
    };
    var ResultDSChart = function (callback) {
        var data_url = CPRO.getVirtualPath() + "/FundArchivementsDS/GetResultDataByFund";
        var chart = echarts.init(document.getElementById('_ResultDSChart'));
        chart.showLoading({
            text: "加载中..."
        });
        var fundID = $("#FundListS option:selected").attr("value");
        var fundName = $("#FundListS  option:selected").text().replace(/[\r\n]/g, "").replace(/[ ]/g, "");
        if (fundName.length === 0) {
            fundID = "0";
        }
        $.ajax({
            url: data_url,
            type: 'get',
            data: "fundID=" + fundID,
            cache: false,
            dataType: 'json',
            async: true,
            success: function (result) {
                chart.hideLoading();
                if (result) {
                    var option = {
                        grid: {
                            bottom: 80
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'cross',
                                animation: false,
                                label: {
                                    backgroundColor: '#505765'
                                }
                            },
                            extraCssText: 'width:300px;min-height:60px;'
                        },
                        dataZoom: [
                            {
                                show: true,
                                realtime: true,
                                start: 60,
                                end: 100
                            }
                        ],
                        xAxis: [
                            {
                                type: 'category',
                                data: result.xColloums,
                            }
                        ],
                        yAxis: [
                            {
                                name: '数据总量',
                                type: 'value'
                            }
                        ],
                        series: [result.projectmodel]
                    };
                    chart.clear();
                    chart.setOption(option);
                    chart.off('click');
                    
                }
            },
            error: function (errorMsg) {
                //alert("图表请求数据失败!" + errorMsg);
                console.log(errorMsg);
                chart.hideLoading();
            }
        });
    };
    $("#FundListS").change(function (data) {
        var fundID = $("#FundListS option:selected").attr("value");
        var fundName = $("#FundListS  option:selected").text().replace(/[\r\n]/g, "").replace(/[ ]/g, "");
        if (fundName.length === 0) {
            fundID = "0";
        }
        if (window.location.href.toLowerCase().indexOf("fundarchivementsds") !== -1) {
            ResultDSChart();
        }
    });
    var getUrlParam = function (name, decodeURI) {
        //console.log(name);
        //构造一个含有目标参数的正则表达式对象
        var reg = new RegExp("(^|&)" + name.toLowerCase() + "=([^&]*)(&|$)");
        //匹配目标参数
        var url = decodeURI ? decodeURIComponent(window.location.search.toLowerCase()) : window.location.search.toLowerCase();
        var r = url.substr(1).match(reg);
        //console.log(r);
        //返回参数值
        if (r !== null) return unescape(r[2]); return null;
    };
    $('#FundListS').select2({
        placeholder: '请输入',
        allowClear: true,
        ajax: {
            url: function (params) {
                return CPRO.getVirtualPath() + "/FundDataStatistics/GetFundList";
            },
            dataType: 'json',
            delay: 250,
            data: function (params) {
                var queryParameters = {
                    keywords: params.term
                };
                return queryParameters;
            },
            processResults: function (data) {
                return {
                    results: data.message
                };
            },
            cache: true
        }
    });
    window.CPRO.FundArchivementsDS = FundArchivementsDSHome;
})(jQuery);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值