overview.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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 type_id = $('input[name="typeid"]').val();
  11. switch (type_id)
  12. {
  13. case '1':
  14. var tab1 = [ //表头
  15. // {field:'city_pid',title:'ID',width:50},
  16. {field:'city_id',title:'ID',width:50},
  17. {field: 'city_name', title: '城市', align:'center',width:150},
  18. {field: 'population_size', title: '人口数量', width:150,align:'center'},
  19. {field: 'livable_index', title: '宜居指数', width:150,align:'center'},
  20. {field: 'rental_rate', title: '租房率', width:150,align:'center'},
  21. {field: 'rentalrate_return', title: '租金回报率', width:150,align:'center'},
  22. {field: 'salerental_ratio', title: '租售比', width:150,align:'center'},
  23. {field: 'url', title: '跳转地址', width:150,align:'center'},
  24. {field: 'create_at', title: '添加时间',width:150, align:'center'},
  25. {field: 'is_show', title: '审核',align:'center',width:150, templet:function (d) {
  26. if(d.is_show == 2){
  27. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  28. } else {
  29. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  30. }
  31. }}
  32. ,{fixed: 'right',title:'操作', width: 300, align:'center', toolbar: '#operate'}
  33. ];
  34. break;
  35. case '2':
  36. var tab1 = [ //表头
  37. // {type:'numbers',title:'序号',width:50},
  38. // {field: 'remark', title: '城市', align:'center',width:250,edit: 'text'},
  39. // {field: 'population_size', title: '人口数量', width:250,align:'center',edit: 'text'},
  40. // {field: 'livable_index', title: '宜居指数', width:250,align:'center',edit: 'text'},
  41. // {field: 'rental_rate', title: '租房率', width:250,align:'center',edit: 'text'},
  42. // {field: 'rentalrate_return', title: '租金回报率', width:250,align:'center',edit: 'text'},
  43. // {field: 'salerental_ratio', title: '租售比', width:250,align:'center',edit: 'text'},
  44. ];
  45. break;
  46. }
  47. //第一个实例
  48. table.render({
  49. elem: '#'+tableIds
  50. ,url: '/categorycity/cityoverviewform' //数据接口
  51. ,where:{token:csrfToken,type:type_id}
  52. ,method:'post'
  53. ,page: true //开启分页
  54. ,text:'数据加载中'
  55. ,id:'tablerReload'
  56. ,limit:15
  57. ,cols: [tab1],
  58. done: function () {
  59. $("[data-field='city_pid']").css("display","none");
  60. }
  61. });
  62. //监听指定开关
  63. form.on('switch(switchTest)', function(data){
  64. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  65. $.post('/categorycity/viewdelshow',{id:data.value,type:'show'},function (data) {
  66. layer.msg(data.msg);
  67. table.reload('tablerReload');
  68. })
  69. },function (aa) {
  70. table.reload('tablerReload'); //重新加载
  71. })
  72. });
  73. //列表操作
  74. table.on('tool('+tableIds+')', function(obj){
  75. var layEvent = obj.event,
  76. data = obj.data;
  77. if(layEvent === 'sortData'){ //修改排序
  78. /* 列表操作 edit 修改后执行 2018.7.24*/
  79. table.on('edit('+tableIds+')', function(obj){
  80. var data = obj.data;
  81. $.post('/pushm/',{id:data.id,type:'sort',sort:data.sort},function (data) {
  82. if(data.code == 200)
  83. {
  84. layer.msg(data.msg);
  85. } else if(data.code == 300 ) {
  86. layer.msg(data.msg);
  87. }
  88. })
  89. })
  90. // layer.prompt({
  91. // formType: 2
  92. // ,title: '排序热销楼盘:<span style="color:red">'+data.name+'</span>'
  93. // ,value: data.sort
  94. // }, function(value, index){
  95. // $.post('/pushm/saledelshow',{id:data.id,type:'sort',sort:value},function (data) {
  96. // layer.msg(data.msg);
  97. // table.reload('tablerReload');
  98. // })
  99. // });
  100. }else if(layEvent === 'edit'){
  101. var index = layer.open({
  102. type: 2,
  103. title: '编辑',
  104. area:['100%','100%'],
  105. content: '/categorycity/overviewedit?id='+data.city_pid,
  106. end:function () {
  107. table.reload('tablerReload'); //重新加载
  108. }
  109. });
  110. }else if(layEvent === 'del') {
  111. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  112. $.post('/categorycity/viewdelshow',{id:data.city_id,type:'del'},function (data) {
  113. layer.msg(data.msg);
  114. table.reload('tablerReload');
  115. })
  116. })
  117. }else if(layEvent === 'produce'){
  118. //
  119. var index = layer.open({
  120. type: 2,
  121. title: '生成['+data.remark+']控制模板代码',
  122. closeBtn: 1, //不显示关闭按钮
  123. shade: [0],
  124. area: ['600px', '500px'],
  125. anim: 2,
  126. content: '/pushm/produce?id='+data.id+'&name='+data.name, //iframe的url,no代表不显示滚动条
  127. end:function () {
  128. renderTable();
  129. }
  130. });
  131. }
  132. });
  133. table.on('edit(videolist)', function(obj){
  134. var value = obj.value //得到修改后的值
  135. ,data = obj.data //得到所在行所有键值
  136. ,field = obj.field; //得到字段
  137. layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为:'+ value);
  138. });
  139. // 新增
  140. var $ = layui.$, active = {
  141. addData: function(){ //获取选中数据
  142. var index = layui.layer.open({
  143. type: 2,
  144. title: '添加时间',
  145. closeBtn: 1, //不显示关闭按钮
  146. area: ['100%','100%'],
  147. content: '/categorycity/create'
  148. ,success:function (layero, index) {
  149. // indexOpen = layer.getChildFrame('body', index) ;
  150. // console.log(indexOpen);
  151. },
  152. end:function () {
  153. table.reload('tablerReload');
  154. }
  155. });
  156. },
  157. reload:function(){
  158. var form = pfgs_serialize($('form'));
  159. // var name = '';
  160. // var house_name = '';
  161. // if(form.input_house == 'name'){
  162. // name = form.input_house_text;
  163. // } else if(form.input_house == 'house_name'){
  164. // house_name = form.input_house_text;
  165. // }
  166. table.reload('tablerReload',{
  167. where:{
  168. house_name: form.input_house_text
  169. }
  170. })
  171. }
  172. };
  173. $('.demoTable .layui-btn').on('click', function(){
  174. var type = $(this).data('type');
  175. active[type] ? active[type].call(this) : '';
  176. });
  177. $('.The_house').focus(function(){
  178. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  179. indexOpen = parent.layui.layer.open({
  180. type: 2,
  181. title: '选择需要添加的楼盘',
  182. area: ['','100%'],
  183. content: '/publicuse/housename',
  184. success:function (layero, index) {
  185. },
  186. end:function(){
  187. }
  188. });
  189. parent.layui.layer.full(indexOpen);
  190. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  191. $(window).on("resize",function(){
  192. parent.layui.layer.full(indexOpen);
  193. })
  194. })
  195. //加载省数据
  196. function loadProvince() {
  197. $.ajax({
  198. url : '/categorycity/citypid',
  199. type : 'post',
  200. async: false,//使用同步的方式,true为异步方式
  201. data : {'pid':0},//这里使用json对象
  202. success : function(data){
  203. var areaData = data.data;
  204. var proHtml = '';
  205. for (var i = 0; i < areaData.length; i++) {
  206. proHtml += '<option value="' + areaData[i].id +'">' + areaData[i].city_name + '</option>';
  207. }
  208. //初始化省数据
  209. $('select[name=country]').append(proHtml);
  210. form.render();
  211. },
  212. fail:function(){
  213. }
  214. });
  215. }
  216. loadProvince();
  217. form.on('select(country)',function (data) {
  218. table.render({
  219. elem: '#overlist'
  220. ,url: '/categorycity/citypidajax' //数据接口
  221. ,where:{token:csrfToken,pid:data.value}
  222. ,method:'post'
  223. // ,page: true //开启分页
  224. ,text:'数据加载中'
  225. ,id:'overlist1'
  226. ,limit:5
  227. ,cols: [[ //表头
  228. {type:'numbers',title:'序号',width:50},
  229. // {field: 'city_name', title: '城市', align:'center',width:250,edit: 'text',name:'sn'},
  230. // {field: 'population_size', title: '人口数量', width:250,align:'center',edit: 'text',name:'sn0'},
  231. // {field: 'livable_index', title: '宜居指数', width:250,align:'center',edit: 'text',name:'sn1'},
  232. // {field: 'rental_rate', title: '租房率', width:250,align:'center',edit: 'text',name:'sn3'},
  233. // {field: 'rentalrate_return', title: '租金回报率', width:250,align:'center',edit: 'text',name:'sn4'},
  234. // {field: 'salerental_ratio', title: '租售比', width:250,align:'center',edit: 'text',name:'sn5'}
  235. {field: 'city_name', title: '城市', align:'center',width:150},
  236. {field: 'population_size', title: '人口数量', width:150,align:'center',edit: 'text'},
  237. {field: 'livable_index', title: '宜居指数', width:150,align:'center',edit: 'text'},
  238. {field: 'rental_rate', title: '租房率', width:150,align:'center',edit: 'text'},
  239. {field: 'rentalrate_return', title: '租金回报率', width:150,align:'center',edit: 'text'},
  240. {field: 'salerental_ratio', title: '租售比', width:150,align:'center',edit: 'text'},
  241. // {field: 'url', title: '跳转地址', width:150,align:'center',edit: 'text'},
  242. ]]
  243. });
  244. $('#reason').css('display','block');
  245. $('#url').css('display','block');
  246. })
  247. //添加页面提交数据
  248. form.on('submit(add)', function(data){
  249. var dh = layui.table.cache.overlist1;
  250. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  251. var formData = new FormData($('.layui-form')[0]);
  252. // console.log(formData)
  253. // formData.push(dh);
  254. // console.log(dh);
  255. $.each(dh,function(k,v){
  256. // console.log(v);
  257. var arr=[];
  258. $.each(v,function (key,val) {
  259. arr[key] = val;
  260. formData.append('as['+k+']['+key+']',val);
  261. })
  262. })
  263. $.ajax({
  264. cache : false,
  265. type : "post",
  266. url : "/categorycity/overviewaddform",
  267. data : formData, // 你的formid
  268. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  269. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  270. error : function(request) {
  271. layer.close(index);
  272. layer.msg("请联系管理员");
  273. },
  274. success : function(data) {
  275. // console.log(formData)
  276. // console.log(dh)
  277. if(data.data != null){
  278. // layer.msg(ReturnInfo(data.data),{icon:5});
  279. // return ;
  280. }
  281. layer.msg(data.msg);
  282. // parent.layer.close(oindex); //再执行关闭
  283. }
  284. });
  285. return false;
  286. });
  287. var obj = $('select[name=country]');
  288. var pid = obj.attr('data-pid');
  289. // alert(pid);
  290. if(pid != "" && pid !=null && pid != 'undefined' && pid != undefined ){
  291. // alert(1111111);
  292. $('option[value='+pid+']').attr('selected',true);
  293. obj.parent().find('input').val($('option[value='+pid+']').text());
  294. $('#reason').css('display','block');
  295. $('#url').css('display','block');
  296. table.render({
  297. elem: '#overlist'
  298. ,url: '/categorycity/cityoverviewform' //数据接口
  299. ,where:{token:csrfToken,pid:pid}
  300. ,method:'post'
  301. // ,page: true //开启分页
  302. ,text:'数据加载中'
  303. ,id:'overlist1'
  304. ,limit:5
  305. ,cols: [[ //表头
  306. {type:'numbers',title:'序号',width:50},
  307. {field: 'city_name', title: '城市', align:'center',width:250,edit: 'text',name:'sn'},
  308. {field: 'population_size', title: '人口数量', width:250,align:'center',edit: 'text',name:'sn0'},
  309. {field: 'livable_index', title: '宜居指数', width:250,align:'center',edit: 'text',name:'sn1'},
  310. {field: 'rental_rate', title: '租房率', width:250,align:'center',edit: 'text',name:'sn3'},
  311. {field: 'rentalrate_return', title: '租金回报率', width:250,align:'center',edit: 'text',name:'sn4'},
  312. {field: 'salerental_ratio', title: '租售比', width:250,align:'center',edit: 'text',name:'sn5'}
  313. ]]
  314. });
  315. }
  316. //修改页面提交数据
  317. form.on('submit(edit)', function(data){
  318. var dh = layui.table.cache.overlist1;
  319. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  320. var formData = new FormData($('.layui-form')[0]);
  321. // console.log(formData)
  322. // formData.push(dh);
  323. // console.log(dh);
  324. $.each(dh,function(k,v){
  325. // console.log(v);
  326. var arr=[];
  327. $.each(v,function (key,val) {
  328. arr[key] = val;
  329. formData.append('as['+k+']['+key+']',val);
  330. })
  331. })
  332. $.ajax({
  333. cache : false,
  334. type : "post",
  335. url : "/categorycity/overvieweditform",
  336. data : formData, // 你的formid
  337. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  338. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  339. error : function(request) {
  340. layer.close(index);
  341. layer.msg("请联系管理员");
  342. },
  343. success : function(data) {
  344. // console.log(formData)
  345. // console.log(dh)
  346. if(data.data != null){
  347. // layer.msg(ReturnInfo(data.data),{icon:5});
  348. // return ;
  349. }
  350. layer.msg(data.msg);
  351. // parent.layer.close(oindex); //再执行关闭
  352. }
  353. });
  354. return false;
  355. });
  356. })