layui table 表格模板按钮的实例代码

这是个是全部的jsp 页面:

<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<html>
<link rel="icon" href="../../../static/images/favicon.png" rel="external nofollow" >
<title>会员列表</title>
<link type="text/css" rel="stylesheet" href="../../../static/layui/css/layui.css" rel="external nofollow" >
<style type="text/css">
 body {
  height: 100%;
  width: 100%;
  /*overflow: hidden;*/
  background-size: cover;
  margin: 0 auto;
 }

 .body_bg {
  /*height: 1000px;;*/
  text-align: center;
  display: block;
  padding-left: 15px;
  padding-right: 15px;
 }

 .t_title {
  height: 65px;
  font-size: 20px;
  display: block;
  /*padding: 10px;*/
  text-align: left;
 }

 .t_test {
  background-color: white;
  width: 100%;

 }

 .table_scroll {
  height: 505px;
  overflow-y: auto;
 }

 td {
  font-size: 12px !important;
 }

 .layui-form-checkbox span {
  height: 30px;
 }

 .layui-field-title {
  border-top: 1px solid white;
 }

 table {
  width: 100% !important;
 }

</style>
<body>
<div class="body_bg">
 <!--标题-->
 <div class="t_title">
  <fieldset class="layui-elem-field layui-field-title">
   <blockquote class="layui-elem-quote">
    <legend>会员列表</legend>
   </blockquote>
  </fieldset>
 </div>
 <div class="t_test">
  <!--搜索 按钮-->
  <div class="layui-form-item">
   <!--按钮-->
   <div style="padding-bottom: 10px; width:100%;height:40px">
    <%-- <div class="layui-input-inline" style="width: 149px">
     <button class="layui-btn" id="addLeaguerInfoCustom ">
      <i class="layui-icon" style="font-size: 20px; "></i> 添加自定义会员
     </button>
    </div>--%>
    <div class="layui-input-inline" style="width: 147px;">
     <button class="layui-btn" id="addLeaguerInfoSpecial">
      <i class="layui-icon" style="font-size: 20px; "></i> 添加特殊会员
     </button>
    </div>

   </div>
   <!--搜索-->
   <form class="layui-form">
    <!-- <div class="layui-input-inline">
      <input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
        autocomplete="off"
        class="layui-input">
     </div>
     <div class="layui-input-inline">
      <input type="text" name="date" id="date1" lay-verify="date" placeholder="yyyy-MM-dd"
        autocomplete="off"
        class="layui-input">
     </div>-->
     <div class="layui-input-inline">
      <input type="tel" name="searContent" autocomplete="off"
        placeholder="姓名/手机号" class="layui-input">
     </div>
    </form>
    <div class="layui-input-inline " style="width: 90px">
     <button class="layui-btn" id="searchEmailCompany" data-type="reload">
      <i class="layui-icon" style="font-size: 20px; "></i> 搜索
     </button>
    </div>
   </div>
   <!--蓝色分割线-->
  <hr class="layui-bg-blue">
  <!--表格分页-->
  <div class="yys-fluid yys-wrapper">
   <div class="layui-row lay-col-space20">
    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
     <section class="yys-body animated rotateInDownLeft">
      <div class="yys-body-content clearfix changepwd">
       <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
        <div class="user-tables">
         <table id="userTables" lay-filter="userTables"></table>
        </div>
       </div>
      </div>
     </section>
    </div>
   </div>
  </div>
 </div>
</div>
<script type="application/javascript" src="../../../static/layui/layui.all.js"></script>
<script type="text/html" id="userbar">
 <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
 <a class="layui-btn layui-btn-xs" lay-event="change">修改</a>
 {{#
 var statusBut= function(date){
 if(date==0){
 return '<a class="layui-btn layui-btn-xs" lay-event="edit">禁用</a>';
 }else if(date==1){
 return'<a class="layui-btn layui-btn-xs" lay-event="edit">启用</a>';
 }
 }
 }}
 {{ statusBut(d.status)}}
 <a class="layui-btn layui-btn-xs" lay-event="recharge">充值</a>
</script>
<script type="text/html" id="TimeTpl">
 {{#
 var parseDate= function(date){
 if(date){
 var t=new Date(date);
 return t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate()+" "+t.getHours()+":"+t.getMinutes();
 }
 }
 }}
 {{parseDate(d.updateTime)}}
</script>
<script type="text/html" id="statusTpl">
 {{#
 var statusTxt= function(date){
 if(date==0){
 return "正常";
 }else if(date==1){
 return '
 <spng style="color:red">禁用</spng>';
 }
 }
 }}
 {{ statusTxt(d.status)}}
