
@{
    ViewData["Title"] = "资产负债表环比";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "报表管理", "资产负债表", "资产负债表环比表" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="alert alert-warning">
            说明：资产负债表的取数时间点是每周二或每月最后一天
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <input id="start" class="form-control" name="start" type="text" style="width:120px;" value="@ViewBag.start" placeholder="开始日期" />
                        <input id="end" name="end" class="form-control" type="text" style="width:120px;" value="@ViewBag.end" placeholder="结束日期" />
                        <button type="button" class="btn btn-sm btn-primary" onclick="init();"><i class="fa fa-search"></i>&nbsp;查询</button>
                        <button id="btnexport" type="button" class="btn btn-sm btn-success" onclick="ExportXsl();">导出</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            @*<div id="chart_content" style="height:600px;width:100%;">

            </div>*@
            <table id="tb" class="table table-hover table-bordered" style="width:100%;">
                <thead>
                    <tr>
                        <th>一级项目</th>
                        <th>二级项目</th>
                        <th>期初</th>
                        <th>期末</th>
                        <th>差异值(期末-期初)</th>
                        <th>环比差值%</th>
                    </tr>
                </thead>
                <tbody id="tbody_"></tbody>
            </table>
        </div>
    </div>
</div>

@section scripts{
    @*<script src="https://cdn.bootcss.com/echarts/3.6.2/echarts.min.js"></script>*@
    <script>
        var myChart;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            //myChart = echarts.init(document.getElementById('chart_content'));
            init();
        })

        function init() {
            var start = $('#start').val();
            var end = $('#end').val();

            if (start == '' || end == '') {
                alert('开始和结束日期必须填写');
                return false;
            }

            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Finance/FinanceDebtChainChartJson")',
                paramData: 'start=' + start + '&end=' + end,
                func: function (result) {
                    $('#tbody_').html('');
                    if (result.success) {
                        //var option = {
                        //    title: {
                        //        text: ''
                        //    },
                        //    tooltip: {},
                        //    legend: {
                        //        data: ['环比%']
                        //    },
                        //    xAxis: {
                        //        data: result.data.col
                        //    },
                        //    yAxis: {},
                        //    series: [{
                        //        name: '环比',
                        //        type: 'bar',
                        //        barWidth: '60%',
                        //        data: result.data.val
                        //    }]
                        //};
                        
                        //myChart.setOption(option);

                        for (var i = 0; i < result.data.length; i++) {
                            if (result.data[i].sencondlevelname.indexOf('合计') > 0) {
                                var s = '<tr><td style="text-align:right;width:190px;background:#eee;">' + result.data[i].onelevelname + '</td><td style="background:#eee;">' + result.data[i].sencondlevelname + '</td><td style="background:#eee;">' + result.data[i].start + '</td><td style="background:#eee;">' + result.data[i].end + '</td><td style="background:#eee;">' + result.data[i].diffval + '</td><td style="background:#eee;">' + result.data[i].diff + '</td><tr>';
                            }
                            else {
                                var s = '<tr><td style="text-align:right;width:190px;" onclick="showDetail(\''+result.data[i].sencondlevelname+'\')">' + result.data[i].onelevelname + '</td><td>' + result.data[i].sencondlevelname + '</td><td>' + result.data[i].start + '</td><td>' + result.data[i].end + '</td><td>' + result.data[i].diffval + '</td><td>' + result.data[i].diff + '</td><tr>';
                            }
                            
                            $('#tbody_').append(s);
                        }

                    }
                }
            })
        }


        function showDetail(colname) {
            var start = $('#start').val();
            var end = $('#end').val();

            if (start == '' || end == '') {
                alert('开始和结束日期必须填写');
                return false;
            }

            var url = '';

            if (colname == '1.平台提现在途') {
                url = '@Url.Content("~/Reports/BalanceSheetSub/WithdrawalInWay?start=")'+start+'&end='+end;
            }


            if (url != '') {
                layer_show(start + '至' + end + ' ' + colname, url, '90%', '90%');
            }

        }

        function ExportXsl() {
            var start = $('#start').val();
            var end = $('#end').val();

            if (start == '' || end == '') {
                alert('开始和结束日期必须填写');
                return false;
            }

            window.open('@Url.Content("~/Reports/Finance/ExportFinanceDebtChainChart?start=")'+start+'&end='+end, "_blank");
        }

    </script>
}
