
@{
    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="platform" name="platform" class="form-control">
                            <option value="">选择平台</option>
                        </select>*@
                        <input id="platform" name="platform" class="form-control" style="width:130px" value="@ViewBag.platform" readonly />
                    </div>
                    <div class="form-group">
                        <label>付款时间</label>
                        <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(ViewBag.start)" readonly />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(ViewBag.end)" readonly />
                    </div>
                </div>
            </form>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <table id="roletable" style="table-layout:fixed;"></table>
        </div>
    </div>
</div>
@section css{
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .alink {
            color: cornflowerblue;
            cursor: pointer;
        }
    </style>
}
@section scripts{
    <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 - 170));

            list();

            //listPlatform();
        })

        function list() {
            var columns = [
                { field: 'platform', title: '平台', width: '100' },
                { field: 'website', title: '站点', width: '90', iscount: true },
                {
                    field: 'ordercount', title: '订单数', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'订单数\',\'\',0)">' + data.ordercount + '</span>';
                    }
                },
                {
                    field: 'saleamount', title: '销售额', width: '90', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'销售额\',\'amount_total\',1)">' + data.saleamount + '</span>';
                    }
                },
                {
                    field: 'customerprice', title: '客单价', width: '90', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span>' + data.customerprice + '</span>';
                    }
                },
                {
                    field: 'platformfee', title: '平台费', width: '90', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'平台费用\',\'cost_platform_fee\',1)">' + data.platformfee + '</span>';
                    }
                },
                {
                    field: 'cost_first', title: '头程费', width: '90', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'头程费\',\'cost_first\',1)">' + data.cost_first + '</span>';
                    }
                },
                {
                    field: 'cost_tail', title: '尾程费', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'尾程费\',\'cost_tail\',1)">' + data.cost_tail + '</span>';
                    }
                },
                {
                    field: 'cost_handle_bailun', title: '处理费', width: '120', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'处理费\',\'cost_handle_bailun\',1)">' + data.cost_handle_bailun + '</span>';
                    }
                },
                {
                    field: 'cost_handle_platform', title: '第三方仓处理费', width: '120', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'第三方仓处理费\',\'cost_handle_platform\',1)">' + data.cost_handle_platform + '</span>';
                    }
                },
                {
                    field: 'amount_prepaid', title: '预收款', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'预收款\',\'amount_prepaid\',1)">' + data.amount_prepaid + '</span>';
                    }
                },
                {
                    field: 'profit', title: '利润', width: '90', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'利润\',\'profit_total\',1)">' + data.profit + '</span>';
                    }
                },
                {
                    field: 'profitrate', title: '利润率%', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span>' + data.profitrate + '</span>';
                    }
                },
                {
                    field: 'returnamount', title: '退款额', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<span class="alink" onclick="ShowDetail(\'' + data.website + '\',\'退款金额\',\'amount_refund\',1)">' + data.returnamount + '</span>';
                    }
                },
                {
                    field: 'returnamountrate', title: '退款率%', width: '100', sortable: true, iscount: true
                    , formatter: function (idx, data) {
                        return '<span>' + data.returnamountrate + '</span>';
                    }
                }
            ];

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

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    showfooter: true, loadsuccess: function (d) {
                        //替换汇总行的相关列值
                        var tr = $('.fixed-table-footer').find('tr');
                        for (var c in columns) {
                            var key = columns[c].field;
                            if (columns[c].iscount) {
                                for (var v in d.count_row) {
                                    if (key == v) {
                                        tr.find('td').eq(c).children('div').first().html(d.count_row[v]);
                                        break;
                                    }
                                }
                            }
                        }
                        
                    }
                });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

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

        @*function ShowDetail(website) {
            
            var start = $('#start').val();
            var end = $('#end').val();

            layer_show("@(ViewBag.platform) " + website + " " + $('#start').val() + "至" + $('#end').val() + ' 订单明细', '@Url.Content("~/Reports/Orders/ListOrderDetail?platform="+ViewBag.platform)' + '&start=' + $('#start').val() + '&end=' + $('#end').val() + '&website=' + website, '90%', '90%');
        }*@

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


    </script>

}

