fresh.js 9.3 KB

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