bottom.js 17 KB

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