columncontent.js 9.8 KB

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