layui.use([ 'laypage', 'layer', 'table', 'element','form'], function(){
var laypage = layui.laypage //分页
,layer = layui.layer //弹层
,table = layui.table //表格
,element = layui.element //元素操作
,form = layui.form;
//第一个实例
table.render({
elem: '#housetypelist'
,url: '/dictionary/housetypeform' //数据接口
,where:{token:csrfToken}
,method:'post'
,page: true //开启分页
,text:'数据加载中'
,id:'tablerReload'
,cols: [[ //表头
// {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
{type:'numbers'},
{field: 'huxing_name', title: '户型', align:'center'}
,{field: 'sort', title: '排序',width:200, event:'sortData',edit: 'text',align:'center',sort: true,templet:"#sortBox"}
// ,{field: 'state', title: '地址', width:200,align:'center'}
// ,{field: 'update_at', title: '更新时间', width:200,align:'center'}
// ,{field: 'create_at', title: '添加时间', width:200,align:'center'}
,{field: 'state', title: '审核',align:'center',width:200, templet:function (d) {
if(d.state == 2){
return ''
} else {
return ''
}
}}
,{fixed: 'right',title:'操作', width: 180, align:'center', toolbar: '#operate'}
]]
});
table.reload('tablerReload'); //重新加载
//监听指定开关
form.on('switch(switchTest)', function(data){
layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
$.post('/dictionary/housetypestate',{id:data.value,type:'state'},function (data) {
layer.msg(data.msg);
table.reload('tablerReload');
})
},function (aa) {
table.reload('tablerReload'); //重新加载
})
});
//列表操作
table.on('tool(housetypelist)', function(obj){
var layEvent = obj.event,
data = obj.data;
if(layEvent === 'edit'){
layer.open({
type: 2,
title: '修改户型',
area: ['600px', '500px'],
content:'/dictionary/housetypeedit?id='+data.id,
end:function(){
table.reload('tablerReload'); //重新加载
}
});
} else if(layEvent === 'del') {
layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
$.post('/dictionary/hosttypedel',{'id':data.id},function (data) {
if(data.code == 200)
{
layer.msg(data.msg);
table.reload('tablerReload'); //重新加载
} else if(data.code == 300 ) {
layer.msg(data.msg);
}
})
})
}else if(layEvent === 'sortData'){ //修改排序
table.on('edit(housetypelist)', function(obj){
var data = obj.data;
$.post('/dictionary/housetypesort',{id:data.id,type:'sort',sort:data.sort},function (data) {
if(data.code == 200)
{
layer.msg(data.msg);
} else if(data.code == 300 ) {
layer.msg(data.msg);
}
})
})
}
});
var $ = layui.$, active = {
addData: function(){ //获取选中数据
layer.open({
type: 2,
title: '添加户型',
area: ['600px', '500px'],
content: '/dictionary/housetypeadd',
end:function(){
table.reload('tablerReload'); //重新加载
}
});
// var checkStatus = table.checkStatus('idTest')
// ,data = checkStatus.data;
// layer.alert(JSON.stringify(data));
}
};
$('.demoTable .layui-btn').on('click', function(){
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//修改
form.on('submit(edithousetype)', function(data){
var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
$.post('/dictionary/housetypeeditform',{'data':data.field,'token':csrfToken},function (data) {
top.layer.close(index); //关闭数据提交信息
if(data.code == 200)
{
layer.msg(data.msg);
// parent.layui.table.reload('housetypelist');
// TableClose();
} else if(data.code == 300 ) {
layer.msg(data.msg);
layer.msg(ReturnInfo(data.data));
}
})
return false;
});
//添加
form.on('submit(addhousetype)', function(data){
var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
$.post('/dictionary/housetypeaddform',{'data':data.field},function (data) {
top.layer.close(index); //关闭数据提交信息
if(data.code == 200)
{
layer.msg(data.msg);
} else if(data.code == 300 ) {
layer.msg(data.msg);
layer.msg(ReturnInfo(data.data),{icon:5});
}
})
return false;
});
});