rotation.js 11 KB

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