
@{
    ViewData["Title"] = "FBA销售统计";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "统计", "亚马逊", "FBA销售统计" };
}

<div class="row">
    <div class="col-sm-12">

        <div id="leftcontain" style="position:relative;float:left;width:215px;margin-right:-220px;background-color:#fff;height:780px;border-top:solid 1px #E7EAEC;display:none;">
            <div id="ztree" class="ztree" style="margin:5px 10px;max-height: 800px;overflow: auto;">

            </div>
        </div>
        <div style="float:right;width:100%;">
            <div id="rightcontain">
                <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>&nbsp;</label>
                                <button type="button" class="btn btn-success" onclick="showleft();">分类筛选</button>
                            </div>
                            @*<div class="form-group">
                                    <label>统计维度：</label>
                                    <select id="stype" name="stype" class="form-control">
                                        <option value="1">按平台账号</option>
                                        <option value="2">按销售员</option>
                                    </select>
                                </div>*@
                            <div class="form-group">
                                <label>销售帐号：</label>
                                <select id="sellaccount" name="sellaccount" class="form-control" style="width:160px;">
                                    <option value="">选择帐号</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>站点：</label>
                                <select id="website" name="website" class="form-control">
                                    <option value="">选择站点</option>
                                </select>
                            </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"))" />
                                <span>至</span>
                                <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.ToString("yyyy-MM-dd"))" />
                            </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>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="ibox-content m-b-sm border-bottom">
                    <table id="roletable" style="table-layout:fixed;"></table>
                </div>
            </div>
        </div>
    </div>
