<!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>

                </div>
            </div>
        </div>
    </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="school_name" autocomplete="off" class="layui-input"
                   placeholder="学校名称"/>
        </div>
        <div class="seach_items">
            <input type="text" name="grade_name" autocomplete="off" class="layui-input"
                   placeholder="年级名称"/>
        </div>
        <div class="seach_items">
            <input type="text" name="classes_name" autocomplete="off" class="layui-input"
                   placeholder="班级名称"/>
        </div>
        <div class="seach_items">
            <input type="text" name="student_name" autocomplete="off" class="layui-input"
                   placeholder="学生名称"/>
        </div>
        <div class="seach_items">
            <input type="text" name="no" autocomplete="off" class="layui-input"
                   placeholder="订单号"/>
        </div>
        <div class="seach_items">
            <select name="status" style="width: 40px;">
                <option value="">请选择状态</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>
        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="query-form-export">导出
        </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/'
            , toolbar: '#toolbarDemo'
            , title: '用户订单' //标题
            , totalRow: true
            , cols: [[
                {field: 'no', title: '订单号', width: 215}
                , {field: 'commodity_name', title: '商品', width: 150}
                , {field: 'total_amount', title: '总金额',totalRow:true, width: 100}
                , {field: 'coupon_deduction', title: '优惠券抵扣',totalRow:true, width: 100}
                , {field: 'actual_amount', title: '实付金额',totalRow:true, width: 100}
                , {field: 'status_text', title: '订单状态', width: 100}
                , {field: 'notes', title: '备注', width: 150,}
                , {field: 'coupon_name', title: '优惠券名称', width: 150,}
                , {field: 'create_time', title: '下单时间', width: 180,}
                , {field: 'create_user_text', title: '下单人', width: 150,}
                , {field: 'student_text', title: '学生姓名', width: 100,}
                , {field: 'class_text', title: '学校班级', width: 240,}
            ]]
            , 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;
        });
        form.on('submit(query-form-export)', function (data) {
            layer.msg("导出中，请稍等...", {
                icon: 16,
                time: -1
            })
            layui.admin.req({
                url: '/order/?export=1',
                data: data.field,
                done: function (res) {
                    layui.view.download(res.data.filename);
                    layer.closeAll()
                }
            });
            return false;
        });
        //监听工具条
        table.on('tool(datagrid-operate)', function (obj) {
            var data = obj.data;
            table.editdata = data;
            if (obj.event === 'order_logisitcs') {
                if (data.status !== 2) {
                    layer.msg('非待发货状态，禁止发货！', {icon: 2});
                    return false
                }
                layer.open({
                    type: 2,
                    title: '发货',
                    area: ['40%', '75%'],
                    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: 'order_logisitcs.html?id=' + data.id + '&express=' + data.express
                });
            } else if (obj.event === 'edit_freight') {
                if (data.status !== 0) {
                    layer.msg('只有待付款状态，才可以修改运费！', {icon: 2});
                    return false
                }
                layer.open({
                    type: 2,
                    title: '修改运费',
                    shadeClose: false,
                    area: ['700px', '400px'],
                    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: 'edit_freight.html?id=' + data.id
                });
            } else if (obj.event === 'confirm_order') {
                if (data.status > 1) {
                    layer.msg('只有待付款、已付款状态，才可以确认订单！', {icon: 2});
                    return false
                }
                layer.confirm('确定要确认订单吗？', function (index) {
                    layer.close(index);
                    layui.admin.req({
                        notice: true
                        , url: '/order/' + data.id + '/confirm_order/'
                        , type: 'post'
                        , done: function (res) {
                            table.reload('datagrid', {});
                        }
                    });
                });
            } else if (obj.event === 'order_detail') {
                layer.open({
                    type: 2,
                    title: '订单明细',
                    shadeClose: false,
                    area: ['60%', '80%'],
                    btn: ['关闭'],
                    yes: function (index, dom) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'order_detail.html?id=' + data.id + '&type=1'
                });
            } else if (obj.event === 'view_voucher') {
                layer.open({
                    type: 2,
                    title: '付款凭证',
                    shadeClose: false,
                    area: ['60%', '80%'],
                    btn: ['关闭'],
                    yes: function (index, dom) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'view_voucher.html?id=' + data.pay_voucher
                });
            }
        });
    });
</script>
</body>
</html>

