<!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;">
                        <div style="float: left">
                            <button class="layui-btn" id="btn_add" data-permission="finance.add_finance_income"><i
                                    class="layui-icon layui-icon-add-circle"></i>添加
                            </button>
                        </div>
                        <form class="layui-form" 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" name="referer_no" autocomplete="off" class="layui-input"
                                       placeholder="引用单号"/>
                            </div>
                            <div class="seach_items">
                                <input type="text" name="account_name" autocomplete="off" class="layui-input"
                                       placeholder="账户名称"/>
                            </div>
                            <div class="seach_items">
                                <input type="text" class="layui-input" autocomplete="off" name="create_time"
                                       id="create_time" placeholder="添加时间">
                            </div>
                        </form>
                        <div style="clear: both;"></div>
                    </div>
                    <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>
                    <script type="text/html" id="datagrid-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="edit"
                               data-permission="finance.add_finance_income">修改</a>
                        </div>
                        <div class="layui-btn-group">
                            {{# if(d.check_status == 0){ }}
                            <a class="layui-btn layui-btn-xs" data-permission="finance.check_finance_income" id="check"
                               lay-event="check">审核</a>
                            {{# } }}
                            {{# if(d.check_status == 1){ }}
                            <a class="layui-btn layui-btn-xs layui-btn-danger "
                               data-permission="finance.check_finance_income" id="checkout" lay-event="check">撤销审核</a>
                            {{# } }}
                        </div>
                    </script>
                </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;

        table.render({
            elem: '#datagrid'
            , url: '/finance/finance_income/data/'
            , cols: [[
                {field: 'no', title: '收支单号', width: 150}
                , {field: 'referer_no', title: '引用单号', width: 150}
                , {field: 'type_text', title: '收支类型', width: 120}
                , {field: 'account_text', title: '收支账户', width: 120}
                , {field: 'amount', align: 'right', title: '收支金额', width: 130}
                , {field: 'purpose_text', align: 'right', title: '收支用途', width: 100}

                , {field: 'create_time', title: '创建时间', width: 150}
                , {field: 'create_user_text', title: '创建人', width: 100}
                , {field: 'check_status_text', title: '审核状态', width: 100}
                , {field: 'check_time', title: '审核时间', width: 150}
                , {field: 'check_user_text', title: '审核人', width: 100}
                , {field: 'notes', title: '备注', minWidth: 120}
                , {width: 150, align: 'left', fixed: 'right', toolbar: '#datagrid-operate-bar'}
            ]]
            , page: true
            , totalRow: true
            , height: 'full-104'
            , parseData: function (res) {
                var cols = this.cols[0];
                for (var i in cols) {
                    if (cols[i].field == 'amount') {
                        cols[i].totalRowText = res.more.sum_amount;
                    }

                }
                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', {});
                        }
                    });
                });
            }
        });
        laydate.render({
            elem: '#create_time'
            , range: true

        });
        laydate.render({
            elem: '#check_time'
            , range: true

        });
        $('#btn_export').on('click', function () {
            layui.admin.req({
                url: '/purchase/godownentry/export/?type=0',
                data: _params,
                done: function (res) {
                    layui.view.download(res.data.filename);
                }
            });
        });
        $('#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>
