investhot.js 9.5 KB

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