pone.js 11 KB

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