var delFiles = []; //用于删除图片 var indexOpen; var filesContainer = {}; 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 = 'videolist'; //表格ID //第一个实例 table.render({ elem: '#'+tableIds ,url: '/grouppurchase/indexform' //数据接口 ,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: 'title', title: '标题', align:'center'}, {field: 'house_name', title: '楼盘名称', align:'center'}, {field: 'city_name', title: '所属区域', align:'center'}, {field: 'sign_num', title: '报名人数', align:'center'}, {field: 'clicks', title: '浏览次数', align:'center'}, {field: 'sort', title: '排序', align:'center'} ,{field: 'create_at', title: '添加时间',width:130, align:'center'} ,{field: 'update_at', title: '更新时间',width:130, align:'center'} ,{field: 'is_view', title: '是否显示',width:100, templet:function (d) { if(d.is_view == 2){ return '' } else { return '' } }} ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'} ]] }); // table.reload('tablerReload'); //重新加载 // 日期 laydate.render({ elem: '#e_date', type:'datetime' }); //监听指定开关 form.on('switch(switchTest)', function(data){ layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () { $.post('/grouppurchase/is_view',{id:data.value},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return ; } layer.msg(data.msg); table.reload('tablerReload'); }) },function (aa) { table.reload('tablerReload'); //重新加载 }) }); //列表操作 table.on('tool('+tableIds+')', function(obj){ var layEvent = obj.event, data = obj.data; if(layEvent === 'edit'){ console.log(data.house_name) var index = layer.open({ title: '修改团购', type : 2, area:['','100%'], content: '/grouppurchase/edit?id='+data.id+'&house_name='+data.house_name, end:function () { table.reload('tablerReload'); //重新加载 } }); layui.layer.full(index); //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作) $(window).on("resize",function(){ layui.layer.full(index); }) } else if(layEvent === 'del') { layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () { $.post('/grouppurchase/del',{'id':data.id},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return ; } layer.msg(data.msg); table.reload('tablerReload'); }) }) } }); $('.layui_magnify').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: '', }); }) // 添加图片上传PC upload.render({ elem: '#img_pc' ,url: '/house/createimg' ,data:{token:csrfToken} ,field:'img' ,auto:false ,bindAction:'#addcity' ,choose: function(obj){ obj.preview(function(index, file, result){ $('#breviary_img').attr('src', result); //图片链接(base64) }); } }); var $ = layui.$, active = { addData: function(){ //获取选中数据 var index = layui.layer.open({ type: 2, title: '添加看房团', area: ['','100%'], content: '/grouppurchase/lookhouseadd' //iframe的url,no代表不显示滚动条 ,success:function (layero, index) { // indexOpen = layer.getChildFrame('body', index) ; // console.log(indexOpen); } }); layui.layer.full(index); //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作) $(window).on("resize",function(){ layui.layer.full(index); }) }, reload:function(){ var form = pfgs_serialize($('form')); var name = ''; var house_name = ''; if(form.input_house == 'name'){ name = form.input_house_text; } else if(form.input_house == 'house_name'){ house_name = form.input_house_text; } table.reload('tablerReload',{ where:{ title:name, house_name:house_name, city:form.input_city, type_name:form.type_name } }) } }; $('.demoTable .layui-btn').on('click', function(){ var type = $(this).data('type'); active[type] ? active[type].call(this) : ''; }); //修改 form.on('submit(edit_group_submit)', function(data){ var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示 var formData = new FormData($( "#signupForm" )[0]); $.each(filesContainer,function (k,v) { if(v != null){ formData.append('img[]',v); } }) //需要删除的图片 if(delFiles.length > 0){ $.each(delFiles,function (k,v) { formData.append('delimg[]',v); }) } $.ajax({ cache : false, type : "post", url : "/grouppurchase/editform", data : formData, contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件 processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data error : function(request) { layer.close(index); layer.msg("请联系管理员"); }, success : function(data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return ; } layer.msg(data.msg); } }); return false; }); //添加 form.on('submit(look_submit)', function(data){ var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示 var formData = new FormData($( "#signupForm" )[0]); var trArry = $('.layui-input-block table.layui-table tbody tr'); var dataObj = []; $.each(trArry,function(key,val){ var _id = $(this).find('input[name="houseid"]').val(); dataObj.push(_id); }) formData.append('hid',dataObj); $.ajax({ cache : false, type : "post", url : "/grouppurchase/lookhouseaddform", data : formData, // 你的formid contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件 processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data error : function(request) { layer.msg("请联系管理员"); }, success : function(data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return false; } layer.msg(data.msg); // if (data.code == 200) { // layer.msg(data.msg); // } else if(data.code == 300){ // layer.msg(data.msg); // } } }); return false; }); $('.The_house').focus(function(){ // $('form').append(''); var indexOpen = layui.layer.open({ type: 2, title: '选择需要添加的楼盘', area: ['','100%'], content: '/grouppurchase/allhouse', success:function (layero, index) { // console.log(index); // indexOpen = parent.layer.getChildFrame('body', index); }, end:function(){ // $('form').append('aaaa'); // console.log($.globalEval("demoS")); } }); layui.layer.full(indexOpen); //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作) $(window).on("resize",function(){ layui.layer.full(indexOpen); }) }) var indexO = table.render({ elem: '#houselist' ,url: '/grouppurchase/allhouseform' //数据接口 ,where:{token:csrfToken} ,method:'post' ,page: true //开启分页 ,text:'数据加载中' ,id:'houseReload' ,cols: [[ //表头 {title:'选择',event:'check',width:60,align:'center',templet:"#checkBox",templet:function(d){ return '
' }}, {type:'numbers',title:'序号'}, {field: 'name', title: '楼盘名称', align:'center'}, ]] }); //删除图片 $('#demo2').on("click","#delimg",function () { var name = $(this).next().attr("imgname"); var delIdentification = $(this).next().attr("delIdentification"); if(typeof(delIdentification) != 'undefined'){ delete filesContainer[delIdentification]; delete files[delIdentification] ; } if(typeof(name) != 'undefined'){ delFiles.push(name); } $(this).parent().remove(); }) //选择所属楼盘添加 var _data; table.on('tool(houselist)', function(obj){ var layEvent = obj.event, data = obj.data; if(layEvent === 'check'){ _data = data; } }); // 提交按钮 $('.xuanzhouse').click(function () { var a = parent.layer.getChildFrame('body', indexOpen); var _length = a.find('input#hiddenBox[type="hidden"]'); if(_length.length > 0){ _length.remove(); } if(typeof _data == 'object'){ //console.log(_data.name) $('#house_name', window.parent.document).val(_data.name) $('#hiddenBox', window.parent.document).val(_data.id) //a.find('#house_name').val(_data.name) //a.find('form').append(''); // $('#house_name', window.parent.document).find('form').append(''); TableClose(); } // layer.msg('请选择楼盘'); }) var ue = UE.getEditor('editor'); //编辑器 //展示数据删除按钮 $('table.layui-table tbody').on('click','.del',function(){ $(this).parents('tr').remove(); }) });