menu.js 8.2 KB

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