123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017 |
- $(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();
- })
- hasWords()
- function hasWords() {
- var showKeyWordLength = $(".showKeyWord ul").find('li').length;
- if (showKeyWordLength === 0) {
- $(".addkeyWord").show();
- } else {
- $(".addkeyWord").hide();
- }
- }
- // 输入框自适应高度
- $('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检查输入框内是否有文字,如果有才能点击添加按钮
- $('.addkeyWord input.enterOne').on('input', function () {
- var buttonDOM = $(this).siblings()[1].children[1]
- if ($(this).val().length >= 1) {
- buttonDOM.style.opacity = 1
- buttonDOM.removeAttribute("disabled")
- } else {
- buttonDOM.style.opacity = .5
- buttonDOM.setAttribute("disabled", true)
- }
- })
- // 添加 确认按钮的点击事件
- $('.addkeyWord').on('click', '.btn button',function () {
- if(sessionStorage.getItem('iconClick') == '1'){
- // 获取这个分类中有多少个关键词
- var classindex = sessionStorage.getItem('classindex')
- // console.log(resArr[classindex].a_key.length)
- var keynum = 0
- for(var i=0;i<resArr.length;i++){
- keynum += resArr[i].a_key.length
- }
- console.log(keynum)
- if(keynum+1>300){
- vTools.jLoading({
- content:'关键词最多300个',
- iconHide:true,
- duration:1500
- })
- }else{
- var dataindex = keynum
- // 关键词添加数量
- $('.keypushnum').html(dataindex+1)
- // 获取关键词
- var keyWord = $('.addkeyWord input.enterOne').val()
- // 去空格
- keyWord = keyWord.replace(/\s+/g, ' ').trim();
- var addition_keys = sessionStorage.getItem('addition_key')
- var add_html = ''
- if(addition_keys){
- addition_keys = JSON.parse(addition_keys)
- for(var i=0;i<addition_keys.length;i++){
- console.log(addition_keys[i])
- add_html += ' '+ addition_keys[i]
- }
- }else{
- addition_keys = []
- }
- var exc_html = ''
- var exclusive_keys = sessionStorage.getItem('exclusive_key')
- if(exclusive_keys){
- exclusive_keys = JSON.parse(exclusive_keys)
- for(var i=0;i<exclusive_keys.length;i++){
- console.log(exclusive_keys[i])
- exc_html += ' '+exclusive_keys[i]
- }
- }else{
- exclusive_keys = []
- }
- // sessionStorage.getItem('dataindex')
- // var dataindex = sessionStorage.getItem('dataindex')
- var html = `<li class="keyclassify-item" data-index="${dataindex}">
- <div class="one">
- <div>
- <span>
- <strong> 关键词:</strong>
- <p class="key">${keyWord}</p>
- </span>
- <span>
- <strong> 附加词:</strong>
- <p class="addition">
- <span class="add_empty" style="padding:0;padding-right:0.3rem;">${add_html }</span>
- </p>
- </span>
- <span>
- <strong> 排除词:</strong>
- <p class="exclusion">
- <span class="exc_empty" style="padding:0;padding-right:0.3rem;">${exc_html }</sapn>
- </p>
- </span>
- </div>
- <button class="editKeyWord"><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="20">${keyWord}</textarea>
- <button class="addAdjunctWord">编辑 附加词</button>
- <button class="addExclusion">添加 排除词</button>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`
- // 关键词重复给出提示
- // isSame=0表示不重复,等于1重复
- var isSame = 0
- for(var i=0;i<resArr.length;i++){
- // console.log(resArr[i])
- for(j=0;j<resArr[i].a_key.length;j++){
- var datakey = resArr[i].a_key[j].key[0]
- if(datakey == keyWord){
- console.log(datakey)
- vTools.jLoading({
- content:'关键词不能重复',
- iconHide:true,
- duration:1500
- })
- isSame = 1
- return
- }
- }
- }
- console.log(isSame)
- if(isSame == 1){
- }else{
- $('.showKeyWord > ul').prepend(html)
- // 如果没有添加附加词和排除词,就不显示
- var add_empty = $('.addition')
- var exc_empty = $('.exclusion')
- for(var i=0;i<add_empty.length;i++){
- if(add_empty[i].children.length== 0){
- $('.addition:eq('+i+')').parent('span').hide()
- }else{
- $('.addition:eq('+i+')').parent('span').show()
- }
- }
- for(var i=0;i<exc_empty.length;i++){
- if(exc_empty[i].children.length == 0){
- $('.exclusion:eq('+i+')').parent('span').hide()
- }else{
- $('.exclusion:eq('+i+')').parent('span').show()
- }
- }
- // 添加完成隐藏输入框
- $(".addkeyWord").hide()
- // 还原状态
- $('.enter.addkeyWord > input').val('')
- var buttonDOM = $('.enter.addkeyWord .btn button')[0]
- buttonDOM.style.opacity = .5
- buttonDOM.setAttribute("disabled", true)
- // 添加关键词
- var addition_key = sessionStorage.getItem('addition_key')
- if(addition_key){
- addition_key = JSON.parse(addition_key)
- }else{
- addition_key = []
- }
- var exclusive_key = sessionStorage.getItem('exclusive_key')
- if(exclusive_key){
- exclusive_key = JSON.parse(exclusive_key)
- }else{
- exclusive_key = []
- }
- var newkey = {
- 'appendkey': addition_key,
- 'key': [keyWord],
- 'notkey':exclusive_key
- }
- // 获取点击的下标
- resArr[classindex].a_key.push(newkey)
- console.log(resArr)
- vTools.ajax({
- url:'/subscribe/key/update',
- type:'POST',
- data:{
- "delete_item":'',
- "update_item":{
- "before":'',
- "after":''
- },
- "a_items":resArr
- },
- success:function(res){
- console.log(res)
- $('.all-classify-column .classify-list .classify-item:eq('+classindex+')').find('.classify-item-detail').find('span').html(resArr[classindex].a_key.length)
- sessionStorage.removeItem('addition_key')
- sessionStorage.removeItem('exclusive_key')
- sessionStorage.removeItem('dataindex')
- $(".classify-item:eq("+classindex+")").find('.classify-item-r').trigger('click')
- },
- error:function(err){
- console.log(err)
- }
- })
- $('.addKeyWord').css({'display':'flex'})
- // 设置状态
- // setEmptyHistory()
- }
-
- }
- }
- })
- // // 点击取消
- $('.cancel').on('click',function(){
- if(sessionStorage.getItem('iconClick') == '1'){
- console.log($(this))
- $(this).parents('.addkeyWord').hide()
- $('.addKeyWord').css({'display':'flex'})
- sessionStorage.removeItem('addition_key')
- sessionStorage.removeItem('exclusive_key')
- }else{
- $(this).parents('.addkeyWord').hide()
- $('.addKeyWord').css({'display':'flex'})
- sessionStorage.removeItem('noaddition_key')
- sessionStorage.removeItem('noexclusive_key')
- }
- $(this).parents('.addkeyWord').find('.enterOne').val('')
- })
- // 编辑
- $(".showKeyWord").on('click', '.editKeyWord', function (e) {
- // 点击修改,把这一项的下标存入session
- sessionStorage.setItem('modifyindex',$(this).parent().parent().attr('data-index'))
- var classindex = sessionStorage.getItem('classindex')
- console.log(classindex)
- var modifyindex = sessionStorage.getItem('modifyindex')
- console.log(modifyindex)
- console.log(resArr)
- // var resArr_num = resArr[classindex].a_key[modifyindex]
- var addition_keyArr = sessionStorage.getItem('addition_key')
- var exclusive_keyArr = sessionStorage.getItem('exclusive_key')
- var parameter = location.search.split('?')[1]
- if(parameter == 'state=1'){
- if(resArr[classindex-1].a_key.length == 1){
- modifyindex = 0
- }
- var appendkey_num = JSON.stringify(resArr[classindex-1].a_key[modifyindex].appendkey)
- var notkey_num = JSON.stringify(resArr[classindex-1].a_key[modifyindex].notkey)
- }else{
- var appendkey_num = JSON.stringify(resArr[classindex].a_key[modifyindex].appendkey)
- var notkey_num = JSON.stringify(resArr[classindex].a_key[modifyindex].notkey)
- }
- console.log(appendkey_num.length)
- var add_length = sessionStorage.getItem('add_length')
- var exc_length = sessionStorage.getItem('exc_length')
- if(addition_keyArr == null || addition_keyArr == '[]'){
- if(appendkey_num == "[]" || add_length !=null){
- $(this).parent().siblings('.modify').find('.addAdjunctWord').html('添加附加词')
- }else{
- appendkey_num = JSON.parse(appendkey_num)
- $(this).parent().siblings('.modify').find('.addAdjunctWord').html('编辑附加词('+appendkey_num.length+')')
- }
- }else{
- addition_keyArr = JSON.parse(addition_keyArr)
- $(this).parent().siblings('.modify').find('.addAdjunctWord').html('编辑附加词('+addition_keyArr.length+')')
- }
- if(exclusive_keyArr == null || exclusive_keyArr == '[]'){
- if(notkey_num == "[]" || exc_length !=null){
- $(this).parent().siblings('.modify').find('.addExclusion ').html('添加排除词')
- }else{
- notkey_num = JSON.parse(notkey_num)
- $(this).parent().siblings('.modify').find('.addExclusion ').html('编辑排除词('+notkey_num.length+')')
- }
- }else{
- exclusive_keyArr = JSON.parse(exclusive_keyArr)
- $(this).parent().siblings('.modify').find('.addExclusion ').html('编辑排除词('+exclusive_keyArr.length+')')
- }
- console.log($(this).siblings('div').find('.addition').text())
- $('.enter.addkeyWord').hide()
- let oSpan = $(this).parent().siblings().children('textarea');
- console.log($(oSpan).val())
- 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()
- // 修改的时候,如果把关键词清楚掉,不能保存
- var _that = $(this)
- _that.parent().siblings('.modify').find('textarea').on('input',function(){
- console.log($(this).val())
- if($(this).val()==''){
- _that.parent().siblings('.modify').find('.addAdjunctWord').attr('disabled',true)
- _that.parent().siblings('.modify').find('.addExclusion ').attr('disabled',true)
- _that.parent().siblings('.modify').find('.ascertainKey ').attr('disabled',true)
- }else{
- _that.parent().siblings('.modify').find('.addAdjunctWord').attr('disabled',false)
- _that.parent().siblings('.modify').find('.addExclusion ').attr('disabled',false)
- _that.parent().siblings('.modify').find('.ascertainKey ').attr('disabled',false)
- }
- })
- })
- // 编辑删除
- $('.showKeyWord').on('click', '.deleteKey', function (e) {
- var jQueryDOM = $(this).parents('li')
- console.log(jQueryDOM)
- var parameter = location.search.split('?')[1]
- console.log(resArr)
- // 获取点击分类的下标
- var classify_index = sessionStorage.getItem('classindex')
- var ArrLength = 0
- if(parameter == 'state=1'){
- ArrLength = resArr[classify_index-1].a_key.length
- }else{
- ArrLength = resArr[classify_index].a_key.length
- }
- console.log(ArrLength)
- weui.confirm('确定要删除关键词?', {
- buttons: [{
- label: '取消',
- type: 'default',
- onClick: function () { console.log('不删了') }
- }, {
- label: '确定',
- type: 'primary',
- onClick: function () {
-
- // console.log(resArr[classify_index].a_key)
- // console.log(jQueryDOM.find('textarea').val())
- // 如果一个分类里只有一个关键词,点击删除关键词则删除整个分类
- if(ArrLength == 1){
- if(parameter == 'state=1'){
- classify_index = parseInt(classify_index)-1
- }else{
- classify_index = sessionStorage.getItem('classindex')
- }
- console.log(resArr[classify_index])
- console.log(resArr[classify_index].s_item)
- var delete_item = resArr[classify_index].s_item
- resArr.splice(classify_index,1)
- // 删除关键词
- vTools.ajax({
- url:'/subscribe/key/update',
- type:'POST',
- data:{
- "delete_item":delete_item,
- "a_items":resArr
- },
- success:function(res){
- console.log(res)
- if(res.data.status == -2){
- vTools.jLoading({
- content:'关联有分发规则,不能删除',
- iconHide:true,
- duration:1500
- })
- return
- }
- jQueryDOM.remove()
- hasWords()
- location.reload()
- },
- error:function(err){
- console.log(err)
- }
- })
- init()
- $('.add-keyword-container').hide()
- $('.addbutton').show()
- }else{
- console.log(classify_index)
- if(parameter == 'state=1'){
- for(var i=0;i<resArr[classify_index-1].a_key.length;i++){
- if(resArr[classify_index-1].a_key[i].key[0] == jQueryDOM.find('textarea').val()){
- resArr[classify_index-1].a_key.splice(i,1)
- }
- }
- }else{
- for(var i=0;i<resArr[classify_index].a_key.length;i++){
- console.log(resArr[classify_index].a_key[i].key[0])
- if(resArr[classify_index].a_key[i].key[0] == jQueryDOM.find('textarea').val()){
- console.log(resArr[classify_index].a_key[i])
- resArr[classify_index].a_key.splice(i,1)
- }
- }
- }
- console.log(resArr)
- // var classindex = sessionStorage.getItem('classindex')
- // console.log(resArr[classindex].a_key.length)
- var keynum = 0
- for(var i=0;i<resArr.length;i++){
- keynum += resArr[i].a_key.length
- }
- var dataindex = keynum
- console.log(dataindex)
- // 删除关键词
- vTools.ajax({
- url:'/subscribe/key/update',
- type:'POST',
- data:{
- "delete_item":'',
- "update_item":{
- "before":'',
- "after":''
- },
- "a_items":resArr
- },
- success:function(res){
- console.log(res)
- if(res.data.status == -2){
- vTools.jLoading({
- content:'关联有分发规则,不能删除',
- iconHide:true,
- duration:1500
- })
- return
- }
- $('.keypushnum').html(dataindex)
- jQueryDOM.remove()
- hasWords()
- if(parameter == 'state=1'){
- $('.all-classify-column .classify-list .classify-item:eq('+classify_index+')').find('.classify-item-detail').find('span').html(resArr[classify_index-1].a_key.length)
- }else{
- $(".classify-item:eq("+classindex+")").find('.classify-item-r').trigger('click')
- $('.all-classify-column .classify-list .classify-item:eq('+classify_index+')').find('.classify-item-detail').find('span').html(resArr[classify_index].a_key.length)
- }
- },
- error:function(err){
- console.log(err)
- }
- })
- $('.addKeyWord').show()
- }
- }
- }]
- });
- console.log('删除关键词:', $(this).parent().find('textarea').val())
- })
- // 编辑确定
- $('.showKeyWord').on('click', '.ascertainKey', function (e) {
- var parameter = location.search.split('?')[1]
- if(parameter == 'state=1'){
- var $this = $(this)
- var keyWord = $(this).siblings('textarea').val()
- // 去空格
- keyWord = keyWord.replace(/\s+/g, ' ').trim();
- // 获取被点击的下标
- var classindex = JSON.parse(sessionStorage.getItem('classindex'))-1
- var modifyindex = sessionStorage.getItem('modifyindex')
- console.log(classindex)
- var beforekey = resArr[classindex].a_key[modifyindex].key[0]
- if(keyWord.length > 20){
- weui.toast('关键词不能超过20字', {
- duration: 2000,
- className: 'custom-toast',
- callback: function () { console.log('close') }
- });
- }else{
- // 关键词重复给出提示
- // isSame=0表示不重复,等于1重复
- var isSame = 0
- for(var i=0;i<resArr.length;i++){
- console.log(resArr[i])
- for(j=0;j<resArr[i].a_key.length;j++){
- var datakey = resArr[i].a_key[j].key[0]
- console.log(beforekey)
- if(datakey == keyWord && keyWord !== beforekey){
- vTools.jLoading({
- content:'关键词不能重复',
- iconHide:true,
- duration:1500
- })
- isSame = 1
- }else{
- isSame = 0
- }
- }
- }
- if(isSame == 1){
- }else{
- $this.parent().siblings().find('.key').text(keyWord)
- // 获取修改关键词参数
- var classify_s = $('.classify-detail').html()
- console.log(resArr)
- var newArr = resArr
- // var a_items = []
- console.log(newArr)
- newArr.forEach(function(value,index){
- if(value.s_item == classify_s){
- console.log(value,index)
- // 分类
- var keywordArr = []
- keywordArr.push(keyWord)
- console.log(keywordArr)
- // 附加词
- // 获取点击修改的下标
- var modifyindex = sessionStorage.getItem('modifyindex')
- var addition_key = sessionStorage.getItem('addition_key')
- if(addition_key == null){
- addition_key = newArr[index].a_key[modifyindex].appendkey
- }else{
- addition_key = JSON.parse(addition_key)
- }
- console.log(addition_key)
- // 排除词
- var exclusive_key = sessionStorage.getItem('exclusive_key')
- console.log(exclusive_key)
- if(exclusive_key == null){
- exclusive_key = newArr[index].a_key[modifyindex].notkey
- }else{
- exclusive_key = JSON.parse(exclusive_key)
- }
- console.log(exclusive_key)
- var keyparameter = {
- "key":keywordArr,
- "appendkey":addition_key,
- "notkey":exclusive_key
- }
- var modifyindex = sessionStorage.getItem('modifyindex')
- console.log(newArr[index].a_key)
- newArr[index].a_key.splice(modifyindex,1,keyparameter)
- }
- })
- console.log(newArr)
- // 获取点击的按钮
- var sureDom = $this.parent()
- // 修改关键词
- vTools.ajax({
- url:'/subscribe/key/update',
- type:'POST',
- data:{
- "a_items":newArr
- },
- success:function(res){
- console.log(res)
- if(res.data.status== 1){
- // console.log(JSON.parse(sessionStorage.getItem('addition_key'))[0])
- // console.log(JSON.parse(sessionStorage.getItem('exclusive_key'))[0])
- sureDom.hide().siblings('.one').show()
- var addition_keyArr = sessionStorage.getItem('addition_key')
- if(addition_keyArr){
- addition_keyArr = JSON.parse(addition_keyArr)
- var html=''
- for(var i = 0;i<addition_keyArr.length;i++){
- html += '<span style="padding:0;padding-right:0.3rem;">'+addition_keyArr[i]+'</span>'
- }
- sureDom.siblings('.one').find('div').find('.addition').html(html)
- }
- var exclusive_keyArr = sessionStorage.getItem('exclusive_key')
- if(exclusive_keyArr){
- exclusive_keyArr = JSON.parse(exclusive_keyArr)
- var htmls=''
- for(var i = 0;i<exclusive_keyArr.length;i++){
- console.log(exclusive_keyArr[i])
- htmls += '<span style="padding:0;padding-right:0.3rem;">'+exclusive_keyArr[i]+'</span>'
- }
- sureDom.siblings('.one').find('div').find('.exclusion').html(htmls)
- }
- // sureDom.siblings().find('div').find('.addition').html(JSON.parse(sessionStorage.getItem('addition_key'))[0])
- // sureDom.siblings().find('div').find('.exclusion').html(JSON.parse(sessionStorage.getItem('exclusive_key'))[0])
- sessionStorage.removeItem('addition_key')
- sessionStorage.removeItem('exclusive_key')
- sessionStorage.removeItem('isadd')
- // 如果没有添加附加词和排除词,就不显示
- var add_empty = $('.addition')
- var exc_empty = $('.exclusion')
- console.log(add_empty)
- console.log(exc_empty)
- for(var i=0;i<add_empty.length;i++){
- if(add_empty[i].children.length== 0){
- $('.addition:eq('+i+')').parent('span').hide()
- }else{
- $('.addition:eq('+i+')').parent('span').show()
- }
- }
- for(var i=0;i<exc_empty.length;i++){
- if(exc_empty[i].children.length == 0){
- $('.exclusion:eq('+i+')').parent('span').hide()
- }else{
- $('.exclusion:eq('+i+')').parent('span').show()
- }
- }
- }
- },
- error:function(err){
- console.log(err)
- }
- })
-
- // $this.parent().hide().siblings().show()
- $('.addKeyWord').show()
- }
- }
- // 如果没有添加附加词和排除词,就不显示
- var add_empty = $('.addition')
- var exc_empty = $('.exclusion')
- console.log(add_empty)
- console.log(exc_empty)
- for(var i=0;i<add_empty.length;i++){
- if(add_empty[i].children.length== 0){
- $('.addition:eq('+i+')').parent('span').hide()
- }else{
- $('.addition:eq('+i+')').parent('span').show()
- }
- }
- for(var i=0;i<exc_empty.length;i++){
- if(exc_empty[i].children.length == 0){
- $('.exclusion:eq('+i+')').parent('span').hide()
- }else{
- $('.exclusion:eq('+i+')').parent('span').show()
- }
- }
- }else{
- var $this = $(this)
- var keyWord = $(this).siblings('textarea').val()
- // 去空格
- keyWord = keyWord.replace(/\s+/g, ' ').trim();
- // 获取被点击的下标
- var classindex = sessionStorage.getItem('classindex')
- var modifyindex = sessionStorage.getItem('modifyindex')
- console.log(classindex)
- var beforekey = resArr[classindex].a_key[modifyindex].key[0]
- if(keyWord.length > 20){
- weui.toast('关键词不能超过20字', {
- duration: 2000,
- className: 'custom-toast',
- callback: function () { console.log('close') }
- });
- }else{
- // 关键词重复给出提示
- // isSame=0表示不重复,等于1重复
- var isSame = 0
- for(var i=0;i<resArr.length;i++){
- console.log(resArr[i])
- for(j=0;j<resArr[i].a_key.length;j++){
- var datakey = resArr[i].a_key[j].key[0]
- console.log(beforekey)
- if(datakey == keyWord && keyWord !== beforekey){
- vTools.jLoading({
- content:'关键词不能重复',
- iconHide:true,
- duration:1500
- })
- isSame = 1
- }else{
- isSame = 0
- }
- }
- }
- if(isSame == 1){
- }else{
- $this.parent().siblings().find('.key').text(keyWord)
- // 获取修改关键词参数
- var classify_s = $('.classify-detail').html()
- console.log(resArr)
- var newArr = resArr
- // var a_items = []
- console.log(newArr)
- newArr.forEach(function(value,index){
- if(value.s_item == classify_s){
- console.log(value,index)
- // 分类
- var keywordArr = []
- keywordArr.push(keyWord)
- console.log(keywordArr)
- // 附加词
- // 获取点击修改的下标
- var modifyindex = sessionStorage.getItem('modifyindex')
- var addition_key = sessionStorage.getItem('addition_key')
- if(addition_key == null){
- addition_key = newArr[index].a_key[modifyindex].appendkey
- }else{
- addition_key = JSON.parse(addition_key)
- }
- console.log(addition_key)
- // 排除词
- var exclusive_key = sessionStorage.getItem('exclusive_key')
- console.log(exclusive_key)
- if(exclusive_key == null){
- exclusive_key = newArr[index].a_key[modifyindex].notkey
- }else{
- exclusive_key = JSON.parse(exclusive_key)
- }
- console.log(exclusive_key)
- var keyparameter = {
- "key":keywordArr,
- "appendkey":addition_key,
- "notkey":exclusive_key
- }
- var modifyindex = sessionStorage.getItem('modifyindex')
- console.log(newArr[index].a_key)
- newArr[index].a_key.splice(modifyindex,1,keyparameter)
- }
- })
- console.log(newArr)
- // 获取点击的按钮
- var sureDom = $this.parent()
- // 修改关键词
- vTools.ajax({
- url:'/subscribe/key/update',
- type:'POST',
- data:{
- "a_items":newArr
- },
- success:function(res){
- console.log(res)
- if(res.data.status== 1){
- // console.log(JSON.parse(sessionStorage.getItem('addition_key'))[0])
- // console.log(JSON.parse(sessionStorage.getItem('exclusive_key'))[0])
- sureDom.hide().siblings('.one').show()
- var addition_keyArr = sessionStorage.getItem('addition_key')
- if(addition_keyArr){
- addition_keyArr = JSON.parse(addition_keyArr)
- var html=''
- for(var i = 0;i<addition_keyArr.length;i++){
- html += '<span style="padding:0;padding-right:0.3rem;">'+addition_keyArr[i]+'</span>'
- }
- sureDom.siblings('.one').find('div').find('.addition').html(html)
- }
- var exclusive_keyArr = sessionStorage.getItem('exclusive_key')
- if(exclusive_keyArr){
- exclusive_keyArr = JSON.parse(exclusive_keyArr)
- var htmls=''
- for(var i = 0;i<exclusive_keyArr.length;i++){
- console.log(exclusive_keyArr[i])
- htmls += '<span style="padding:0;padding-right:0.3rem;">'+exclusive_keyArr[i]+'</span>'
- }
- sureDom.siblings('.one').find('div').find('.exclusion').html(htmls)
- }
- // sureDom.siblings().find('div').find('.addition').html(JSON.parse(sessionStorage.getItem('addition_key'))[0])
- // sureDom.siblings().find('div').find('.exclusion').html(JSON.parse(sessionStorage.getItem('exclusive_key'))[0])
- sessionStorage.removeItem('addition_key')
- sessionStorage.removeItem('exclusive_key')
- sessionStorage.removeItem('isadd')
- // 如果没有添加附加词和排除词,就不显示
- var add_empty = $('.addition')
- var exc_empty = $('.exclusion')
- console.log(add_empty)
- console.log(exc_empty)
- for(var i=0;i<add_empty.length;i++){
- if(add_empty[i].children.length== 0){
- $('.addition:eq('+i+')').parent('span').hide()
- }else{
- $('.addition:eq('+i+')').parent('span').show()
- }
- }
- for(var i=0;i<exc_empty.length;i++){
- if(exc_empty[i].children.length == 0){
- $('.exclusion:eq('+i+')').parent('span').hide()
- }else{
- $('.exclusion:eq('+i+')').parent('span').show()
- }
- }
- }
- },
- error:function(err){
- console.log(err)
- }
- })
-
- // $this.parent().hide().siblings().show()
- $('.addKeyWord').show()
- }
- }
- // 如果没有添加附加词和排除词,就不显示
- var add_empty = $('.addition')
- var exc_empty = $('.exclusion')
- console.log(add_empty)
- console.log(exc_empty)
- for(var i=0;i<add_empty.length;i++){
- if(add_empty[i].children.length== 0){
- $('.addition:eq('+i+')').parent('span').hide()
- }else{
- $('.addition:eq('+i+')').parent('span').show()
- }
- }
- for(var i=0;i<exc_empty.length;i++){
- if(exc_empty[i].children.length == 0){
- $('.exclusion:eq('+i+')').parent('span').hide()
- }else{
- $('.exclusion:eq('+i+')').parent('span').show()
- }
- }
- }
- sessionStorage.removeItem('exc_length')
- sessionStorage.removeItem('add_length')
- })
-
- //防止键盘把当前输入框给挡住
- $('input[type="text"],textarea').focus(function () {
- var target = this;
- setTimeout(function(){
- target.scrollIntoViewIfNeeded();
- },400);
- });
- // 显示关键词分类弹框
- var modifyArr=[]
- $('.classify-r').on('click', function(){
- console.log(resArr)
- modifyArr = resArr
- console.log(modifyArr)
- // 如果是苹果手机,打开时候要设置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()
- $('input.classify-keyword').val(currentClassifyName).focus()
- })
- console.log(modifyArr)
- // 改变关键词分类
- function changeDesc( value, desc) {
- console.log(modifyArr)
- for (var i in modifyArr) {
- if (modifyArr[i].s_item == value) {
- modifyArr[i].s_item = desc;
- console.log(modifyArr)
- // 修改关键词分类
- vTools.ajax({
- url:'/subscribe/key/update',
- type:'POST',
- data:{
- "update_item":{
- "before":value,
- "after":desc
- },
- "a_items":modifyArr
- },
- success:function(res){
- console.log(res)
- if(res.data.status == -1){
- vTools.jLoading({
- content:'此分类名已存在',
- iconHide:true,
- duration:1500,
- callback:function(){
- location.reload()
- }
- })
- return;
- }
- $('.classify-r .classify-detail').text(desc)
- location.reload()
- },
- error:function(err){
- console.log(err)
- }
- })
- }
- }
- }
- // 关键词分类 - 确定按钮点击事件
- $('.classify-edit-pop .dialog__btn_confirm').on('click', function() {
- var parameter = location.search.split('?')[1]
- if(sessionStorage.getItem('iconClick') == 0 && parameter == 'state=1'){
- var s = $('input.classify-keyword').val()
- // 去空格
- s = s.replace(/\s+/g, ' ').trim();
- if (s.length === 0) {
- return
- }
- // changeDesc(classifyName,s)
- var clone_classindex= sessionStorage.getItem('clone-classindex')
- var classindex= sessionStorage.getItem('classindex')
- var classifyName = sessionStorage.getItem('classifyName')
- for(i=0;i<resArr.length;i++){
- if(resArr[i].s_item == s&& classindex == clone_classindex){
- vTools.jLoading({
- content:'此分类名已存在',
- iconHide:true,
- duration:1500
- })
- return;
- }else if(s != classifyName && classindex !== clone_classindex){
- // 修改关键词分类
- var modifyresArr = []
- for(var j=0;j<resArr.length;j++){
- if(resArr[j].s_item == classifyName){
- resArr[j].s_item = s
- }
- }
- modifyresArr = resArr
- vTools.ajax({
- url:'/subscribe/key/update',
- type:'POST',
- data:{
- "update_item":{
- "before":classifyName,
- "after":s
- },
- "a_items":modifyresArr
- },
- success:function(res){
- console.log(res)
- if(res.data.status == -1){
- console.log('222222')
- vTools.jLoading({
- content:'此分类名已存在',
- iconHide:true,
- duration:1500,
- })
- $('.classify-edit-pop').show()
- $('.classify-r .classify-detail').text(classifyName)
- sessionStorage.setItem('classifyName',classifyName)
- sessionStorage.setItem('keyclassify',classifyName)
- return
- }
- $('.classify-r .classify-detail').text(s)
- // location.reload()
- },
- error:function(err){
- console.log(err)
- }
- })
- }
- }
- $('.classify-r .classify-detail').text(s)
- sessionStorage.setItem('classifyName',s)
- sessionStorage.setItem('keyclassify',s)
- // 关闭弹框后要重置input内容
- $('.classify-edit-pop').hide()
- $('input.classify-keyword').val('')
- }else{
- console.log(22)
- var classifyName = sessionStorage.getItem('classifyName')
- var s = $('input.classify-keyword').val()
- // 去空格
- s = s.replace(/\s+/g, ' ').trim();
- if (s.length === 0) {
- return
- }
- changeDesc(classifyName,s)
- // 关闭弹框后要重置input内容
- $('.classify-edit-pop').hide()
- $('input.classify-keyword').val('')
- }
-
- })
- // 关键词分类 - 取消按钮点击事件
- $('.classify-edit-pop .dialog__btn_cancel').on('click', function() {
- var parameter = location.search.split('?')[1]
- if(sessionStorage.getItem('iconClick') == 0 && parameter == 'state=1'){
- // changeDesc(classifyName,s)
- var classifyList = []
- var newclassify = ''
- for(i=0;i<resArr.length;i++){
- var samelist = resArr[i].s_item.indexOf('未分类')
- if(samelist != -1){
- classifyList.push(resArr[i].s_item)
- }
- }
- var sum = getClassifyName(classifyList)
- console.log(sum)
- var clone_classindex= sessionStorage.getItem('clone-classindex')
- var classindex= sessionStorage.getItem('classindex')
- if(classindex == clone_classindex){
- $('.classify-r .classify-detail').text(sum)
- sessionStorage.setItem('keyclassify',sum)
- }
- }
- $('.classify-edit-pop').hide()
- $('input.classify-keyword').val('')
-
- })
- })
- // 判断创建的分类名是否重复
- // 传入一个已经存在的未分类(数组)
- function getClassifyName(existed) {
- var index = existed.length + 1
- function getName() {
- var leadingString = '未分类'
- // 创建的未分类后面的数字
- var cName = leadingString + index
- // 判断数组中的每一项是否包含未分类 == -1说明不包含 否则包含:让数字加一知道不重复为止
- var ei = existed.indexOf(cName)
- if (ei === -1) {
- return cName
- } else {
- index ++
- console.log(index);
-
- return getName()
- }
- }
- return getName()
- }
|