</div>
@section css{
    <link href="~/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .alink {
            color: cornflowerblue;
            cursor: pointer;
        }
    </style>
}
@section scripts{
    <script src="~/js/jquery.ztree.core.min.js"></script>
    <script src="~/js/jquery.ztree.excheck.min.js"></script>
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 160));

            list();

            listAccount();

            listWebsite();

            listcategory12();
        })

        function list() {
            var columns = [
                { field: 'platform_type', title: '平台', width: '100', sortable: false },
                {
                    field: 'seller_account', title: '销售帐号', width: '130', sortable: false, formatter: function (idx, data) {
                        var str = '<p class="mules" title="' + data.seller_account + '">' + data.seller_account + '</p>';
                        return str;
                    }
                },
                { field: 'website', title: '站点', width: '80', sortable: false, iscount: true },
                {
                    field: 'amount_product', title: '销售额', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'商品收入\',\'amount_sales\',1)">' + data.amount_product + '</span><img style="width:16px;margin-left:3px;cursor:pointer;" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account +'\',\'amount_sales\',\'销售额\');" title="点击查看曲线图">';
                    }
                },
                {
                    field: 'order_count', title: '销售数量', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'订单数\',\'\',0)">' + data.order_count + '</span><img style="width:16px;margin-left:3px;cursor:pointer;" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account +'\',\'order_count\',\'订单数\');" title="点击查看曲线图">';
                    }
                },
                {
                    field: 'cost_product', title: '产品成本', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'产品成本\',\'cost_product\',1)">' + data.cost_product + '</span>';
                    }
                },
                {
                    field: 'platform_fee', title: '平台佣金费', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'平台佣金费\',\'cost_platform_fee\',1)">' + data.platform_fee + '</span>';
                    }
                },
                {
                    field: 'cost_fba_fee', title: 'fba费用', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'fba费用\',\'cost_fba_fee\',1)">' + data.cost_fba_fee + '</span>';
                    }
                },
                {
                    field: 'cost_package', title: '包装费用', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'包装费用\',\'cost_package\',1)">' + data.cost_package + '</span>';
                    }
                },
                {
                    field: 'head_fee', title: '头程费', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'头程费\',\'cost_first\',1)">' + data.head_fee + '</span>';
                    }
                },
                { field: 'loss_withdrawal', title: '提现损耗', width: '100', sortable: false, iscount: true },
                {
                    field: 'cost_count', title: '总支出', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'总支出\',\'cost_total\',1)">' + data.cost_count + '</span>';
                    }
                },
                {
                    field: 'nofba_logisticsfee', title: '实际物流费', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'实际物流费\',\'cost_shipping\',1)">' + data.nofba_logisticsfee + '</span>';
                    }
                },
                {
                    field: 'amount_refund', title: '退款金额', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'退款金额\',\'amount_refund\',1)">' + data.amount_refund + '</span>';
                    }
                },
                {
                    field: 'amount_prepaid', title: '预收金额', width: '120', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'预收金额\',\'amount_prepaid\',1)">' + data.amount_prepaid + '</span>';
                    }
                },
                //{
                //    field: 'noshippingcount', title: '预收订单数', width: '120', sortable: true, iscount: true
                //},
                //{ field: 'forecast_profit_rate', title: '预测利润率%', width: '120', sortable: true },
                {
                    field: 'profit_count', title: '实际利润', width: '120', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account + '\',\'实际利润\',\'profit_total\',1)">' + data.profit_count + '</span><img style="width:16px;margin-left:3px;cursor:pointer;" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'' + data.platform_type + '\',\'' + data.website + '\',\'' + data.seller_account +'\',\'profit_total\',\'利润\');" title="点击查看曲线图">';
                    }
                },
                { field: 'profit_rate', title: '总实际利润率%', width: '130', sortable: true, iscount: true },
            ];

            var s = '';

            try {
                s = getChkNode();
            } catch (e) {
                s = '';
            }

            var url = '@Url.Content("~/Reports/Orders/ListFBASaleStatisticsJson")' + '?' + $("#toolbar").serialize() + '&skucategoryids=' + s;

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", { showfooter: true, showCount: true });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function listAccount() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListAccount")',
                type:'POST',
                paramData: 'platform=FBA',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#sellaccount').html('<option value="">选择帐号</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#sellaccount').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

        function listWebsite() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListWebSite")',
                type:'POST',
                paramData: 'platform=FBA',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#website').html('<option value="">选择站点</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#website').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

        function ShowDetail(platform, website, account, coltitle, colval, single) {
            layer_show(platform + " " + website + " " + $('#start').val() + "至" + $('#end').val() + ' 订单明细', '@Url.Content("~/Reports/Orders/ListOrderDetail?platform=")' + platform + '&website=' + website + '&account=' + account + '&start=' + $('#start').val() + '&end=' + $('#end').val() + '&col=' + colval + '&coltitle=' + coltitle + '&showsingle=' + single, '90%', '90%');
        }

        function showleft() {
            var c = $('#leftcontain').css('display');
            if (c == 'none') {
                $('#leftcontain').css('display', 'inline');
                $("#rightcontain").animate({ marginLeft: "220px" });
            }
            else {
                $('#leftcontain').css('display', 'none');
                $("#rightcontain").animate({ marginLeft: "0px" });
            }
        }

        function listcategory12() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListSkuCategoryOneAndSecondLevel")',
                paramData: '',
                type: 'POST',
                func: function (result) {
                    var setting = {
                        check: {
                            chkStyle:'checkbox',
                            enable: true
                        }
                    };
                    zTreeObj = $.fn.zTree.init($("#ztree"), setting, eval('('+result+')'));
                }
            })
        }

        function getChkNode() {
            var s = '';
            var o = $.fn.zTree.getZTreeObj("ztree");
            var nodes = o.getCheckedNodes();
            for (var i in nodes) {
                if (nodes[i].children == null || nodes[i].children.length <= 0) {
                    s += (nodes[i].id) + '|';
                }
            }

            return s;
        }

        function ShowChart(platform, website, account, colval,title)
        {
            layer_show(platform + " " + website + " " + account + ' 曲线图', '@Url.Content("~/Reports/Orders/OrderSalesGraph?platform=")' + platform + '&website=' + website + '&sellaccount=' + account + '&start=' + $('#start').val() + '&end=' + $('#end').val() + '&col=' + colval + '&titlename=' + title + '&warehousetype=&warehousecode=', '90%', '90%');
        }

    </script>

}

