live.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. //第一个实例
  12. table.render({
  13. elem: '#' + tableIds
  14. , url: '/live/liveform' //数据接口
  15. , where: {token: csrfToken}
  16. , method: 'post'
  17. , page: true //开启分页
  18. , text: '数据加载中'
  19. , id: 'tablerReload'
  20. , cols: [[ //表头
  21. // {type: "checkbox", width:50},
  22. {type: 'numbers', title: '序号', width: 50},
  23. {field: 'title', title: '直播标题', align: 'center'},
  24. {field: 'city_name', width: 120, title: '所属区域', align: 'center'},
  25. {field: 'name', title: '所属楼盘', 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. , {field: 'img', title: '图片路径', align: 'center'}
  32. , {field: 'time', title: '直播时间', width: 200, align: 'center'}
  33. , {
  34. field: 'sort',
  35. title: '排序',
  36. width: 100,
  37. event: 'sortData',
  38. edit: 'text',
  39. align: 'center',
  40. sort: true,
  41. templet: "#sortBox"
  42. }
  43. , {field: 'create_at', title: '添加时间', width: 200, align: 'center'}
  44. , {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#operate'}
  45. ]]
  46. });
  47. table.reload('tablerReload'); //重新加载
  48. // 列表点击放大图片
  49. $('.layui-table-main').on('click', '.layui_magnify', function () {
  50. var _src = $(this).attr('src');
  51. layui.layer.open({
  52. type: 1,
  53. title: false, //是否显示标题
  54. area: ['95%', '55%'],
  55. shade: 0.6, //透明度
  56. closeBtn: 1, //按钮 1有,0无
  57. shadeClose: true,
  58. content: '<img style="width:100%;height:100%" src="' + _src + '">',
  59. });
  60. });
  61. //日期
  62. laydate.render({
  63. elem: '#date1',
  64. trigger: 'click',
  65. type: 'datetime'
  66. });
  67. //列表操作
  68. table.on('tool(' + tableIds + ')', function (obj) {
  69. var layEvent = obj.event,
  70. data = obj.data;
  71. if (layEvent === 'edit') {
  72. var index = layer.open({
  73. type: 2,
  74. title: '修改直播信息',
  75. area: ['50%', '80%'],
  76. content: '/live/liveedit?id=' + data.id + '&house_name=' + data.name,
  77. end: function () {
  78. table.reload('tablerReload'); //重新加载
  79. }
  80. });
  81. } else if (layEvent === 'del') {
  82. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  83. $.post('/live/setlive', {id: data.id, type: 'del'}, function (data) {
  84. layer.msg(data.msg);
  85. table.reload('tablerReload');
  86. })
  87. })
  88. } else if (layEvent === 'remark') {
  89. var index = layer.open({
  90. type: 2,
  91. title: '直播评论信息',
  92. area: ['100%', '100%'],
  93. content: '/live/liveremark?id=' + data.id,
  94. end: function () {
  95. table.reload('tablerReload'); //重新加载
  96. }
  97. });
  98. } else if (layEvent === 'sortData') { //修改排序
  99. table.on('edit(' + tableIds + ')', function (obj) {
  100. var data = obj.data;
  101. // console.log(data)
  102. $.post('/live/setlive', {id: data.id, type: 'sort', sort: data.sort}, function (data) {
  103. if (data.code == 200) {
  104. layer.msg(data.msg);
  105. } else if (data.code == 300) {
  106. layer.msg(data.msg);
  107. }
  108. })
  109. })
  110. }
  111. });
  112. //添加图片上传
  113. upload.render({
  114. elem: '#test1'
  115. , url: '/house/createimg'
  116. , data: {token: csrfToken}
  117. , field: 'img'
  118. , size: 500 //限制上传图片的大小,单位为KB
  119. , exts: 'png|jpg|jpeg' //只允许上传压缩文件
  120. , auto: false
  121. , bindAction: '#addcity'
  122. , choose: function (obj) {
  123. obj.preview(function (index, file, result) {
  124. $('#breviary_img').attr('src', result); //图片链接(base64)
  125. });
  126. }
  127. });
  128. // 图片放大浏览
  129. $('.layui_magnify').click(function () {
  130. var _src = $(this).attr('src');
  131. layui.layer.open({
  132. type: 1,
  133. title: false, //是否显示标题
  134. area: ['60%', '80%'],
  135. shade: 0.6, //透明度
  136. closeBtn: 1, //按钮 1有,0无
  137. shadeClose: true,
  138. content: '<img style="width:100%;height:100%" src="' + _src + '">',
  139. });
  140. })
  141. // 新增
  142. var $ = layui.$, active = {
  143. addData: function () { //获取选中数据
  144. var index = layui.layer.open({
  145. type: 2,
  146. title: '添加直播信息',
  147. closeBtn: 1, //不显示关闭按钮
  148. area: ['50%', '80%'],
  149. content: '/live/liveadd' //iframe的url,no代表不显示滚动条
  150. , success: function (layero, index) {
  151. },
  152. end: function () {
  153. table.reload('tablerReload');
  154. }
  155. });
  156. },
  157. reload: function () {//搜索
  158. var form = pfgs_serialize($('form'));
  159. table.reload('tablerReload', {
  160. where: {
  161. title: form.input_house_text,
  162. },
  163. page: {
  164. curr: 1
  165. }
  166. })
  167. },
  168. };
  169. $('.demoTable .layui-btn').on('click', function () {
  170. var type = $(this).data('type');
  171. active[type] ? active[type].call(this) : '';
  172. });
  173. $('.The_house').focus(function () {
  174. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  175. indexOpen = parent.layui.layer.open({
  176. type: 2,
  177. title: '选择需要添加的楼盘',
  178. area: ['', '100%'],
  179. content: '/publicuse/housename',
  180. success: function (layero, index) {
  181. },
  182. end: function () {
  183. }
  184. });
  185. parent.layui.layer.full(indexOpen);
  186. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  187. $(window).on("resize", function () {
  188. parent.layui.layer.full(indexOpen);
  189. })
  190. })
  191. //添加页面提交数据
  192. form.on('submit(adds)', function (data) {
  193. var formData = new FormData($('form')[0]);
  194. // if (formData.getAll('img')[0].size == 0) {
  195. // layer.msg('请选择图片');
  196. // return false;
  197. // }
  198. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  199. $.ajax({
  200. cache: false,
  201. type: "post",
  202. url: "/live/liveaddform",
  203. data: formData, // 你的formid
  204. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  205. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  206. error: function (request) {
  207. layer.close(index);
  208. layer.msg("请联系管理员");
  209. },
  210. success: function (data) {
  211. if (data.data != null) {
  212. layer.msg(ReturnInfo(data.data), {icon: 5});
  213. return;
  214. }
  215. layer.msg(data.msg);
  216. }
  217. });
  218. return false;
  219. });
  220. form.on('submit(edit)', function (data) {
  221. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  222. // var oindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  223. var formData = new FormData($('form')[0]);
  224. $.ajax({
  225. type: "post",
  226. url: "/live/liveeditform",
  227. data: formData,
  228. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  229. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  230. error: function (request) {
  231. layer.close(index);
  232. layer.msg("请联系管理员");
  233. },
  234. success: function (data) {
  235. if (data.data != null) {
  236. layer.msg(ReturnInfo(data.data), {icon: 5});
  237. return;
  238. }
  239. layer.msg(data.msg);
  240. parent.layer.close(oindex); //再执行关闭
  241. }
  242. });
  243. return false;
  244. });
  245. })