cityintro.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. var url = '';
  11. var where = '';
  12. var len = $('input[name=cityId]').length;
  13. if(len == 0){
  14. url = '/knowledge/cityintroform';
  15. where = {token:csrfToken};
  16. }else{
  17. url = '/knowledge/subcityintroform';
  18. where = {city:$('input[name=cityId]').val(),token:csrfToken};
  19. }
  20. //第一个实例
  21. var wtable = table.render({
  22. elem: '#'+tableIds
  23. ,url: url //数据接口
  24. ,where:where
  25. ,method:'post'
  26. ,page: true //开启分页
  27. ,height:600
  28. ,text:'数据加载中'
  29. ,id:'tablerReload'
  30. ,limit:15
  31. ,cols: [[ //表头
  32. {field: 'id',title:'ID',width:50},
  33. {field: 'city_name', title: '地区', align:'center'},
  34. {field: 'img', title: '图片', align:'center',templet:function(d){
  35. return '<img class="layui_magnify" src="'+d.img+'"/>'
  36. }}
  37. ,{field: 'url', title: '跳转地址',width:150, align:'center'}
  38. ,{field: 'create_at', title: '添加时间',width:150, align:'center'}
  39. ,{field: 'sort', title: '排序',width:100, event:'sortData',edit: 'text', align:'center',sort: true,templet:"#sortBox"}
  40. ,{field: 'is_show', title: '审核',align:'center',width:100, templet:function (d) {
  41. if(d.is_show == 2){
  42. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  43. } else {
  44. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  45. }
  46. }}
  47. ,{field:'tools',fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  48. ]] ,done:function () {
  49. var tools = $("[data-field='tools'] :eq(0)").width();
  50. // console.log(tools);
  51. if (tools > 500) {
  52. wtable.reload('tablerReload'); //重新加载
  53. }
  54. }
  55. });
  56. // 列表点击放大图片
  57. $('.layui-table-main').on('click','.layui_magnify', function(){
  58. var _src = $(this).attr('src');
  59. layui.layer.open({
  60. type: 1,
  61. title: false, //是否显示标题
  62. area: ['95%', '55%'],
  63. shade: 0.6, //透明度
  64. closeBtn: 1, //按钮 1有,0无
  65. shadeClose: true,
  66. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  67. });
  68. });
  69. //监听指定开关
  70. form.on('switch(switchTest)', function(data){
  71. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  72. $.post('/knowledge/introdelshow',{id:data.value,type:'show'},function (data) {
  73. layer.msg(data.msg);
  74. table.reload('tablerReload');
  75. })
  76. },function (aa) {
  77. table.reload('tablerReload'); //重新加载
  78. })
  79. });
  80. //列表操作
  81. table.on('tool('+tableIds+')', function(obj){
  82. var layEvent = obj.event,
  83. data = obj.data;
  84. if(layEvent === 'sortData'){ //修改排序
  85. table.on('edit('+tableIds+')', function(obj){
  86. var data = obj.data;
  87. // console.log(data)
  88. $.post('/knowledge/introdelshow',{id:data.id,type:'sort',sort:data.sort},function (data) {
  89. if(data.code == 200)
  90. {
  91. layer.msg(data.msg);
  92. } else if(data.code == 300 ) {
  93. layer.msg(data.msg);
  94. }
  95. })
  96. })
  97. // layer.prompt({
  98. // formType: 2
  99. // ,title: '排序热门区域:<span style="color:red">'+data.city_name+'</span>'
  100. // ,value: data.sort
  101. // }, function(value, index){
  102. // $.post('/push/citydelshow',{id:data.id,type:'sort',sort:value},function (data) {
  103. // layer.msg(data.msg);
  104. // table.reload('tablerReload');
  105. // })
  106. // });
  107. }else if(layEvent === 'del') {
  108. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  109. $.post('/knowledge/introdelshow',{id:data.id,type:'del'},function (data) {
  110. layer.msg(data.msg);
  111. table.reload('tablerReload');
  112. })
  113. })
  114. }else if(layEvent === 'edit'){
  115. var index = layer.open({
  116. type: 2,
  117. title: '修改'+data.city_name+'相关内容',
  118. area:['800px','500px'],
  119. content: '/knowledge/cityintroedit?id='+data.id,
  120. end:function () {
  121. table.reload('tablerReload'); //重新加载
  122. }
  123. });
  124. }else if(layEvent === 'Relation'){
  125. var index =layui.layer.open({
  126. title :'<span style="color:red" >['+data.city_name+']</span>区域相关楼盘',
  127. type : 2,
  128. area:['','100%'],
  129. maxmin: true,
  130. content : "/knowledge/subcityintro?id="+data.city_id,
  131. end:function () {
  132. table.reload('tablerReload');
  133. }
  134. })
  135. layui.layer.full(index);
  136. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  137. $(window).on("resize",function(){
  138. layui.layer.full(index);
  139. })
  140. }
  141. });
  142. //添加图片上传
  143. upload.render({
  144. elem: '#test1'
  145. ,url: '/house/createimg'
  146. ,data:{token:csrfToken}
  147. ,field:'img'
  148. ,size:1000 //限制上传图片的大小,单位为KB
  149. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  150. ,auto:false
  151. ,bindAction:'#addcity'
  152. ,choose: function(obj){
  153. obj.preview(function(index, file, result){
  154. $('#breviary_img').attr('src', result); //图片链接(base64)
  155. });
  156. }
  157. });
  158. // 图片放大浏览
  159. $('.layui_magnify').click(function(){
  160. var _src = $(this).attr('src');
  161. layui.layer.open({
  162. type: 1,
  163. title: false, //是否显示标题
  164. area: ['60%', '80%'],
  165. shade: 0.6, //透明度
  166. closeBtn: 1, //按钮 1有,0无
  167. shadeClose: true,
  168. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  169. });
  170. })
  171. // 新增
  172. var $ = layui.$, active = {
  173. addData: function(){ //获取选中数据
  174. var index = layui.layer.open({
  175. type: 2,
  176. title: '添加区域介绍',
  177. closeBtn: 1, //不显示关闭按钮
  178. area: ['100%','100%'],
  179. content: '/knowledge/cityintroadd' //iframe的url,no代表不显示滚动条
  180. ,success:function (layero, index) {
  181. },
  182. end:function () {
  183. table.reload('tablerReload');
  184. }
  185. });
  186. },
  187. reload:function(){//搜索
  188. var form = pfgs_serialize($('form'));
  189. var name = form.input_city;
  190. table.reload('tablerReload', {
  191. where: {
  192. city_name: name
  193. }
  194. })
  195. },
  196. };
  197. $('.demoTable .layui-btn').on('click', function(){
  198. var type = $(this).data('type');
  199. active[type] ? active[type].call(this) : '';
  200. });
  201. $('.The_house').focus(function(){
  202. indexOpen = parent.layui.layer.open({
  203. type: 2,
  204. title: '选择需要添加的区域',
  205. area: ['','100%'],
  206. content: '/publicuse/city',
  207. success:function (layero, index) {
  208. },
  209. end:function(){
  210. }
  211. });
  212. parent.layui.layer.full(indexOpen);
  213. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  214. $(window).on("resize",function(){
  215. parent.layui.layer.full(indexOpen);
  216. })
  217. })
  218. //添加页面提交数据
  219. // form.on('submit(add_hotcity)', function(data){
  220. // var trArry = $('.layui-input-block table.layui-table tbody tr');
  221. // var formData = new FormData($('form')[0]);
  222. // var dataObj = [{}];
  223. // var dataArry = new Array();
  224. // if(formData.getAll('img')[0].size == 0){
  225. // layer.msg('请选择图片');
  226. // return false;
  227. // }
  228. // $.each(trArry,function(key,val){
  229. // // var _title = $(this).find('input[name="matingName"]').val();
  230. // var _rout = $(this).find('input[name="id"]').val();
  231. // // dataObj[key] = {name:_title,id:_rout} //把数据以数组对象的方式保存
  232. // dataArry.push(_rout)
  233. // // dataArry.push(dataObj[key])
  234. // })
  235. // layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  236. //
  237. // $.post("/push/hotcityaddform",{city_id:dataArry,formData:formData},function(data){
  238. //
  239. // if(data.data != null){
  240. // layer.msg(ReturnInfo(data.data),{icon:5});
  241. // return ;
  242. // }
  243. // layer.msg(data.msg);
  244. //
  245. // })
  246. // return false;
  247. // });
  248. form.on('submit(add_cityintro)', function(data){
  249. var formData = new FormData($('form')[0]);
  250. var pid =$('select[name=city] option:selected').attr('data-pid');
  251. if(pid == 0){
  252. if(formData.getAll('img')[0].size == 0){
  253. layer.msg('请选择图片');
  254. return false;
  255. }
  256. }
  257. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  258. $.ajax({
  259. cache : false,
  260. type : "post",
  261. url : "/knowledge/cityintroaddform",
  262. data : formData, // 你的formid
  263. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  264. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  265. error : function(request) {
  266. layer.close(index);
  267. layer.msg("请联系管理员");
  268. },
  269. success : function(data) {
  270. if(data.data != null){
  271. layer.msg(ReturnInfo(data.data),{icon:5});
  272. return ;
  273. }
  274. layer.msg(data.msg);
  275. }
  276. });
  277. return false;
  278. });
  279. form.on('submit(edit_cityintro)', function(data){
  280. var formData = new FormData($('form')[0]);
  281. // if(formData.getAll('img')[0].size == 0){
  282. // layer.msg('请选择图片');
  283. // return false;
  284. // }
  285. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  286. $.ajax({
  287. cache : false,
  288. type : "post",
  289. url : "/knowledge/cityintroeditform",
  290. data : formData, // 你的formid
  291. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  292. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  293. error : function(request) {
  294. layer.close(index);
  295. layer.msg("请联系管理员");
  296. },
  297. success : function(data) {
  298. if(data.data != null){
  299. layer.msg(ReturnInfo(data.data),{icon:5});
  300. return ;
  301. }
  302. layer.msg(data.msg);
  303. }
  304. });
  305. return false;
  306. });
  307. form.on('submit(edit_choice)', function(data){
  308. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  309. var formData = new FormData($('form')[0]);
  310. $.ajax({
  311. type : "post",
  312. url : "/push/choiceeditform",
  313. data : formData,
  314. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  315. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  316. error : function(request) {
  317. layer.close(index);
  318. layer.msg("请联系管理员");
  319. },
  320. success : function(data) {
  321. if(data.data != null){
  322. layer.msg(ReturnInfo(data.data),{icon:5});
  323. return ;
  324. }
  325. layer.msg(data.msg);
  326. parent.layer.close(oindex); //再执行关闭
  327. }
  328. });
  329. return false;
  330. });
  331. // //判断是否需要编辑,需要才加载
  332. var verdict = $('#editor1').html();
  333. if(typeof verdict == "string") {
  334. var ue = UE.getEditor('editor1'); //编辑器
  335. var ue = UE.getEditor('editor2'); //编辑器
  336. // var ue = UE.getEditor('editor3'); //编辑器
  337. // var ue = UE.getEditor('editor4'); //编辑器
  338. // var ue = UE.getEditor('editor5'); //编辑器
  339. // var ue = UE.getEditor('editor6'); //编辑器
  340. }
  341. form.on('select(city)',function (data) {
  342. var pid =$('select[name=city] option:selected').attr('data-pid');
  343. if(pid == 0 ){
  344. $('ul li').show();
  345. // $('ul li[lay-id=assign_2]').hide();
  346. // $('ul li[lay-id=assign_3]').hide();
  347. $('input[name=title]').parent().parent().css('display','none');
  348. $('textarea[name=intro]').parent().parent().css('display','block');
  349. $('.xm_pr').css('display','block');
  350. $('ul li').each(function(){
  351. if(typeof($(this).attr('data-id')) != 'undefined'){
  352. var v = $(this).attr('data-id');
  353. var ue = UE.getEditor('edi'+v); //编辑器;
  354. }
  355. });
  356. }
  357. if(pid != 0){
  358. $('ul li').hide();
  359. $('ul li[lay-id=assign_1]').show();
  360. $('input[name=title]').parent().parent().css('display','block');
  361. $('textarea[name=intro]').parent().parent().css('display','none');
  362. $('.xm_pr').css('display','none');
  363. // $('ul li[lay-id=assign_2]').show();
  364. // $('ul li[lay-id=assign_3]').show();
  365. }
  366. })
  367. var pid =$('select[name=city] option:selected').attr('data-pid');
  368. //编辑页面加载编辑器
  369. if(typeof pid != 'undefined' ){
  370. // var ue = UE.getEditor('editor1'); //编辑器
  371. // var ue = UE.getEditor('editor2'); //编辑器
  372. $('ul li').each(function(){
  373. if(typeof($(this).attr('data-id')) != 'undefined'){
  374. var v = $(this).attr('data-id');
  375. var ue = UE.getEditor('edi'+v); //编辑器;
  376. }
  377. });
  378. }
  379. if(pid != 0){
  380. $('ul li').hide();
  381. $('ul li[lay-id=assign_1]').show();
  382. $('input[name=title]').parent().parent().css('display','block');
  383. $('textarea[name=intro]').parent().parent().css('display','none');
  384. $('.xm_pr').css('display','none');
  385. // $('ul li[lay-id=assign_2]').show();
  386. // $('ul li[lay-id=assign_3]').show();
  387. }else if(pid == 0){
  388. $('input[name=title]').parent().parent().css('display','none');
  389. $('textarea[name=intro]').parent().parent().css('display','block');
  390. $('.xm_pr').css('display','block');
  391. }
  392. })