cnnews.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. subject: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/cnnewsform' //数据接口
  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: 'subject', 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. console.log(val.subject);
  51. if(val.subject == obj.data.subject){
  52. del.push(key);
  53. }
  54. })
  55. if(del.length >0){
  56. $.each(del,function(key,val){
  57. console.log(key);
  58. _data.splice(key,1);
  59. })
  60. }
  61. }
  62. });
  63. // 提交按钮
  64. $('.xuanzhouse').click(function () {
  65. var a = parent.layer.getChildFrame('body', indexOpen);
  66. var type = $('#types').html();
  67. // console.log(type);
  68. if(type == 1){
  69. var _length = a.find('input#hiddenBox[type="hidden"]');
  70. if(_length.length > 0){
  71. _length.remove();
  72. }
  73. if(_data.length > 1){
  74. layer.msg('请勿选择多个');
  75. return ;
  76. }
  77. console.log(_data[0].subject);
  78. a.find('#house_name').val(_data[0].subject)
  79. a.find('form').append('<input type="hidden" id="hiddenBox" name="nid" value="'+_data[0].id+'" />');
  80. } else {
  81. a.find('tbody').html('');
  82. if(typeof _data == 'object'){
  83. for(var i=0;i<_data.length;i++){
  84. var tr ='<tr>'
  85. +'<td lay-event="del">'
  86. +'<div class="layui-table-cell del"><i class="layui-icon" style="font-size: 30px; color: #1E9FFF;cursor: pointer">&#xe640;</i></div>'
  87. +'</td>'
  88. +'<td data-field="matingName" align="center" data-content="">'
  89. +'<div class="layui-table-cell"><input type="text" name="matingName" value="'+_data[i].city_name+'" autocomplete="off" class="layui-input" ><input type="hidden" name="id" value="'+_data[i].id+'"></div>'
  90. +'</td>'
  91. +'</tr>'
  92. a.find('tbody').append(tr);
  93. }
  94. }
  95. }
  96. TableClose();
  97. })
  98. });