bottom.js 16 KB

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