Blame view

public/js/service/chat-qa.page.js 2.27 KB
1 2

'use strict';
lijing authored
3
var tip = require('../plugin/tip');
4
lijing authored
5 6 7 8
var $hotGroup = $('.hot-group'),
    $searchGroup = $('.search-group'),
    $noResult = $('.no-result');
9 10 11
require('../common');

$('.list-group div').on('touchstart',
lijing authored
12 13 14 15 16 17
    function() {
        $(this).addClass('highlight');
    }).on('touchend touchcancel',
    function() {
        $(this).removeClass('highlight');
    }
18 19 20
);

$('.open-down').click(
lijing authored
21 22 23
    function() {
        $(this).next('.down-item').toggle().siblings('.down-item').hide();
    }
24 25 26
);

$('.cancel-btn').click(
lijing authored
27 28 29 30 31 32 33 34 35
    function() {
        window.history.go(-1);
    }
);

$(
    function() {
        $('.get-qa').focus();
    }
36 37
);
lijing authored
38 39 40
$('.get-qa').on('keyup focus',
    function() {
        var searchText = $(this).val();
lijing authored
41
lijing authored
42 43 44 45 46 47 48 49 50 51 52 53 54 55
        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();
56
                    var keyList = result.data.helper_list;
lijing authored
57
lijing authored
58 59 60 61 62 63
                    if (keyList == '') {
                        $searchGroup.empty();
                        $noResult.show();
                        $noResult.find('.noKey').html(searchText);
                    } else {
                        var keyItem = '';
lijing authored
64
lijing authored
65 66 67
                        for (var i = 0; i < keyList.length; i++) {
                            var redText = keyList[i].caption.replace(searchText, '<span>$&</span>');
                            var id = keyList[i].id;
lijing authored
68
lijing authored
69 70 71 72 73 74 75 76 77 78 79 80
                            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('网络异常!');
                }
            });
lijing authored
81
        }
lijing authored
82
    }
83
);