var reloadFunc = function(){
//去空格方法
// String.prototype.trim = function () {
// return this.replace(/(^\s*)|(\s*$)/g, ' ');
// }
// 疑问解答相关操作
$('.knowBtn').on('click', function () {
$(".problemPop").hide()
})
$(".problem").on('click', function () {
$(".problemPop").css("display", 'flex');
})
$(".enterOne").focus(function () {
$(".btnChoose").show();
})
// 输入框自适应高度
$('textarea').each(function(i,dom){
dom.style.height = dom.scrollHeight +'px';
})
$("textarea").on("input", function() {
this.style.height = 'auto';
this.style.height = this.scrollHeight + "px";
})
// 添加keyWords检查输入框内是否有文字,如果有才能点击添加按钮
$('.content .addkeyWord input.enterOne').on('input', function () {
var buttonDOM = $(this).siblings()[1].children[1]
if ($.trim($(this).val()).length >= 1) {
buttonDOM.style.opacity = 1
buttonDOM.removeAttribute("disabled")
} else {
buttonDOM.style.opacity = .5
buttonDOM.setAttribute("disabled", true)
}
})
// 添加 确认按钮的点击事件
$('.content .addkeyWord .btn button:nth-child(2)').on('click', function () {
setTimeout(function(){
var keyWord = $.trim($('.addkeyWord input.enterOne').val());
if(keyWord==""){
return
}
if(kws_arr[keyWord]!=undefined){
weui.toast('您设置的关键词已存在,请调整后再添加。', {
duration: 2000,
className: 'custom-toast',
callback: function () { console.log('close') }
});
return
}
if(kws_name.length > 20){
weui.toast('关键词不能超过20字', {
duration: 2000,
className: 'custom-toast',
callback: function () { console.log('close') }
});
}
kws_name = keyWord;
kws_index = $(".showKeyWord li").length;
if(kws_index==0){
//分类首次添加关键词需重新获取分类索引
classify_index = a_items.length;
}
var _index = 0;
if($(".showKeyWord li").length>0){
_index = Number($(".showKeyWord li:first").find(".editKeyWord").attr("dataIndex")) + Number(1);
}
classify_name = $.trim($('.classify-r .classify-detail').text());
//保存关键词
kws_count = parseInt(kws_count) + 1;
if(kws_count>300){
weui.toast('您设置的关键词已超出最高上限,请调整后再添加。', {
duration: 2000,
className: 'custom-toast',
callback: function () { console.log('close') }
});
}else if (saveData("SK")){
// 设置状态 首次添加关键词
if(a_items.length==0){
setEmptyHistory();
}
//
doSessionData("",_index);
$(".add-keyword-container .addNewKeyword i").show();
//点击保存关键词,查看缓存中存的附加词 和排除词。
$(".kws_count").text(kws_count);
var html = `
关键词:
${keyWord}
`
if (addition_kws.length>0){
html +='
'
+' 附加词:'
+''+addition_kws.join(" ")+'
'
+''
}
if (not_kws.length>0){
html +='
'
+' 排除词:'
+''+not_kws.join(" ")+'
'
+''
}
html +=`
`
if (addition_kws.length>0){
html +=``
}else{
html +=``
}
if (not_kws.length>0){
html +=``
}else{
html +=``
}
html +=`
`
$('.showKeyWord > ul').prepend(html);
// 添加完成隐藏输入框
$(".enter.addkeyWord").hide();
// 还原状态
$('.enter.addkeyWord > input').val('')
//把kws_name,kws_index,addition_kws,not_kws初始化
kws_index = 0;
kws_name = "";
addition_kws = [];
not_kws = [];
//
var buttonDOM = $('.enter.addkeyWord .btn button')[1]
buttonDOM.style.opacity = .5
buttonDOM.setAttribute("disabled", true)
//保存关键词 查看关键词数量 未分类 超过20 100提示
if(classify_name.indexOf("未分类")>-1){
if((kws_tips==1&&$(".showKeyWord li").length>=20)||(kws_tips==20&&$(".showKeyWord li").length>=100)){
//未分类 20个关键词提示,100个关键词提示
showMeg();
var param = {};
param.classify_index = classify_index;
if(kws_tips==1){
param.kws_tips = 20;
}else if(kws_tips==20){
param.kws_tips = 100;
}
$.post("/subscribepay/afterPay/updateUserTips",param,function(r){
if(r.flag){
kws_tips = param.kws_tips;
$(".classify").attr("tips",kws_tips);
}
})
}
}
}
},150)
})
// 编辑
$(".showKeyWord").on('click', '.editKeyWord', function (e) {
kws_name = $.trim($(this).parent().find('.key').text());
//当前关键词数组的位置 是数组的总长度-当前所在的位置-1 数组正序索引
kws_index = $('.showKeyWord li').length - $(this).parent().parent("li").index() -1;
if($(this).prev('div').find(".addition").text()!=""){
addition_kws = $(this).prev('div').find(".addition").text().split(" ")
}else{
addition_kws = []
}
if ($(this).prev('div').find(".notkey").text()!=""){
not_kws = $(this).prev('div').find(".notkey").text().split(" ")
}else{
not_kws = []
}
$('.enter.addkeyWord').hide()
let oSpan = $(this).parent().siblings().children('textarea');
let val = $(oSpan).val()
$(this).parent().hide()
$(this).parent().siblings().show().parent().siblings().children('.modify').hide().siblings('.one').show()
$(oSpan).val('').focus().val(val)
$(".add-keyword-container .addNewKeyword i").hide()
})
// 编辑删除
$('.showKeyWord').on('click', '.deleteKey', function (e) {
var _index = Number($(this).next(".ascertainKey").attr("dataindex"));
var jQueryDOM = $(this).parents('li')
weui.confirm('确定要删除关键词?', {
buttons: [{
label: '取消',
type: 'default',
onClick: function () { console.log('不删了') }
}, {
label: '确定',
type: 'primary',
onClick: function () {
if(saveData('DK')){
kws_count -= 1;
$(".kws_count").text(kws_count);
jQueryDOM.remove();
if($(".showKeyWord ul").find('li').length==0){
$(".enter.addkeyWord").find(".btnChoose button").eq(0).html('添加 附加词');
$(".enter.addkeyWord").find(".btnChoose button").eq(1).html('添加 附加词');
$(".enter.addkeyWord").find("input").val("");
}else{
$(".add-keyword-container .addNewKeyword i").show();
}
hasWords();
doSessionData('DK',_index);
//把kws_name,kws_index,addition_kws,not_kws初始化
kws_index = 0;
kws_name = "";
addition_kws = [];
not_kws = [];
}else{
weui.toast('无法删除', {
duration: 2000,
className: 'custom-toast',
callback: function () { console.log('close') }
});
}
}
}]
});
console.log('删除关键词:', $(this).parent().find('textarea').val())
})
// 编辑确定
// $('.showKeyWord').on('click', '.ascertainKey', function (e) {
// var $this = $(this)
// var keyWord = $(this).siblings('textarea').val()
// if(keyWord.length > 20){
// weui.toast('关键词不能超过20字', {
// duration: 2000,
// className: 'custom-toast',
// callback: function () { console.log('close') }
// });
// }else{
// $this.parent().siblings().find('.key').text(keyWord)
// $this.parent().hide().siblings().show()
// $('.addKeyWord').show()
// }
// })
//防止键盘把当前输入框给挡住
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if(isAndroid){
//防止键盘把当前输入框给挡住
window.addEventListener('resize', function () {
if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {
window.setTimeout(function () {
document.activeElement.scrollIntoViewIfNeeded();
}, 0);
}
})
}
(/iphone|ipod|ipad/i.test(navigator.appVersion)) && document.addEventListener('blur', (e) => {
// 这里加了个类型判断,因为a等元素也会触发blur事件
['input', 'textarea'].includes(e.target.localName) && document.body.scrollIntoView(false)
}, true)
// 显示关键词分类弹框
$('.classify-r').on('click', function(){
modalOne();
})
//
$('.classify-edit-pop .classify-keyword').bind('input propertychange', function() {
var s = $('input.classify-keyword').val()
// 去空格
s = s.trim()
if (s.length === 0) {
$('.weui-dialog__ft .dialog__btn_confirm').addClass("opacity6");
return
}
$('.weui-dialog__ft .dialog__btn_confirm').removeClass("opacity6");
})
// 关键词分类 - 确定按钮点击事件
$('.classify-edit-pop .dialog__btn_confirm').on('click', function() {
classify_name = $.trim($('input.classify-keyword').val());
// 去空格
classify_name = classify_name.trim();
if (classify_name.length === 0) {
return
}
//分类名称是否已存在
if($.inArray(classify_name, classify_arr)>-1){
weui.toast('此分类名称已存在', {
duration: 2000,
className: 'custom-toast',
callback: function () { console.log('close') }
});
return
}
if(classify_name.length > 20){
classify_name = classify_name.substring(0,20);
}
$(this).removeClass("opacity6");
$('.classify-r .classify-detail').text(classify_name);
// 关闭弹框后要重置input内容
$('.classify-edit-pop').hide();
$('input.classify-keyword').val('');
if($(".showKeyWord li").length>0){
saveData('SC')
a_items[classify_index]["s_item"] = classify_name;
}
})
// 关键词分类 - 取消按钮点击事件
$('.classify-edit-pop .dialog__btn_cancel').on('click', function() {
$('.classify-edit-pop').hide()
$('input.classify-keyword').val('')
})
}