cncity.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // $('.The_house').focus(function(){
  24. // indexOpen = parent.layui.layer.open({
  25. // type: 2,
  26. // title: '选择需要添加的楼盘',
  27. // area: ['','100%'],
  28. // content: '/routinevideo/allhouse',
  29. // success:function (layero, index) {
  30. // },
  31. // end:function(){
  32. // }
  33. // });
  34. // parent.layui.layer.full(indexOpen);
  35. // //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  36. // $(window).on("resize",function(){
  37. // parent.layui.layer.full(indexOpen);
  38. // })
  39. // })
  40. table.render({
  41. elem: '#houselist'
  42. ,url: '/publicuse/allcncity' //数据接口
  43. ,where:{token:csrfToken}
  44. ,method:'post'
  45. ,page: true //开启分页
  46. ,limit : 20
  47. ,text:'数据加载中'
  48. ,id:'houseReload'
  49. ,cols: [[ //表头
  50. {type: "checkbox", width:50},
  51. // {title:'选择',event:'checkbox',width:50,align:'center',templet:"#checkBox",templet:function(d){
  52. // return '<div class="layui-inline" style="width: 100%"><input type="checkbox" name="sex" ></div>'
  53. // }},
  54. {type:'numbers',title:'序号'},
  55. {field: 'city_name', title: '区域名称', align:'center'},
  56. ]]
  57. });
  58. //选择所属楼盘添加
  59. var _data = [];
  60. // table.on('tool(houselist)', function(obj){
  61. // var layEvent = obj.event,
  62. // data = obj.data;
  63. // if(layEvent === 'check'){
  64. // console.log($(this).children('input'));
  65. //
  66. // if($(this).checked)
  67. // {
  68. // _data.push(data);
  69. // console.log(_data)
  70. // }
  71. // // _data = data;
  72. //
  73. //
  74. // }
  75. // });
  76. table.on('checkbox(houselist)', function(obj){
  77. if(obj.checked == true){
  78. _data.push(obj.data);
  79. }
  80. if(obj.checked == false){
  81. var del = [];
  82. $.each(_data,function(key,val){
  83. console.log(val.city_name);
  84. if(val.city_name == obj.data.city_name){
  85. del.push(key);
  86. }
  87. })
  88. if(del.length >0){
  89. $.each(del,function(key,val){
  90. console.log(key);
  91. _data.splice(key,1);
  92. })
  93. }
  94. }
  95. });
  96. // 提交按钮
  97. $('.xuanzhouse').click(function () {
  98. var a = parent.layer.getChildFrame('body', indexOpen);
  99. var type = $('#types').html();
  100. console.log(type);
  101. if(type == 1){
  102. var _length = a.find('input#hiddenBox[type="hidden"]');
  103. if(_length.length > 0){
  104. _length.remove();
  105. }
  106. if(_data.length > 1){
  107. layer.msg('请勿选择多个');
  108. return ;
  109. }
  110. console.log(_data[0].city_name);
  111. a.find('#house_name').val(_data[0].city_name)
  112. a.find('form').append('<input type="hidden" id="hiddenBox" name="city_id" value="'+_data[0].id+'" />');
  113. } else {
  114. a.find('tbody').html('');
  115. if(typeof _data == 'object'){
  116. for(var i=0;i<_data.length;i++){
  117. var tr ='<tr>'
  118. +'<td lay-event="del">'
  119. +'<div class="layui-table-cell del"><i class="layui-icon" style="font-size: 30px; color: #1E9FFF;cursor: pointer">&#xe640;</i></div>'
  120. +'</td>'
  121. +'<td data-field="matingName" align="center" data-content="">'
  122. +'<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>'
  123. +'</td>'
  124. +'</tr>'
  125. a.find('tbody').append(tr);
  126. }
  127. }
  128. }
  129. TableClose();
  130. })
  131. });