<!DOCTYPE html>
<html>
<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">
    <link rel="stylesheet" type="text/css" href="../../layuiadmin/style/formSelects-v4.css"/>
    <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: 40px;
        }

        .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 {
            display: inline-block;
            margin-right: 5px;
            margin-top: 5px;
        }
    </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">
                    <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>
                    <script type="text/html" id="order-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="order_check"
                            >审批</a>
                        </div>
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="order_reject"
                            >拒单</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="cancel_order" style="display: none">
    <div class="layui-card-body" pad15>
        <form class="layui-form" lay-filter="form-cancel">
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label"><font color='red' size="4">*</font>拒单原因：</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="reason"
                               lay-verify="required" placeholder="请输入拒单原因">
                    </div>
                </div>
                <div class="layui-form-item" style="text-align:right">
                    <button class="layui-btn" lay-submit id="cancel_order_btn" lay-filter="form-cancel"
                            style="display: none">保存
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script type="text/html" id="toolbarDemo">
    <form class="layui-form" lay-filter="query-form-element">
        <div class="seach_items">
            <input type="text" name="tel" autocomplete="off" class="layui-input"
                   placeholder="电话"/>
        </div>
        <div class="seach_items">
            <input type="text" name="name" autocomplete="off" class="layui-input"
                   placeholder="电话"/>
        </div>
        <div class="seach_items">
            <select name="status" style="width: 40px;">
                <option value="">请选择状态</option>
                <option value="0">待审核</option>
                <option value="1">已通过</option>
                <option value="2">退回修改</option>
                <option value="3">拒绝审批</option>
            </select>
        </div>
        <div class="seach_items">
            <input type="text" class="layui-input" name="create_time" id="id_create_time" placeholder="提交时间">
        </div>
        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="query-form-element">查询
        </button>
    </form>
</script>

<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        , formSelects: 'formSelects-v4'
    }).use(['index', 'table', 'form', 'formSelects', 'laydate'], function () {
        var $ = layui.$
            , table = layui.table
            , form = layui.form
            , laydate = layui.laydate
            , admin = layui.admin;

        table.render({
            elem: '#datagrid'
            , url: '/order/?category=1'
            , toolbar: '#toolbarDemo'
            , title: '用户订单' //标题
            , totalRow: true
            , cols: [[
                {field: 'name', title: '姓名', width: 150}
                , {field: 'sex_text', title: '性别', width: 90}
                , {field: 'tel', title: '手机号', width: 130}
                , {field: 'inumber', title: '证件号', width: 180}
                , {field: 'laompany_text', title: '贷款产品', width: 230}
                , {field: 'status_text', title: '订单状态', width: 100}
                , {field: 'create_time_f', title: '下单时间', width: 160,}
                , {field: 'create_user_text', title: '下单人', width: 120,}
                , {field: 'seller_text', title: '业务人员', width: 120,}
                , {field: 'cancel_reason', title: '拒单原因', width: 120,}
                , {width: 150, align: 'center', fixed: 'right', toolbar: '#order-operate-bar'}
            ]]
            , page: true
            , height: 'full-108'
            , done: function () {
                laydate.render({
                    elem: '#id_create_time'
                    , range: true
                });
            }
        });
        var _params;
        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}
            });
            form.val("query-form-element", data.field);
            layer.closeAll();
            return false;
        });
        //监听工具条
        var order_id;
        table.on('tool(datagrid-operate)', function (obj) {
            var data = obj.data;
            table.editdata = data;
            order_id = data.id
            if (obj.event === 'order_check') {
                layer.open({
                    type: 2,
                    title: '审批',
                    area: ['70%', '80%'],
                    btn: ['返回修改', '审批通过', '取消'],
                    yes: function (index, dom) {
                        layui.onSubmitEdit = function (data) {
                            layer.close(index);
                            table.reload('datagrid', {});
                        };
                        layui.submitEdit();
                    },
                    btn2: function (index, layero) {
                        layui.onSubmitPass = function (data) {
                            layer.close(index);
                            table.reload('datagrid', {});
                        };
                        layui.submitPass();
                    },
                    btn3: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'order_detail_check.html?id=' + data.id
                });
            }
            else if (obj.event === 'order_reject') {
                layer.open({
                    type: 1,
                    title: '拒单',
                    area: ['40%', '60%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        $('#cancel_order_btn').click();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: $('#cancel_order')
                });
            }

        });
        form.on('submit(form-cancel)', function (data) {
            admin.req({
                url: '/order/' + order_id + '/checkEdit/?statu=3'
                , data: data.field
                , type: 'post'
                , done: function (res) {
                    layer.closeAll();
                    table.reload('datagrid', {});
                }
            });
            return false;
        });
    });
</script>
</body>
</html>

