floorinfo.js 11 KB

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