Commit ff954139 by guanzhenshan

产品类型筛选改为多选

parent e5ed80b7
......@@ -1653,7 +1653,7 @@ namespace Bailun.DC.Services
/// <param name="start">付款开始时间</param>
/// <param name="end">付款结束时间</param>
/// <returns></returns>
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfit(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int? producttype, int? skusource, int? shippingstrategy, DateTime? createstart = null, DateTime? createend = null)
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfit(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy, DateTime? createstart = null, DateTime? createend = null)
{
var sqlparam = new DynamicParameters();
var sql = "select tb.platform_type,count(distinct tb.bailun_order_id) order_count,sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "* tb.bailun_sku_quantity_ordered) as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay'," + (isUSD ? "tb.other_to_usd_exchange_rate" : "tb.seller_other_exchange_rate") + "," + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "))*tb.bailun_sku_quantity_ordered) as cost_platform_fee,sum(tb.cost_first*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) as cost_first,sum(tb.cost_tail*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_tail,sum(tb.cost_handle_bailun*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_handle_bailun,sum(tb.cost_handle_platform*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_handle_platform,sum(tb.amount_refund*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) amount_refund,sum(tb.cost_fba_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) cost_fba_fee,sum(tb.cost_paypal_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) cost_paypal_fee,sum(tb.amount_shipping*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) amount_shipping,sum(tb.cost_promotion*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) cost_promotion,sum(tb.cost_product*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_product,sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) profit_total,(sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ")/sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) amount_prepaid from dc_base_oms_sku tb ";
......@@ -1718,13 +1718,13 @@ namespace Bailun.DC.Services
}
//Add by Allan at 20200320,for 增加sku级别的利润统计
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue)
{
sql += " join dc_base_sku t10 on tb.bailun_sku=t10.bailun_sku ";
if (producttype.HasValue)
if (producttype.Count()>0)
{
sql += " and t10.product_type=" + producttype.Value;
sql += " and t10.product_type in (" + string.Join(",",producttype)+") ";
}
if (skusource.HasValue)
......@@ -1820,7 +1820,7 @@ namespace Bailun.DC.Services
/// <param name="shipstart">发货开始时间</param>
/// <param name="shipend">发货结束时间</param>
/// <returns></returns>
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfitByShipTime(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int? producttype, int? skusource, int? shippingstrategy)
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfitByShipTime(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy)
{
var sqlparam = new DynamicParameters();
var sql = @"select t2.platform_type,count(DISTINCT t2.bailun_order_id) order_count,sum(t2.amount_sales*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) as amount_sales,sum(t2.cost_platform_fee*(if(t2.platform_type='Ebay'," + (isUSD ? "t2.other_to_usd_exchange_rate" : "t2.seller_other_exchange_rate") + "," + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "))*t1.quantity_shipped) as cost_platform_fee,sum(t2.cost_first*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) as cost_first,sum(t2.cost_logistics*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_tail,sum(t2.cost_handle_bailun*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_handle_bailun,sum(t2.cost_handle_platform*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_handle_platform,sum(t2.amount_refund*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) amount_refund,sum(t2.cost_product*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_product,sum(t2.profit_total*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) profit_total,(sum(t2.profit_total*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped)/sum(t2.amount_sales*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped)) profit_rate,count(t2.amount_prepaid>0 or null) as noshippingcount,sum(t2.amount_prepaid*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) amount_prepaid,sum(t2.cost_fba_fee*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) cost_fba_fee,sum(t2.cost_paypal_fee*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) cost_paypal_fee,sum(t2.amount_shipping*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) amount_shipping,sum(t2.cost_promotion*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) cost_promotion from (select id,bailun_order_id,quantity_shipped,bailun_sku from dc_base_oms_pick where has_delete=0 and shipping_status = 'TotalShipping' ";
......@@ -1843,13 +1843,13 @@ namespace Bailun.DC.Services
sql += " join dc_base_oms_sku t2 on t1.bailun_order_id = t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and ((t2.platform_type!='FBA' and t2.bailun_order_status!='CantHandle') or t2.platform_type='FBA') and t2.has_scalp = 0 and t2.has_innersale = 0 and t2.has_delete=0 ";
//Add by Allan at 20200320,for 增加sku级别的利润统计
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue)
{
sql += " join dc_base_sku t10 on t2.bailun_sku=t10.bailun_sku ";
if (producttype.HasValue)
if (producttype.Count() > 0)
{
sql += " and t10.product_type="+producttype.Value;
sql += " and t10.product_type in ("+string.Join(",", producttype)+") ";
}
if (skusource.HasValue)
......@@ -1914,14 +1914,7 @@ namespace Bailun.DC.Services
var strwhere = " ";
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
{
}
else
{
strwhere += " group by t2.platform_type";
}
......@@ -3275,7 +3268,7 @@ namespace Bailun.DC.Services
/// <param name="total"></param>
/// <param name="feetype"></param>
/// <returns></returns>
public dc_base_finance_ebay EbayFeeCount(int? companyid, DateTime? start, DateTime? end, string[] feetype, string orderno, string account,bool isUSD,string itemid, int? producttype, int? skusource, int? shippingstrategy)
public dc_base_finance_ebay EbayFeeCount(int? companyid, DateTime? start, DateTime? end, string[] feetype, string orderno, string account,bool isUSD,string itemid, int[] producttype, int? skusource, int? shippingstrategy)
{
var sqlparam = new DynamicParameters();
var sql = $"select sum(t1.gross_amount) gross_amount,sum(t1.net_amount) net_amount,sum(t1.{(isUSD? "exchange_rate_usd" : "exchange_rate")}*t1.gross_amount) gross_amount_rmb from dc_base_finance_ebay t1 ";
......@@ -3288,7 +3281,7 @@ namespace Bailun.DC.Services
}
//Add by Allan at 20200320
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue)
{
sql = $"select 0 gross_amount,0 net_amount,sum(t1.{(isUSD ? "exchange_rate_usd" : "exchange_rate")}*t1.sku_amount*t1.sku_count) gross_amount_rmb from dc_base_finance_ebay_item t1 ";
......@@ -3302,13 +3295,11 @@ namespace Bailun.DC.Services
}
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
{
sql += " join dc_base_sku t10 on t1.bailun_sku=t10.bailun_sku ";
if (producttype.HasValue)
if (producttype.Count() > 0)
{
sql += " and t10.product_type=" + producttype.Value;
sql += " and t10.product_type in (" + string.Join(",", producttype) + ") ";
}
if (skusource.HasValue)
......@@ -3321,7 +3312,6 @@ namespace Bailun.DC.Services
}
}
}
sql += " where t1.id!=0 ";
......@@ -5201,18 +5191,18 @@ namespace Bailun.DC.Services
/// <param name="website"></param>
/// <param name="isUSD"></param>
/// <returns></returns>
public List<dc_base_oms_order> ListPlatformRefund(DateTime? start, DateTime? end, int? companyid, string platform, string website, bool isUSD,bool containNotShipping, int? producttype, int? skusource, int? shippingstrategy)
public List<dc_base_oms_order> ListPlatformRefund(DateTime? start, DateTime? end, int? companyid, string platform, string website, bool isUSD,bool containNotShipping, int[] producttype, int? skusource, int? shippingstrategy)
{
var sqlparam = new DynamicParameters();
var sql = $"select t1.platform_type,{(isUSD? "sum(t1.amount_refund_usd)" : "sum(t1.amount_refund_rmb)")} as amount_refund from dc_base_crm_refund t1 ";
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
if ((producttype!=null && producttype.Count()>0) || skusource.HasValue || shippingstrategy.HasValue)
{
sql += " join dc_base_sku t10 on t1.bailun_sku=t10.bailun_sku ";
if (producttype.HasValue)
if (producttype.Count()>0)
{
sql += " and t10.product_type=" + producttype.Value;
sql += " and t10.product_type in (" + string.Join(",",producttype)+") ";
}
if (skusource.HasValue)
......@@ -5405,7 +5395,7 @@ namespace Bailun.DC.Services
/// <param name="end"></param>
/// <param name="companyid"></param>
/// <returns></returns>
public dc_base_finance_amazon_ad_product ListAmazonADSkuCount(string account, DateTime? start, DateTime? end, int? companyid,bool isUSD, int? producttype, int? skusource, int? shippingstrategy)
public dc_base_finance_amazon_ad_product ListAmazonADSkuCount(string account, DateTime? start, DateTime? end, int? companyid,bool isUSD, int[] producttype, int? skusource, int? shippingstrategy)
{
var sqlparam = new DynamicParameters();
var sql = $"select sum(cost) cost,sum(cost*{(isUSD?"exchange_rate_usd":"exchange_rate")}) cost_rmb from dc_base_finance_amazon_ad_product t1 join dc_base_company_account t2 on t1.account_id=t2.account_id ";
......@@ -5417,7 +5407,7 @@ namespace Bailun.DC.Services
}
//Add by Allan at 20200320
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue)
{
sql = $"select sum(cost) cost,sum(cost*{(isUSD ? "exchange_rate_usd" : "exchange_rate")}) cost_rmb from dc_base_finance_amazon_item t1 join dc_base_company_account t2 on t1.account_id=t2.account_id ";
......@@ -5431,9 +5421,9 @@ namespace Bailun.DC.Services
sql += " join dc_base_sku t10 on t1.bailun_sku=t10.bailun_sku ";
if (producttype.HasValue)
if (producttype.Count()>0)
{
sql += " and t10.product_type=" + producttype.Value;
sql += " and t10.product_type in (" + string.Join(",",producttype)+") ";
}
if (skusource.HasValue)
......
......@@ -1549,7 +1549,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
/// <returns></returns>
[BailunAuthentication(LoginMode.Enforce)]
[HttpPost]
public JsonResult PlatformProfitCountJson(string platform,string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, string currency, string skucategoryids,int? producttype,int? skusource,int? shippingstrategy)
public JsonResult PlatformProfitCountJson(string platform,string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, string currency, string skucategoryids,string product_type,int? skusource,int? shippingstrategy)
{
var _service = new Services.OrdersServices();
var companyid = HttpContextHelper.Current?.User?.GetCompanyId().ToInt32();
......@@ -1590,8 +1590,16 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
"CrediteBayStores"
};
var producttype = new int[] { };
if (!string.IsNullOrEmpty(product_type))
{
producttype = product_type.Split(",").Where(a => !string.IsNullOrEmpty(a)).Select(b => int.Parse(b)).ToArray();
}
//Add by Allan at 20200320,for 增加sku级别的利润统计
if (producttype.HasValue || skusource.HasValue || shippingstrategy.HasValue)
if (producttype.Length>0 || skusource.HasValue || shippingstrategy.HasValue)
{
if (shipstart.HasValue || shipend.HasValue)
......
......@@ -58,8 +58,8 @@
</div>
<div class="form-group">
<label>产品类型</label>
<select id="producttype" name="producttype" class="form-control">
<option value="">选择产品类型</option>
<select id="producttype" name="producttype" class="form-control" multiple="multiple">
@*<option value="">选择产品类型</option>*@
@if (ViewBag.listSkuType.Count > 0)
{
foreach (var item in ViewBag.listSkuType)
......@@ -140,6 +140,7 @@
</div>
@section css{
<link href="~/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<link href="~/js/yselect/yselect.css" rel="stylesheet" />
<style>
.mules {
white-space: nowrap;
......@@ -175,6 +176,7 @@
<script src="~/js/jquery.ztree.core.min.js"></script>
<script src="~/js/jquery.ztree.excheck.min.js"></script>
<script src="~/js/jquery.tablesorter.min.js" type="text/javascript"></script>
<script src="~/js/yselect/yselect.js"></script>
<script type="text/javascript">
var tb;
$(document).ready(function () {
......@@ -195,9 +197,23 @@
$('#platform').change(function () {
listwebsite();
})
$('#producttype').ySelect(
{
placeholder: '请选择产品类型',
searchText: '搜索',
showSearch: false,
numDisplayed: 10,
overflowText: '已选中 {n}项'
}
);
})
function list() {
var producttype = $("#producttype").ySelectedValues(",");
var shipstart = $('#shipstart').val();
var shipend = $('#shipend').val();
var start = $('#start').val();
......@@ -224,7 +240,7 @@
$.submit({
type:'POST',
url: '@Url.Content("~/Reports/Orders/PlatformProfitCountJson")',
paramData: $("#toolbar").serialize() + '&skucategoryids=' + s,
paramData: $("#toolbar").serialize() + '&skucategoryids=' + s + '&product_type=' + producttype,
func: function (result) {
layer.close(lindex);
if (result && result.length > 0) {
......
.fs-wrap {
position: relative;
display: inline-block;
width: 200px;
margin: 3px;
font-size: 12px;
line-height: 1;
}
.fs-label-wrap {
position: relative;
border: 1px solid #ccc;
cursor: default;
color: #555;
border-radius: 4px;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
height: 32px;
margin-top: 3px;
}
.fs-label-wrap,
.fs-dropdown {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.fs-label-wrap .fs-label {
padding: 4px 22px 4px 8px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
cursor: pointer;
}
.fs-label {
position: relative;
top: 5px;
}
.fs-arrow {
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 6px solid #000;
position: absolute;
top: 0;
right: 4px;
bottom: 0;
margin: auto;
cursor: pointer;
}
.fs-dropdown {
position: absolute;
background-color: #fff;
border: 1px solid #ccc;
/*margin-top: 2px;*/
width: 100%;
z-index: 1000;
border-radius: 4px;
}
.fs-dropdown .fs-options {
max-height: 200px;
overflow: auto;
}
.fs-search input {
width: 90%;
padding: 2px 4px;
border: 0;
}
.fs-selectAll {
float: right;
cursor: pointer;
margin-top: 4px;
height: auto;
}
.fs-selectAll.selected {
float: right;
cursor: pointer;
margin-top: 4px;
height: auto;
color: green;
}
.fs-selectAll:hover {
background-color: #eee;
}
.fs-option,
.fs-search,
.fs-optgroup-label {
padding: 8px 8px;
border-bottom: 1px solid #eee;
cursor: default;
}
.fs-option {
cursor: pointer;
}
.fs-option.hl {
background-color: #f5f5f5;
}
.fs-wrap.multiple .fs-option {
position: relative;
padding-left: 30px;
}
.fs-wrap.multiple .fs-checkbox {
position: absolute;
display: block;
width: 30px;
top: 0;
left: 0;
bottom: 0;
}
.fs-wrap.multiple .fs-option .fs-checkbox i {
position: absolute;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 14px;
height: 14px;
border: 1px solid #aeaeae;
border-radius: 4px;
background-color: #fff;
}
.fs-wrap.multiple .fs-option.selected .fs-checkbox i {
background-color: rgb(17, 169, 17);
border-color: transparent;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAGCAYAAAD+Bd/7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNXG14zYAAABMSURBVAiZfc0xDkAAFIPhd2Kr1WRjcAExuIgzGUTIZ/AkImjSofnbNBAfHvzAHjOKNzhiQ42IDFXCDivaaxAJd0xYshT3QqBxqnxeHvhunpu23xnmAAAAAElFTkSuQmCC');
background-repeat: no-repeat;
background-position: center;
}
.fs-wrap .fs-option:hover {
/*background-color: #f5f5f5;*/
background: #D1F3E5;
border-radius: 4px;
margin-left: 0px;
margin-right: 2px;
}
.fs-optgroup-label {
font-weight: bold;
}
.hidden {
display: none;
}
.fs-options::-webkit-scrollbar {
width: 6px;
}
.fs-options::-webkit-scrollbar-track {
-webkit-border-radius: 2em;
-moz-border-radius: 2em;
border-radius: 2em;
-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
background: rgba(0,0,0,0.1);
}
.fs-options::-webkit-scrollbar-thumb {
-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
background: rgba(0,0,0,0.2);
-webkit-border-radius: 2em;
-moz-border-radius: 2em;
border-radius: 2em;
}
(function ($) {
$.fn.ySelect = function (options) {
var defaultOptions = {
placeholder: '请选择',
numDisplayed: 4,
overflowText: '{n} selected',
searchText: '搜索',
showSearch: true
}
if (typeof options == 'string') {
var settings = options;
}
else {
var settings = $.extend(true, {}, defaultOptions, options);
}
/**
* Constructor
*/
function ySelect(select, settings) {
this.$select = $(select);
this.settings = settings;
this.create();
}
/**
* Prototype class
*/
ySelect.prototype = {
create: function () {
var multiple = this.$select.is('[multiple]') ? ' multiple' : '';
this.$select.wrap('<div class="fs-wrap' + multiple + '"></div>');
this.$select.before('<div class="fs-label-wrap"><div class="fs-label">' + this.settings.placeholder + '</div><span class="fs-arrow"></span></div>');
this.$select.before('<div class="fs-dropdown hidden"><div class="fs-options"></div></div>');
this.$select.addClass('hidden');
this.$wrap = this.$select.closest('.fs-wrap');
this.reload();
},
reload: function () {
if (this.settings.showSearch) {
var search = '<div class="fs-search"><input type="search" placeholder="' + this.settings.searchText + '" /><span class="fs-selectAll"><i class="fa fa-check-square-o"></i></span></div>';
this.$wrap.find('.fs-dropdown').prepend(search);
}
var choices = this.buildOptions(this.$select);
this.$wrap.find('.fs-options').html(choices);
this.reloadDropdownLabel();
},
destroy: function () {
this.$wrap.find('.fs-label-wrap').remove();
this.$wrap.find('.fs-dropdown').remove();
this.$select.unwrap().removeClass('hidden');
},
buildOptions: function ($element) {
var $this = this;
var choices = '';
$element.children().each(function (i, el) {
var $el = $(el);
if ('optgroup' == $el.prop('nodeName').toLowerCase()) {
choices += '<div class="fs-optgroup">';
choices += '<div class="fs-optgroup-label">' + $el.prop('label') + '</div>';
choices += $this.buildOptions($el);
choices += '</div>';
}
else {
var selected = $el.is('[selected]') ? ' selected' : '';
choices += '<div class="fs-option' + selected + '" data-value="' + $el.prop('value') + '"><span class="fs-checkbox"><i></i></span><div class="fs-option-label">' + $el.html() + '</div></div>';
}
});
return choices;
},
reloadDropdownLabel: function () {
var settings = this.settings;
var labelText = [];
this.$wrap.find('.fs-option.selected').each(function (i, el) {
labelText.push($(el).find('.fs-option-label').text());
});
if (labelText.length < 1) {
labelText = settings.placeholder;
}
else if (labelText.length > settings.numDisplayed) {
labelText = settings.overflowText.replace('{n}', labelText.length);
}
else {
labelText = labelText.join(', ');
}
this.$wrap.find('.fs-label').html(labelText);
this.$select.change();
},
setwrap: function () {
// if(settings.isCheck==false)
// this.$wrap.find('.fs-dropdown').addClass('hidden');
return "123";
},
}
/**
* Loop through each matching element
*/
return this.each(function () {
var data = $(this).data('ySelect');
if (!data) {
data = new ySelect(this, settings);
$(this).data('ySelect', data);
}
if (typeof settings == 'string') {
data[settings]();
}
});
}
/**
* Events
*/
window.ySelect = {
'active': null,
'idx': -1
};
function setIndexes($wrap) {
$wrap.find('.fs-option:not(.hidden)').each(function (i, el) {
$(el).attr('data-index', i);
$wrap.find('.fs-option').removeClass('hl');
});
$wrap.find('.fs-search input').focus();
window.ySelect.idx = -1;
}
function setScroll($wrap) {
var $container = $wrap.find('.fs-options');
var $selected = $wrap.find('.fs-option.hl');
var itemMin = $selected.offset().top + $container.scrollTop();
var itemMax = itemMin + $selected.outerHeight();
var containerMin = $container.offset().top + $container.scrollTop();
var containerMax = containerMin + $container.outerHeight();
if (itemMax > containerMax) { // scroll down
var to = $container.scrollTop() + itemMax - containerMax;
$container.scrollTop(to);
}
else if (itemMin < containerMin) { // scroll up
var to = $container.scrollTop() - containerMin - itemMin;
$container.scrollTop(to);
}
}
$(document).on('click', '.fs-selectAll', function () {
$(this).parent().next().find('.fs-option.selected').click();
$(this).parent().next().find('.fs-option').click();
$(this).addClass('selected');
});
$(document).on('click', '.fs-selectAll.selected', function () {
$(this).parent().next().find('.fs-option.selected').click();
$(this).removeClass('selected');
});
$(document).on('click', '.fs-option', function () {
var $wrap = $(this).closest('.fs-wrap');
if ($wrap.hasClass('multiple')) {
var selected = [];
$(this).toggleClass('selected');
$wrap.find('.fs-option.selected').each(function (i, el) {
selected.push($(el).attr('data-value'));
});
}
else {
var selected = $(this).attr('data-value');
$wrap.find('.fs-option').removeClass('selected');
$(this).addClass('selected');
$wrap.find('.fs-dropdown').hide();
}
$wrap.find('select').val(selected);
$wrap.find('select').ySelect('reloadDropdownLabel');
$wrap.find('select').ySelect('setwrap');
});
$(document).on('keyup', '.fs-search input', function (e) {
if (40 == e.which) {
$(this).blur();
return;
}
var $wrap = $(this).closest('.fs-wrap');
var keywords = $(this).val();
$wrap.find('.fs-option, .fs-optgroup-label').removeClass('hidden');
if ('' != keywords) {
$wrap.find('.fs-option').each(function () {
var regex = new RegExp(keywords, 'gi');
if (null === $(this).find('.fs-option-label').text().match(regex)) {
$(this).addClass('hidden');
}
});
$wrap.find('.fs-optgroup-label').each(function () {
var num_visible = $(this).closest('.fs-optgroup').find('.fs-option:not(.hidden)').length;
if (num_visible < 1) {
$(this).addClass('hidden');
}
});
}
setIndexes($wrap);
});
$(document).on('click', function (e) {
var $el = $(e.target);
var $wrap = $el.closest('.fs-wrap');
if (0 < $wrap.length) {
if ($el.hasClass('fs-label') || $el.hasClass('fs-arrow')) {
window.ySelect.active = $wrap;
var is_hidden = $wrap.find('.fs-dropdown').hasClass('hidden');
$('.fs-dropdown').addClass('hidden');
if (is_hidden) {
$wrap.find('.fs-dropdown').removeClass('hidden');
}
else {
$wrap.find('.fs-dropdown').addClass('hidden');
}
setIndexes($wrap);
}
}
else {
$('.fs-dropdown').addClass('hidden');
window.ySelect.active = null;
}
});
$(document).on('keydown', function (e) {
var $wrap = window.ySelect.active;
if (null === $wrap) {
return;
}
else if (38 == e.which) { // up
e.preventDefault();
$wrap.find('.fs-option').removeClass('hl');
if (window.ySelect.idx > 0) {
window.ySelect.idx--;
$wrap.find('.fs-option[data-index=' + window.ySelect.idx + ']').addClass('hl');
setScroll($wrap);
}
else {
window.ySelect.idx = -1;
$wrap.find('.fs-search input').focus();
}
}
else if (40 == e.which) { // down
e.preventDefault();
var last_index = $wrap.find('.fs-option:last').attr('data-index');
if (window.ySelect.idx < parseInt(last_index)) {
window.ySelect.idx++;
$wrap.find('.fs-option').removeClass('hl');
$wrap.find('.fs-option[data-index=' + window.ySelect.idx + ']').addClass('hl');
setScroll($wrap);
}
}
else if (32 == e.which || 13 == e.which) { // space, enter
$wrap.find('.fs-option.hl').click();
}
else if (27 == e.which) { // esc
$('.fs-dropdown').addClass('hidden');
window.ySelect.active = null;
}
});
//update by ycx,for this plugin to get selected values
$.fn.ySelectedValues = function (splitString) {
var result = "";
var $selects = this.find("option:selected");
for (var i = 0; i < $selects.length; i++) {
result += $selects[i].value + ((i == $selects.length - 1) ? "" : splitString);
}
return result;
}
$.fn.ySelectedTexts = function (splitString) {
var result = "";
var $selects = this.find("option:selected");
for (var i = 0; i < $selects.length; i++) {
result += $selects[i].text + ((i == $selects.length - 1) ? "" : splitString);
}
return result;
}
})(jQuery);
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