index.js 11 KB

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