sojourncity.js 8.7 KB

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