1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- $(function(){
- var chooseindex;
- var debouncedInputHandler = utils.debounce(function(e) {
- if($('.keyWord .addkeyWord').css('display') != 'none'){
- var input_query = $('.keyWord input').val()
- $('.association-list-box').removeClass('pb-0-impor')
- }else{
- var input_query = $('.keyWord textarea').eq(chooseindex).val()
- $('.association-list-box').addClass('pb-0-impor')
- }
- let type = ''
- if(window.location.href.indexOf('buyer') > -1){
- type = 'buyer'
- }else{
- type = 'ent'
- }
- associationNameList(type,input_query,function(res){
- $('.keyWord .association-list').html('')
- if(res.length > 0){
- $('.keyWord .association-list').html('')
- res.forEach(function(item){
- $('.keyWord .association-list').append('<li class="association-item" data-val='+item.value+'>'+ utils.replaceKeyword(item.value,input_query, '<span class="highlight-text">' + input_query + '</span>')+'</li>')
- })
- $('.keyWord .association-list-box').show()
- }else{
- $('.keyWord .association-list-box').hide()
- }
- })
- },300)
- $('.keyWord').on('click','.editKeyWord',function(){
- chooseindex = $(this).index('.editKeyWord') // 当前修改索引赋值
- console.log(chooseindex)
- })
- $('.keyWord input').on('input',debouncedInputHandler) // 新增
- $('.keyWord').on('input','textarea',debouncedInputHandler) // 修改
- $('.keyWord input').on('blur',function(){
- setTimeout(function () {
- $('.keyWord .association-list-box').hide()
- }, 100);
- })
- $('.keyWord').on('blur','textarea',function(){
- setTimeout(function () {
- $('.keyWord .association-list-box').hide()
- }, 100);
- })
- $('.keyWord .association-list').on('click','.association-item',function(){
- if($('.keyWord .addkeyWord').css('display') != 'none'){
- $('.keyWord input').val($(this).attr('data-val'))
- }else{
- $('.keyWord textarea').eq(chooseindex).val($(this).attr('data-val'))
- }
- $('.keyWord .association-list-box').hide()
- })
- })
- function associationNameList (type,str, cb) {
- const query = str.replace(/\s+/g, '')
- if (query.length < 2) {
- return cb([])
- }
- $.ajax({
- type: 'post',
- url: '/bigmember/search/'+type+'/association',
- dataType: "json",
- data: {
- name:query,
- },
- success: function (res) {
- if (res.error_code == 0) {
- if (res.data) {
- const result = (res.data.list || []).map(v => {
- return {
- ...v,
- value: v.name?v.name:v
- }
- })
- // const result = [{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'}]
- cb(result)
- }
- }
- },
- error: function (error) {
- cb([])
- }
- })
- }
|