city.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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: '/pushfresh/freshcityform' //数据接口
  14. ,where:{token:csrfToken}
  15. ,method:'post'
  16. ,page: true //开启分页
  17. ,text:'数据加载中'
  18. ,id:'tablerReload'
  19. ,limit:15
  20. ,cols: [[ //表头
  21. {type:'numbers',title:'序号',width:50},
  22. {field: 'city_name', title: '区域', align:'center'},
  23. {field: 'img', title: '图片',width:200, align:'center',templet:function(d){
  24. return '<img class="layui_magnify" src="'+d.img+'"/>'
  25. }},
  26. {field: 'sort', title: '排序',width:100, event:'sortData', align:'center',sort: true,templet:"#sortBox"}
  27. ,{field: 'create_at', title: '添加时间',width:150, align:'center'}
  28. ,{field: 'is_show', title: '审核',align:'center',width:100, templet:function (d) {
  29. if(d.is_show == 2){
  30. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  31. } else {
  32. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  33. }
  34. }}
  35. ,{fixed: 'right',title:'操作', width: 200, align:'center', toolbar: '#operate'}
  36. ]]
  37. });
  38. // 列表点击放大图片
  39. $('.layui-table-main').on('click','.layui_magnify', function(){
  40. var _src = $(this).attr('src');
  41. layui.layer.open({
  42. type: 1,
  43. title: false, //是否显示标题
  44. area: ['95%', '55%'],
  45. shade: 0.6, //透明度
  46. closeBtn: 1, //按钮 1有,0无
  47. shadeClose: true,
  48. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  49. });
  50. });
  51. //监听指定开关
  52. form.on('switch(switchTest)', function(data){
  53. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  54. $.post('/pushfresh/citydelandshow',{id:data.value,type:'show'},function (data) {
  55. layer.msg(data.msg);
  56. table.reload('tablerReload');
  57. })
  58. },function (aa) {
  59. table.reload('tablerReload'); //重新加载
  60. })
  61. });
  62. //列表操作
  63. table.on('tool('+tableIds+')', function(obj){
  64. var layEvent = obj.event,
  65. data = obj.data;
  66. if(layEvent === 'sortData'){ //修改排序
  67. layer.prompt({
  68. formType: 2
  69. ,title: '排序热门区域:<span style="color:red">'+data.city_name+'</span>'
  70. ,value: data.sort
  71. }, function(value, index){
  72. $.post('/pushfresh/citydelandshow',{id:data.id,type:'sort',sort:value},function (data) {
  73. layer.msg(data.msg);
  74. table.reload('tablerReload');
  75. })
  76. });
  77. }else if(layEvent === 'del') {
  78. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  79. $.post('/pushfresh/citydelandshow',{id:data.id,type:'del'},function (data) {
  80. layer.msg(data.msg);
  81. table.reload('tablerReload');
  82. })
  83. })
  84. } else if(layEvent === 'edit'){
  85. var index = layer.open({
  86. type: 2,
  87. title: '编辑',
  88. area:['800px','500px'],
  89. content: '/pushfresh/freshcityedit?id='+data.id+'&name='+data.city_name,
  90. end:function () {
  91. table.reload('tablerReload'); //重新加载
  92. }
  93. });
  94. } else if(layEvent === 'Relation'){
  95. var index =layui.layer.open({
  96. title :'<span style="color:red" >['+data.city_name+']</span>区域相关楼盘',
  97. type : 2,
  98. area:['','100%'],
  99. maxmin: true,
  100. content : "/pushfresh/cityhouse?id="+data.city_id,
  101. end:function () {
  102. table.reload('tablerReload');
  103. }
  104. })
  105. layui.layer.full(index);
  106. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  107. $(window).on("resize",function(){
  108. layui.layer.full(index);
  109. })
  110. }
  111. });
  112. //添加图片上传
  113. upload.render({
  114. elem: '#test1'
  115. ,url: '/house/createimg'
  116. ,data:{token:csrfToken}
  117. ,field:'img'
  118. ,size:1000 //限制上传图片的大小,单位为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: ['800px','500px'],
  149. content: '/pushfresh/freshcityadd' //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. var name = '';
  160. var house_name = '';
  161. if(form.input_house == 'name'){
  162. name = form.input_house_text;
  163. } else if(form.input_house == 'house_name'){
  164. house_name = form.input_house_text;
  165. }
  166. table.reload('tablerReload',{
  167. where:{
  168. title:name,
  169. house_name:house_name,
  170. city:form.input_city,
  171. type_name:form.type_name
  172. }
  173. })
  174. },
  175. };
  176. $('.demoTable .layui-btn').on('click', function(){
  177. var type = $(this).data('type');
  178. active[type] ? active[type].call(this) : '';
  179. });
  180. $('.The_house').focus(function(){
  181. indexOpen = parent.layui.layer.open({
  182. type: 2,
  183. title: '选择需要添加的区域111',
  184. area: ['','100%'],
  185. content: '/publicuse/city?type=1',
  186. success:function (layero, index) {
  187. },
  188. end:function(){
  189. }
  190. });
  191. parent.layui.layer.full(indexOpen);
  192. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  193. $(window).on("resize",function(){
  194. parent.layui.layer.full(indexOpen);
  195. })
  196. })
  197. //添加页面提交数据
  198. form.on('submit(add_city)', function(data){
  199. var formData = new FormData($('form')[0]);
  200. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  201. $.ajax({
  202. type : "post",
  203. url : "/pushfresh/freshcityaddform",
  204. data : formData,
  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. parent.layer.close(oindex); //再执行关闭
  218. }
  219. });
  220. return false;
  221. });
  222. form.on('submit(edit_city)', function(data){
  223. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  224. var formData = new FormData($('form')[0]);
  225. $.ajax({
  226. type : "post",
  227. url : "/pushfresh/freshcityeditform",
  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. })