live.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. ,height:600
  19. , text: '数据加载中'
  20. , id: 'tablerReload'
  21. , cols: [[ //表头
  22. // {type: "checkbox", width:50},
  23. {type: 'numbers', title: '序号', width: 50},
  24. {field: 'title', title: '直播标题', align: 'center'},
  25. {field: 'city_name', width: 120, title: '所属区域', align: 'center'},
  26. {field: 'name', title: '所属楼盘', align: 'center'}
  27. // {
  28. // field: 'img', title: '封面图', width: 300, align: 'center', templet: function (d) {
  29. // return '<img class="layui_magnify" src="' + d.img + '"/>'
  30. // }
  31. // }
  32. , {field: 'img', title: '图片路径', align: 'center'}
  33. , {field: 'time', title: '直播时间', width: 200, align: 'center'}
  34. , {
  35. field: 'sort',
  36. title: '排序',
  37. width: 100,
  38. event: 'sortData',
  39. edit: 'text',
  40. align: 'center',
  41. sort: true,
  42. templet: "#sortBox"
  43. }
  44. , {field: 'create_at', title: '添加时间', width: 200, align: 'center'}
  45. , {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#operate'}
  46. ]]
  47. });
  48. table.reload('tablerReload'); //重新加载
  49. // 列表点击放大图片
  50. $('.layui-table-main').on('click', '.layui_magnify', function () {
  51. var _src = $(this).attr('src');
  52. layui.layer.open({
  53. type: 1,
  54. title: false, //是否显示标题
  55. area: ['95%', '55%'],
  56. shade: 0.6, //透明度
  57. closeBtn: 1, //按钮 1有,0无
  58. shadeClose: true,
  59. content: '<img style="width:100%;height:100%" src="' + _src + '">',
  60. });
  61. });
  62. //日期
  63. laydate.render({
  64. elem: '#date1',
  65. trigger: 'click',
  66. type: 'datetime'
  67. });
  68. //列表操作
  69. table.on('tool(' + tableIds + ')', function (obj) {
  70. var layEvent = obj.event,
  71. data = obj.data;
  72. if (layEvent === 'edit') {
  73. var index = layer.open({
  74. type: 2,
  75. title: '修改直播信息',
  76. area: ['50%', '80%'],
  77. content: '/live/liveedit?id=' + data.id + '&house_name=' + data.name,
  78. end: function () {
  79. table.reload('tablerReload'); //重新加载
  80. }
  81. });
  82. } else if (layEvent === 'del') {
  83. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  84. $.post('/live/setlive', {id: data.id, type: 'del'}, function (data) {
  85. layer.msg(data.msg);
  86. table.reload('tablerReload');
  87. })
  88. })
  89. } else if (layEvent === 'remark') {
  90. var index = layer.open({
  91. type: 2,
  92. title: '直播评论信息',
  93. area: ['100%', '100%'],
  94. content: '/live/liveremark?id=' + data.id,
  95. end: function () {
  96. table.reload('tablerReload'); //重新加载
  97. }
  98. });
  99. } else if (layEvent === 'sortData') { //修改排序
  100. table.on('edit(' + tableIds + ')', function (obj) {
  101. var data = obj.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. city: form.input_city,
  163. },
  164. page: {
  165. curr: 1
  166. }
  167. })
  168. },
  169. };
  170. $('.demoTable .layui-btn').on('click', function () {
  171. var type = $(this).data('type');
  172. active[type] ? active[type].call(this) : '';
  173. });
  174. $('.The_house').focus(function () {
  175. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  176. indexOpen = parent.layui.layer.open({
  177. type: 2,
  178. title: '选择需要添加的楼盘',
  179. area: ['', '100%'],
  180. content: '/publicuse/housenamecn',
  181. success: function (layero, index) {
  182. },
  183. end: function () {
  184. }
  185. });
  186. parent.layui.layer.full(indexOpen);
  187. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  188. $(window).on("resize", function () {
  189. parent.layui.layer.full(indexOpen);
  190. })
  191. })
  192. //添加页面提交数据
  193. form.on('submit(adds)', function (data) {
  194. var formData = new FormData($('form')[0]);
  195. // if (formData.getAll('img')[0].size == 0) {
  196. // layer.msg('请选择图片');
  197. // return false;
  198. // }
  199. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  200. $.ajax({
  201. cache: false,
  202. type: "post",
  203. url: "/live/liveaddform",
  204. data: formData, // 你的formid
  205. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  206. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  207. error: function (request) {
  208. layer.close(index);
  209. layer.msg("请联系管理员");
  210. },
  211. success: function (data) {
  212. if (data.data != null) {
  213. layer.msg(ReturnInfo(data.data), {icon: 5});
  214. return;
  215. }
  216. layer.msg(data.msg);
  217. }
  218. });
  219. return false;
  220. });
  221. form.on('submit(edit)', function (data) {
  222. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  223. // var oindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  224. var formData = new FormData($('form')[0]);
  225. $.ajax({
  226. type: "post",
  227. url: "/live/liveeditform",
  228. data: formData,
  229. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  230. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  231. error: function (request) {
  232. layer.close(index);
  233. layer.msg("请联系管理员");
  234. },
  235. success: function (data) {
  236. if (data.data != null) {
  237. layer.msg(ReturnInfo(data.data), {icon: 5});
  238. return;
  239. }
  240. layer.msg(data.msg);
  241. parent.layer.close(oindex); //再执行关闭
  242. }
  243. });
  244. return false;
  245. });
  246. })