bootgrid插件+knockout.JS列表展示

var mpf = mpf || {};
mpf.viewModel = mpf.viewModel || {};
var myChartByProject;

mpf.viewModel.search = function (data) {
var self = this;
self.idField = data.idField || “FID”;
self.urls = data.urls;
self.resx = data.resx;
self.index = null;
self.dataSource = ko.mapping.fromJS(data.dataSource);
self.form = ko.mapping.fromJS(data.form);
delete self.form.ko_mapping;

this.defaulltFormatters = {
    "FIDFormatter": function (column, row) { return row.Name; },
    "DateFormatter": function (column, row) {
        //对比一下,如果是最小时间或者没有初始化时间,则清空
        var tempDate = utils.formatDate(eval("row." + column.id), "yyyy-MM-dd");
        if (new Date(tempDate) > new Date("2001-01-01")) {
            return tempDate;
        }
        else {
            return "";
        }
    }, 
};

$("#gridlist").bootgrid({
    ajaxSettings: {
        method: "GET",
        cache: false
    },
    ajax: true,
    selection: false,
    rowSelect: true,
    sorting: true,
    labels:
    {
        noResults: bootgrid_noResults, //多语言
        all: bootgrid_all,
        loading: bootgrid_loading,
        refresh: bootgrid_refresh,
        search: bootgrid_search,
        infos: bootgrid_infos
    },
    url: "/api/UserCenter/UM/UMAppointment/Pagging", //请求地址
    post: function () {
        /* To accumulate custom parameter with the request object */
        var result = ko.toJS(self.form); //请求的参数
        result.sort = utils.GetCustomerOrderInfo(true);
        result.order = utils.GetCustomerOrderInfo(false);
        return result;
    },
    converters: {
        datetime: {
            from: function (value) {
                return moment(value, "YYYY-MM-DD");
            },
            to: function (value) {
                return value.format("LL");
            }
        }
    },
    formatters: self.defaulltFormatters
}).on("load.rs.jquery.bootgrid", function (e) {
    self.index = com.loading();
}).on("loaded.rs.jquery.bootgrid", function (e) {
    com.closeLoading(self.index);
    var totalRowCount = $("#gridlist").bootgrid("getTotalRowCount");
    //如果没有数据,则隐藏分页控件
    if (totalRowCount <= 0) {
        if (!$("#gridlist").parent().hasClass("bootgrid-hiddenInfoBar")) {
            $("#gridlist").parent().addClass("bootgrid-hiddenInfoBar");
        }
    }
    else {
        if ($("#gridlist").parent().hasClass("bootgrid-hiddenInfoBar")) {
            $("#gridlist").parent().removeClass("bootgrid-hiddenInfoBar");
        }
    }
});

};

