adviser.js 9.6 KB

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