</script>
<script>
 var $ = null;
 layui.use(["jquery", "upload", "form", "table", "layer", "element", "laydate"], function () {
  $ = layui.jquery;
  var element = layui.element,
   layer = layui.layer,
   upload = layui.upload,
   form = layui.form,
   laydate = layui.laydate,
   table = layui.table;
  //日期
  laydate.render({
   elem: '#date'
  });
  laydate.render({
   elem: '#date1'
  });

  //添加自定义会员
  $("#addLeaguerInfoCustom").click(function () {
   var roleHtml = '';
   $.post('${pageContext.request.contextPath}/leaguer/getRoleList', {}, function (data) {
    if (data.code == 200) {
     console.log(data.body)
     $.each(data.body, function (i, role) {
      console.log(role)
      roleHtml = roleHtml + '<option value="' + role.id + '">' + role.title + '</option>';
     })
     layer.open({
      title: '添加普通会员',
      type: 1,
      area: ['700px', '450px'],
      offset: ['50px', '250px'],
      content: '<blockquote class="layui-elem-quote layui-text">注意事项: 请填写相关的数据信息! </blockquote>' +
      '<form class="layui-form"> ' +
      '<div class="layui-form-item">' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">姓名</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="leaguerName" class="layui-input" value="" >' +
      '</div></div>' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">角色</label>' +
      '<div class="layui-input-inline">' +
      '<select name="roleId" >' +
      '<option value="">请选择一个角色</option>' +
      roleHtml +
      '</select>' +
      '</div></div>' +
      '</div>' +
      '<div class="layui-form-item">' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">手机号</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="leaguerPhone" class="layui-input" value="" >' +
      '</div></div>' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">客服电话</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="servicePhone" class="layui-input" value="" >' +
      '</div></div>' +
      '</div>' +
      '<div class="layui-form-item" style="width: 621px;">' +
      '<label class="layui-form-label">公司名称</label>' +
      '<div class="layui-input-block">' +
      '<input type="text" required lay-verify="required" name="company" class="layui-input" value="" >' +
      '</div>' +
      '</div>' +

      '<div class="layui-form-item">' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">logo图标</label>' +
      '<div class="layui-input-inline">' +
      '<div class="layui-upload">' +
      '<button type="button" class="layui-btn" id="logn_upload">上传图片</button>' +
      '<div class="layui-upload-list">' +
      '<img class="layui-upload-img" id="demo1" style=" width: 100px; height: 100px; margin-bottom: 8px;">' +
      '<p id="demoText"></p>' +
      '</div>' +
      '</div>' +
      '<input type="text" hidden name="logoUrl" value="" >' +
      '</div></div>' +
      '</div>' +
      '</form>',
      btnAlign: 'c',
      btn: ['确定', '取消'],
      yes: function (index, layero) {
       var str = $("input[name=isIndividual]").val();
       if (str == "on") {
        str = "1";
       } else {
        str = "0";
       }
       if ($("input[name=leaguerName]").val() == null || $("input[name=leaguerName]").val() == "") {
        layer.msg('请输入姓名', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6
        }, function () {
         $("input[name=leaguerName]").focus();
        });
        return false;
       } else if ($("select[name=roleId]").val() == null || $("select[name=roleId]").val() == "") {
        layer.msg('请选择角色', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6
        }, function () {
         $("input[name=roleId]").focus();
        });
        return false;
       } else if ($("input[name=leaguerPhone]").val() == null || $("input[name=leaguerPhone]").val() == "") {
        layer.msg('请输入手机号', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6
        }, function () {
         $("input[name=leaguerPhone]").focus();
        });
        return false;
       } else if ($("input[name=servicePhone]").val() == null || $("input[name=servicePhone]").val() == "") {
        layer.msg('请输入客服电话', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6
        }, function () {
         $("input[name=servicePhone]").focus();
        });
        return false;
       } else if ($("input[name=company]").val() == null || $("input[name=company]").val() == "") {
        layer.msg('请输入企业名称', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6
        }, function () {
         $("input[name=company]").focus();
        });
        return false;
       }
//        else if ($("input[name=logoUrl]").val() == null || $("input[name=logoUrl]").val() == "") {
//         layer.msg('请上传logo', {icon: 5, time: 2000, area: '200px', type: 0, anim: 6,}, function () {
//          $("input[name=logoUrl]").focus();
//         });
//         return false;
//        }

       var formData = {
        leaguerName: $("input[name=leaguerName]").val(),
        roleId: $("select[name=roleId]").val(),
        leaguerPhone: $("input[name=leaguerPhone]").val(),
        servicePhone: $("input[name=servicePhone]").val(),
        company: $("input[name=company]").val(),
        logoUrl: $("input[name=logoUrl]").val()
       };
       console.log(formData);
       $.post('${pageContext.request.contextPath}/leaguer/addLeaguerCustom', formData, function (data) {
        //判断是否发送成功
        if (data.code == 200) {
         layer.msg(data.message);
         layer.close(index);
         parent.document.getElementById('my_iframe').contentWindow.location.reload(true);
        } else {
         layer.msg("保存失败...", {type: 1});
        }
       })
      }, btn2: function (index, layero) {
       layer.msg("取消");
       //return false 开启该代码可禁止点击该按钮关闭
      }, cancel: function () {
       layer.msg("关闭窗口");
       //右上角关闭回调
       //return false 开启该代码可禁止点击该按钮关闭
      },
      success: function () {
       layui.use('form', function () {
        var form = layui.form; //只有执行了这一步,部分表单元素才会修饰成功
        form.render('checkbox');
        form.render('select');
        form.on('checkbox(istrue)', function (data) {
         /* if(data.elem.checked){
          emailConfig['isenterprise']=1;
          }; //是否被选中,true或者false*/
        });
        //普通图片上传
        var uploadInst = upload.render({
         elem: '#logn_upload'
         , url: '/leaguer/upload/headImg'
         , before: function (obj) {
          //预读本地文件示例,不支持ie8
          obj.preview(function (index, file, result) {
           $('#demo1').attr('src', result); //图片链接(base64)
          });
         }
         , done: function (res) {
          //如果上传失败
          if (res.code > 0) {
           return layer.msg('上传失败');
          }
          if (res.code == 0) {
           $("input[name=logoUrl]").val(res.data.src);
           //do something (比如将res返回的图片链接保存到表单的隐藏域)
          }
          //上传成功
         }
         , error: function () {
          //演示失败状态,并实现重传
          var demoText = $('#demoText');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function () {
           uploadInst.upload();
          });
         }
        });
        element.init();
       });
      }
     });

    } else {
     layer.msg("获取角色失败...", {type: 1});
    }
   })
   return;
  })

  //添加特殊会员
  $("#addLeaguerInfoSpecial").click(function () {
   var roleHtml = '';
   $.post('${pageContext.request.contextPath}/leaguer/getRoleList', {}, function (data) {
    if (data.code == 200) {
     console.log(data.body)
     $.each(data.body, function (i, role) {
      console.log(role)
      if (role.id !=1) {
       roleHtml = roleHtml + '<option value="' + role.id + '">' + role.title + '</option>';
      }
     })
     layer.open({
      title: '添加特殊会员',
      type: 1,
      area: ['700px', '450px'],
      offset: ['50px', '250px'],
      content: '<blockquote class="layui-elem-quote layui-text">注意事项: 请填写相关的数据信息! </blockquote>' +
      '<form class="layui-form"> ' +
      '<div class="layui-form-item">' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">姓名</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="leaguerName" class="layui-input" value="" >' +
      '</div></div>' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">角色</label>' +
      '<div class="layui-input-inline">' +
      '<select name="roleId" >' +
      '<option value="">请选择一个角色</option>' +
      roleHtml +
      '</select>' +
      '</div></div>' +
      '</div>' +
      '<div class="layui-form-item">' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">手机号</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="leaguerPhone" class="layui-input" value="" >' +
      '</div></div>' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">客服电话</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="servicePhone" class="layui-input" value="" >' +
      '</div></div>' +
      '</div>' +
      '<div class="layui-form-item" style="width: 621px;">' +
      '<label class="layui-form-label">公司名称</label>' +
      '<div class="layui-input-block">' +
      '<input type="text" required lay-verify="required" name="company" class="layui-input" value="" >' +
      '</div>' +
      '</div>' +

      '<div class="layui-form-item">' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">logo图标</label>' +
      '<div class="layui-input-inline">' +
//    '<input type="text" required lay-verify="required" name="type" class="layui-input" value="" >' +

      '<div class="layui-upload">' +
      ' <button type="button" class="layui-btn" id="logn_upload">上传图片</button>' +
      ' <div class="layui-upload-list">' +
      ' <img class="layui-upload-img" id="demo1" src="../../../static/upload/user/headImage/leibao.png" style=" width: 100px; height: 100px; margin-bottom: 8px;">' +
      '<p id="demoText"></p>' +
      ' </div>' +
      ' </div>' +
      '<input type="text" hidden name="logoUrl" value="" >' +
      '</div></div>' +
      '</div>' +
      '</form>',
      btnAlign: 'c',
      btn: ['确定', '取消'],
      yes: function (index, layero) {
       var str = $("input[name=isIndividual]").val();
       if (str == "on") {
        str = "1";
       } else {
        str = "0";
       }
       if ($("input[name=leaguerName]").val() == null || $("input[name=leaguerName]").val() == "") {
        layer.msg('请输入姓名', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6,
        }, function () {
         $("input[name=leaguerName]").focus();
        });
        return false;
       } else if ($("select[name=roleId]").val() == null || $("select[name=roleId]").val() == "") {
        layer.msg('请选择角色', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6,
        }, function () {
         $("input[name=roleId]").focus();
        });
        return false;
       } else if ($("input[name=leaguerPhone]").val() == null || $("input[name=leaguerPhone]").val() == "") {
        layer.msg('请输入手机号', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6,
        }, function () {
         $("input[name=leaguerPhone]").focus();
        });
        return false;
       } else if ($("input[name=servicePhone]").val() == null || $("input[name=servicePhone]").val() == "") {
        layer.msg('请输入客服电话', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6,
        }, function () {
         $("input[name=servicePhone]").focus();
        });
        return false;
       } else if ($("input[name=company]").val() == null || $("input[name=company]").val() == "") {
        layer.msg('请输入企业名称', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6,
        }, function () {
         $("input[name=company]").focus();
        });
        return false;
       }

       var formData = {
        leaguerName: $("input[name=leaguerName]").val(),
        roleId: $("select[name=roleId]").val(),
        leaguerPhone: $("input[name=leaguerPhone]").val(),
        servicePhone: $("input[name=servicePhone]").val(),
        company: $("input[name=company]").val(),
        logoUrl: $("input[name=logoUrl]").val()
       };
       console.log(formData);
       $.post('${pageContext.request.contextPath}/leaguer/addLeaguerSpecial', formData, function (data) {
        //判断是否发送成功
        if (data.code == 200) {
         layer.msg(data.message);
         layer.close(index);
         parent.document.getElementById('my_iframe').contentWindow.location.reload(true);
        } else {
         layer.msg("保存失败...", {type: 1});
        }
       })
      }, btn2: function (index, layero) {
       layer.msg("取消");
       //return false 开启该代码可禁止点击该按钮关闭
      }, cancel: function () {
       layer.msg("关闭窗口");
       //右上角关闭回调
       //return false 开启该代码可禁止点击该按钮关闭
      },
      success: function () {
       layui.use('form', function () {
        var form = layui.form; //只有执行了这一步,部分表单元素才会修饰成功
        form.render('checkbox');
        form.render('select');
        form.on('checkbox(istrue)', function (data) {
         /* if(data.elem.checked){
          emailConfig['isenterprise']=1;
          }; //是否被选中,true或者false*/
        });
        //普通图片上传
        var uploadInst = upload.render({
         elem: '#logn_upload'
         , url: '/leaguer/upload/headImg'
         , before: function (obj) {
          //预读本地文件示例,不支持ie8
          obj.preview(function (index, file, result) {
           $('#demo1').attr('src', result); //图片链接(base64)
          });
         }
         , done: function (res) {
          //如果上传失败
          if (res.code > 0) {
           return layer.msg('上传失败');
          }
          if (res.code == 0) {
           $("input[name=logoUrl]").val(res.data.src);
           //do something (比如将res返回的图片链接保存到表单的隐藏域)
          }
          //上传成功
         }
         , error: function () {
          //演示失败状态,并实现重传
          var demoText = $('#demoText');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function () {
           uploadInst.upload();
          });
         }
        });
        element.init();
       });
      }
     });

    } else {
     layer.msg("获取角色失败...", {type: 1});
    }
   })
   return;
  })

  //表格加载
  var a = table.render({
   elem: "#userTables",
   skin: 'line', //行边框风格
   cols: [[
//    {checkbox: false, width: 60, fixed: true},
    {type: 'numbers', title: '序号', width: '30'},
    {
     field: "leaguerName",
     width: 90,
     title: "姓名",
     align: "left"
    },
    {
     field: "leaguerPhone",
     width: 130,
     title: "手机号",
     align: "left"
    },
    {
     field: "balanceMoney",
     width: 100,
     title: "余额(元)",
     align: "left"
    },
    {
     field: "company",
     width: 120,
     title: "公司名称",
     align: "left"
    },
    {
     field: "status",
     width: 60,
     title: "状态",
     align: "left",
     templet: '#statusTpl'
    },
    {
     field: "title",
     width: 120,
     title: "角色",
     align: "left"
    },
    {
     field: "updateTime",
     width: 140,
     title: "更新时间",
     align: "left",
     templet: '#TimeTpl'
    },
    {
     title: "常用操作",
     width: 200,
     align: "left",
     toolbar: "#userbar",
     fixed: "right"
    }
   ]],
   url: "/leaguer/getLeaguerInfoList?t="+new Date(),
//   data: userData,
   page: { //分页设定
    layout: ['count', 'prev', 'page', 'next'] //自定义分页布局
    , curr: 1 //设定初始在第 1 页
    , limit: 10//每页多少数据
    , groups: 5 //只显示 5 个连续页码
   },
   even: true
  });

  //表格按钮监听
  table.on("tool(userTables)", function (e) {
   var leaguerDate = e.data;
//   console.log(leaguerDate);
   if (e.event === "edit" && leaguerDate.status == 0) {
    var formData = {
     leaguerId: leaguerDate.leaguerId,
     status: 1
    };
    $.post('/leaguer/setLeaguerStatus', formData, function (data) {
     //判断是否发送成功
     if (data.code == 200) {
      layer.msg(data.message);
//      layer.close(index);
      parent.document.getElementById('my_iframe').contentWindow.location.reload(true);
     } else {
      layer.msg(data.message, {type: 1});
     }
    })
   }
   if (e.event === "edit" && leaguerDate.status == 1) {
    var formData = {
     leaguerId: leaguerDate.leaguerId,
     status: 0
    };
    $.post('/leaguer/setLeaguerStatus', formData, function (data) {
     //判断是否发送成功
     if (data.code == 200) {
      layer.msg(data.message);
//      layer.close(index);
      parent.document.getElementById('my_iframe').contentWindow.location.reload(true);
     } else {
      layer.msg(data.message, {type: 1});
     }
    })
   }
   if (e.event === "detail") {
    var formData5 = {
     leaguerId: leaguerDate.leaguerId
    };
    $.post('/leaguer/getLeaguerInfoById', formData5, function (data) {
     var json = eval(data);
     var mapDate = data.body;
     console.log(data);
     if (data.code == 200) {
      var leaguer = data.body.leaguer;
      console.log(data.body)
      var roleHtml = '';
      $.each(data.body.roleList, function (i, role) {
       console.log(role);
       if (leaguer.roleId == role.id) {
        roleHtml = roleHtml + '<option value="' + role.id + '" selected="">' + role.title + '</option>';
       } else {
        if (role.id == 2 || role.id == 3) {
         roleHtml = roleHtml + '<option value="' + role.id + '">' + role.title + '</option>';
        }
       }
      })

      layer.open({
       title: '查看会员',
       type: 1,
       area: ['700px', '450px'],
       offset: ['50px', '250px'],
       content: '<blockquote class="layui-elem-quote layui-text">注意事项: 请填写相关的数据信息! </blockquote>' +
       '<form class="layui-form"> ' +
       '<div class="layui-form-item">' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">姓名</label>' +
       '<div class="layui-input-inline">' +
       '<input type="text" required lay-verify="required" name="leaguerName" class="layui-input" value="' + undefined_data(leaguer.leaguerName) + '" disabled="" >' +
       '</div></div>' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">角色</label>' +
       '<div class="layui-input-inline">' +
       '<select name="roleId" disabled="">' +
       '<option value="">请选择一个角色</option>' +
       roleHtml +
       '</select>' +
       '</div></div>' +
       '</div>' +
       '<div class="layui-form-item">' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">手机号</label>' +
       '<div class="layui-input-inline">' +
       '<input type="text" required lay-verify="required" name="leaguerPhone" class="layui-input" value="' + undefined_data(leaguer.leaguerPhone) + '" disabled="" >' +
       '</div></div>' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">客服电话</label>' +
       '<div class="layui-input-inline">' +
       '<input type="text" required lay-verify="required" name="servicePhone" class="layui-input" value="' + undefined_data(leaguer.servicePhone) + '" disabled="" >' +
       '</div></div>' +
       '</div>' +
       '<div class="layui-form-item" style="width: 621px;">' +
       '<label class="layui-form-label">公司名称</label>' +
       '<div class="layui-input-block">' +
       '<input type="text" required lay-verify="required" name="company" class="layui-input" value="' + undefined_data(leaguer.company) + '" disabled="">' +
       '</div>' +
       '</div>' +

       '<div class="layui-form-item">' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">logo图标</label>' +
       '<div class="layui-input-inline">' +
//    '<input type="text" required lay-verify="required" name="type" class="layui-input" value="" >' +

       '<div class="layui-upload">' +
//       ' <button type="button" class="layui-btn" id="logn_upload">上传图片</button>' +
       ' <div class="layui-upload-list">' +
       ' <img class="layui-upload-img" src="' + leaguer.logoUrl + '" id="demo1" style=" width: 100px; height: 100px; margin-bottom: 8px;">' +
       '<p id="demoText"></p>' +
       ' </div>' +
       ' </div>' +
       '<input type="text" hidden name="logoUrl" value="' + leaguer.logoUrl + '" >' +
       '</div></div>' +
       '</div>' +
       '</form>',
       btnAlign: 'c',
       btn: ['确定'],
       yes: function (index, layero) {
        layer.close(index);
       }, btn2: function (index, layero) {
        layer.msg("取消");
        //return false 开启该代码可禁止点击该按钮关闭
       }, cancel: function () {
        layer.msg("关闭窗口");
        //右上角关闭回调
        //return false 开启该代码可禁止点击该按钮关闭
       },
       success: function () {
        layui.use('form', function () {
         var form = layui.form; //只有执行了这一步,部分表单元素才会修饰成功
         form.render('checkbox');
         form.render('select');
         form.on('checkbox(istrue)', function (data) {
          /* if(data.elem.checked){
           emailConfig['isenterprise']=1;
           }; //是否被选中,true或者false*/
         });
         //普通图片上传
         var uploadInst = upload.render({
          elem: '#logn_upload'
          , url: '/leaguer/upload/headImg'
          , before: function (obj) {
           //预读本地文件示例,不支持ie8
           obj.preview(function (index, file, result) {
            $('#demo1').attr('src', result); //图片链接(base64)
           });
          }
          , done: function (res) {
           //如果上传失败
           if (res.code > 0) {
            return layer.msg('上传失败');
           }
           if (res.code == 0) {
            $("input[name=logoUrl]").val(res.data.src);
            //do something (比如将res返回的图片链接保存到表单的隐藏域)
           }
           //上传成功

          }
          , error: function () {
           //演示失败状态,并实现重传
           var demoText = $('#demoText');
           demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
           demoText.find('.demo-reload').on('click', function () {
            uploadInst.upload();
           });
          }
         });
         element.init();
        });
       }
      });
     } else {
      layer.open({
       title: "查询数据失败"
       , content: "查询数据失败"
       , time: 20000
      });
     }
    });
   }
   if (e.event === "change") {
    var formData4 = {
     leaguerId: leaguerDate.leaguerId
    };
    $.post('/leaguer/getLeaguerInfoById', formData4, function (data) {
     var json = eval(data);
     var mapDate = data.body;
     console.log(data);
     if (data.code == 200) {
      var leaguer = data.body.leaguer;
      console.log(data.body)
      var roleHtml = '';
      $.each(data.body.roleList, function (i, role) {
       console.log(role);
       if (leaguer.roleId == role.id) {
        roleHtml = roleHtml + '<option value="' + role.id + '" selected="">' + role.title + '</option>';
       } else {
        if (role.id == 2 || role.id == 3) {
         roleHtml = roleHtml + '<option value="' + role.id + '">' + role.title + '</option>';
        }
       }
      })

      layer.open({
       title: '修改会员',
       type: 1,
       area: ['700px', '450px'],
       offset: ['50px', '250px'],
       content: '<blockquote class="layui-elem-quote layui-text">注意事项: 请填写相关的数据信息! </blockquote>' +
       '<form class="layui-form"> ' +
       '<div class="layui-form-item">' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">姓名</label>' +
       '<div class="layui-input-inline">' +
       '<input type="text" required lay-verify="required" name="leaguerName" class="layui-input" value="' + undefined_data(leaguer.leaguerName) + '" >' +
       '</div></div>' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">角色</label>' +
       '<div class="layui-input-inline">' +
       '<select name="roleId" >' +
       '<option value="">请选择一个角色</option>' +
       roleHtml +
       '</select>' +
       '</div></div>' +
       '</div>' +
       '<div class="layui-form-item">' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">手机号</label>' +
       '<div class="layui-input-inline">' +
       '<input type="text" required lay-verify="required" name="leaguerPhone" class="layui-input" value="' + undefined_data(leaguer.leaguerPhone) + '" >' +
       '</div></div>' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">客服电话</label>' +
       '<div class="layui-input-inline">' +
       '<input type="text" required lay-verify="required" name="servicePhone" class="layui-input" value="' + undefined_data(leaguer.servicePhone) + '" >' +
       '</div></div>' +
       '</div>' +
       '<div class="layui-form-item" style="width: 621px;">' +
       '<label class="layui-form-label">公司名称</label>' +
       '<div class="layui-input-block">' +
       '<input type="text" required lay-verify="required" name="company" class="layui-input" value="' + undefined_data(leaguer.company) + '" >' +
       '</div>' +
       '</div>' +

       '<div class="layui-form-item">' +
       '<div class="layui-inline">' +
       '<label class="layui-form-label">logo图标</label>' +
       '<div class="layui-input-inline">' +
       '<div class="layui-upload">' +
       ' <button type="button" class="layui-btn" id="logn_upload">上传图片</button>' +
       ' <div class="layui-upload-list">' +
       ' <img class="layui-upload-img" src="' + leaguer.logoUrl + '" id="demo1" style=" width: 100px; height: 100px; margin-bottom: 8px;">' +
       '<p id="demoText"></p>' +
       ' </div>' +
       ' </div>' +
       '<input type="text" hidden name="logoUrl" value="' + leaguer.logoUrl + '" >' +
       '</div></div>' +
       '</div>' +
       '</form>',
       btnAlign: 'c',
       btn: ['保存', '取消'],
       yes: function (index, layero) {
        var str = $("input[name=isIndividual]").val();
        if (str == "on") {
         str = "1";
        } else {
         str = "0";
        }
        if ($("input[name=leaguerName]").val() == null || $("input[name=leaguerName]").val() == "") {
         layer.msg('请输入姓名', {
          icon: 5,
          time: 2000,
          area: '200px',
          type: 0,
          anim: 6
         }, function () {
          $("input[name=leaguerName]").focus();
         });
         return false;
        } else if ($("select[name=roleId]").val() == null || $("select[name=roleId]").val() == "") {
         layer.msg('请选择角色', {
          icon: 5,
          time: 2000,
          area: '200px',
          type: 0,
          anim: 6
         }, function () {
          $("input[name=roleId]").focus();
         });
         return false;
        } else if ($("input[name=leaguerPhone]").val() == null || $("input[name=leaguerPhone]").val() == "") {
         layer.msg('请输入手机号', {
          icon: 5,
          time: 2000,
          area: '200px',
          type: 0,
          anim: 6
         }, function () {
          $("input[name=leaguerPhone]").focus();
         });
         return false;
        } else if ($("input[name=servicePhone]").val() == null || $("input[name=servicePhone]").val() == "") {
         layer.msg('请输入客服电话', {
          icon: 5,
          time: 2000,
          area: '200px',
          type: 0,
          anim: 6
         }, function () {
          $("input[name=servicePhone]").focus();
         });
         return false;
        } else if ($("input[name=company]").val() == null || $("input[name=company]").val() == "") {
         layer.msg('请输入企业名称', {
          icon: 5,
          time: 2000,
          area: '200px',
          type: 0,
          anim: 6
         }, function () {
          $("input[name=company]").focus();
         });
         return false;
        }
//        else if ($("input[name=logoUrl]").val() == null || $("input[name=logoUrl]").val() == "") {
//         layer.msg('请上传logo', {icon: 5, time: 2000, area: '200px', type: 0, anim: 6,}, function () {
//          $("input[name=logoUrl]").focus();
//         });
//         return false;
//        }

        var formData = {
         leaguerId: leaguer.leaguerId,
         leaguerName: $("input[name=leaguerName]").val(),
         roleId: $("select[name=roleId]").val(),
         leaguerPhone: $("input[name=leaguerPhone]").val(),
         servicePhone: $("input[name=servicePhone]").val(),
         company: $("input[name=company]").val(),
         logoUrl: $("input[name=logoUrl]").val()
        };
        console.log(formData);
        $.post('${pageContext.request.contextPath}/leaguer/updateLeaguer', formData, function (data) {
         //判断是否发送成功
         if (data.code == 200) {
          layer.msg(data.message);
          layer.close(index);
          parent.document.getElementById('my_iframe').contentWindow.location.reload(true);
         } else {
          layer.msg("保存失败...", {type: 1});
         }
        })
       }, btn2: function (index, layero) {
        layer.msg("取消");
        //return false 开启该代码可禁止点击该按钮关闭
       }, cancel: function () {
        layer.msg("关闭窗口");
        //右上角关闭回调
        //return false 开启该代码可禁止点击该按钮关闭
       },
       success: function () {
        layui.use('form', function () {
         var form = layui.form; //只有执行了这一步,部分表单元素才会修饰成功
         form.render('checkbox');
         form.render('select');
         form.on('checkbox(istrue)', function (data) {
          /* if(data.elem.checked){
           emailConfig['isenterprise']=1;
           }; //是否被选中,true或者false*/
         });
         //普通图片上传
         var uploadInst = upload.render({
          elem: '#logn_upload'
          , url: '/leaguer/upload/headImg'
          , before: function (obj) {
           //预读本地文件示例,不支持ie8
           obj.preview(function (index, file, result) {
            $('#demo1').attr('src', result); //图片链接(base64)
           });
          }
          , done: function (res) {
           //如果上传失败
           if (res.code > 0) {
            return layer.msg('上传失败');
           }
           if (res.code == 0) {
            $("input[name=logoUrl]").val(res.data.src);
            //do something (比如将res返回的图片链接保存到表单的隐藏域)
           }
           //上传成功

          }
          , error: function () {
           //演示失败状态,并实现重传
           var demoText = $('#demoText');
           demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
           demoText.find('.demo-reload').on('click', function () {
            uploadInst.upload();
           });
          }
         });
         element.init();
        });
       }
      });
     } else {
      layer.open({
       title: "查询数据失败"
       , content: "查询数据失败"
       , time: 20000
      });
     }
    });
   }
   if (e.event === "recharge") {
    var formData6 = {
     leaguerId: leaguerDate.leaguerId
    };
    $.post('${pageContext.request.contextPath}/leaguer/getLeaguerInfo', formData6, function (data) {

     console.log(data);
     layer.open({
      title: '充值金额',
      type: 1,
      area: ['500px', '350px'],
      offset: ['50px', '250px'],
      content: '<blockquote class="layui-elem-quote layui-text">注意事项: 请填写相关的数据信息! </blockquote>' +
      '<form class="layui-form"> ' +
      '<div class="layui-form-item">' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">姓名:</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="leaguerName" class="layui-input" value="' + data.body.leaguerName + '" disabled="">' +
      '</div></div>' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">手机号</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="leaguerPhone" class="layui-input" value="' + data.body.leaguerPhone + '" disabled="" >' +
      '</div></div>' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">余额</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="balanceMoney" class="layui-input" value="' + data.body.balanceMoney + '" disabled="" >' +
      '</div></div>' +
      '<div class="layui-inline">' +
      '<label class="layui-form-label">充值余额</label>' +
      '<div class="layui-input-inline">' +
      '<input type="text" required lay-verify="required" name="money" placeholder="请输入充值金额" class="layui-input" value="" >' +
      '</div></div>' +
      '</div>' +
      '</form>',
      btnAlign: 'c',
      btn: ['确定', '取消'],
      yes: function (index, layero) {
       var str = $("input[name=isIndividual]").val();
       if (str == "on") {
        str = "1";
       } else {
        str = "0";
       }
       if ($("input[name=money]").val() == null || $("input[name=money]").val() == "") {

        layer.msg('请输入充值金额', {
         icon: 5,
         time: 2000,
         area: '200px',
         type: 0,
         anim: 6
        }, function () {
         $("input[name=money]").focus();
        });
        return false;
       }
       var formData9 = {

        money: $("input[name=money]").val(),
        leaguerId: leaguerDate.leaguerId
       };
       console.log(formData9);
       $.post('${pageContext.request.contextPath}/leaguer/rechargeMoney', formData9, function (data) {
        //判断是否发送成功
        if (data.code == 200) {
         layer.msg(data.message);
         layer.close(index);
         parent.document.getElementById('my_iframe').contentWindow.location.reload(true);
        } else {
         layer.msg("保存失败...", {type: 1});
        }
       })
      }, btn2: function (index, layero) {
       layer.msg("取消");
       //return false 开启该代码可禁止点击该按钮关闭
      }, cancel: function () {
       layer.msg("关闭窗口");
       //右上角关闭回调
       //return false 开启该代码可禁止点击该按钮关闭
      },
      success: function () {
       layui.use('form', function () {
        var form = layui.form; //只有执行了这一步,部分表单元素才会修饰成功
        form.render('checkbox');
        form.render('select');
        form.on('checkbox(istrue)', function (data) {
         /* if(data.elem.checked){
          emailConfig['isenterprise']=1;
          }; //是否被选中,true或者false*/
        });
        //普通图片上传
        element.init();
       });
      }
     })
    })
   }

  });

  //搜索加载--数据表格重载
  var $ = layui.$, active = {
   reload: function () {
    //执行重载
    table.reload('userTables', {
     page: {
      curr: 1 //重新从第 1 页开始
     }
     , where: {
      searContent: $("input[name=searContent]").val()
     }
    });
   }
  };
  $('#searchEmailCompany').on('click', function () {
   var type = $(this).data('type');
   active[type] ? active[type].call(this) : '';
  });

  //初始化加载
  element.init();

  //数据表格数据undefined 替换
  function undefined_data(data) {
   if (data == undefined || data == 'undefined' || data == null || data == "null") {
    return "";
   } else {
    return data;
   }
  }
 });

