Commit c5a27791 by zhoujinhui
parents 1ff33071 1094ee3b
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models.DataWareHouse
{
/// <summary>
/// 平台账单流水
/// </summary>
public class flowing_sales
{
public int id { get; set; }
public string platform { get; set; }
public string website { get; set; }
public string jsondata { get; set; }
public string month { get; set; }
public DateTime createtime { get; set; }
public string orderno { get; set; }
public string accountname { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Dapper;
using System.Linq;
using Bailun.DC.Models;
namespace Bailun.DC.Services.DataWareHouse
{
public class PlatformOrderServices
{
/// <summary>
/// 获取平台站点信息
/// </summary>
/// <param name="platform"></param>
/// <returns></returns>
public List<string> ListPlatformSite(string platform)
{
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString_DW))
{
if(cn.State== System.Data.ConnectionState.Closed)
{
cn.Open();
}
var sql = $"select t1.website from flowing_sales t1 where t1.platform='{platform}' group by t1.website";
return cn.Query<string>(sql).ToList();
}
}
/// <summary>
/// 获取平台销售账单流水
/// </summary>
/// <param name="parameter">分页信息</param>
/// <param name="platform">平台类型</param>
/// <param name="website">站点</param>
/// <param name="account">销售帐号</param>
/// <param name="month">月份</param>
/// <param name="total">符合条件的记录数</param>
/// <returns></returns>
public List<Models.DataWareHouse.flowing_sales> List(int page, string platform, string website, string account, string month,ref int total,int pagesize)
{
var sql = "select * from flowing_sales t1 where 1=1";
var sqlparam = new DynamicParameters();
if(!string.IsNullOrEmpty(platform))
{
sql += " and t1.platform=@platform";
sqlparam.Add("platform", platform);
}
if (!string.IsNullOrEmpty(website))
{
sql += " and t1.website=@website";
sqlparam.Add("website", website);
}
if (!string.IsNullOrEmpty(account))
{
sql += " and t1.accountname=@account";
sqlparam.Add("account", account);
}
if(!string.IsNullOrEmpty(month))
{
sql += " and t1.month=@month";
sqlparam.Add("month", month);
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString_DW))
{
if(cn.State== System.Data.ConnectionState.Closed)
{
cn.Open();
}
if (pagesize > 0)
{
var obj = cn.Page<Models.DataWareHouse.flowing_sales>(page, pagesize, sql, ref total, sqlparam);
return obj.ToList();
}
else
{
var obj = cn.Query<Models.DataWareHouse.flowing_sales>(sql, sqlparam);
return obj.ToList();
}
}
}
}
}
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using System.Threading.Tasks;
namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
{
[Area("DataWareHouse")]
public class PlatformOrderController : Base.BaseController
{
private readonly IHostingEnvironment _hostingEnvironment;
public PlatformOrderController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public IActionResult OrderBillings(string platform)
{
var listsite = new Services.DataWareHouse.PlatformOrderServices().ListPlatformSite(platform);
ViewBag.platform = platform;
ViewBag.sites = listsite;
return View();
}
[HttpPost]
public JsonResult OrderBillingsJson(int page,string platform,string website,string account,string month, int pagesize = 25)
{
if (string.IsNullOrEmpty(platform))
{
return Json(new {
success= false,
msg = "请选择平台类型"
});
}
if(string.IsNullOrEmpty(website))
{
return Json(new {
success = false,
msg = "请选择站点",
});
}
if(string.IsNullOrEmpty(month))
{
return Json(new {
success = false,
msg = "请选择月份"
});
}
if(page<=0)
{
page = 1;
}
int total = 0;
var obj = new Services.DataWareHouse.PlatformOrderServices().List(page, platform, website, account, month, ref total,pagesize);
var list = obj.Select(a => new {
a.accountname,
a.createtime,
jsondata = Newtonsoft.Json.Linq.JRaw.Parse(a.jsondata),
a.month,
a.orderno,
a.platform,
a.website,
});
return Json(new {
success = true,
msg = "",
rows = list,
total = total,
page = page,
totalpage = total/pagesize+(total%pagesize>0?1:0),
});
}
public ActionResult ExportOrderBillings(string platform, string website, string account, string month)
{
if (string.IsNullOrEmpty(platform))
{
return Json(new
{
success = false,
msg = "请选择平台类型"
});
}
if (string.IsNullOrEmpty(website))
{
return Json(new
{
success = false,
msg = "请选择站点",
});
}
if (string.IsNullOrEmpty(month))
{
return Json(new
{
success = false,
msg = "请选择月份"
});
}
var total = 0;
var obj = new Services.DataWareHouse.PlatformOrderServices().List(1, platform, website, account, month, ref total, 0);
if(obj.Count==0)
{
return Json(new
{
success = true,
msg = "没有数据"
});
}
//列头
DataTable dataTable = new DataTable(); //实例化
var objFirst = obj.FirstOrDefault();
var jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(objFirst.jsondata);
var colnames = new List<string>();
foreach (var item in jsonData)
{
dataTable.Columns.Add(item.Key, typeof(string));
colnames.Add(item.Key);
}
foreach (var item in obj)
{
jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(item.jsondata);
DataRow dataRow = dataTable.NewRow();
foreach (var c in jsonData)
{
dataRow[c.Key] = c.Value;
}
dataTable.Rows.Add(dataRow);
}
//for (var i = 0; i < dataTable.Columns.Count; i++)
//{
// colnames.Add(dataTable.Columns[i].ColumnName);
//}
var listVal = new List<string>();
for (int j = 0; j < dataTable.Rows.Count; j++)
{
var s = "";
for (int k = 0; k < dataTable.Columns.Count; k++)
{
string tmpRowValue = dataTable.Rows[j][k].ToString();
s += tmpRowValue + "|";
}
//s = s.Substring(0, s.Length - 1);
listVal.Add(s);
}
var guid = Guid.NewGuid().ToString();
var filename = platform+ " " + month + "的账单流水";
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(listVal, colnames, guid, filepath);
var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
}
}
}
@{
ViewData["Title"] = "平台账单流水";
Layout = "~/Pages/Shared/_MainLayout.cshtml";
ViewBag.Nav = new string[] { "销售平台流水", ViewBag.platform+"账单流水" };
}
<div class="row">
<div class="col-sm-12">
<div class="ibox-content m-b-sm border-bottom">
<form id="toolbar">
<div class="form-inline" style="line-height:40px;">
<div class="form-group">
@*<label>站点</label>
<select id="website" name="website" class="form-control" style="width:130px;">
<option value="">请选择站点</option>
@foreach (var item in ViewBag.sites)
{
<option value="@item">@item</option>
<button class="btn btn-info" type="button" aria-pressed="false"></button>
}
</select>*@
站点:
<div data-toggle="buttons-checkbox" class="btn-group">
@foreach (var item in ViewBag.sites)
{
//<option value="@item">@item</option>
<button class="btn btn-info wsites" type="button" aria-pressed="false" onclick="selWebsite('@item',this)">@item</button>
}
</div>
</div>
<div class="form-group" style="margin-left:10px">
<label>月份</label>
<input id="month" name="month" class="form-control" style="width:100px" value="@(DateTime.Now.AddMonths(-1).ToString("yyyy-MM"))" />
</div>
<div class="form-group">
<label>&nbsp;</label>
<button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
<button id="btnexport" style="" type="button" class="btn btn-success" onclick="ExportCSV()">导出</button>
</div>
</div>
</form>
</div>
<div class="ibox-content m-b-sm border-bottom table-responsive">
<table id="roletable" class="table table-hover table-bordered table-striped" style="table-layout:fixed;">
<thead id="tb_head">
</thead>
<tbody id="tb">
</tbody>
</table>
<div id="page-contain">
<span id="pageresult"></span>
<div id="pagination" class="pagination" style="margin-left:50px;"></div>
</div>
</div>
</div>
</div>
@section css{
<style>
.mules {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/*.pagination ul{
list-style-type:none;
padding:0px;
margin:0px;
}
.pagination ul li{float:left;width:20px;}
*/
.pagination {
margin: 20px 0;
}
.pagination ul {
display: inline-block;
*display: inline;
margin-bottom: 0;
margin-left: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
*zoom: 1;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
padding-left:0px;
}
.pagination ul > li {
display: inline;
}
.pagination ul > li > a,
.pagination ul > li > span {
float: left;
padding: 4px 12px;
line-height: 20px;
text-decoration: none;
background-color: #ffffff;
border: 1px solid #dddddd;
border-left-width: 0;
}
.pagination ul > li > a:hover,
.pagination ul > li > a:focus,
.pagination ul > .active > a,
.pagination ul > .active > span {
background-color: #f5f5f5;
}
.pagination ul > .active > a,
.pagination ul > .active > span {
color: #999999;
cursor: default;
}
.pagination ul > .disabled > span,
.pagination ul > .disabled > a,
.pagination ul > .disabled > a:hover,
.pagination ul > .disabled > a:focus {
color: #999999;
cursor: default;
background-color: transparent;
}
.pagination ul > li:first-child > a,
.pagination ul > li:first-child > span {
border-left-width: 1px;
-webkit-border-bottom-left-radius: 4px;
border-bottom-left-radius: 4px;
-webkit-border-top-left-radius: 4px;
border-top-left-radius: 4px;
-moz-border-radius-bottomleft: 4px;
-moz-border-radius-topleft: 4px;
}
.pagination ul > li:last-child > a,
.pagination ul > li:last-child > span {
-webkit-border-top-right-radius: 4px;
border-top-right-radius: 4px;
-webkit-border-bottom-right-radius: 4px;
border-bottom-right-radius: 4px;
-moz-border-radius-topright: 4px;
-moz-border-radius-bottomright: 4px;
}
.pagination-centered {
text-align: center;
}
.pagination-right {
text-align: right;
}
</style>
}
@section scripts{
<script src="~/js/jspagination/bootstrap-paginator.js"></script>
<script type="text/javascript">
var tb;
var current_page = 1;
var website = '';
$(document).ready(function () {
//list();
laydate.render({ elem: '#month', type: 'month' });
})
function list() {
//var website = $('#website').val();
var month = $('#month').val();
if (website == '') {
alert('请选择站点');
return false;
}
if (month == '') {
alert('请选择月份');
return false;
}
var load_index = layer.load();
$.submit({
url: '@Url.Content("~/DataWareHouse/PlatformOrder/OrderBillingsJson")',
type:'POST',
paramData: 'page=' + current_page + '&platform=@(ViewBag.platform)&website=' + website + '&month=' + month,
func: function (result) {
layer.close(load_index)
$('#tb').html('');
if (result.success) {
//表头
if (result.total == 0) {
alert('没有找到该平台数据,请上传');
return false;
}
var firstrow = result.rows[0].jsondata;
var _head = '<tr>';
for (var i in firstrow) {
_head += '<th style="width:130px;">' + '<div class="mules" title="' + i + '">' + i + '</div>'+'</th>';
}
_head += '</tr>';
$('#tb_head').html(_head);
//内容
for (var i in result.rows) {
var _obj = result.rows[i].jsondata;
var _r = '<tr>';
for (var r in _obj) {
_r += '<td style="width:130px;">' + '<div class="mules" title="' + _obj[r] + '">' + _obj[r] + '</div>' +'</td>';
}
_r += '</tr>';
$('#tb').append(_r);
}
//分页
InitPage(result.totalpage);
$('#pageresult').html('总记录数:' + result.total + ';总页数:' + result.totalpage);
}
else {
alert('获取数据出现异常')
}
}
})
}
function selWebsite(site,data) {
website = site;
$('.wsites').each(function () {
$(this).attr('aria-pressed', 'false');
$(this).removeClass('active');
})
$(data).prop('aria-pressed', 'true');
}
function InitPage(totalpage) {
$('#page-contain').html('<span id="pageresult"></span><div id="pagination" class="pagination" style="margin-left:5px;"></div>');
var container = $('#pagination');
options = {
containerClass: "pagination"
, currentPage: current_page
//, numberOfPages: 6
, totalPages: totalpage
, pageUrl: function (type, page) {
//return null;
}
, onPageClicked: function (e, originalEvent, type, page) {
current_page = page;
list();
}
, onPageChanged: function (page) {
}
};
container.bootstrapPaginator(options);
}
function ExportCSV() {
//var website = $('#website').val();
var month = $('#month').val();
if (website == '') {
alert('请选择站点');
return false;
}
if (month == '') {
alert('请选择月份');
return false;
}
window.open('@Url.Content("~/DataWareHouse/PlatformOrder/ExportOrderBillings")' + '?platform=@(ViewBag.platform)&website=' + website + '&month=' + month);
}
</script>
}
\ No newline at end of file
......@@ -2482,7 +2482,6 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
}
#region 资产负债表-子表
public ActionResult MonetaryFund(DateTime date, int paycompanyid)
{
var m = new Services.FinanceReportServices().GetMonetaryFundCount(date, paycompanyid);
......
......@@ -38,7 +38,7 @@
<label>付款时间</label>
<input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"))" />
<span>至</span>
<input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.ToString("yyyy-MM-dd"))" />
<input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
</div>
<div class="form-group">
<label>利润率</label>
......
......@@ -15,7 +15,7 @@
<div style="float:right;width:100%;">
<div id="rightcontain">
<div class="alert alert-warning">
说明:退款数据统计的是时间段内的退款发生额,并且排除已取消订单的退款。
说明:1、退款数据统计的是时间段内的退款发生额,并且排除已取消订单的退款;2、时间段内没有数据的平台不会显示出来;3、广告费、上架费和退款无法分摊到订单里面,但总利润有减去这三项费用;
</div>
<div class="ibox-content m-b-sm border-bottom">
......
......@@ -49,9 +49,9 @@
</div>
<div class="form-group">
<label>付款时间</label>
<input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
<input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"))" />
<span>至</span>
<input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.ToString("yyyy-MM-dd"))" />
<input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
</div>
<div class="form-group">
<label>&nbsp;</label>
......
/**
* bootstrap-paginator.js v0.5
* --
* Copyright 2013 Yun Lai <lyonlai1984@gmail.com>
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function ($) {
"use strict"; // jshint ;_;
/* Paginator PUBLIC CLASS DEFINITION
* ================================= */
/**
* Boostrap Paginator Constructor
*
* @param element element of the paginator
* @param options the options to config the paginator
*
* */
var BootstrapPaginator = function (element, options) {
this.init(element, options);
},
old = null;
BootstrapPaginator.prototype = {
/**
* Initialization function of the paginator, accepting an element and the options as parameters
*
* @param element element of the paginator
* @param options the options to config the paginator
*
* */
init: function (element, options) {
this.$element = $(element);
var version = (options && options.bootstrapMajorVersion) ? options.bootstrapMajorVersion : $.fn.bootstrapPaginator.defaults.bootstrapMajorVersion,
id = this.$element.attr("id");
if (version === 2 && !this.$element.is("div")) {
throw "in Bootstrap version 2 the pagination must be a div element. Or if you are using Bootstrap pagination 3. Please specify it in bootstrapMajorVersion in the option";
} else if (version > 2 && !this.$element.is("ul")) {
throw "in Bootstrap version 3 the pagination root item must be an ul element."
}
this.currentPage = 1;
this.lastPage = 1;
this.setOptions(options);
this.initialized = true;
},
/**
* Update the properties of the paginator element
*
* @param options options to config the paginator
* */
setOptions: function (options) {
this.options = $.extend({}, (this.options || $.fn.bootstrapPaginator.defaults), options);
this.totalPages = parseInt(this.options.totalPages, 10); //setup the total pages property.
this.numberOfPages = parseInt(this.options.numberOfPages, 10); //setup the numberOfPages to be shown
//move the set current page after the setting of total pages. otherwise it will cause out of page exception.
if (options && typeof (options.currentPage) !== 'undefined') {
this.setCurrentPage(options.currentPage);
}
this.listen();
//render the paginator
this.render();
if (!this.initialized && this.lastPage !== this.currentPage) {
this.$element.trigger("page-changed", [this.lastPage, this.currentPage]);
}
},
/**
* Sets up the events listeners. Currently the pageclicked and pagechanged events are linked if available.
*
* */
listen: function () {
this.$element.off("page-clicked");
this.$element.off("page-changed");// unload the events for the element
if (typeof (this.options.onPageClicked) === "function") {
this.$element.bind("page-clicked", this.options.onPageClicked);
}
if (typeof (this.options.onPageChanged) === "function") {
this.$element.on("page-changed", this.options.onPageChanged);
}
this.$element.bind("page-clicked", this.onPageClicked);
},
/**
*
* Destroys the paginator element, it unload the event first, then empty the content inside.
*
* */
destroy: function () {
this.$element.off("page-clicked");
this.$element.off("page-changed");
this.$element.removeData('bootstrapPaginator');
this.$element.empty();
},
/**
* Shows the page
*
* */
show: function (page) {
this.setCurrentPage(page);
this.render();
if (this.lastPage !== this.currentPage) {
this.$element.trigger("page-changed", [this.lastPage, this.currentPage]);
}
},
/**
* Shows the next page
*
* */
showNext: function () {
var pages = this.getPages();
if (pages.next) {
this.show(pages.next);
}
},
/**
* Shows the previous page
*
* */
showPrevious: function () {
var pages = this.getPages();
if (pages.prev) {
this.show(pages.prev);
}
},
/**
* Shows the first page
*
* */
showFirst: function () {
var pages = this.getPages();
if (pages.first) {
this.show(pages.first);
}
},
/**
* Shows the last page
*
* */
showLast: function () {
var pages = this.getPages();
if (pages.last) {
this.show(pages.last);
}
},
/**
* Internal on page item click handler, when the page item is clicked, change the current page to the corresponding page and
* trigger the pageclick event for the listeners.
*
*
* */
onPageItemClicked: function (event) {
var type = event.data.type,
page = event.data.page;
this.$element.trigger("page-clicked", [event, type, page]);
},
onPageClicked: function (event, originalEvent, type, page) {
//show the corresponding page and retrieve the newly built item related to the page clicked before for the event return
var currentTarget = $(event.currentTarget);
switch (type) {
case "first":
currentTarget.bootstrapPaginator("showFirst");
break;
case "prev":
currentTarget.bootstrapPaginator("showPrevious");
break;
case "next":
currentTarget.bootstrapPaginator("showNext");
break;
case "last":
currentTarget.bootstrapPaginator("showLast");
break;
case "page":
currentTarget.bootstrapPaginator("show", page);
break;
}
},
/**
* Renders the paginator according to the internal properties and the settings.
*
*
* */
render: function () {
//fetch the container class and add them to the container
var containerClass = this.getValueFromOption(this.options.containerClass, this.$element),
size = this.options.size || "normal",
alignment = this.options.alignment || "left",
pages = this.getPages(),
listContainer = this.options.bootstrapMajorVersion === 2 ? $("<ul></ul>") : this.$element,
listContainerClass = this.options.bootstrapMajorVersion === 2 ? this.getValueFromOption(this.options.listContainerClass, listContainer) : null,
first = null,
prev = null,
next = null,
last = null,
p = null,
i = 0;
this.$element.prop("class", "");
this.$element.addClass("pagination");
switch (size.toLowerCase()) {
case "large":
case "small":
case "mini":
this.$element.addClass($.fn.bootstrapPaginator.sizeArray[this.options.bootstrapMajorVersion][size.toLowerCase()]);
break;
default:
break;
}
if (this.options.bootstrapMajorVersion === 2) {
switch (alignment.toLowerCase()) {
case "center":
this.$element.addClass("pagination-centered");
break;
case "right":
this.$element.addClass("pagination-right");
break;
default:
break;
}
}
this.$element.addClass(containerClass);
//empty the outter most container then add the listContainer inside.
this.$element.empty();
if (this.options.bootstrapMajorVersion === 2) {
this.$element.append(listContainer);
listContainer.addClass(listContainerClass);
}
//update the page element reference
this.pageRef = [];
if (pages.first) {//if the there is first page element
first = this.buildPageItem("first", pages.first);
if (first) {
listContainer.append(first);
}
}
if (pages.prev) {//if the there is previous page element
prev = this.buildPageItem("prev", pages.prev);
if (prev) {
listContainer.append(prev);
}
}
for (i = 0; i < pages.length; i = i + 1) {//fill the numeric pages.
p = this.buildPageItem("page", pages[i]);
if (p) {
listContainer.append(p);
}
}
if (pages.next) {//if there is next page
next = this.buildPageItem("next", pages.next);
if (next) {
listContainer.append(next);
}
}
if (pages.last) {//if there is last page
last = this.buildPageItem("last", pages.last);
if (last) {
listContainer.append(last);
}
}
},
/**
*
* Creates a page item base on the type and page number given.
*
* @param page page number
* @param type type of the page, whether it is the first, prev, page, next, last
*
* @return Object the constructed page element
* */
buildPageItem: function (type, page) {
var itemContainer = $("<li></li>"),//creates the item container
itemContent = $("<a></a>"),//creates the item content
text = "",
title = "",
itemContainerClass = this.options.itemContainerClass(type, page, this.currentPage),
itemContentClass = this.getValueFromOption(this.options.itemContentClass, type, page, this.currentPage),
tooltipOpts = null;
switch (type) {
case "first":
if (!this.getValueFromOption(this.options.shouldShowPage, type, page, this.currentPage)) { return; }
text = this.options.itemTexts(type, page, this.currentPage);
title = this.options.tooltipTitles(type, page, this.currentPage);
break;
case "last":
if (!this.getValueFromOption(this.options.shouldShowPage, type, page, this.currentPage)) { return; }
text = this.options.itemTexts(type, page, this.currentPage);
title = this.options.tooltipTitles(type, page, this.currentPage);
break;
case "prev":
if (!this.getValueFromOption(this.options.shouldShowPage, type, page, this.currentPage)) { return; }
text = this.options.itemTexts(type, page, this.currentPage);
title = this.options.tooltipTitles(type, page, this.currentPage);
break;
case "next":
if (!this.getValueFromOption(this.options.shouldShowPage, type, page, this.currentPage)) { return; }
text = this.options.itemTexts(type, page, this.currentPage);
title = this.options.tooltipTitles(type, page, this.currentPage);
break;
case "page":
if (!this.getValueFromOption(this.options.shouldShowPage, type, page, this.currentPage)) { return; }
text = this.options.itemTexts(type, page, this.currentPage);
title = this.options.tooltipTitles(type, page, this.currentPage);
break;
}
itemContainer.addClass(itemContainerClass).append(itemContent);
itemContent.addClass(itemContentClass).html(text).on("click", null, {type: type, page: page}, $.proxy(this.onPageItemClicked, this));
if (this.options.pageUrl) {
itemContent.attr("href", this.getValueFromOption(this.options.pageUrl, type, page, this.currentPage));
}
if (this.options.useBootstrapTooltip) {
tooltipOpts = $.extend({}, this.options.bootstrapTooltipOptions, {title: title});
itemContent.tooltip(tooltipOpts);
} else {
itemContent.attr("title", title);
}
return itemContainer;
},
setCurrentPage: function (page) {
if (page > this.totalPages || page < 1) {// if the current page is out of range, throw exception.
throw "Page out of range";
}
this.lastPage = this.currentPage;
this.currentPage = parseInt(page, 10);
},
/**
* Gets an array that represents the current status of the page object. Numeric pages can be access via array mode. length attributes describes how many numeric pages are there. First, previous, next and last page can be accessed via attributes first, prev, next and last. Current attribute marks the current page within the pages.
*
* @return object output objects that has first, prev, next, last and also the number of pages in between.
* */
getPages: function () {
var totalPages = this.totalPages,// get or calculate the total pages via the total records
pageStart = (this.currentPage % this.numberOfPages === 0) ? (parseInt(this.currentPage / this.numberOfPages, 10) - 1) * this.numberOfPages + 1 : parseInt(this.currentPage / this.numberOfPages, 10) * this.numberOfPages + 1,//calculates the start page.
output = [],
i = 0,
counter = 0;
pageStart = pageStart < 1 ? 1 : pageStart;//check the range of the page start to see if its less than 1.
for (i = pageStart, counter = 0; counter < this.numberOfPages && i <= totalPages; i = i + 1, counter = counter + 1) {//fill the pages
output.push(i);
}
output.first = 1;//add the first when the current page leaves the 1st page.
if (this.currentPage > 1) {// add the previous when the current page leaves the 1st page
output.prev = this.currentPage - 1;
} else {
output.prev = 1;
}
if (this.currentPage < totalPages) {// add the next page when the current page doesn't reach the last page
output.next = this.currentPage + 1;
} else {
output.next = totalPages;
}
output.last = totalPages;// add the last page when the current page doesn't reach the last page
output.current = this.currentPage;//mark the current page.
output.total = totalPages;
output.numberOfPages = this.options.numberOfPages;
return output;
},
/**
* Gets the value from the options, this is made to handle the situation where value is the return value of a function.
*
* @return mixed value that depends on the type of parameters, if the given parameter is a function, then the evaluated result is returned. Otherwise the parameter itself will get returned.
* */
getValueFromOption: function (value) {
var output = null,
args = Array.prototype.slice.call(arguments, 1);
if (typeof value === 'function') {
output = value.apply(this, args);
} else {
output = value;
}
return output;
}
};
/* TYPEAHEAD PLUGIN DEFINITION
* =========================== */
old = $.fn.bootstrapPaginator;
$.fn.bootstrapPaginator = function (option) {
var args = arguments,
result = null;
$(this).each(function (index, item) {
var $this = $(item),
data = $this.data('bootstrapPaginator'),
options = (typeof option !== 'object') ? null : option;
if (!data) {
data = new BootstrapPaginator(this, options);
$this = $(data.$element);
$this.data('bootstrapPaginator', data);
return;
}
if (typeof option === 'string') {
if (data[option]) {
result = data[option].apply(data, Array.prototype.slice.call(args, 1));
} else {
throw "Method " + option + " does not exist";
}
} else {
result = data.setOptions(option);
}
});
return result;
};
$.fn.bootstrapPaginator.sizeArray = {
"2": {
"large": "pagination-large",
"small": "pagination-small",
"mini": "pagination-mini"
},
"3": {
"large": "pagination-lg",
"small": "pagination-sm",
"mini": ""
}
};
$.fn.bootstrapPaginator.defaults = {
containerClass: "",
size: "normal",
alignment: "left",
bootstrapMajorVersion: 2,
listContainerClass: "",
itemContainerClass: function (type, page, current) {
return (page === current) ? "active" : "";
},
itemContentClass: function (type, page, current) {
return "";
},
currentPage: 1,
numberOfPages: 5,
totalPages: 1,
pageUrl: function (type, page, current) {
return null;
},
onPageClicked: null,
onPageChanged: null,
useBootstrapTooltip: false,
shouldShowPage: function (type, page, current) {
var result = true;
switch (type) {
case "first":
result = (current !== 1);
break;
case "prev":
result = (current !== 1);
break;
case "next":
result = (current !== this.totalPages);
break;
case "last":
result = (current !== this.totalPages);
break;
case "page":
result = true;
break;
}
return result;
},
itemTexts: function (type, page, current) {
switch (type) {
case "first":
return "&lt;&lt;";
case "prev":
return "&lt;";
case "next":
return "&gt;";
case "last":
return "&gt;&gt;";
case "page":
return page;
}
},
tooltipTitles: function (type, page, current) {
switch (type) {
case "first":
return "Go to first page";
case "prev":
return "Go to previous page";
case "next":
return "Go to next page";
case "last":
return "Go to last page";
case "page":
return (page === current) ? "Current page is " + page : "Go to page " + page;
}
},
bootstrapTooltipOptions: {
animation: true,
html: true,
placement: 'top',
selector: false,
title: "",
container: false
}
};
$.fn.bootstrapPaginator.Constructor = BootstrapPaginator;
}(window.jQuery));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment