字段宽度

名称示例值正常尺寸小尺寸大尺寸
日期时间2019-01-01 00:00:00160142
日期时间2019-01-01...118
日期2019-01-0110692
文字名字5854
文字处理中7368
文字王者荣耀8678
文字超级马里奥 90
按钮编辑6563
按钮编辑 删除115100
按钮编辑 删除 日志158132
按钮编辑 删除 日志 详情 158
数字13888888888118105
数字99999.99 82
数字999999 72
数字999.9 62

内容

<div class="layui-fluid">
    <div class="layui-card">
        <form class="layui-form layui-card-header layuiadmin-card-header-auto search">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="number" name="id" value="" placeholder="请输入预约ID" class="layui-input">
                </div>
                <div class="layui-inline">
                    <input type="number" name="user_id" value="" placeholder="请输入用户ID" class="layui-input">
                </div>
                <div class="layui-inline">
                    <input type="text" name="name" value="" placeholder="请输入姓名" class="layui-input">
                </div>
                <div class="layui-inline">
                    <input type="text" name="tel" value="" placeholder="请输入电话号码" class="layui-input">
                </div>
                <div class="layui-inline">
                    <input type="text" name="area" value="" placeholder="请输入安装地区" class="layui-input">
                </div>
                <div class="layui-inline">
                    <input type="text" name="address" value="" placeholder="请输入详细地址" class="layui-input">
                </div>
                <div class="layui-inline">
                    <select name="product_id" lay-search>
                        <option value="">请选择产品</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="status">
                        <option value="">请选择状态</option>
                        <option value="0">已取消</option>
                        <option value="1">待派单</option>
                        <option value="2">已接单</option>
                        <option value="3">已安装</option>
                    </select>
                </div>
            </div>
        </form>
        <div class="layui-card-body">
            <table class="layui-hide" id="table" lay-filter="table"></table>
        </div>
    </div>
</div>

内容模板

<script type="text/html" id="status">
    {{#  switch(d.status){ case 0:}}
    删除
    {{#  break; case 1:}}
    <span style="color: #1E9FFF"><i class="layui-icon layui-icon-friends"></i>&nbsp;在籍</span>
    {{#  break; case 2:}}
    <span style="color: #999999"><i class="layui-icon layui-icon-friends"></i>&nbsp;退学</span>
    {{#  break; case 3:}}
    转校
    {{#  break; case 4:}}
    <span style="color: #FF5722"><i class="layui-icon layui-icon-friends"></i>&nbsp;毕业</span>
    {{#  } }}
</script>
<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="view">查看</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
</script>

JavaScript

layui.use(['table', 'jquery', 'layer', 'form'], function(){
    let table   = layui.table,
        $       = layui.jquery,
        form    = layui.form;

    // 获取数据并渲染表格
    table.render({
        elem: '#table'
        ,url: location.href
        ,method: 'post'
        ,id: 'table'
        ,toolbar: false
        ,cols: [[
            {type: 'checkbox', fixed: 'left'}
            ,{field:'id', title: 'ID', width:68}
            ,{field:'user_id', title: '用户', width:168, templet: '#user_id'}
            ,{field:'name', title: '姓名', width:86}
            ,{field:'tel', title: '手机号码', width:120}
            ,{field:'area', title: '安装地区', width:138}
            ,{field:'address', title: '详细地址', width:138}
            ,{field:'install_date', title: '安装日期', width:138}
            ,{field:'product_id', title: '产品', width:138}
            ,{field:'birthday', title: '出生年月日', width:106}
            ,{field:'create_time', title: '时间', width:160}
            ,{field:'status', title: '状态', width:80, templet: '#status'}
            ,{field:'options', title: '操作', width:118, toolbar: '#toolbar', fixed: 'right'}
        ]]
        ,where: getSearchWhere('form')
        ,page: true
        ,height: 'auto'
    });

    table.on('tool(table)', function(obj){
        switch (obj.event) {
            case 'view':
                layer.open({
                    type: 2
                    ,title: '查看内容'
                    ,content: "{:url('merchant/Feedback/view')}?id=" + obj.data.id
                    ,area: ['600px', '500px']
                    ,btn: ''
                    ,end: function () {
                        // 重载表格
                        table.reload('table');
                    }
                });
                break;
            case 'delete':
                layer.confirm('确定要删除 ' + obj.data.id + ' ?', function(index){
                    $.post("{:url('merchant/Feedback/delete')}", {id: obj.data.id}, function (data) {
                        layer.msg(data.msg);

                        if (data.code == 0) {
                            // 重载表格
                            table.reload('table');
                        }
                    });

                    layer.close(index);
                });

                break;
            case 'icon':
                layer.photos({
                    photos: {
                        "title": "预览",
                        "data": [
                            {"src": obj.data.icon,}
                        ]
                    }
                });
                break;
        }
    });

    $('#search').click(function () {
        table.reload('table', {
            where: getSearchWhere('form')
        });
    });

    form.on('select(search)', function(){
        table.reload('table', {
            where: getSearchWhere('.search')
        });
    });
    $('.search input').change(function () {
        table.reload('table', {
            where: getSearchWhere('.search')
        });
    });

    function getSearchWhere(form_ele) {
        let data = {};
        $.each($(form_ele).serializeArray(), function (key, value) {
            data[value.name] = value.value;
        });

        return data;
    }
});

标签: none

添加新评论