
@{
    ViewData["Title"] = "固定资产明细";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <div class="form-inline" style="line-height:40px;">
                <div class="form-group">
                    <label>采购公司</label>
                    <select id="companyvalue" name="companyvalue" class="form-control">
                        <option value="">请选择采购公司</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>&nbsp;</label>
                    <button class="btn btn-primary" onclick="list()">查询</button>
                    <button class="btn btn-success" onclick="exportFile()">导出</button>
                </div>
            </div>
        </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;
        }
    </style>
}
@section scripts{
    <script>
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 100));

            list();

            listCompany();
        })

        function list() {
            var columns = [
                {
                    field: 'company_name', title: '采购公司', width: '150', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="' + (data.company_value > 0 ?'color:#7092E6;cursor:pointer;':"")+'" class="mules" title="' + data.company_name + '" onclick="showSecondLevel(' + data.company_value + ',\'' + data.company_name+'\',\''+data.day+'\')">' + data.company_name + '</div>';
                    }
                },
                { field: 'start_amount', title: '期初金额', width: '110', sortable: true },
                { field: 'debit_amount', title: '借方发生额', width: '110', sortable: false, iscount: true },
                { field: 'credit_amount', title: '贷方发生额', width: '110', sortable: false, iscount: true },
                { field: 'end_amount', title: '期末金额', width: '100', sortable: true },
                { field: 'day', title: '统计日期', width: '90', sortable: true }
            ];

            var pvalue = $('#companyvalue').val();

            var url = '@Url.Content("~/Reports/Finance/ListFixedAssetsJson")' + '?date=@(ViewBag.date)&paycompanyid=@(ViewBag.paycompanyid)&companyvalue=' + pvalue;

            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 listCompany() {
            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Finance/ListCompanyValue")',
                paramData: '',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#companyvalue').html('<option value="">请选择采购公司</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#companyvalue').append('<option value="' + result[i].company_value + '">' + result[i].company_name + '</option>');
                        }
                    }
                }
            })
        }

        function showSecondLevel(value, name, date) {
            if (value == 0) {
                return false;
            }

            layer_show(date + ' ' + name + ' 的固定资产二级明细', '@Url.Content("~/Reports/Finance/ListFixedAssetsDetails?companyvalue=")' + value + '&date=' + date,'95%','95%');
        }

        function exportFile() {
            var pvalue = $('#companyvalue').val();

            window.open('@Url.Content("~/Reports/Finance/ListFixedAssetsExport?date=")' + '@(ViewBag.date)&paycompanyid=@(ViewBag.paycompanyid)&companyvalue=' + pvalue, "_blank");
        }

    </script>

}

