layui.use(['layer', 'table', 'element', 'form'], function () {
var $ = layui.jquery
, layer = layui.layer //弹层
, table = layui.table //表格
, form = layui.form
var tableIns = table.render({
elem: '#hainanvillelist',
url: '/zt/hainanvilleform',
method: 'get',
page: false,
id: 'tablerReload',
cols: [[
{type: 'numbers', title: '序号'},
{field: 'title', title: '地区名称', width: 400, align: "center"},
{
field: 'sort',
title: '排序',
width: 100,
event: 'sortData',
edit: 'text',
align: 'center',
sort: true,
templet: "#sortBox"
},
{
field: 'state', title: '状态', align: 'center', templet: function (d) {
if (d.state == 1) {
return ''
} else {
return ''
}
}
},
{title: '操作', templet: '#hainanvillefunc', fixed: "right", align: "center"}
]]
});
table.reload('tablerReload'); //重新加载
//表格头部操作菜单
var $ = layui.$, active = {
addData: function () {
var index = layui.layer.open({
title: "添加导航地区",
type: 2,
area: ['70%', '50%'],
content: '/zt/hainanvilleadd',
})
},
};
$('.demoTable .layui-btn').on('click', function () {
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//监听指定开关
form.on('switch(switchTest)', function (data) {
var id = $(this).val();
var state = $(this).data('state');
layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
$.post('/zt/hainanvillestate', {id: id, state: state}, function (data) {
if (data.code == 200) {
layer.msg(data.msg);
table.reload('tablerReload');
} else if (data.code == 300) {
layer.msg(data.msg);
}
})
}, function (aa) {
table.reload('tablerReload'); //重新加载
})
});
//排序
table.on('edit(hainanvillelist)', function (obj) {
var data = obj.data;
$.post('/zt/hainanvillesort', {id: data.id, sort: data.sort}, function (data) {
if (data.code == 200) {
layer.msg(data.msg);
} else if (data.code == 300) {
layer.msg(data.msg);
}
})
})
//表格右边操作栏目
table.on('tool(hainanvillelist)', function (obj) {
var data = obj.data;
var id = data.id;
if (obj.event === 'del') { //删除操作
layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
$.post('/zt/hainanvilledel', {id: 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 (obj.event === 'edit') {//修改排序
var index = layui.layer.open({
title: "添加导航地区",
type: 2,
area: ['70%', '50%'],
content: '/zt/hainanvilleedit?id='+id,
})
}else if(obj.event === 'gl'){
var index = layui.layer.open({
title: "关联楼盘",
type: 2,
area: ['100%', '100%'],
content: '/zt/hainanvillegl?id='+id,
})
parent.layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize",function(){
parent.layui.layer.full(indexOpen);
})
}
})
$('.The_house').focus(function(){
indexOpen = parent.layui.layer.open({
type: 2,
title: '选择需要添加的区域',
area: ['','100%'],
content: '/publicuse/cncity?type=1',
success:function (layero, index) {
},
end:function(){
}
});
parent.layui.layer.full(indexOpen);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize",function(){
parent.layui.layer.full(indexOpen);
})
})
form.on('submit(add_hainanville)', function (data) {
$.post('/zt/tohainanvilleadd', {'data': data.field}, function (data) {
if (data.code == 200) {
layer.msg(data.msg);
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
window.parent.location.reload();
}
})
return false;
});
form.on('submit(edit_hainanville)', function (data) {
$.post('/zt/tohainanvilleedit', {'data': data.field}, function (data) {
if (data.code == 200) {
layer.msg(data.msg);
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
window.parent.location.reload();
}
})
return false;
});
})