housenews.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. layui.use(['form','layer','laydate','table','laytpl','layedit'],function(){
  2. var form = layui.form,
  3. layer = parent.layer === undefined ? layui.layer : top.layer,
  4. $ = layui.jquery,
  5. table = layui.table;
  6. var tableIds = 'newsList';
  7. var tableIns = table.render({
  8. elem: '#'+tableIds,
  9. url : '/house/newslistform',
  10. where:{hid:$('#houseId').val()},
  11. method:'post',
  12. page : true,
  13. limit : 20,
  14. id:'tablerReload',
  15. cols : [[
  16. {type:'numbers'},
  17. {type: "checkbox", width:50},
  18. {field: 'id', title: 'ID', width:80, align:"center",sort: true},
  19. {field: 'subject', title: '标题',align:'left'},
  20. // {field: 'city_name', title: '区域',width:80, align:'center'},
  21. {field: 'news_name', title: '栏目',width:150, align:'center'},
  22. // {field: 'is_view', title: '审核',width:80, event:'housesNews', align:'center',templet:'#sexTpl'},
  23. // {field: 'comment', title: '评论',width:80, align:'center',templet:"#comment",templet:function(d){
  24. // return '<a href="#">['+d.comment+']</a>'
  25. // }},
  26. {field: 'clicks', title: '点击数',width:100, align:'center',sort: true},
  27. // {field: 'create_at', title: '添加时间',width:180, event:'sortData', align:'center',sort: true},
  28. {title: '操作', width:200, templet:'#housesListBar',fixed:"right",align:"center"}
  29. ]]
  30. });
  31. tableIns.reload('tablerReload'); //重新加载
  32. $('.demoTable .layui-btn').on('click', function(){
  33. var type = $(this).data('type');
  34. active[type] ? active[type].call(this) : '';
  35. });
  36. var $ = layui.$, active = {
  37. loadnews: function(){ //获取选中数据
  38. var index = parent.layui.layer.open({
  39. title : "加载资讯",
  40. type : 2,
  41. area:['','100%'],
  42. maxmin: true,
  43. content : "/house/loadnews",
  44. })
  45. parent.layui.layer.full(index);
  46. // // //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  47. $(window).on("resize",function(){
  48. parent.layui.layer.full(index);
  49. })
  50. },//筛选
  51. reload:function () {
  52. var form = pfgs_serialize($('form'));
  53. var name = '';
  54. var id = '';
  55. // console.log($('form').serializeArray());
  56. if(form.input_house == 'name'){
  57. name = form.input_house_text;
  58. } else if(form.input_house == 'id'){
  59. id = form.input_house_text;
  60. }
  61. table.reload('tablerReload',{
  62. where:{
  63. sort:form.input_sort,
  64. id:id,
  65. name:name,
  66. category:form.category
  67. }
  68. })
  69. }, //加载资讯的搜索
  70. load_news_reload:function () {
  71. var form = pfgs_serialize($('form'));
  72. var name = '';
  73. var id = '';
  74. // console.log($('form').serializeArray());
  75. if(form.input_house == 'name'){
  76. name = form.input_house_text;
  77. } else if(form.input_house == 'id'){
  78. id = form.input_house_text;
  79. }
  80. table.reload('loadnewsId',{
  81. where:{
  82. id:id,
  83. name:name,
  84. news:form.category
  85. }
  86. })
  87. }
  88. };
  89. //列表操作
  90. table.on('tool('+tableIds+')', function(obj){
  91. var data = obj.data;
  92. if(obj.event === 'del'){ //删除楼盘文章
  93. layer.confirm('您确定要删除吗?',{btn:['确认','取消']},function () {
  94. $.post('/house/housenewsdelgai',{nid:data.id},function (data) {
  95. if(data.code == 200){
  96. layer.msg(data.msg);
  97. table.reload('tablerReload');
  98. }else if(data.code == 300){
  99. layer.msg(data.msg);
  100. }
  101. })
  102. })
  103. }else if(obj.event === 'Relieve'){
  104. var _this = $(this);
  105. layer.confirm('您确定要解审吗?',{btn:['确认','取消']},function () {
  106. $.post('/house/housenewsdel',{dataid:data.hnid,type:2},function (data) {
  107. if(data.code == 200){
  108. // _this.text('aa');
  109. layer.msg('操作成功');
  110. table.reload('tablerReload');
  111. }else if(data.code == 300){
  112. layer.msg('操作失败');
  113. }
  114. })
  115. })
  116. }
  117. });
  118. //加载资讯
  119. $('.loadnews').click(function () {
  120. var index = parent.layui.layer.open({
  121. title :'<span style="color:red" >'+$('.house_name').html()+'</span>加载资讯',
  122. type : 2,
  123. area:['','100%'],
  124. maxmin: true,
  125. content : "/house/loadnews?hid="+$('#houseId').val(),
  126. end:function () {
  127. layui.table.reload('tablerReload');
  128. }
  129. })
  130. parent.layui.layer.full(index);
  131. // // //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  132. $(window).on("resize",function(){
  133. parent.layui.layer.full(index);
  134. })
  135. })
  136. //资讯列表
  137. table.render({
  138. elem: '#loadnewsList',
  139. url : '/house/loadnewslist',
  140. method:'post',
  141. where:{hid:$('#houseId').val()}, //接口的其它参数。如:where: {token: 'sasasas', id: 123}
  142. // height:'380px', //容器高度
  143. id:'loadnewsId',
  144. page : true,
  145. limit : 20, //注意:请务必确保 limit 参数(默认:10)是与你服务端限定的数据条数一致
  146. cols : [[
  147. {type: "checkbox", fixed:"left", width:50},
  148. {field: 'id', title: 'ID', width:80, align:"center",sort: true},
  149. {field: 'subject', title: '标题',align:'left'},
  150. // {field: 'city_name', title: '区域',width:80, align:'center'},
  151. // {field: 'news_name', title: '栏目',width:150, align:'center'},
  152. {field: 'state', title: '审核',width:80, event:'housesNews', align:'center'},
  153. // {field: 'comment', title: '评论',width:80, align:'center',templet:"#comment",templet:function(d){
  154. // return '<a href="#">['+d.comment+']</a>'
  155. // }},
  156. {field: 'clicks', title: '点击数',width:100, align:'center',sort: true},
  157. {field: 'create_at', title: '添加时间',width:150, event:'sortData', align:'center',sort: true},
  158. // {title: '操作', width:200, templet:'#housesListBar',fixed:"right",align:"center"}
  159. ]]
  160. });
  161. form.on('submit(add_load_news)',function (data) {
  162. var checkStatus = table.checkStatus('loadnewsId');
  163. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  164. // console.log(checkStatus.length);
  165. // console.log(typeof checkStatus.data[0]);
  166. // return false;
  167. if(typeof checkStatus.data[0] == 'object'){
  168. var Hid = $('#houseId').val();
  169. var formdat = new FormData();
  170. $.each(checkStatus.data,function (key,val) {
  171. formdat.append('nid[]',val.id);
  172. })
  173. formdat.append('hid',Hid);
  174. $.ajax({
  175. cache : true,
  176. type : "post",
  177. url : "/house/relationnews",
  178. data : formdat, // 你的formid
  179. // async : false, //async 默认为true异步,修改为false为同步
  180. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  181. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  182. error : function(request) {
  183. layer.close(index); //关闭数据提交信息
  184. layer.alert("网络超时");
  185. },
  186. success : function(data) {
  187. if (data.code == 200) {
  188. layer.msg(data.msg);
  189. // table.reload('loadnewsId');
  190. TableClose();
  191. } else {
  192. layer.msg(data.msg);
  193. TableClose();
  194. }
  195. }
  196. });
  197. return false;
  198. }
  199. layer.msg('请选择资讯');
  200. return false;
  201. })
  202. })