layui.use(['form','layer','laydate','table','laytpl','layedit','upload'],function(){
var form = layui.form,
layer = layui.layer,
$ = layui.jquery,
laydate = layui.laydate,
table = layui.table,
layedit = layui.layedit
,upload = layui.upload;
var tableIds = 'wxuserlist';
//楼盘列表
var tableIns = table.render({
elem: '#'+tableIds,
url : '/wx/homeform',
method:'post',
page : true,
limit : 20,
id:'tablerReload',
cols : [[
{type: "checkbox", width:50},
{type:'numbers'},
{field: 'name', title: '昵称', width:120, align:"center",sort: true},
{field: 'rand', title: '抽奖码', width:120, align:"center",sort: true},
{field: 'photo', title: '头像',align:'center',templet:function (d) {
return '';
}},
{field: 'create_at', title: '添加时间',width:150, event:'sortData', align:'center',sort: true},
{title: '操作', width:200, templet:'#housesListBar',fixed:"right",align:"center"}
]]
});
// table.reload('tablerReload'); //重新加载
//表格头部操作菜单
var $ = layui.$, active = {
addData: function(){ //获取选中数据
var index = layui.layer.open({
title : "添加微信用户",
type : 2,
area:['80%','100%'],
maxmin: true,
content : "/wx/create",
end:function () {
table.reload('tablerReload');
}
})
},
reload:function () {
var form = pfgs_serialize($('form'));
var name = '';
var id = '';
if(form.input_house == 'name'){
name = form.name;
} else if(form.input_house == 'id'){
id = form.name;
}
table.reload('tablerReload',{
where:{
name:name,
rand:id,
}
})
}
};
$('.demoTable .layui-btn').on('click', function(){
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//表格右边操作栏目
table.on('tool('+tableIds+')', function(obj){
var data = obj.data;
if(obj.event === 'del'){ //删除操作
layer.confirm('确定要删除吗?',{btn: ['确定', '取消']},function () {
$.post('/wx/udel',{id:data.id},function (data) {
layer.msg(data.msg);
table.reload('tablerReload');
})
})
} else if(obj.event === 'edit'){ //编辑操作
var index = layui.layer.open({
title : "编辑资讯",
type : 2,
area:['','100%'],
maxmin: true,
content : "/news/newsedit?id="+data.id
})
layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize",function(){
layui.layer.full(index);
})
}
});
//添加
form.on('submit(adduser)',function (data) {
var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
$.post('/wx/createform',{data:data.field},function (data) {
layer.msg(data.msg);
console.log(data.data.rand);
if(data.code == 200){
layer.open({
type: 1,
area:['200px','200px'],
content: '抽奖码:'+data.data.rand+'' //这里content是一个普通的String
});
}
table.reload('tablerReload');
})
return false;
})
});