
@{
    ViewData["Title"] = "Amazon广告费";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "统计", "Amazon", "Sku广告费" };
}

<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>&nbsp;</label>
                        <select id="account" name="account" class="form-control">
                            <option value="">请选择帐号</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <select id="t" name="t" class="form-control">
                            <option value="">广告类型</option>
                            <option value="1">广告推广</option>
                            <option value="2">品牌推广</option>
                            <option value="3">品牌推广_视频</option>
                            <option value="4">品牌展示</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>费用时间</label>
                        <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(ViewBag.start.ToString("yyyy-MM-dd"))" />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(ViewBag.end.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="exportlist();">导出</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>
@section css{
    <link href="~/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <link href="~/css/bootstrap-table-fixed-columns.css" rel="stylesheet" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script src="~/js/jquery.ztree.core.min.js"></script>
    <script src="~/js/jquery.ztree.excheck.min.js"></script>
    <script src="~/js/bootstrap-table-fixed-columns.js" type="text/javascript"></script>
    <script type="text/javascript">
        var companyid = 0;
        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();

            listAccount();

            //listWebsite();

            //listcategory12();
        })

        function list() {
            var columns = [
                {
                    field: 'account_name', title: '帐号', width: '200', iscount: true
                },
                { field: 'sku', title: 'SKU', width: '120', sortable: true },
                { field: 'cost', title: '费用', width: '120', sortable: true, iscount: true },
                { field: 'type', title: '广告类型', width: '150' },
                { field: 'currency', title: '币种', width: '130' },
                { field: 'cost_rmb', title: '费用RMB', width: '100', iscount: true},
                { field: 'report_date', title: '报告日期', width: '100' }
            ];

            var url = '@Url.Content("~/Reports/Orders/AmazonADJson")' + '?' + $("#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;
                                    }
                                }
                            }
                        }

                        companyid = d.companyid;
                        if (d.isexport == 1) {
                            $('#btnexport').show();
                        }
                    }
                }, {
                        fixedcol: true,
                        fixedcolnum: 1
                    });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function listAccount() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListAccount")',
                type:'POST',
                paramData: 'platform=Amazon',
                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 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 exportlist() {
            window.open('@Url.Content("~/Reports/Orders/ExportAmazonAD?")' + $("#toolbar").serialize() + '&companyid=' + companyid, '_blank');
        }

    </script>

}

