liveremark.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. layui.use(['laypage', 'layer', 'laydate', '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. , laydate = layui.laydate
  9. , upload = layui.upload;
  10. var tableIds = 'videolist'; //表格ID
  11. var tableIds1 = 'videolist1'; //表格ID
  12. var check = $('input[name=zzz]').val();
  13. var liveID = $('input[name=lid]').val();
  14. var col = '';
  15. var checkcount = 0;
  16. var returntime = 5;//轮询请求返回时间
  17. if(check==1){
  18. col = [[ //表头
  19. {
  20. field: 'comment', title: '', align: 'center', templet: function (d) {
  21. return '<div><div style="float: left;"><p>'+d.comment+'</p></div><div><a class="layui-btn layui-btn-radius layui-btn-warm">删除</a></div></div>';
  22. }
  23. }
  24. ]];
  25. $('#div_1').css('display','none');
  26. }
  27. if(check==2){
  28. col = [[ //表头
  29. {
  30. field: 'comment', title: '已审核', align: 'center', templet: function (d) {
  31. return '<div><div style="float: left;"><p>'+d.comment+'</p></div><div><a class="layui-btn layui-btn-radius layui-btn-warm">删除</a></div></div>';
  32. }
  33. }
  34. ]];
  35. $('#div_1').css({"float":"left","width":"50%",'display':'block'});
  36. $('#div_2').css({'float':'left','width':'50%'});
  37. }
  38. //第一个实例
  39. table.render({
  40. elem: '#' + tableIds
  41. , url: '/live/liveremarkform' //数据接口
  42. , where: {token: csrfToken,lid:liveID}
  43. , method: 'post'
  44. , page: true //开启分页
  45. , text: '数据加载中'
  46. , id: 'tablerReload'
  47. , cols: col,
  48. });
  49. // if(check==2) tabelcheck();
  50. if(check==2) getcheckremark(checkcount);
  51. table.reload('tablerReload'); //重新加载
  52. // 列表点击放大图片
  53. $('.layui-table-main').on('click', '.layui_magnify', function () {
  54. var _src = $(this).attr('src');
  55. layui.layer.open({
  56. type: 1,
  57. title: false, //是否显示标题
  58. area: ['95%', '55%'],
  59. shade: 0.6, //透明度
  60. closeBtn: 1, //按钮 1有,0无
  61. shadeClose: true,
  62. content: '<img style="width:100%;height:100%" src="' + _src + '">',
  63. });
  64. });
  65. //日期
  66. laydate.render({
  67. elem: '#date1',
  68. trigger: 'click',
  69. type: 'datetime'
  70. });
  71. //显示或隐藏
  72. form.on('switch(switchCheck)', function(data){
  73. var state = '';
  74. if(data.value == 1){
  75. state = 2;
  76. }else if(data.value == 2){
  77. state = 1;
  78. preRequest.abort();
  79. }
  80. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  81. $.post('/live/allremarkcheck',{id:liveID,state:state},function (data) {
  82. if(data.data != null){
  83. layer.msg(ReturnInfo(data.data),{icon:5});
  84. return false;
  85. }
  86. layer.msg(data.msg);
  87. if(state==1){
  88. $('#div_1').css('display','none');
  89. $('#div_2').attr('style','');
  90. $('input[name=zzz]').attr('value',state);
  91. table.reload('tablerReload',{
  92. cols:[[ //表头
  93. {
  94. field: 'comment', title: '', align: 'center', templet: function (d) {
  95. return '<div><div style="float: left;"><p>'+d.comment+'</p></div><div><a class="layui-btn layui-btn-radius layui-btn-warm">删除</a></div></div>';
  96. }
  97. }
  98. ]],
  99. });
  100. // clearInterval(lx);
  101. }
  102. if(state==2){
  103. $('#div_1').css({"float":"left","width":"50%",'display':'block'});
  104. $('#div_2').css({'float':'left','width':'50%'});
  105. $('input[name=zzz]').attr('value',state);
  106. table.reload('tablerReload',{
  107. cols:[[ //表头
  108. {
  109. field: 'comment', title: '审核', align: 'center', templet: function (d) {
  110. return '<div><div style="float: left;"><p>'+d.comment+'</p></div><div><a class="layui-btn layui-btn-radius layui-btn-warm">删除</a></div></div>';
  111. }
  112. }
  113. ]],
  114. });
  115. // tabelcheck();
  116. //开启人工审核
  117. checkcount = 0;
  118. $('#div_check').empty();
  119. getcheckremark(checkcount);
  120. }
  121. })
  122. },function (aa) {
  123. table.reload('tablerReload');
  124. // tabelcheck();
  125. getcheckremark(checkcount);
  126. })
  127. });
  128. //列表操作
  129. table.on('tool(' + tableIds + ')', function (obj) {
  130. var layEvent = obj.event,
  131. data = obj.data;
  132. if (layEvent === 'edit') {
  133. var index = layer.open({
  134. type: 2,
  135. title: '修改直播信息',
  136. area: ['50%', '80%'],
  137. content: '/live/liveedit?id=' + data.id + '&house_name=' + data.name,
  138. end: function () {
  139. table.reload('tablerReload'); //重新加载
  140. }
  141. });
  142. } else if (layEvent === 'del') {
  143. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  144. $.post('/live/setlive', {id: data.id, type: 'del'}, function (data) {
  145. layer.msg(data.msg);
  146. table.reload('tablerReload');
  147. })
  148. })
  149. }
  150. });
  151. //添加图片上传
  152. upload.render({
  153. elem: '#test1'
  154. , url: '/house/createimg'
  155. , data: {token: csrfToken}
  156. , field: 'img'
  157. , size: 500 //限制上传图片的大小,单位为KB
  158. , exts: 'png|jpg|jpeg' //只允许上传压缩文件
  159. , auto: false
  160. , bindAction: '#addcity'
  161. , choose: function (obj) {
  162. obj.preview(function (index, file, result) {
  163. $('#breviary_img').attr('src', result); //图片链接(base64)
  164. });
  165. }
  166. });
  167. // 图片放大浏览
  168. $('.layui_magnify').click(function () {
  169. var _src = $(this).attr('src');
  170. layui.layer.open({
  171. type: 1,
  172. title: false, //是否显示标题
  173. area: ['60%', '80%'],
  174. shade: 0.6, //透明度
  175. closeBtn: 1, //按钮 1有,0无
  176. shadeClose: true,
  177. content: '<img style="width:100%;height:100%" src="' + _src + '">',
  178. });
  179. })
  180. // 新增
  181. var $ = layui.$, active = {
  182. addData: function () { //获取选中数据
  183. var index = layui.layer.open({
  184. type: 2,
  185. title: '添加直播信息',
  186. closeBtn: 1, //不显示关闭按钮
  187. area: ['50%', '80%'],
  188. content: '/live/liveadd' //iframe的url,no代表不显示滚动条
  189. , success: function (layero, index) {
  190. },
  191. end: function () {
  192. table.reload('tablerReload');
  193. }
  194. });
  195. },
  196. reload: function () {//搜索
  197. var form = pfgs_serialize($('form'));
  198. table.reload('tablerReload', {
  199. where: {
  200. title: form.input_house_text,
  201. },
  202. page: {
  203. curr: 1
  204. }
  205. })
  206. },
  207. send:function(){//发送
  208. // var form = pfgs_serialize($('form'));
  209. // console.log(form.input_house_text);
  210. // $.post('/live/comperesend', {id: liveID, comment: form.input_house_text,initiator:2}, function (data) {
  211. // layer.msg(data.msg);
  212. // table.reload('tablerReload');
  213. // })
  214. var formData = new FormData($('form')[0]);
  215. if(form.input_house_text == ''){
  216. layer.msg('发送内容不能为空');
  217. return false;
  218. }
  219. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  220. $.ajax({
  221. cache: false,
  222. type: "post",
  223. url: "/live/comperesend",
  224. data: formData, // 你的formid
  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. table.reload('tablerReload');
  238. }
  239. });
  240. return false;
  241. }
  242. };
  243. $('.demoTable .layui-btn').on('click', function () {
  244. var type = $(this).data('type');
  245. active[type] ? active[type].call(this) : '';
  246. });
  247. $('.The_house').focus(function () {
  248. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  249. indexOpen = parent.layui.layer.open({
  250. type: 2,
  251. title: '选择需要添加的楼盘',
  252. area: ['', '100%'],
  253. content: '/publicuse/housename',
  254. success: function (layero, index) {
  255. },
  256. end: function () {
  257. }
  258. });
  259. parent.layui.layer.full(indexOpen);
  260. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  261. $(window).on("resize", function () {
  262. parent.layui.layer.full(indexOpen);
  263. })
  264. })
  265. //添加页面提交数据
  266. form.on('submit(adds)', function (data) {
  267. var formData = new FormData($('form')[0]);
  268. if (formData.getAll('img')[0].size == 0) {
  269. layer.msg('请选择图片');
  270. return false;
  271. }
  272. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  273. $.ajax({
  274. cache: false,
  275. type: "post",
  276. url: "/live/liveaddform",
  277. data: formData, // 你的formid
  278. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  279. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  280. error: function (request) {
  281. layer.close(index);
  282. layer.msg("请联系管理员");
  283. },
  284. success: function (data) {
  285. if (data.data != null) {
  286. layer.msg(ReturnInfo(data.data), {icon: 5});
  287. return;
  288. }
  289. layer.msg(data.msg);
  290. }
  291. });
  292. return false;
  293. });
  294. form.on('submit(edit)', function (data) {
  295. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  296. // var oindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  297. var formData = new FormData($('form')[0]);
  298. $.ajax({
  299. type: "post",
  300. url: "/live/liveeditform",
  301. data: formData,
  302. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  303. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  304. error: function (request) {
  305. layer.close(index);
  306. layer.msg("请联系管理员");
  307. },
  308. success: function (data) {
  309. if (data.data != null) {
  310. layer.msg(ReturnInfo(data.data), {icon: 5});
  311. return;
  312. }
  313. layer.msg(data.msg);
  314. parent.layer.close(oindex); //再执行关闭
  315. }
  316. });
  317. return false;
  318. });
  319. function tabelcheck(){
  320. table.render({
  321. elem: '#' + tableIds1
  322. , url: '/live/checkstart' //数据接口
  323. , where: {token: csrfToken,lid:liveID}
  324. , method: 'post'
  325. , page: false //开启分页
  326. , text: '数据加载中'
  327. , id: 'tablerReload1'
  328. , cols: [[ //表头
  329. // {type: "checkbox", width:50},
  330. // {type: 'numbers', title: '序号', width: 50},
  331. // {field: 'title', title: '直播标题', align: 'center'}
  332. {
  333. field: 'comment', title: '未审核', align: 'center', templet: function (d) {
  334. return '<div><div style="float: left;"><p>'+d.comment+'</p></div><div><a class="layui-btn layui-btn-radius layui-btn-normal">通过</a><a class="layui-btn layui-btn-radius layui-btn-warm">删除</a></div></div>';
  335. // console.log(d);
  336. }
  337. }
  338. ]],
  339. done:function(res, curr, count){
  340. checkcount = count;
  341. // lx = setInterval(function(){
  342. // lunxun(checkcount);
  343. // console.log(checkcount);
  344. // },3000);
  345. },
  346. });
  347. }
  348. function lunxun(oldcount){
  349. $.ajax({
  350. type: "post",
  351. url: "/live/checkstart",
  352. async:true,
  353. data: {token: csrfToken,lid:liveID,oldcount:oldcount},
  354. // contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  355. // processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  356. error: function (request) {
  357. layer.close(index);
  358. layer.msg("请联系管理员");
  359. },
  360. success: function (data) {
  361. // console.log(data);
  362. if(data.code == 200){
  363. checkcount = data.data.count;
  364. // console.log(checkcount);
  365. // setInterval(function(){lunxun(checkcount);},3000);
  366. table.reload('tablerReload1');
  367. // var oldData = table.cache["videolist1"];
  368. // console.log(oldData);
  369. // oldData.push(data.data.data);
  370. // table.reload('test2',{data : oldData});
  371. }
  372. }
  373. });
  374. }
  375. function getcheckremark(oldcount){
  376. preRequest = $.ajax({
  377. type: "post",
  378. url: "/live/checkstart",
  379. async:true,
  380. data: {token: csrfToken,lid:liveID,oldcount:oldcount,returntime:returntime},
  381. success: function (data) {
  382. // console.log(data);
  383. if(data.code == 200){
  384. var html = '';
  385. $.each(data.data.data,function(i,v){
  386. html += '<div class="layui-col-md6 layui-bg-green" ><p>'+v.comment+'</p></div>';
  387. html += '<div class="layui-col-md6 layui-bg-blue" ><a class="layui-btn layui-btn-radius layui-btn-normal">通过</a><a class="layui-btn layui-btn-radius layui-btn-warm">删除</a></div>';
  388. });
  389. // console.log(html);
  390. $('#div_check').prepend(html);
  391. checkcount = data.data.count;
  392. getcheckremark(checkcount);
  393. }
  394. if(data.code == 300){
  395. getcheckremark(checkcount);
  396. }
  397. }
  398. });
  399. }
  400. });