<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户</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">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item layui-hide">
                <div class="layui-inline">
                    <label class="layui-form-label">商品类型</label>
                    <div class="layui-input-block">
                        <select name="type" lay-filter="type">
                            <option value="0">普通区</option>
                            <option value="1">金币区</option>
                            <option value="2">至尊区</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="table" lay-filter="table"></table>
        </div>
    </div>
</div>
@verbatim
    <script type="text/html" id="user">
    {{ d.user.name }}
    </script>

    <script type="text/html" id="status">
        {{#  if(d.status === 0){ }}
        待发货
        {{# } else if(d.status === 1) { }}
        已发货
        {{# } else { }}
        已完成
        {{#  } }}
    </script>

    <script type="text/html" id="toolbar">
        {{#  if(d.status === 0){ }}
        <a class="layui-btn layui-btn-xs" lay-event="send">发货</a>
        {{#  } }}
    </script>


@endverbatim
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'table', 'layer'], function () {
        const $ = layui.$, form = layui.form, table = layui.table, layer = layui.layer;
        let tableList = table.render({
            elem: '#table',
            id: 'table',
            url: "{{url('orders/data')}}",
            // toolbar: true,
            defaultToolbar: [],
            cols: [[
                {field: 'order_no', title: "订单编号",width:200},
                {title: '用户', width: 150, templet: "#user"},
                {field: 'goods_name', title: '商品名',},
                {field: 'name', title: '收货人',},
                {field: 'phone', title: '手机',},
                {field: 'address', title: '地址',},
                {field: 'status', title: '状态', templet: "#status"},
                {title: '操作', width: 200, toolbar: '#toolbar'}
            ]],
            page: true,
            limit: 20,
            limits: [20, 100, 200, 300],
            where: {lang: 'zh-CN', type: 0},
            height: 'full-90',
            text: {none: '无数据'},
            parseData(res) {
                return {
                    code: res.data.code,
                    msg: res.data.msg,
                    count: res.data.count,
                    data: res.data.data
                };
            }
        });
        table.on('tool(table)', function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "send":
                    $.ajax({
                        url: "{{ route('order.send') }}",
                        method: "post",
                        headers: {
                            'X-CSRF-TOKEN': "{{ csrf_token() }}",
                        },
                        data: {id: data.id},
                        success: (res) => (res.code === 0 ? (layer.msg('已发货'), tableList.reloadData()) : layer.alert(res.msg))
                    });
                    break;
                default:
                    layer.alert('未定义事件');
                    break;
            }
        });
    });
</script>
</body>
</html>
