rotation.js 14 KB

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