newshotactivity.js 9.5 KB

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