selecthouse.js 10 KB

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