chat-qa.page.js 2.27 KB

'use strict';
var tip = require('../plugin/tip');

var $hotGroup = $('.hot-group'),
    $searchGroup = $('.search-group'),
    $noResult = $('.no-result');

require('../common');

$('.list-group div').on('touchstart',
    function() {
        $(this).addClass('highlight');
    }).on('touchend touchcancel',
    function() {
        $(this).removeClass('highlight');
    }
);

$('.open-down').click(
    function() {
        $(this).next('.down-item').toggle().siblings('.down-item').hide();
    }
);

$('.cancel-btn').click(
    function() {
        window.history.go(-1);
    }
);

$(
    function() {
        $('.get-qa').focus();
    }
);

$('.get-qa').on('keyup focus',
    function() {
        var searchText = $(this).val();

        if (searchText == '') {
            $hotGroup.show();
            $searchGroup.hide();
            $noResult.hide();
        } else {
            $.ajax({
                url: '/service/keySearch',
                data: {
                    keyword: searchText
                },
                success: function(result) {
                    $searchGroup.show();
                    $noResult.hide();
                    $hotGroup.hide();
                    var keyList = result.data.helper_list;

                    if (keyList == '') {
                        $searchGroup.empty();
                        $noResult.show();
                        $noResult.find('.noKey').html(searchText);
                    } else {
                        var keyItem = '';

                        for (var i = 0; i < keyList.length; i++) {
                            var redText = keyList[i].caption.replace(searchText, '<span>$&</span>');
                            var id = keyList[i].id;

                            keyItem += '<a class="common-item" href="./qaDetail?keyword=' + searchText + '&sonId=' + id + '">' +
                                            '<p>' + redText + '</p>' +
                                            '<i class="arr-ico iconfont">&#xe604;</i>' +
                                        '</a>';
                        }
                        $searchGroup.html(keyItem);
                    }
                },
                error: function() {
                    tip.show('网络异常!');
                }
            });
        }
    }
);