<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>银行总账</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <style type="text/css">
        .LAY-btns .layui-nav {
            padding-left: 0;
            padding-right: 10px;
            top: -4px;
            margin: 0 10px;
            border: 0;
            background-color: #009688;
        }

        .LAY-btns .layui-nav .layui-nav-item {
            line-height: 30px;
        }

        .LAY-btns .layui-nav .layui-nav-child {
            top: 34px;
        }

        .LAY-btns .layui-nav .layui-nav-bar {
            display: none;
        }

        .LAY-btns .layui-nav .layui-nav-child dd.layui-this a {
            color: #333;
            background-color: #fff;
        }

        .LAY-btns .layui-nav .layui-nav-child dd.layui-this a:hover {
            background-color: #f2f2f2;
            color: #000;
        }

        .seach_items {
            float: right;
            margin-left: 10px;
        }

    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="LAY-btns" style="margin-bottom: 10px;">
                        <form class="layui-form seach_items" lay-filter="query-form-element">
                            <div class="seach_items">
                                <button class="layui-btn" lay-submit lay-filter="query-form-element"><i
                                        class="layui-icon layui-icon-search"></i>查询
                                </button>
                            </div>

                            <div class="seach_items">
                                <input type="text" class="layui-input" autocomplete="off" name="end_time"
                                       id="end_time" placeholder="终止时间">
                            </div>

                            <div class="seach_items" style="margin-top: 5px;">
                                终止时间：
                            </div>
                            <div class="seach_items">
                                <input type="text" class="layui-input" autocomplete="off" name="create_time"
                                       id="create_time" placeholder="开始时间">
                            </div>
                            <div class="seach_items" style="margin-top: 5px;">
                                开始时间：
                            </div>
                        </form>
                        <div style="clear: both;"></div>
                    </div>
                    <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    var _params = '';
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        utils: 'utils'
    }).use(['index', 'table', 'laydate', 'form', 'utils'], function () {
        var $ = layui.$;
        var table = layui.table
            , form = layui.form
            , laydate = layui.laydate;
        var date = new Date();
        var create_time = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + '01'
        var end_time = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        laydate.render({
            elem: '#create_time'
            , value: create_time

        });
        laydate.render({
            elem: '#end_time'
            , value: end_time

        });
        table.render({
            elem: '#datagrid'
            , url: '/finance/finance_income/bank_data/'
            , cols: [[
                {field: 'name', title: '银行账户', width: 150}
                , {field: 'qichu_yue', title: '期初余额', width: 150}
                , {field: 'benqi_shouru', title: '本期收入', width: 150}
                , {field: 'benqi_fachu', title: '本期发出', width: 150}
                , {field: 'qimo_yue', title: '期末余额', width: 150}
            ]]
            , totalRow: true
            , height: 'full-104'
            , where: {create_time: create_time, end_time: end_time}
            , parseData: function (res) {
                var cols = this.cols[0];
                for (var i in cols) {
                    if (cols[i].field == 'qichu_yue') {
                        cols[i].totalRowText = res.more.qichu_yue;
                    }
                    else if (cols[i].field == 'benqi_shouru') {
                        cols[i].totalRowText = res.more.benqi_shouru;
                    }
                    else if (cols[i].field == 'benqi_fachu') {
                        cols[i].totalRowText = res.more.benqi_fachu;
                    }
                    else if (cols[i].field == 'qimo_yue') {
                        cols[i].totalRowText = res.more.qimo_yue;
                    }
                }
                return {
                    "code": res.code, //解析接口状态
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
            , done: function () {
                layui.index.removeNoPermButtons();
            }
        });

        //监听工具条
        table.on('tool(datagrid-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                table.editdata = data;
                if (data.check_status === 1) {
                    layer.msg('入库单已审核，无法修改！');
                    return;
                }
                layer.open({
                    type: 2,
                    title: '修改',
                    shadeClose: false,
                    area: ['50%', '60%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        layui.onSubmitChild = function (data) {
                            layer.close(index);
                            table.reload('datagrid', {});
                        };
                        layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'finance_edit.html?id=' + data.id
                });
            } else if (obj.event === 'check') {
                layer.confirm('确定要审核吗？', function (index) {

                    layer.close(index);
                    layui.admin.req({
                        url: '/finance/finance_income/check/?check_status=1&id=' + data.id
                        , done: function (res) {
                            table.reload('datagrid', {});
                        }
                    });
                });
            } else if (obj.event === 'checkout') {
                layer.confirm('确定要撤销审核吗？', function (index) {
                    layer.close(index);
                    layui.admin.req({
                        url: '/finance/finance_income/check/?check_status=0&id=' + data.id
                        , done: function (res) {
                            table.reload('datagrid', {});
                        }
                    });
                });
            }
        });

        $('#btn_add').on('click', function () {
            layer.open({
                type: 2,
                title: '添加',
                area: ['40%', '65%'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'finance_edit.html'
            });
        });

        form.on('submit(query-form-element)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            _params = data.field;
            table.reload('datagrid', {
                where: data.field,
                page: {curr: 1}
            });
            layer.closeAll();
            return false
        });
    })
</script>
</body>
</html>
