houseload.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var laypage = layui.laypage //分页
  3. ,$ = layui.jquery
  4. ,layer = layui.layer //弹层
  5. ,table = layui.table //表格
  6. ,element = layui.element //元素操作
  7. ,form = layui.form
  8. ,upload = layui.upload;
  9. var tableIds = 'videolist'; //表格ID
  10. var cat_id = $('input[name="cat_id"]').val();
  11. //第一个实例
  12. table.render({
  13. elem: '#'+tableIds
  14. ,url: '/pushrecommend/houseloadform' //数据接口
  15. ,where:{token:csrfToken,cat_id:cat_id}
  16. ,method:'post'
  17. ,page: true //开启分页
  18. ,text:'数据加载中'
  19. ,id:'tablerReload'
  20. ,cols: [[ //表头
  21. {type: "checkbox", width:50},
  22. {type:'numbers',title:'序号',width:50},
  23. {field: 'name', title: '楼盘名称', align:'center'},
  24. {field: 'city_name', title: '所属区域', align:'center',width:150},
  25. {field: 'sort', title: '排序',width:100, event:'sortData',edit: 'text', align:'center',sort: true,templet:"#sortBox"},
  26. {field: 'create_at', title: '添加时间',width:150, align:'center'},
  27. {field: 'is_show', title: '审核',align:'center',width:100, templet:function (d) {
  28. if(d.is_show == 2){
  29. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  30. } else {
  31. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  32. }
  33. }}
  34. ,{fixed: 'right',title:'操作', width: 100, align:'center', toolbar: '#operate'}
  35. ]]
  36. });
  37. //监听指定开关
  38. form.on('switch(switchTest)', function(data){
  39. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  40. $.post('/pushrecommend/saledelshow',{id:data.value,type:'show'},function (data) {
  41. layer.msg(data.msg);
  42. table.reload('tablerReload');
  43. })
  44. },function (aa) {
  45. table.reload('tablerReload'); //重新加载
  46. })
  47. });
  48. //列表操作
  49. table.on('tool('+tableIds+')', function(obj){
  50. var layEvent = obj.event,
  51. data = obj.data;
  52. if(layEvent === 'sortData'){ //修改排序
  53. table.on('edit('+tableIds+')', function(obj){
  54. var data = obj.data;
  55. // console.log(data)
  56. $.post('/pushrecommend/delshow',{id:data.id,type:'sort',sort:data.sort},function (data) {
  57. if(data.code == 200)
  58. {
  59. layer.msg(data.msg);
  60. } else if(data.code == 300 ) {
  61. layer.msg(data.msg);
  62. }
  63. })
  64. })
  65. // layer.prompt({
  66. // formType: 2
  67. // ,title: '排序热销楼盘:<span style="color:red">'+data.name+'</span>'
  68. // ,value: data.sort
  69. // }, function(value, index){
  70. // $.post('/push/saledelshow',{id:data.id,type:'sort',sort:value},function (data) {
  71. // layer.msg(data.msg);
  72. // table.reload('tablerReload');
  73. // })
  74. // });
  75. }
  76. if(layEvent === 'del') {
  77. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  78. $.post('/pushrecommend/delshow',{id:data.id,type:'del'},function (data) {
  79. layer.msg(data.msg);
  80. table.reload('tablerReload');
  81. })
  82. })
  83. }
  84. });
  85. // 新增
  86. var $ = layui.$, active = {
  87. addData: function(){ //获取选中数据
  88. var index = layui.layer.open({
  89. type: 2,
  90. title: '添加楼盘',
  91. closeBtn: 1, //不显示关闭按钮
  92. area: ['600px','300px'],
  93. content: '/pushrecommend/houseadd?cat_id='+cat_id
  94. ,success:function (layero, index) {
  95. // indexOpen = layer.getChildFrame('body', index) ;
  96. // console.log(indexOpen);
  97. },
  98. end:function () {
  99. table.reload('tablerReload');
  100. }
  101. });
  102. },
  103. reload:function(){
  104. var form = pfgs_serialize($('form'));
  105. // var name = '';
  106. // var house_name = '';
  107. // if(form.input_house == 'name'){
  108. // name = form.input_house_text;
  109. // } else if(form.input_house == 'house_name'){
  110. // house_name = form.input_house_text;
  111. // }
  112. table.reload('tablerReload',{
  113. where:{
  114. house_name: form.input_house_text
  115. },
  116. page:{
  117. curr:1
  118. }
  119. })
  120. }
  121. };
  122. $('.demoTable .layui-btn').on('click', function(){
  123. var type = $(this).data('type');
  124. active[type] ? active[type].call(this) : '';
  125. });
  126. $('.The_house').focus(function(){
  127. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  128. indexOpen = parent.layui.layer.open({
  129. type: 2,
  130. title: '选择需要添加的楼盘',
  131. area: ['','100%'],
  132. content: '/publicuse/housename',
  133. success:function (layero, index) {
  134. },
  135. end:function(){
  136. }
  137. });
  138. parent.layui.layer.full(indexOpen);
  139. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  140. $(window).on("resize",function(){
  141. parent.layui.layer.full(indexOpen);
  142. })
  143. })
  144. //添加页面提交数据
  145. form.on('submit(add)', function(data){
  146. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  147. var formData = new FormData($('form')[0]);
  148. $.ajax({
  149. cache : false,
  150. type : "post",
  151. url : "/pushrecommend/houseaddform",
  152. data : formData, // 你的formid
  153. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  154. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  155. error : function(request) {
  156. layer.close(index);
  157. layer.msg("请联系管理员");
  158. },
  159. success : function(data) {
  160. if(data.data != null){
  161. layer.msg(ReturnInfo(data.data),{icon:5});
  162. return ;
  163. }
  164. layer.msg(data.msg);
  165. parent.layer.close(oindex); //再执行关闭
  166. }
  167. });
  168. return false;
  169. });
  170. //批量删除
  171. form.on('submit(del_alls_push)',function (data) {
  172. var checkStatus = table.checkStatus('tablerReload');
  173. if(typeof checkStatus.data[0] == 'object'){
  174. layer.confirm('您确定要删除吗?',{btn:['确认','取消']},function(){
  175. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  176. var formdat = new FormData();
  177. $.each(checkStatus.data,function (key,val) {
  178. formdat.append('id[]',val.id);
  179. })
  180. $.ajax({
  181. cache : true,
  182. type : "post",
  183. url : "/pushrecommend/housedelall",
  184. data : formdat, // 你的formid
  185. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  186. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  187. error : function(request) {
  188. layer.close(index); //关闭数据提交信息
  189. layer.alert("网络超时");
  190. },
  191. success : function(data) {
  192. if (data.code == 200) {
  193. layer.msg(data.msg);
  194. table.reload('tablerReload')
  195. } else {
  196. layer.msg(data.msg);
  197. }
  198. }
  199. });
  200. })
  201. return false;
  202. }
  203. layer.msg('请选择需要删除的内容',{icon:5});
  204. return false;
  205. });
  206. })