help.page.js 2.77 KB
/**
 * [帮助中心]
 * @author: jiangmin
 * @date: 2016/07/25
 */

var $subsets = $('.subsets');
var helpSearch = require('./help-search');
var problemBox = require('./problem-box');
var helper = require('./help-helper');
var comI = require('../common/index');
var searchTemplet = require('../../tpl/help/search-cont.hbs');
var qs = comI.queryString();
var queryId = qs.id;
var page = qs.page || 1;
var keywords = qs.helpQuery;
var $cate = $('.cateId-' + queryId);// 当前分类
var parentID;

require('../common/header');
require('../common/return-top');

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 (parseInt(s.secendCategoryId, 10) === 0) {
                    id = s.firstCategoryId;
                } else {
                    id = s.secendCategoryId;
                }
                s.content = helper.cutStr({
                    str: s.content,
                    len: 375,
                    type: s.helperType,
                    url: '/help/detail?id=' + id + '&contId=' + s.id
                });

                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));
            });
        }
    });
}

/**
 * 目录切换
 */

/**
 * 目录切换
 */
$subsets.click(function() {
    var $this = $(this);
    var className = $this.attr('class').split(' ')[1];
    var parentId = 'parentId-' + className.split('-')[1];
    var $child = $this.parent().find('.' + parentId);// 当前子分类

    if ($this.hasClass('open')) {
        $child.hide();
        $this.removeClass('open').children('.icon').removeClass('minus').addClass('plus');
    } else {
        $('.smll-category').hide();
        $('.subsets').children('.icon').removeClass('minus').addClass('plus');
        $child.show();
        $subsets.removeClass('open');
        $this.addClass('open').children('.icon').removeClass('plus').addClass('minus');
    }
});

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

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

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