hotactivity.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. //第一个实例
  11. table.render({
  12. elem: '#'+tableIds
  13. ,url: '/push/hotactivityform' //数据接口
  14. ,where:{token:csrfToken}
  15. ,method:'post'
  16. ,page: true //开启分页
  17. ,text:'数据加载中'
  18. ,id:'tablerReload'
  19. ,cols: [[ //表头
  20. {type:'numbers',title:'序号',width:50},
  21. {field: 'title', title: '活动标题', align:'center'},
  22. {field: 'name', title: '归属楼盘名称', align:'center'},
  23. {field: 'img', title: '图片',width:200, align:'center',templet:function(d){
  24. return '<img class="layui_magnify" src="'+d.img+'"/>'
  25. }}
  26. , {field: 'url', title: '地址',width:200, align:'center',templet:function(d){
  27. return '<a href="'+d.url+'" target="_blank">'+d.url+'</a>';
  28. }}
  29. ,{field: 'expiration_date', title: '有效期',event:'expirationData',edit: 'text',width:150, align:'center'}
  30. ,{field: 'create_at', title: '添加时间',width:150, align:'center'}
  31. ,{field: 'is_show', title: '审核',align:'center',width:100, templet:function (d) {
  32. if(d.is_show == 2){
  33. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  34. } else {
  35. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  36. }
  37. }}
  38. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  39. ]]
  40. });
  41. //table.reload('tablerReload'); //重新加载
  42. // 列表点击放大图片
  43. $('.layui-table-main').on('click','.layui_magnify', function(){
  44. var _src = $(this).attr('src');
  45. layui.layer.open({
  46. type: 1,
  47. title: false, //是否显示标题
  48. area: ['95%', '55%'],
  49. shade: 0.6, //透明度
  50. closeBtn: 1, //按钮 1有,0无
  51. shadeClose: true,
  52. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  53. });
  54. });
  55. //监听指定开关
  56. form.on('switch(switchTest)', function(data){
  57. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  58. $.post('/push/hotactivitydelshow',{id:data.value,type:'show'},function (data) {
  59. layer.msg(data.msg);
  60. table.reload('tablerReload');
  61. })
  62. },function (aa) {
  63. table.reload('tablerReload'); //重新加载
  64. })
  65. });
  66. //列表操作
  67. table.on('tool('+tableIds+')', function(obj){
  68. var layEvent = obj.event,
  69. data = obj.data;
  70. if(layEvent === 'edit'){
  71. var index = layer.open({
  72. type: 2,
  73. title: '修改热门活动',
  74. area:['800px','500px'],
  75. content: '/push/hotactivityedit?id='+data.id+'&house_name='+data.name,
  76. end:function () {
  77. table.reload('tablerReload'); //重新加载
  78. }
  79. });
  80. } else if(layEvent === 'del') {
  81. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  82. $.post('/push/hotactivitydelshow',{id:data.id,type:'del'},function (data) {
  83. layer.msg(data.msg);
  84. table.reload('tablerReload');
  85. })
  86. })
  87. }else if(layEvent === 'expirationData'){
  88. table.on('edit('+tableIds+')', function(obj){
  89. var data = obj.data;
  90. $.post('/push/hotactivitydelshow',{id:data.id,type:'expiration',expiration:data.expiration_date},function (data) {
  91. if(data.code == 200)
  92. {
  93. layer.msg(data.msg);
  94. } else if(data.code == 300 ) {
  95. layer.msg(data.msg);
  96. }
  97. })
  98. })
  99. }
  100. });
  101. //添加图片上传
  102. upload.render({
  103. elem: '#test1'
  104. ,url: '/house/createimg'
  105. ,data:{token:csrfToken}
  106. ,field:'img'
  107. ,size:1000 //限制上传图片的大小,单位为KB
  108. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  109. ,auto:false
  110. ,bindAction:'#addcity'
  111. ,choose: function(obj){
  112. obj.preview(function(index, file, result){
  113. $('#breviary_img').attr('src', result); //图片链接(base64)
  114. });
  115. }
  116. });
  117. // 图片放大浏览
  118. $('.layui_magnify').click(function(){
  119. var _src = $(this).attr('src');
  120. layui.layer.open({
  121. type: 1,
  122. title: false, //是否显示标题
  123. area: ['60%', '80%'],
  124. shade: 0.6, //透明度
  125. closeBtn: 1, //按钮 1有,0无
  126. shadeClose: true,
  127. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  128. });
  129. })
  130. // 新增
  131. var $ = layui.$, active = {
  132. addData: function(){ //获取选中数据
  133. var index = layui.layer.open({
  134. type: 2,
  135. title: '添加轮播图',
  136. closeBtn: 1, //不显示关闭按钮
  137. area: ['800px','500px'],
  138. content: '/push/hotactivityadd' //iframe的url,no代表不显示滚动条
  139. ,success:function (layero, index) {
  140. },
  141. end:function () {
  142. table.reload('tablerReload');
  143. }
  144. });
  145. },
  146. reload:function(){//搜索
  147. var form = pfgs_serialize($('form'));
  148. // var name = '';
  149. // var house_name = '';
  150. // if(form.input_house == 'name'){
  151. // name = form.input_house_text;
  152. // } else if(form.input_house == 'house_name'){
  153. // house_name = form.input_house_text;
  154. // }
  155. table.reload('tablerReload',{
  156. where:{
  157. title:form.input_house_text,
  158. city:form.input_city,
  159. type_name:form.type_name
  160. },
  161. page:{
  162. curr:1
  163. }
  164. })
  165. },
  166. };
  167. $('.demoTable .layui-btn').on('click', function(){
  168. var type = $(this).data('type');
  169. active[type] ? active[type].call(this) : '';
  170. });
  171. $('.The_house').focus(function(){
  172. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  173. indexOpen = parent.layui.layer.open({
  174. type: 2,
  175. title: '选择需要添加的楼盘',
  176. area: ['','100%'],
  177. content: '/publicuse/housename',
  178. success:function (layero, index) {
  179. },
  180. end:function(){
  181. }
  182. });
  183. parent.layui.layer.full(indexOpen);
  184. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  185. $(window).on("resize",function(){
  186. parent.layui.layer.full(indexOpen);
  187. })
  188. })
  189. //添加页面提交数据
  190. form.on('submit(add_hotactivity)', function(data){
  191. var formData = new FormData($('form')[0]);
  192. if(formData.getAll('img')[0].size == 0){
  193. layer.msg('请选择图片');
  194. return false;
  195. }
  196. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  197. $.ajax({
  198. cache : false,
  199. type : "post",
  200. url : "/push/hotactivityaddform",
  201. data : formData, // 你的formid
  202. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  203. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  204. error : function(request) {
  205. layer.close(index);
  206. layer.msg("请联系管理员");
  207. },
  208. success : function(data) {
  209. if(data.data != null){
  210. layer.msg(ReturnInfo(data.data),{icon:5});
  211. return ;
  212. }
  213. layer.msg(data.msg);
  214. }
  215. });
  216. return false;
  217. });
  218. form.on('submit(edit_hotactivity)', function(data){
  219. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  220. var formData = new FormData($('form')[0]);
  221. $.ajax({
  222. type : "post",
  223. url : "/push/hotactivityeditform",
  224. data : formData,
  225. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  226. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  227. error : function(request) {
  228. layer.close(index);
  229. layer.msg("请联系管理员");
  230. },
  231. success : function(data) {
  232. if(data.data != null){
  233. layer.msg(ReturnInfo(data.data),{icon:5});
  234. return ;
  235. }
  236. layer.msg(data.msg);
  237. parent.layer.close(oindex); //再执行关闭
  238. }
  239. });
  240. return false;
  241. });
  242. })