{{ define "kas/home.htm" }}
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <title>首页 - 后台管理 - 看丽人</title>
    <script type="text/javascript">
        const ISGOKEEP = true;
    </script>
    {{ template "_common.htm" .}}
    <script type="text/javascript">
        LoadMemberInfo();
    </script>
</head>

<body>
    {{ template "kas/_header.htm" .}}
    <main role="main">
        <div class="album py-3 bg-light">
            <div class="container">
                {{ template "kas/_nav.htm" .}}
                <div class="alert alert-dark border-bottom"><a href="/kas/">首页</a></div>

                <div class="row">
                    <div class="col-md-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <span class="label label-primary pull-right">今天</span>
                                <h5>图片数</h5>
                            </div>
                            <div class="ibox-content">
                                <h1 class="no-margins" id="todayArchiveTotal">...</h1>

                                <div class="stat-percent font-bold" id="archivePercent"></div>
                                <div class="d-flex">
                                    <div class="bd-highlight"><small>同昨天相比</small></div>
                                    <div class="ml-auto bd-highlight"><small>总数：<span id="archiveTotal"></span>（收费：<span
                                                id="archiveMoneyTotal"></span>）</small></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <span class="label label-primary pull-right">今天</span>
                                <h5>视频数</h5>
                            </div>
                            <div class="ibox-content">
                                <h1 class="no-margins" id="todayArchiveVideoTotal">...</h1>

                                <div class="stat-percent font-bold" id="archiveVideoPercent"></div>
                                <div class="d-flex">
                                    <div class="bd-highlight"><small>同昨天相比</small></div>
                                    <div class="ml-auto bd-highlight"><small>总数：<span
                                                id="archiveVideoTotal"></span>（收费：<span
                                                id="archiveVideoMoneyTotal"></span>）</small></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <span class="label label-primary pull-right">今天</span>
                                <h5>文章数</h5>
                            </div>
                            <div class="ibox-content">
                                <h1 class="no-margins" id="todayArchiveArticleTotal">...</h1>

                                <div class="stat-percent font-bold" id="archiveArticlePercent"></div>
                                <div class="d-flex">
                                    <div class="bd-highlight"><small>同昨天相比</small></div>
                                    <div class="ml-auto bd-highlight"><small>总数：<span
                                                id="archiveArticleTotal"></span>（收费：<span
                                                id="archiveArticleMoneyTotal"></span>）</small></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <span class="label label-primary pull-right">今天</span>
                                <h5>会员数</h5>
                            </div>
                            <div class="ibox-content">
                                <h1 class="no-margins" id="todayMemberTotal">...</h1>
                                <div class="stat-percent font-bold" id="memberPercent"></div>
                                <div class="d-flex">
                                    <div class="bd-highlight"><small>同昨天相比</small></div>
                                    <div class="ml-auto bd-highlight"><small>总数：<span id="memberTotal"></span></small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <span class="label label-info pull-right">本周</span>
                                <h5>订单数</h5>
                            </div>
                            <div class="ibox-content">
                                <h1 class="no-margins" id="thisWeekOrderTotal">...</h1>
                                <div class="stat-percent font-bold text-info" id="orderPercent"></div>
                                <div class="d-flex">
                                    <div class="bd-highlight"><small>同上周相比</small></div>
                                    <div class="ml-auto bd-highlight"><small>总数：<span id="orderTotal"></span></small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <span class="label label-warning pull-right">本月</span>
                                <h5>收入</h5>
                            </div>
                            <div class="ibox-content">
                                <h1 class="no-margins" id="thisMonthOrderMoneySum">...</h1>
                                <div class="stat-percent font-bold text-warning" id="moneyPercent"></div>
                                <div class="d-flex">
                                    <div class="bd-highlight"><small>同上月相比</small></div>
                                    <div class="ml-auto bd-highlight"><small>总数：<span
                                                id="orderMoneySumTotal"></span></small></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

    </main>

    {{ template "kas/_footer.htm" .}}
    <script type="text/javascript">
        var gokeep_token = GetCookie(TokenName())
        if (gokeep_token == null) {
            DirectTo("/kas");
        }

        $(document).ready(function () {
            $.ajax({
                url: '/api/v1/auth/statistics',
                type: 'GET',
                dataType: 'json',
                data: { param1: 'value1' },
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('Authorization', 'Bearer ' + gokeep_token);
                },
            })
                .done(function (data) {
                    Log(data)
                    if (data.code == 0) {
                        $('#todayArchiveTotal').text(data.result.todayArchiveTotal);
                        var archiveGrowth = 0;
                        if (data.result.yestodayArchiveTotal > 0) {
                            archiveGrowth = (data.result.todayArchiveTotal - data.result.yestodayArchiveTotal) / data.result.yestodayArchiveTotal * 100;
                        }

                        if (archiveGrowth > 0) {
                            $("#archivePercent").html("<span class='text-success'>" + Math.abs(archiveGrowth).toFixed(2) + "%↑</span>");
                        } else {
                            $("#archivePercent").html("<span class='text-danger'>" + Math.abs(archiveGrowth).toFixed(2) + "%↓</span>");
                        }
                        $('#todayArchiveVideoTotal').text(data.result.todayArchiveVideoTotal);

                        var archiveVideoGrowth = 0;
                        if (data.result.yestodayArchiveVideoTotal > 0) {
                            archiveVideoGrowth = (data.result.todayArchiveVideoTotal - data.result.yestodayArchiveVideoTotal) / data.result.yestodayArchiveVideoTotal * 100;
                        }

                        if (archiveVideoGrowth > 0) {
                            $("#archiveVideoPercent").html("<span class='text-success'>" + Math.abs(archiveVideoGrowth).toFixed(2) + "%↑</span>");
                        } else {
                            $("#archiveVideoPercent").html("<span class='text-danger'>" + Math.abs(archiveVideoGrowth).toFixed(2) + "%↓</span>");
                        }

                        var archiveArticleGrowth = 0;
                        if (data.result.yestodayArchiveArticleTotal > 0) {
                            archiveArticleGrowth = (data.result.todayArchiveArticleTotal - data.result.yestodayArchiveArticleTotal) / data.result.yestodayArchiveArticleTotal * 100;
                        }

                        if (archiveArticleGrowth > 0) {
                            $("#archiveArticlePercent").html("<span class='text-success'>" + Math.abs(archiveArticleGrowth).toFixed(2) + "%↑</span>");
                        } else {
                            $("#archiveArticlePercent").html("<span class='text-danger'>" + Math.abs(archiveArticleGrowth).toFixed(2) + "%↓</span>");
                        }
                        $('#todayArchiveArticleTotal').text(data.result.todayArchiveArticleTotal);

                        $('#todayMemberTotal').text(data.result.todayMemberTotal);
                        var memberGrowth = 0;
                        if (data.result.yestodayMemberTotal > 0) {
                            memberGrowth = (data.result.todayMemberTotal - data.result.yestodayMemberTotal) / data.result.yestodayMemberTotal * 100;
                        }
                        if (memberGrowth > 0) {
                            $("#memberPercent").html("<span class='text-success'>" + Math.abs(memberGrowth).toFixed(2) + "%↑</span>");
                        } else {
                            $("#memberPercent").html("<span class='text-danger'>" + Math.abs(memberGrowth).toFixed(2) + "%↓</span>");
                        }

                        $('#thisWeekOrderTotal').text(data.result.thisWeekOrderTotal);
                        var orderGrowth = 0;

                        if (data.result.preWeekOrderTotal > 0) {
                            orderGrowth = (data.result.thisWeekOrderTotal - data.result.preWeekOrderTotal) / data.result.preWeekOrderTotal * 100;
                        }
                        if (orderGrowth > 0) {
                            $("#orderPercent").html("<span class='text-success'>" + Math.abs(orderGrowth).toFixed(2) + "%↑</span>");
                        } else {
                            $("#orderPercent").html("<span class='text-danger'>" + Math.abs(orderGrowth).toFixed(2) + "%↓</span>");
                        }

                        $('#thisMonthOrderMoneySum').text("¥" + data.result.thisMonthOrderMoneySum.Value.toFixed(2));
                        var moneyGrowth = 0;
                        if (data.result.preMonthOrderMoneySum.Value > 0) {
                            moneyGrowth = (data.result.thisMonthOrderMoneySum.Value - data.result.preMonthOrderMoneySum.Value) / data.result.preMonthOrderMoneySum.Value * 100;
                        }
                        if (moneyGrowth > 0) {
                            $("#moneyPercent").html("<span class='text-success'>" + Math.abs(moneyGrowth).toFixed(2) + "%↑</span>");
                        } else {
                            $("#moneyPercent").html("<span class='text-danger'>" + Math.abs(moneyGrowth).toFixed(2) + "%↓</span>");
                        }

                        $("#archiveTotal").text(data.result.archiveTotal);
                        $("#archiveMoneyTotal").text(data.result.archiveMoneyTotal);
                        $("#archiveVideoTotal").text(data.result.archiveVideoTotal);
                        $("#archiveArticleTotal").text(data.result.archiveArticleTotal);
                        $("#archiveVideoMoneyTotal").text(data.result.archiveVideoMoneyTotal);
                        $("#archiveArticleMoneyTotal").text(data.result.archiveArticleMoneyTotal);
                        $("#memberTotal").text(data.result.memberTotal);
                        $("#orderTotal").text(data.result.orderTotal);
                        $("#orderMoneySumTotal").text("¥" + data.result.orderMoneySumTotal.Value);

                    }
                })
                .fail(function () {
                    console.log("error");
                });

        });
    </script>
</body>

</html>
{{ end }}