layui.use(['form', 'layer', 'laydate', 'table', 'laytpl', 'layedit', 'upload'], function () {
var form = layui.form,
// layer = parent.layer === undefined ? layui.layer : top.layer,
layer = layui.layer,
$ = layui.jquery,
laydate = layui.laydate,
laytpl = layui.laytpl,
table = layui.table,
layedit = layui.layedit
, upload = layui.upload;
//调用编辑器
var tableIds = 'housesList';
var reloadId = 'tablerReload';
//楼盘列表
var tableIns = table.render({
elem: '#' + tableIds,
url: '/house/indexform',
cellMinWidth: 95,
method: 'post',
page: true,
height: 600,
limit: 20,
id: reloadId,
// limits : [10,15,20,25],is_view
cols: [[
{type: "checkbox", width: 50},
{field: 'id', title: 'ID', width: 80, align: "center", sort: true},
{
field: 'name', title: '标题', align: "center", templet: function (d) {
var html = '
';
if (d.is_push == 2) {
html += '';
}
if (d.thumb != null && d.thumb != "") {
html += '';
}
if (d.evaluating != null && d.evaluating != "") {
html += '';
}
if (d.video == 1) {
html += '';
}
if (d.permit != 0) {
html += '- ' + d.permit + '
';
}
html += '
';
html += ' ' + d.name + '';
return html;
}
},
{field: 'city_name', title: '区域', width: 90, sort: true, align: 'center'},
{
field: 'album_num',
title: '相册',
width: 80,
event: 'housesPhoto',
align: 'center',
templet: "#housesPhoto",
templet: function (d) {
return '[' + d.album_num + ']'
}
},
{field: 'news_num', title: '资讯',width:70, event:'housesNews', align:'center',templet:"#housesNews",templet:function(d){
return '['+d.news_num+']'
}},
{
field: 'type_num',
title: '户型',
width: 80,
event: 'housesType',
align: 'center',
templet: "#housesType",
templet: function (d) {
return '[' + d.type_num + ']'
}
},
{
field: 'peitao_num',
title: '周边配套',
width: 90,
event: 'houseFacilities',
align: 'center',
templet: "#houseFacilities",
templet: function (d) {
return '[' + d.peitao_num + ']'
}
},
{field: 'click_num', title: '点击', width: 80, align: 'center', sort: true},
{field: 'sort', title: '排序', width: 80, edit: 'text', align: 'center', sort: true, templet: "#sortBox"},
{field: 'create_at', title: '添加时间', width: 150, align: 'center'},
{
field: 'is_view',
title: '审核',
width: 70,
align: 'center',
templet: "#Toexamine",
templet: function (d) {
switch (d.is_view) {
case '2':
return ''
break;
case '1':
return ''
break;
}
}
},
{title: '操作', width: 200, templet: '#housesListBar', fixed: "right", align: "center"}
]]
});
tableIns.reload('tablerReload'); //重新加载
var $ = layui.$, active = {
reload: function () {
var form = pfgs_serialize($('form'));
var name = '';
var id = '';
if (form.input_house == 'name') {
name = form.input_house_text;
} else if (form.input_house == 'id') {
id = form.input_house_text;
}
var city = '';
if (form.province != '') {
city = form.province;
}
if (form.city != '') {
city = form.city;
}
table.reload('tablerReload', {
where: {
sort: form.input_sort,
id: id,
name: name,
city: city,
is_view: form.show,
end_time: form.end_time,
start_time: form.start_time,
is_push: form.is_push
},
page: {
curr: 1
}
})
},
};
$('.demoTable .layui-btn').on('click', function () {
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//日期
laydate.render({
elem: '#date1'
});
laydate.render({
elem: '#date2'
});
//选项卡切换
$('.layui-tab-title .site-demo-active').on('click', function () {
$(this).addClass('layui-this').siblings().removeClass('layui-this');
var lay_id = $(this).attr('lay-id');
$('.layui-tab-item').removeClass('layui-show')
$('.layui-tab-content #' + lay_id).addClass('layui-show')
});
//监听指定开关
form.on('switch(switchTest)', function (data) {
var house = data.elem.attributes.house.value;
layer.open({
title: '修改[' + house + ']状态',
type: 2,
area: ['50%', '80%'],
maxmin: true,
content: "/house/openstate?hid=" + data.value + "&name=" + house,
end: function () {
table.reload('tablerReload');
}
})
});
form.on('submit(del_alls_house)', function (data) {
var checkStatus = table.checkStatus('tablerReload');
var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
if (typeof checkStatus.data[0] == 'object') {
layer.confirm('您确定要删除吗?', {btn: ['确认', '取消']}, function () {
var formdat = new FormData();
$.each(checkStatus.data, function (key, val) {
formdat.append('hid[]', val.id);
})
$.ajax({
cache: true,
type: "post",
url: "/house/housedel",
data: formdat, // 你的formid
// async : false, //async 默认为true异步,修改为false为同步
contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
error: function (request) {
layer.close(index); //关闭数据提交信息
layer.alert("网络超时");
},
success: function (data) {
if (data.code == 200) {
layer.msg(data.msg);
reloadTable(reloadId);
} else {
layer.msg(data.msg);
}
}
});
})
return false;
}
layer.msg('请选择需要删除的楼盘', {icon: 5});
return false;
})
//检测关键词
form.on('submit(check_words)',function (data) {
var content=UE.getEditor('editor').getContentTxt();
var centhtml = UE.getEditor('editor').getContent();
$.ajax({
//cache : false,
type : "post",
url : "/sensitivewords/checkword",
data:{content:content}, // 你的formid
//contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
//processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
error : function(request) {
layer.close(index);
layer.alert("网络超时");
},
success : function(data) {
if(data.data!=null){
var index=layer.open({
type: 1,
// skin: 'layui-layer-rim', //加上边框
title:'违禁词信息',
area: ['420px', '240px'], //宽高
content: ''+data.data+'
'
});
for(var i=0;i"+data.data[i]+"");
}
UE.getEditor('editor_content').setContent(centhtml);
layer.msg(data.msg)
}else{
layer.msg(data.msg)
}
}
});
return false;
})
/* 列表操作 edit 修改后执行 */
table.on('edit(' + tableIds + ')', function (obj) {
var data = obj.data;
$.post('/house/housesortedit', {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);
}
})
})
/* 列表操作 tool 点击执行 */
table.on('tool(' + tableIds + ')', function (obj) {
var data = obj.data;
if (obj.event === 'edit') {
var index = layui.layer.open({
title: '[' + data.name + ']修改楼盘信息',
type: 2,
area: ['', '100%'],
maxmin: true,
content: "/house/edit?id=" + data.id,
end: function () {
layui.table.reload('tablerReload');
}
})
layui.layer.full(index);
// // //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize", function () {
layui.layer.full(index);
})
} else if (obj.event === 'del') {
layer.confirm('您确认要删除吗?', {btn: ['确认', '取消']}, function () {
$.post('/house/housedel', {id: data.id}, function (data) {
if (data.code == 200) {
layer.msg(data.msg);
// parent.layui.
table.reload('tablerReload');
// TableClose();
} else {
layer.msg(data.msg);
}
})
})
}else if(obj.event === 'housesNews'){
var index =layui.layer.open({
title :'['+data.name+']楼盘资讯',
type : 2,
area:['','100%'],
maxmin: true,
content : "/house/newslist?id="+data.id+"&name="+data.name,
end:function () {
table.reload('tablerReload');
}
})
layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize",function(){
layui.layer.full(index);
})
} else if (obj.event === 'housesPhoto') {
var index = layui.layer.open({
title: '[' + data.name + ']楼盘相册',
type: 2,
area: ['', '100%'],
maxmin: true,
content: "/house/album?id=" + data.id + "&name=" + data.name,
end: function () {
table.reload('tablerReload');
}
})
layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize", function () {
layui.layer.full(index);
})
} else if (obj.event === 'housesType') {
var index = layui.layer.open({
title: '[' + data.name + ']楼盘户型',
type: 2,
area: ['', '100%'],
maxmin: true,
content: "/house/housetype?id=" + data.id + "&name=" + data.name,
end: function () {
table.reload('tablerReload');
}
})
layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize", function () {
layui.layer.full(index);
})
} else if (obj.event === 'house_price') {
var index = layui.layer.open({
title: '[' + data.name + ']楼盘历史价格',
type: 2,
area: ['', '100%'],
maxmin: true,
content: "/house/priceview?id=" + data.id + "&name=" + data.name + '&price=' + data.sale_price,
end: function () {
table.reload('tablerReload');
}
})
layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize", function () {
layui.layer.full(index);
})
} else if (obj.event === 'houseFacilities') {
var index = layui.layer.open({
title: '[' + data.name + ']楼盘周边配套',
type: 2,
area: ['', '100%'],
maxmin: true,
content: "/house/peitao?id=" + data.id + "&name=" + data.name,
end: function () {
table.reload('tablerReload');
}
})
layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize", function () {
layui.layer.full(index);
})
} else if (obj.event === 'house_presell') {
var index = layui.layer.open({
title: '[' + data.name + ']预售许可证',
type: 2,
area: ['', '100%'],
maxmin: true,
content: "/house/presell?id=" + data.id + "&name=" + data.name,
end: function () {
table.reload('tablerReload');
}
})
layui.layer.full(index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
$(window).on("resize", function () {
layui.layer.full(index);
})
}
});
//楼盘名称,区域, 注释装修情况
//添加图片上传
upload.render({
elem: '#test1'
, url: '/house/createimg'
, data: {token: csrfToken}
, field: 'img'
, size: 1000 //限制上传图片的大小,单位为KB
, exts: 'png|jpg|jpeg' //只允许上传压缩文件
, auto: false
, bindAction: '#addcity'
, choose: function (obj) {
obj.preview(function (index, file, result) {
$('#demo1').attr('src', result); //图片链接(base64)
});
}
});
// 点击放大图片
$('#demo1').on('click', function () {
var _src = $(this).attr('src');
layui.layer.open({
type: 1,
title: false, //是否显示标题
area: ['60%', '80%'],
shade: 0.6, //透明度
closeBtn: 1, //按钮 1有,0无
shadeClose: true,
content: '',
});
});
//判断是否需要编辑,需要才加载
var verdict = $('#editor').html();
if (typeof verdict == "string") {
var ue = UE.getEditor('editor'); //编辑器
}
//重载表格
function reloadTable(obj) {
table.reload(obj);
}
//编辑楼盘
form.on('submit(edit)', function (data) {
var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
var formData = new FormData($('#house_edit_form')[0]);
$.ajax({
cache: true,
type: "post",
url: "/house/editfrom",
data: formData, // 你的formid
// async : false, //async 默认为true异步,修改为false为同步
contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
error: function (request) {
layer.close(index); //关闭数据提交信息
layer.alert("请联系管理员");
},
success: function (data) {
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;
});
//楼盘上架下架操作
form.on('submit(openstate)', function (data) {
var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
$.ajax({
cache: true,
type: "post",
url: "/house/openstateform",
data: data.field, // 你的formid
// async : false, //async 默认为true异步,修改为false为同步
// contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
// processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
error: function (request) {
layer.close(index); //关闭数据提交信息
layer.alert("请联系管理员");
},
success: function (data) {
if (data.data != null) {
layer.msg(ReturnInfo(data.data), {icon: 5});
return;
}
layer.msg(data.msg);
}
});
return false;
});
//加载省数据
function loadProvince(data) {
$.ajax({
url: '/categorycity/citypid',
type: 'post',
async: false,//使用同步的方式,true为异步方式
data: {'pid': 0},//这里使用json对象
success: function (data) {
// console.log(data);
var areaData = data.data;
var proHtml = '';
for (var i = 0; i < areaData.length; i++) {
proHtml += '';
}
//初始化省数据
$('select[name=province]').append(proHtml);
form.render();
},
fail: function () {
}
});
}
loadProvince();
form.on('select(province)', function (data) {
$.post('/categorycity/citypid', {'pid': data.value}, function (data) {
var areaData = data.data;
var proHtml = '';
$('select[name=city]').html('');
proHtml = '';
for (var i = 0; i < areaData.length; i++) {
proHtml += '';
}
//初始化省数据
$('select[name=city]').append(proHtml);
form.render();
})
})
// 添加楼盘评测
var leng = 50;
$('.layui_w_addbtn').on('click', function () {
datumInsert(leng)
$('body').append('') //编辑器
var ue = UE.getEditor("evaluating" + leng);
ue.ready(function () {
// ue.setContent('编辑器1的内容
', true);
});
leng++;
})
//展示数据删除按钮
$('.layui_w_licence table.layui-table tbody.mai').on('click', '.del', function () {
var _this = $(this)
var oid = _this.parents('.otr').attr('id');
var index = layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
// layer.close(index)
_this.parents('#' + oid).remove();
$('body script#' + oid).remove();
layer.msg('已成功删除!');
})
})
})
$(function () {
$('.editmai tr.otr').each(function () {
var _ind = $(this).attr('data-id');
UE.getEditor("evaluating" + _ind);
// console.log(_ind)
})
//选项卡切换
$('.layui-tab-title .site-demo-active').on('click', function () {
$(this).addClass('layui-this').siblings().removeClass('layui-this');
var lay_id = $(this).attr('lay-id');
$('.layui-tab-item').removeClass('layui-show')
$('.layui-tab-content #' + lay_id).addClass('layui-show')
});
// 转换拼音
$('.layui_w_name').on('keyup ', function () {
var _txt = $(this).val();
var _convert = pinyinUtil.getPinyin(_txt, ' ', false).replace(/\s/g, "");
$('.layui_w_spell').val(_convert)
})
// 动态添加批量删除按钮
var _btn = ''
$('.layui-form').append(_btn)
// 修改楼盘编辑高度问题
var i = 0;
$('li[lay-id="assign_4"]').on('click', function () {
var _text = UE.getEditor('editor').getContent()
if (_text != '') {
if (i < 1) {
var editorHeight = UE.getEditor('editor').iframe.clientHeight;
if (editorHeight > 400) {
var _setHeight = parseInt(UE.getEditor('editor').iframe.clientHeight / 7.5);
$('#assign_4').find('#edui1_iframeholder').css('height', _setHeight);
}
i++;
}
}
})
})
//楼盘评测 添加
function datumInsert(leng) {
// var leng = $(".layui_w_licence table.layui-table tbody tr").length;
// console.log(leng)
var tr = ''
+ ''
+ ' '
+ ' | '
+ ''
+ ' '
+ ''
+ ' '
+ ' | '
+ '
';
$(".layui_w_licence table.layui-table tbody.mai").append(tr);
}