</script>
</body>
</html>

效果图:

整体效果

搜索页:

添加特殊会员页:

充值金额页:

禁用效果:

查看会员页:

以上这篇layui table 表格模板按钮的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • layui实现数据表格点击搜索功能

    本文实例为大家分享了layui实现数据表格点击搜索的具体代码,供大家参考,具体内容如下 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>更正地址</title> <style> </style> <link rel="stylesheet" href=&q

  • 对layui中table组件工具栏的使用详解

    layui工具栏 第一步:在table中引入table,在table控件下加入: fixed:'right',title:'操作',width:"28%",align:'center',toolbar:"#barlist" 第二步:在table标签中加入以下js代码: <script type="text/html" id="barlist"> <!--<a class="layui-btn

  • layui实现点击按钮给table添加一行

    •问题描述:想实现点击按钮在表格添加一行的功能,但发现layuii并未集成该工具栏,因此,需要自己手动添加这个功能: •原先我写的table是这样实现的: $("#addTable").click(function(){ var tr=" <tr>"+ " <td>11</td>"+ " <td>22</td>"+ " <td>33</td

  • layui问题之模拟table表格中的选中按钮选中事件的方法

    一.问题 不操作页面,实现table表格中的checkbox选中功能 二.经过 刚开始的思路: 1.通过table的id,找到table渲染时生成的div,即table的下一个兄弟节点div.layui-table-view 2.由于checkbox是固定列,再通过第一步,找到div.layui-table-view的子元素.layui-table-fixed 3.紧接着,找出table的第一行的第一个td里面的input,即tr[data-index="0"] td input(注:

  • 使用layui 渲染table数据表格的实例代码

    先上最终效果图: 1,引入layui的css和js文件 <link rel="stylesheet" href="lib/layui/css/layui.css" rel="external nofollow" > <script src="lib/layui/layui.js"></script> 2,在页面放置一个table元素 <table class="layui-h

  • layui框架table 数据表格的方法级渲染详解

    如下所示: <table class="layui-table" lay-filter="demo11" id="test11"></table> //js 规范书写 var tst=table.render({ elem: '#test11' ,cols: [[ //标题栏 {checkbox: true} ,{field: 'pay_ct_time', title: '创建时间', width: 80} ,{field

  • layui table 表格模板按钮的实例代码

    这是个是全部的jsp 页面: <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> <html> <link rel="icon" href="../../../static/images/favicon.png" rel="external nofollow" > <title

  • 在Layui 的表格模板中,实现layer父页面和子页面传值交互的方法

    最近,在项目中使用到了layer.layer的弹层组件可以说是非常好用,layer 至今仍作为 layui 的代表作.在项目中,需要实现一个在表格里面点击操作,然后弹出layer层,将父层表格的行值传给子页面,子页面拿到值后,进行业务处理,从而实现真正的父子页面交互. 其实,官方文档都说的很清楚了. layui官方文档:http://layer.layui.com/ 使用版本:2.3.0 只是,需要我们耐心的读懂文档内容,然后根据自己的业务情况,实现自己想要的效果. 一.子页面获取父页面数据 子

  • php+layui数据表格实现数据分页渲染代码

    一.HTML <table class="layui-hide layui-table" id="spu-data"></table> 二.JS 说明:需要引入layui中的table和laytpl模板引擎,laytpl可以自定义事件及自定义数据字段等 <!-- 拼接图片 --> <script type="text/html" id="pimg"> <img class=

  • el表达式 写入bootstrap表格数据页面的实例代码

    el表达式,写入bootstrap表格,简化代码,效果图: 不多说,上干货: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.

  • Android实现一个包含表格的图标库实例代码

    之前有写过一个图表lib,但是开发的速度,大多很难跟上产品需求变化的脚步,所以修改了下原先的图表库,支持图表下面能整合table显示对应的类目,用曲线替换了折线,支持多曲线的显示,增加了显示的动画,,增加了一些可定制的属性,支持水平柱状图和叠加柱状图,以及多曲线图和饼状图的显示 1.效果图 2.各种图表的使用方式 1.饼状图 这个和原先的使用一样,只不过增加了一个动画,可以参看之前的文章,饼状图使用. 2.水平多柱状图 2.1 xml布局 <wellijohn.org.varchart.hor_

  • layui table 表格上添加日期控件的两种方法

    方法一: var tableInit = table.render({ elem: '#tbtxrz' , method: 'post' , data: jsonData , height: "auto" , id: "tbtxrz" , text: {none: '暂无相关数据'} , toolbar: toolbartxrz , cols: [[ { //设置表格中部分字体的颜色 field: "number", title: "序

  • layui table表格数据的新增,修改,删除,查询,双击获取行数据方式

    layui table利用参数新增,修改,删除,查询,双击数据行获取本行数据等.模块化使用layui table表格,通过二次封装实现语法上的解耦使用layui table,使用参数就可以以及外部的方法调用即可实现对layui table表格的操作,通过封装,把更多自主权交给页面自定义,layui:v:2.3.0.感谢layui的作者贤心. 演示效果如下: 以上json显示不完整是录屏的原因,请见谅! var Table = function(ops){ this.dataList = [];

  • vue悬浮可拖拽悬浮按钮的实例代码

    前言 vue开发手机端悬浮按钮实现,可以拖拽,滚动的时候收到里边,不影响视线 github地址 使用,基于vue-cli3.0+webpack 4+vant ui + sass+ rem适配方案+axios封装,构建手机端模板脚手架 vue-h5-template 后续将发布各种商城组件组件,让商城简单高效开发 线上体验 使用 将 src/components文件夹下的s-icons组件放到你的组件目录下 使用组件 // template <template> <div> <

  • iOS 中根据屏幕宽度自适应分布按钮的实例代码

    下载demo链接:https://github.com/MinLee6/buttonShow.git 屏幕摆放的控件有两种方式,一种根据具体内容变化,一种根据屏幕宽度变化. 下面我分别将两个方式,用代码的方式呈现: 1:根据具体内容变化 // // StyleOneViewController.m // buttonShow // // Created by limin on 15/06/15. // Copyright © 2015年 信诺汇通信息科技(北京)有限公司. All rights

  • iOS 增加右侧按钮功能实例代码

    一,工程图. 二,代码. ViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //增加右侧按钮 [self addRightButton]; } #pragma -mark -functions //增加右侧按钮 -(void)addRightButton { UIBarButtonI

随机推荐