help.page.js 2.01 KB
/**
 * [帮助中心]
 * @author: wsl(shuiling.wang@yoho.cn)
 * @date: 2016/07/25
 */
var helpSearch = require('./help-search');
var problemBox = require('./help-common');
var helper = require('./help-helper');
var searchTemplet = require('../../hbs/help/search-cont.hbs');
var parentID, qs, queryId, page, keywords, $cate;

require('../common');

qs = window.queryString();
queryId = qs.id;
page = qs.page || 1;
keywords = qs.helpQuery;
$cate = $('.cateId-' + queryId);// 当前分类


helpSearch.init();
problemBox();

// 获取搜索的结果
if (keywords) {
    $.get('/help/search', {
        page: page,
        keywords: keywords
    }, function(result) {
        var id,
            $detailCont = $('.detail-cont');

        if (result.helper_list) {
            $.each(result.helper_list, function(k, s) {
                if (s.helperType === 2) {
                    s.problem = true;
                }

                if (s.secendCategoryId === '0') {
                    id = s.firstCategoryId;
                } else {
                    id = s.secendCategoryId;
                }
                s.content = helper.cutStr({
                    str: s.content,
                    len: 290,
                    type: s.helperType,
                    url: '/help/detail?id=' + id + '&contId=' + s.id
                });

                // console.log(s.content)

                s.content = helper.keywordLabel(s.content, keywords);
                s.caption = helper.keywordLabel(s.caption, keywords);
            });

            $detailCont.html(searchTemplet(result));
        } else {
            $.get('/help/onlineService', {}, function(url) {
                result.jumpUrl = url;
                $detailCont.html(searchTemplet(result));
            });
        }
    });
}


if (!$cate.hasClass('big-category')) {
    parentID = $cate.data('parentId');

    $('.parentId-' + parentID).show();
    $('.cateId-' + parentID).find('.icon').removeClass('plus').addClass('minus');
}

$('.center-content').css('border-top-color', '#fff');