
@{
    ViewData["Title"] = "平台费用流水";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "平台费用流水", ViewBag.platform };
}

<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;">
                            <input type="hidden" id="platform" name="platform" value="@ViewBag.platform" />
                            <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="warehousetype" name="warehousetype" class="form-control">
                                    <option value="">仓库类型</option>
                                    <option value="国内仓">国内仓</option>
                                    <option value="海外仓">海外仓</option>
                                    <option value="第三方仓库">第三方仓库</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>仓库</label>
                                <select id="warehousecode" name="warehousecode" class="form-control">
                                    <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>
                                <select id="account" name="account" class="form-control" style="width:160px;">
                                    <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>
                                <button id="btnexport" style="display:none;" type="button" class="btn btn-success" onclick="exportxls();">导出</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 companyid = -1;
        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();

            //listWarehouse();

            $('#warehousetype').change(function () {
                listwarehouse();
            })
            //listcategory12();
            listsimplecategory();
        })

        function list() {
            var columns = [
                { field: 'origin_order_id', title: '平台订单号', width: '220' },
                //{ field: 'bailun_order_id', title: '百伦订单号', width: '220' },
                { field: 'platform_type', title: '平台名称', width: '100' },
                { field: 'website', title: '平台站点', width: '90' },
                {
                    field: 'seller_account', title: '卖家帐号', width: '160', formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.seller_account + '">' + data.seller_account + '</div>';
                    }
                },
                { field: 'amount_sales', title: '销售额', width: '120', sortable: true, iscount: true },
                { field: 'cost_platform_fee', title: '平台费', width: '100', sortable: true, iscount: true },

                //{ field: 'cost_package', title: '包装费', width: '100', sortable: false, iscount: true },

                @if (ViewBag.platform == "FBA")
                {
                    @Html.Raw("{ field: 'cost_fba_fee', title: 'FBA费用', width: '100', sortable: true, iscount: true },")
                    @Html.Raw("{ field: 'amount_shipping', title: '运费收入', width: '110', sortable: true, iscount: true },")
                }
                @if (ViewBag.platform == "FBA" || ViewBag.platform == "Amazon")
                {
                    @Html.Raw("{ field: 'cost_promotion', title: '促销费', width: '100', sortable: true, iscount: true },")
                }
                @if (ViewBag.platform == "Ebay")
                {
                    @Html.Raw("{ field: 'cost_paypal_fee', title: 'Paypal费用', width: '120', sortable: true, iscount: true },")
                }
                @if (ViewBag.platform != "FBA")
                {
                    @Html.Raw("{ field: 'cost_logistics', title: '尾程费', width: '120', sortable: true, iscount: true },{ field: 'cost_handle_bailun', title: '百伦处理费', width: '160', sortable: true, iscount: true},")
                }

                //{ field: 'cost_refund_commisson', title: '退款佣金', width: '120', sortable: true, iscount: true },

                //{ field: 'cost_handle_platform', title: '操作费', width: '120', sortable: true, iscount: true },
                { field: 'cost_product', title: '产品成本', width: '100', sortable: true, iscount: true },
                { field: 'cost_first', title: '头程费', width: '120', sortable: true, iscount: true },
                { field: 'amount_prepaid', title: '预收款金额', width: '130', sortable: true, iscount: true },
                { field: 'profit_total', title: '利润', width: '120', sortable: true, iscount: true },
                { field: 'profit_rate', title: '利润率', width: '120', sortable: true, iscount: true },
                { field: 'amount_refund', title: '退款金额', width: '110', sortable: true, iscount: true },
                { field: 'paid_time', title: '付款时间', width: '160', sortable: true, iscount: true },
            ];

            var s = '';

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

            var url = '@Url.Content("~/Reports/Orders/ListPlatformCostJson")' + '?' + $("#toolbar").serialize() + '&skucategoryids=' + s;
            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    showfooter: true, showCount: true, loadsuccess: function (result) {
                        companyid = result.companyid;
                        if (result.isexport == 1) {
                            $('#btnexport').show();
                        }
                    }
                });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

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

        function listWebsite() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListWebSite")',
                type:'POST',
                paramData: 'platform=@(ViewBag.platform)',
                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 listwarehouse() {
            var wtype = $('#warehousetype').val();

            $.submit({
                url: '@Url.Content("~/Home/ListWareHouse")',
                paramData: 'warehousetype=' + wtype,
                type:'POST',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#warehousecode').html('<option value="">选择仓库</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#warehousecode').append('<option value="' + result[i].warehouse_code + '">' + result[i].warehouse_name + '</option>');
                        }
                    }
                }
            })

        }

        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 listsimplecategory() {
            $.submit({
                url: '@Url.Content("~/Home/ListSimpleCategory")',
                paramData: '',
                type: 'POST',
                func: function (result) {
                    var setting = {
                        check: {
                            chkStyle: 'checkbox',
                            enable: true
                        }
                    };
                    zTreeObj = $.fn.zTree.init($("#ztree"), setting, 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 exportxls() {
            if ($('#start').val() == '' || $('#end').val() == '') {
                alert('请选择付款时间');
                return false;
            }

            var s = '';

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

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

            window.open(url + '&companyid=' + companyid, '_blank');
        }

    </script>

}

