association.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. $(function(){
  2. var chooseindex;
  3. var debouncedInputHandler = utils.debounce(function(e) {
  4. if($('.keyWord .addkeyWord').css('display') != 'none'){
  5. var input_query = $('.keyWord input').val()
  6. $('.association-list-box').removeClass('pb-0-impor')
  7. }else{
  8. var input_query = $('.keyWord textarea').eq(chooseindex).val()
  9. $('.association-list-box').addClass('pb-0-impor')
  10. }
  11. let type = ''
  12. if(window.location.href.indexOf('buyer') > -1){
  13. type = 'buyer'
  14. }else{
  15. type = 'ent'
  16. }
  17. associationNameList(type,input_query,function(res){
  18. $('.keyWord .association-list').html('')
  19. if(res.length > 0){
  20. $('.keyWord .association-list').html('')
  21. res.forEach(function(item){
  22. $('.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>')
  23. })
  24. $('.keyWord .association-list-box').show()
  25. }else{
  26. $('.keyWord .association-list-box').hide()
  27. }
  28. })
  29. },300)
  30. $('.keyWord').on('click','.editKeyWord',function(){
  31. chooseindex = $(this).index('.editKeyWord') // 当前修改索引赋值
  32. console.log(chooseindex)
  33. })
  34. $('.keyWord input').on('input',debouncedInputHandler) // 新增
  35. $('.keyWord').on('input','textarea',debouncedInputHandler) // 修改
  36. $('.keyWord input').on('blur',function(){
  37. setTimeout(function () {
  38. $('.keyWord .association-list-box').hide()
  39. }, 100);
  40. })
  41. $('.keyWord').on('blur','textarea',function(){
  42. setTimeout(function () {
  43. $('.keyWord .association-list-box').hide()
  44. }, 100);
  45. })
  46. $('.keyWord .association-list').on('click','.association-item',function(){
  47. if($('.keyWord .addkeyWord').css('display') != 'none'){
  48. $('.keyWord input').val($(this).attr('data-val'))
  49. }else{
  50. $('.keyWord textarea').eq(chooseindex).val($(this).attr('data-val'))
  51. }
  52. $('.keyWord .association-list-box').hide()
  53. })
  54. })
  55. function associationNameList (type,str, cb) {
  56. const query = str.replace(/\s+/g, '')
  57. if (query.length < 2) {
  58. return cb([])
  59. }
  60. $.ajax({
  61. type: 'post',
  62. url: '/bigmember/search/'+type+'/association',
  63. dataType: "json",
  64. data: {
  65. name:query,
  66. },
  67. success: function (res) {
  68. if (res.error_code == 0) {
  69. if (res.data) {
  70. const result = (res.data.list || []).map(v => {
  71. return {
  72. ...v,
  73. value: v.name?v.name:v
  74. }
  75. })
  76. // const result = [{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'},{value:'中国佛学院'}]
  77. cb(result)
  78. }
  79. }
  80. },
  81. error: function (error) {
  82. cb([])
  83. }
  84. })
  85. }