var UMAppointmentIndex = {
Status: 0,
IsDisplay: false,
FID: '',
Init: function () {
    UMAppointmentIndex.Status = $("#status").val();
    UMAppointmentIndex.ChangeTabStatus(UMAppointmentIndex.Status, 0);
}, ChangeTabStatus: function (val, type) {
    UMAppointmentIndex.Status = val;
    $("#status").val(val).change();
    switch (val) {
        case "0":
            $("#tab li all").removeClass("curr").addClass("curr");
            $("#tab_li_wait").removeClass("curr");
            $("#tab_li_accomplish").removeClass("curr");
            break;
        case "3":
            $("#tab_li_all").removeClass("curr");
            $("#tab_li_wait").removeClass("curr").addClass("curr");
            $("#tab_li_accomplish").removeClass("curr");
            break;
        case "2":
            $("#tab_li_all").removeClass("curr");
            $("#tab_li_wait").removeClass("curr");
            $("#tab_li_accomplish").removeClass("curr").addClass("curr");
            break;
    }
    if (type != 0) {
        UMAppointmentIndex.AppointmentLodingData();
    }
}, AppointmentLodingData: function () {
    $("#gridlist").bootgrid("deselect");
    $("#gridlist").bootgrid("clear");
    $("#gridlist").bootgrid("reload");
}, ProductPutaway: function (vid) {
    //同意预约提示框
    UMAppointmentIndex.IsDisplay = true;
    UMAppointmentIndex.FID = vid;
    com.confirmLayer("您确定要同意预约吗?", UMAppointmentIndex.UpdateIsDisplay);
}, ProductSoldOut: function (vid) {
    //拒绝预约提示框
    UMAppointmentIndex.IsDisplay = false;
    UMAppointmentIndex.FID = vid;
    com.confirmLayer("您确定要拒绝预约吗?", UMAppointmentIndex.UpdateIsDisplay);
},
UpdateIsDisplay: function () {
    com.closeLayer();
    $.get("/api/UserCenter/UM/UMAppointment/AuditAppointment", { id: UMAppointmentIndex.FID, auditResult: UMAppointmentIndex.IsDisplay }, function (data) {
        if (data) {
            if (data.IsTrue) {
                com.succeedMessage("操作成功!");
                UMAppointmentIndex.AppointmentLodingData();
                //setTimeout(function () { window.location.reload(); }, 1000);
            } else {
                if (data.ValidationList.length > 0) {
                    com.errorMessage(data.ValidationList[0].Value);
                } else {
                    com.errorMessage("操作失败,请重新操作!");
                }
            }
        }
    });
}, LoadInitStatisticsPeriodType: function () {
    //预约时间段
    var dom = document.getElementById("main");
    var myChart = echarts.init(dom);
    $.get("/api/UserCenter/UM/UMAppointment/GetStatisticsPeriodType", {}, function (data) {
        if (data != null && data.length > 0) {
            var vjson = eval("(" + data + ")");
            var vname = new Array();
            var vjsd = "";
            var vdata;
            $.each(vjson, function (index, item) {
                vname[index] = item.Name;
                vjsd += "{\"value\":" + item.Value + ",\"name\":\"" + item.Name + "\"},";
            });
            if (vjsd.length > 0) {
                vjsd = "[" + vjsd.substring(0, vjsd.length - 1) + "]";
                vdata = eval("(" + vjsd + ")");
            }
            option = {
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    data: vname
                },
                series: [
                    {
                        name: '预约时间段',
                        type: 'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '20',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data: vdata
                    }
                ]
            };
            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
        }
    });
}, 
LoadInitStatisticsResultType: function () {
    //预约统计
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    $.get("/api/UserCenter/UM/UMAppointment/GetStatisticsResultType", {}, function (data) {

        var datatime;
        var ResultType;
        //    var list = [
        //{ "Date": "2016-11-12", "ResultType": "等待确认", "Value": "1", "Tag": null, "IsFromCached": false, "IsSuccess": true, "IsAuth": false, "IsMustAuth": false, "ErrorList": [], "ValidationList": [], "series": [120, 132, 101, 134, 90, 230, 210] },
        //{ "Date": "2016-11-18", "ResultType": "已确认", "Value": "1", "Tag": null, "IsFromCached": false, "IsSuccess": true, "IsAuth": false, "IsMustAuth": false, "ErrorList": [], "ValidationList": [], "series": [220, 182, 191, 234, 290, 330, 310] },
        //{ "Date": "2016-12-17", "ResultType": "预约成功", "Value": "1", "Tag": null, "IsFromCached": false, "IsSuccess": true, "IsAuth": false, "IsMustAuth": false, "ErrorList": [], "ValidationList": [], "series": [150, 232, 201, 154, 190, 330, 410] }
        //    ];
        var data = $.parseJSON(data);//把data转换成json
        var arr = new Array();
        var xAxis = new Array();
        var seires_data = new Array();
        for (i = 0; i < data.length; i++) {
            var riqi = data[i].Date;
            var arys1 = new Array();
            arys1 = riqi.split('-');   //日期为输入日期,格式为 2013-3-10
            var ssdate = new Date(arys1[0], parseInt(arys1[1] - 1), arys1[2]);
            ssdate.getDay()
            var d = new Date();
            var day = new Array(7);
            day[0] = "星期日"
            day[1] = "星期一"
            day[2] = "星期二"
            day[3] = "星期三"
            day[4] = "星期四"
            day[5] = "星期五"
            day[6] = "星期六"
            var datatime = day[ssdate.getDay()];
            var ResultType = data[i].ResultType;
            var series = data[i].series;

            var obj = new Object();
            obj.name = ResultType;
            obj.type = 'line';
            obj.stack = '总量';
            obj.data = series;

            arr.push(ResultType);
            xAxis.push(datatime);
            seires_data.push(obj);
        }


        option = {
            title: {
                text: null
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: arr
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: xAxis
            },
            yAxis: {
                type: 'value'
            },
            series: seires_data
        };



        if (option && typeof option === "object") {
            myChart.setOption(option, true);
        }

    });
}, FiltrationData: function (obj, mark) {
    $.each(obj, function (index, item) {
        if (mark == index.ResultType) {

        }
    });
}, unique: function (arr) {
    var tmp = new Array();
    for (var i in arr) {
        if (tmp.indexOf(arr[i]) == -1) {
            tmp.push(arr[i]);
        }
    }
    return tmp;
}, showData: function (data) {

}

}

