123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- 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[0]
- if ($(this).val().length >= 1) {
- buttonDOM.style.opacity = 1
- buttonDOM.removeAttribute("disabled")
- } else {
- buttonDOM.style.opacity = .5
- buttonDOM.setAttribute("disabled", true)
- }
- })
- // 添加 确认按钮的点击事件
- $('.content .addkeyWord .btn button').on('click', function () {
- var keyWord = $('.addkeyWord input.enterOne').val();
- if(kws_arr[keyWord]!=undefined){
- weui.toast('您设置的关键词已存在,请调整后再添加。', {
- duration: 2000,
- className: 'custom-toast',
- callback: function () { console.log('close') }
- });
- return
- }
- kws_name = keyWord;
- kws_index = $(".showKeyWord li").length;
- if(kws_index==0){
- //分类首次添加关键词需重新获取分类索引
- classify_index = a_items.length;
- }
- classify_name = $('.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")){
- //
- doSessionData();
- $(".add-keyword-container .addNewKeyword").show();
- //点击保存关键词,查看缓存中存的附加词 和排除词。
- $(".kws_count").text(kws_count);
- var html = `<li><div class="one"><div>
- <span>
- <strong> 关键词:</strong>
- <p class="key">${keyWord}</p>
- </span>`
- if (addition_kws.length>0){
- html +='<span>'
- +'<strong> 附加词:</strong>'
- +'<p class="addition">'+addition_kws.join(" ")+'</p>'
- +'</span>'
- }
- if (not_kws.length>0){
- html +='<span>'
- +'<strong> 排除词:</strong>'
- +'<p class="notkey">'+not_kws.join(" ")+'</p>'
- +'</span>'
- }
- html +=`</div>
- <button class="editKeyWord" dataIndex=`+kws_index+`><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="20">${keyWord}</textarea>`
- if (addition_kws.length>0){
- html +=`<button class="addAdjunctWord" onClick="toappendkey(this)">编辑 附加词<i>(`+addition_kws.length+`)</i></button>`
- }else{
- html +=`<button class="addAdjunctWord" onClick="toappendkey(this)">添加 附加词</button>`
- }
- if (not_kws.length>0){
- html +=`<button class="addAdjunctWord" onClick="tonotkey(this)">编辑 排除词<i>(`+not_kws.length+`)</i></button>`
- }else{
- html +=`<button class="addAdjunctWord" onClick="tonotkey(this)">添加 排除词</button>`
- }
- html +=`<button class="deleteKey">删除</button><button class="ascertainKey" dataIndex=`+kws_index+` onclick="saveK(this)">确定</button></div></li>`
- $('.showKeyWord > ul').prepend(html);
- // 添加完成隐藏输入框
- $(".enter.addkeyWord").hide();
- // 还原状态
- $('.enter.addkeyWord > input').val('')
- var buttonDOM = $('.enter.addkeyWord .btn button')[0]
- buttonDOM.style.opacity = .5
- buttonDOM.setAttribute("disabled", true)
- // 设置状态 首次添加关键词
- if(a_items.length==0){
- setEmptyHistory();
- }
- //保存关键词 查看关键词数量 未分类 超过20 100提示
- if(classify_name.indexOf("未分类")>-1){
- if((kws_tips==0&&$(".showKeyWord li").length>=20)||(kws_tips==20&&$(".showKeyWord li").length>=100)){
- //未分类 20个关键词提示,100个关键词提示
- showMeg();
- var param = {};
- param.classify_index = classify_index;
- if(kws_tips==0){
- 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);
- }
- })
- }
- }
- }
- })
- // 编辑
- $(".showKeyWord").on('click', '.editKeyWord', function (e) {
- kws_name = $(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)
- $('.addKeyWord').hide()
- })
- // 编辑删除
- $('.showKeyWord').on('click', '.deleteKey', function (e) {
- 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();
- hasWords();
- $('.addKeyWord').show();
- doSessionData('DK');
- }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(){
- // 如果是苹果手机,打开时候要设置top
- var agent = navigator.userAgent.toLowerCase();
- var dialog = $('.classify-edit-pop .weui-dialog')
- if( /iphone|ipod|ipad|ios/.test(agent) ){
- dialog.css({ 'top': '30%' })
- } else {
- dialog.css({ 'top': '50%' })
- }
- $('.classify-edit-pop').show()
- var currentClassifyName = $(this).find('.classify-detail').text()
- if(currentClassifyName=="未分类"){
- currentClassifyName = ""
- }
- $('input.classify-keyword').val(currentClassifyName).focus()
- })
- //
- $('.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 = $('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
- }
- $(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('')
- })
- }
|