characteristic.js 9.9 KB

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