recommend.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. ,form = layui.form
  7. // ,upload = layui.upload;
  8. var tableIds = 'videolist'; //表格ID
  9. //第一个实例
  10. table.render({
  11. elem: '#'+tableIds
  12. ,url: '/pushm/recommendform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,text:'数据加载中'
  17. ,id:'tablerReload'
  18. ,cols: [[ //表头
  19. {type:'numbers',title:'序号',width:50},
  20. {field: 'title', title: '标题', align:'center'},
  21. {field: 'url', title: '地址', align:'center'}
  22. ,{field: 'create_at', title: '添加时间',width:150, align:'center'}
  23. ,{field: 'is_show', title: '审核',align:'center',width:100, templet:function (d) {
  24. if(d.is_show == 2){
  25. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  26. } else {
  27. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  28. }
  29. }}
  30. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  31. ]]
  32. });
  33. //table.reload('tablerReload'); //重新加载
  34. //监听指定开关
  35. form.on('switch(switchTest)', function(data){
  36. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  37. $.post('/pushm/recommenddelshow',{id:data.value,type:'show'},function (data) {
  38. layer.msg(data.msg);
  39. table.reload('tablerReload');
  40. })
  41. },function (aa) {
  42. table.reload('tablerReload'); //重新加载
  43. })
  44. });
  45. //列表操作
  46. table.on('tool('+tableIds+')', function(obj){
  47. var layEvent = obj.event,
  48. data = obj.data;
  49. if(layEvent === 'edit'){
  50. var index = layer.open({
  51. type: 2,
  52. title: '修改',
  53. area:['800px','500px'],
  54. content: '/pushm/recommendedit?id='+data.id+'&house_name='+data.name,
  55. end:function () {
  56. table.reload('tablerReload'); //重新加载
  57. }
  58. });
  59. } else if(layEvent === 'del') {
  60. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  61. $.post('/pushm/recommenddelshow',{id:data.id,type:'del'},function (data) {
  62. layer.msg(data.msg);
  63. table.reload('tablerReload');
  64. })
  65. })
  66. }
  67. });
  68. // 新增
  69. var $ = layui.$, active = {
  70. addData: function(){ //获取选中数据
  71. var index = layui.layer.open({
  72. type: 2,
  73. title: '添加轮播图',
  74. closeBtn: 1, //不显示关闭按钮
  75. area: ['800px','500px'],
  76. content: '/pushm/recommendadd' //iframe的url,no代表不显示滚动条
  77. ,success:function (layero, index) {
  78. },
  79. end:function () {
  80. table.reload('tablerReload');
  81. }
  82. });
  83. },
  84. reload:function(){//搜索
  85. var form = pfgs_serialize($('form'));
  86. var name = '';
  87. var house_name = '';
  88. if(form.input_house == 'name'){
  89. name = form.input_house_text;
  90. } else if(form.input_house == 'house_name'){
  91. house_name = form.input_house_text;
  92. }
  93. table.reload('tablerReload',{
  94. where:{
  95. title:name,
  96. house_name:house_name,
  97. city:form.input_city,
  98. type_name:form.type_name
  99. }
  100. })
  101. },
  102. };
  103. $('.demoTable .layui-btn').on('click', function(){
  104. var type = $(this).data('type');
  105. active[type] ? active[type].call(this) : '';
  106. });
  107. $('.The_house').focus(function(){
  108. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  109. indexOpen = parent.layui.layer.open({
  110. type: 2,
  111. title: '选择需要添加的楼盘',
  112. area: ['','100%'],
  113. content: '/publicuse/housename',
  114. success:function (layero, index) {
  115. },
  116. end:function(){
  117. }
  118. });
  119. parent.layui.layer.full(indexOpen);
  120. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  121. $(window).on("resize",function(){
  122. parent.layui.layer.full(indexOpen);
  123. })
  124. })
  125. //添加页面提交数据
  126. form.on('submit(add_hotactivity)', function(data){
  127. var formData = new FormData($('form')[0]);
  128. // if(formData.getAll('img')[0].size == 0){
  129. // layer.msg('请选择图片');
  130. // return false;
  131. // }
  132. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  133. $.ajax({
  134. cache : false,
  135. type : "post",
  136. url : "/pushm/recommendaddform",
  137. data : formData, // 你的formid
  138. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  139. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  140. error : function(request) {
  141. layer.msg("请联系管理员");
  142. },
  143. success : function(data) {
  144. if(data.data != null){
  145. layer.msg(ReturnInfo(data.data),{icon:5});
  146. return ;
  147. }
  148. layer.msg(data.msg);
  149. }
  150. });
  151. return false;
  152. });
  153. form.on('submit(edit_hotactivity)', function(data){
  154. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  155. var formData = new FormData($('form')[0]);
  156. $.ajax({
  157. type : "post",
  158. url : "/pushm/recommendeditform",
  159. data : formData,
  160. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  161. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  162. error : function(request) {
  163. layer.close(index);
  164. layer.msg("请联系管理员");
  165. },
  166. success : function(data) {
  167. if(data.data != null){
  168. layer.msg(ReturnInfo(data.data),{icon:5});
  169. return ;
  170. }
  171. layer.msg(data.msg);
  172. parent.layer.close(oindex); //再执行关闭
  173. }
  174. });
  175. return false;
  176. });
  177. })