select.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. //第一个实例
  11. table.render({
  12. elem: '#'+tableIds
  13. ,url: '/selecthouses/indexform' //数据接口
  14. ,where:{token:csrfToken}
  15. ,method:'post'
  16. ,page: true //开启分页
  17. ,height:600
  18. ,text:'数据加载中'
  19. ,id:'tablerReload'
  20. ,limit:15
  21. ,cols: [[ //表头
  22. {type:'numbers',title:'序号',width:50},
  23. {field: 'title', title: '栏目名称', align:'center'},
  24. // {field: 'city_name', 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: 200, 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('/pushm/citydelandshow',{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.city_name+'</span>'
  72. ,value: data.sort
  73. }, function(value, index){
  74. $.post('/pushm/citydelandshow',{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('/pushm/citydelandshow',{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: '/pushm/freshcityedit?id='+data.id+'&name='+data.city_name,
  92. end:function () {
  93. table.reload('tablerReload'); //重新加载
  94. }
  95. });
  96. } else if(layEvent === 'Relation'){
  97. var index =layui.layer.open({
  98. title :'<span style="color:red" >['+data.city_name+']</span>相关楼盘',
  99. type : 2,
  100. area:['','100%'],
  101. maxmin: true,
  102. content : "/selecthouses/indexhouse?id="+data.id,
  103. end:function () {
  104. table.reload('tablerReload');
  105. }
  106. })
  107. layui.layer.full(index);
  108. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  109. $(window).on("resize",function(){
  110. layui.layer.full(index);
  111. })
  112. }
  113. });
  114. //添加图片上传
  115. upload.render({
  116. elem: '#test1'
  117. ,url: '/house/createimg'
  118. ,data:{token:csrfToken}
  119. ,field:'img'
  120. ,size:1000 //限制上传图片的大小,单位为KB
  121. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  122. ,auto:false
  123. ,bindAction:'#addcity'
  124. ,choose: function(obj){
  125. obj.preview(function(index, file, result){
  126. $('#breviary_img').attr('src', result); //图片链接(base64)
  127. });
  128. }
  129. });
  130. // 图片放大浏览
  131. $('.layui_magnify').click(function(){
  132. var _src = $(this).attr('src');
  133. layui.layer.open({
  134. type: 1,
  135. title: false, //是否显示标题
  136. area: ['60%', '80%'],
  137. shade: 0.6, //透明度
  138. closeBtn: 1, //按钮 1有,0无
  139. shadeClose: true,
  140. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  141. });
  142. })
  143. // 新增
  144. var $ = layui.$, active = {
  145. addData: function(){ //获取选中数据
  146. var index = layui.layer.open({
  147. type: 2,
  148. title: '添加',
  149. closeBtn: 1, //不显示关闭按钮
  150. area: ['800px','500px'],
  151. content: '/selecthouses/indexadd' //iframe的url,no代表不显示滚动条
  152. ,success:function (layero, index) {
  153. },
  154. end:function () {
  155. table.reload('tablerReload');
  156. }
  157. });
  158. },
  159. reload:function(){//搜索
  160. var form = pfgs_serialize($('form'));
  161. var name = form.input_city;
  162. table.reload('tablerReload', {
  163. where: {
  164. city_name: name
  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. indexOpen = parent.layui.layer.open({
  175. type: 2,
  176. title: '选择需要添加',
  177. area: ['','100%'],
  178. content: '/publicuse/city?type=1',
  179. success:function (layero, index) {
  180. },
  181. end:function(){
  182. }
  183. });
  184. parent.layui.layer.full(indexOpen);
  185. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  186. $(window).on("resize",function(){
  187. parent.layui.layer.full(indexOpen);
  188. })
  189. })
  190. //添加页面提交数据
  191. form.on('submit(add_city)', function(data){
  192. var formData = new FormData($('form')[0]);
  193. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  194. $.ajax({
  195. type : "post",
  196. url : "/selecthouses/indexaddform",
  197. data : formData,
  198. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  199. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  200. error : function(request) {
  201. layer.close(index);
  202. layer.msg("请联系管理员");
  203. },
  204. success : function(data) {
  205. if(data.data != null){
  206. layer.msg(ReturnInfo(data.data),{icon:5});
  207. return ;
  208. }
  209. layer.msg(data.msg);
  210. parent.layer.close(oindex); //再执行关闭
  211. }
  212. });
  213. return false;
  214. });
  215. form.on('submit(edit_city)', function(data){
  216. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  217. var formData = new FormData($('form')[0]);
  218. $.ajax({
  219. type : "post",
  220. url : "/pushm/discounteditform",
  221. data : formData,
  222. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  223. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  224. error : function(request) {
  225. layer.close(index);
  226. layer.msg("请联系管理员");
  227. },
  228. success : function(data) {
  229. if(data.data != null){
  230. layer.msg(ReturnInfo(data.data),{icon:5});
  231. return ;
  232. }
  233. layer.msg(data.msg);
  234. parent.layer.close(oindex); //再执行关闭
  235. }
  236. });
  237. return false;
  238. });
  239. })