home.js 13 KB

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