help.page.js 2.84 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);// 当前分类
let 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) {
            result.helper_list.forEach(function(s) {
                if (s.helperType === '2') {
                    s.problem = true;
                    s.allCont = s.content;
                }

                if (s.secendCategoryId === 0) {
                    id = s.firstCategoryId;
                } else {
                    id = s.secendCategoryId;
                }
                s.content = helper.cutStr({
                    str: s.content,
                    len: 380,
                    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('.plus').css('background-image', 'url(\'../img/help/plus.png\')');
    } else {
        $('.smll-category').hide();
        $('.subsets').children('.plus').css('background-image', 'url(\'../img/help/plus.png\')');
        $child.show();
        $subsets.removeClass('open');
        $this.addClass('open').children('.plus').css('background-image', 'url(\'../img/help/minus.png\')');
    }
});

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

    $('.parentId-' + parentID).show();
    $('.cateId-' + parentID).find('.plus').css('background-image', 'url(\'../img/help/minus.png\')');
}

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