$(function () {
UMAppointmentIndex.Init();
UMAppointmentIndex.LoadInitStatisticsPeriodType();
UMAppointmentIndex.LoadInitStatisticsResultType();
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Knockout.js 是一个基于 MVVM 架构的 JavaScript 框架,它可以帮助我们实现数据绑定、模板渲染、事件绑定等功能。要显示上传文件的进度,我们可以使用 XMLHttpRequest 对象来发送文件,并使用 Knockout.js 来更新进度条的值。 首先,我们需要定义一个 ViewModel,用来绑定页面上的元素和数据: ``` function ViewModel() { var self = this; self.uploadProgress = ko.observable(0); self.uploadFile = function() { var fileInput = document.getElementById("fileInput"); var file = fileInput.files[0]; var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", function(event) { if (event.lengthComputable) { var percentComplete = event.loaded / event.total * 100; self.uploadProgress(percentComplete); } }, false); xhr.open("POST", "/upload"); xhr.send(file); }; } ko.applyBindings(new ViewModel()); ``` 在这个 ViewModel 中,我们定义了一个 uploadProgress 可观察的属性,它用来绑定页面上的进度条。我们还定义了一个 uploadFile 方法,用来上传文件。在上传文件的过程中,我们使用 XMLHttpRequest 的 upload 事件来监听文件上传的进度,如果进度发生变化,我们就更新 uploadProgress 的值,从而更新页面上的进度条。 在 HTML 代码中,我们可以使用 Knockout.js 的数据绑定语法来绑定 uploadProgress 属性,以显示进度条: ``` <input type="file" id="fileInput"> <button data-bind="click: uploadFile">Upload File</button> <div class="progress"> <div class="progress-bar" role="progressbar" style="width: 0%;" data-bind="style: { width: uploadProgress() + '%' }"> <span data-bind="text: uploadProgress() + '%'"></span> </div> </div> ``` 在这个 HTML 代码中,我们使用了 Bootstrap 的进度条样式,并使用了 Knockout.js 的数据绑定语法来绑定 uploadProgress 属性。当 uploadProgress 的值发生变化时,进度条的宽度和文本也会相应地更新。 总结一下,要显示上传文件的进度,我们可以使用 XMLHttpRequest 对象来发送文件,并使用 Knockout.js 来更新进度条的值。我们可以定义一个 ViewModel,用来绑定页面上的元素和数据,定义一个 uploadFile 方法,用来上传文件,使用 XMLHttpRequest 的 upload 事件来监听文件上传的进度,如果进度发生变化,就更新 uploadProgress 的值,从而更新页面上的进度条。在 HTML 代码中,我们可以使用 Knockout.js 的数据绑定语法来绑定 uploadProgress 属性,以显示进度条。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值