city.js 9.1 KB

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