$(function() { // 添加元素到右侧 function RightElementAdd(value, name) { if($('ul.ul-right').find('.items-li-'+value).length == 0) { var html = '
  • '+name+'
  • '; $('ul.ul-right').append(html); } // 右侧数据同步 RightElementAlipayLife(); // 左侧是否还有内容 if($('ul.ul-left li').length == 0) { $('ul.ul-left .table-no').removeClass('none'); } else { $('ul.ul-left .table-no').addClass('none'); } } // 批量-生活号id同步 function RightElementAlipayLife() { var value_all = []; $('ul.ul-right li').each(function(k, v) { value_all[k] = $(this).find('span.name').data('value'); }); $('.life-container input[name="alipay_life_ids"]').val(value_all.join(',')).blur(); // 右侧是否还有数据 if($('ul.ul-right li').length == 0) { $('ul.ul-right .table-no').removeClass('none'); } else { $('ul.ul-right .table-no').addClass('none'); } } // 左侧点击到右侧 $('ul.ul-left').on('click', 'i.am-icon-angle-right', function() { var value = $(this).prev().data('value'); var name = $(this).prev().text(); $(this).parent().remove(); RightElementAdd(value, name); }); // 左侧全部移动到右侧 $('.selected-all').on('click', function() { $('ul.ul-left li').each(function(k, v) { var value = $(this).find('span.name').data('value'); var name = $(this).find('span.name').text(); $(this).remove(); RightElementAdd(value, name); }); }); // 右侧删除 $('ul.ul-right').on('click', 'i.am-icon-trash-o', function() { $(this).parent().remove(); RightElementAlipayLife(); }); // 生活号搜索 $('.life-form .search-submit').on('click', function() { var category_id = $('.life-form .life-form-category').val(); var keywords = $('.life-form .life-form-keywords').val(); console.log(category_id, keywords) // ajax请求 $.ajax({ url:$('.life-form').data('search-url'), type:'POST', dataType:"json", timeout:10000, data:{"category_id": category_id, "keywords": keywords}, success:function(result) { if(result.code == 0) { var html = ''; for(var i in result.data) { html += '
  • '+result['data'][i]['name']+'
  • '; } $('ul.ul-left .table-no').addClass('none'); $('ul.ul-left li').remove(); $('ul.ul-left').append(html); } else { Prompt(result.msg); } }, error:function() { Prompt('网络异常错误'); } }); }); });