newscolumn.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var indexOpen;
  2. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  3. var laypage = layui.laypage //分页
  4. ,$ = layui.jquery
  5. ,layer = layui.layer //弹层
  6. ,table = layui.table //表格
  7. var tableIds = 'videolist'; //表格ID
  8. var $ = layui.$, active = {
  9. house_reload:function(){
  10. var form = pfgs_serialize($('form'));
  11. // console.log(form);
  12. table.reload('houseReload',{
  13. where:{
  14. name:form.input_house_text
  15. }
  16. })
  17. }
  18. };
  19. $('.demoTable .layui-btn').on('click', function(){
  20. var type = $(this).data('type');
  21. active[type] ? active[type].call(this) : '';
  22. });
  23. var indexO = table.render({
  24. elem: '#houselist'
  25. ,url: '/publicuse/newscolumnform' //数据接口
  26. ,where:{token:csrfToken}
  27. ,method:'post'
  28. ,page: true //开启分页
  29. ,text:'数据加载中'
  30. ,id:'houseReload'
  31. ,limit : 20
  32. ,cols: [[ //表头
  33. {type: "checkbox", width:50},
  34. // {title:'选择',event:'checkbox',width:50,align:'center',templet:"#checkBox",templet:function(d){
  35. // return '<div class="layui-inline" style="width: 100%"><input type="checkbox" name="sex" ></div>'
  36. // }},
  37. {type:'numbers',title:'序号'},
  38. {field: 'news_name', title: '资讯名称', align:'center'},
  39. ]]
  40. });
  41. //选择所属楼盘添加
  42. var _data = [];
  43. table.on('checkbox(houselist)', function(obj){
  44. if(obj.checked == true){
  45. _data.push(obj.data);
  46. }
  47. // if(obj.checked == false){
  48. // var del = [];
  49. // $.each(_data,function(key,val){
  50. // if(val.news_name == obj.data.news_name){
  51. // console.log(val.news_name);
  52. // del.push(key);
  53. // }
  54. // })
  55. //
  56. // if(del.length >0){
  57. // $.each(del,function(key,val){
  58. // // console.log(key);
  59. // _data.splice(key,1);
  60. // console.log(_data);
  61. // })
  62. // }
  63. // }
  64. });
  65. // 提交按钮
  66. $('.xuanzhouse').click(function () {
  67. var a = parent.layer.getChildFrame('body', indexOpen);
  68. var type = $('#types').html();
  69. // console.log(_data);
  70. // return ;
  71. if(type == 1){
  72. var _length = a.find('input#hiddenBox[type="hidden"]');
  73. if(_length.length > 0){
  74. _length.remove();
  75. }
  76. if(_data.length > 1){
  77. layer.msg('请勿选择多个');
  78. return ;
  79. }
  80. a.find('#house_name').val(_data[0].news_name)
  81. a.find('form').append('<input type="hidden" id="hiddenBox" name="nid" value="'+_data[0].id+'" />');
  82. } else {
  83. a.find('tbody').html('');
  84. if(typeof _data == 'object'){
  85. for(var i=0;i<_data.length;i++){
  86. var tr ='<tr>'
  87. +'<td lay-event="del">'
  88. +'<div class="layui-table-cell del"><i class="layui-icon" style="font-size: 30px; color: #1E9FFF;cursor: pointer">&#xe640;</i></div>'
  89. +'</td>'
  90. +'<td data-field="matingName" align="center" data-content="">'
  91. +'<div class="layui-table-cell"><input type="text" name="matingName" value="'+_data[i].news_name+'" autocomplete="off" class="layui-input" ><input type="hidden" name="id" value="'+_data[i].id+'"></div>'
  92. +'</td>'
  93. +'</tr>'
  94. a.find('tbody').append(tr);
  95. }
  96. }
  97. }
  98. TableClose();
  99. })
  100. });