housenews.js 8.9 KB

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