wx.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. layui.use(['form','layer','laydate','table','laytpl','layedit','upload'],function(){
  2. var form = layui.form,
  3. layer = layui.layer,
  4. $ = layui.jquery,
  5. laydate = layui.laydate,
  6. table = layui.table,
  7. layedit = layui.layedit
  8. ,upload = layui.upload;
  9. var tableIds = 'wxuserlist';
  10. //楼盘列表
  11. var tableIns = table.render({
  12. elem: '#'+tableIds,
  13. url : '/wx/homeform',
  14. method:'post',
  15. page : true,
  16. limit : 20,
  17. id:'tablerReload',
  18. cols : [[
  19. {type: "checkbox", width:50},
  20. {type:'numbers'},
  21. {field: 'name', title: '昵称', width:120, align:"center",sort: true},
  22. {field: 'rand', title: '抽奖码', width:120, align:"center",sort: true},
  23. {field: 'photo', title: '头像',align:'center',templet:function (d) {
  24. return '<img class="layui_magnify" src="'+d.photo+'">';
  25. }},
  26. {field: 'create_at', title: '添加时间',width:150, event:'sortData', align:'center',sort: true},
  27. {title: '操作', width:200, templet:'#housesListBar',fixed:"right",align:"center"}
  28. ]]
  29. });
  30. // table.reload('tablerReload'); //重新加载
  31. //表格头部操作菜单
  32. var $ = layui.$, active = {
  33. addData: function(){ //获取选中数据
  34. var index = layui.layer.open({
  35. title : "添加微信用户",
  36. type : 2,
  37. area:['80%','100%'],
  38. maxmin: true,
  39. content : "/wx/create",
  40. end:function () {
  41. table.reload('tablerReload');
  42. }
  43. })
  44. },
  45. reload:function () {
  46. var form = pfgs_serialize($('form'));
  47. var name = '';
  48. var id = '';
  49. if(form.input_house == 'name'){
  50. name = form.name;
  51. } else if(form.input_house == 'id'){
  52. id = form.name;
  53. }
  54. table.reload('tablerReload',{
  55. where:{
  56. name:name,
  57. rand:id,
  58. }
  59. })
  60. }
  61. };
  62. $('.demoTable .layui-btn').on('click', function(){
  63. var type = $(this).data('type');
  64. active[type] ? active[type].call(this) : '';
  65. });
  66. //表格右边操作栏目
  67. table.on('tool('+tableIds+')', function(obj){
  68. var data = obj.data;
  69. if(obj.event === 'del'){ //删除操作
  70. layer.confirm('确定要删除吗?',{btn: ['确定', '取消']},function () {
  71. $.post('/wx/udel',{id:data.id},function (data) {
  72. layer.msg(data.msg);
  73. table.reload('tablerReload');
  74. })
  75. })
  76. } else if(obj.event === 'edit'){ //编辑操作
  77. var index = layui.layer.open({
  78. title : "编辑资讯",
  79. type : 2,
  80. area:['','100%'],
  81. maxmin: true,
  82. content : "/news/newsedit?id="+data.id
  83. })
  84. layui.layer.full(index);
  85. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  86. $(window).on("resize",function(){
  87. layui.layer.full(index);
  88. })
  89. }
  90. });
  91. //添加
  92. form.on('submit(adduser)',function (data) {
  93. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  94. $.post('/wx/createform',{data:data.field},function (data) {
  95. layer.msg(data.msg);
  96. console.log(data.data.rand);
  97. if(data.code == 200){
  98. layer.open({
  99. type: 1,
  100. area:['200px','200px'],
  101. content: '<span style="color:red;font-size:30px;">抽奖码:'+data.data.rand+'</span>' //这里content是一个普通的String
  102. });
  103. }
  104. table.reload('tablerReload');
  105. })
  106. return false;
  107. })
  108. });