rotation.js 10 KB

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