123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- $(function(){
- $('.knowBtn').on('click',function(){
- $(".problemPop").hide()
- })
- $(".problem").on('click',function(){
- $(".problemPop").css("display",'flex');
- })
- function hasWords () {
- var showKeyWordLength = $(".showKeyWord ul").find('li').length;
- if(showKeyWordLength === 0){
- $(".enter.addkeyWord").show();
- $(".addKeyWord").hide();
- $(".showKeyWord").hide();
- $('#add-buyer-word').hide()
- } else {
- $(".enter.addkeyWord").hide();
- $(".showKeyWord").show();
- $(".addKeyWord").show();
- if (showKeyWordLength >= buyerLimit) {
- $('#add-buyer-word').hide()
- $('.buyer-more-tips').show()
- } else {
- $('#add-buyer-word').show()
- $('.buyer-more-tips').hide()
- }
- }
- }
- hasWords();
-
- // 添加按钮
- $(".addKeyBtn i").on('click',function(){
- window.location.href="/front/wx_dataExport/buyerInput";
- });
- $('textarea').each(function(i,dom){
- // console.log(i,dom)
- dom.style.height = dom.scrollHeight +'px';
- });
- $("textarea").on("input", function() {
- this.style.height = 'auto';
- this.style.height = this.scrollHeight + "px";
- });
- 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){
- //防止键盘把当前输入框给挡住
- $('input[type="text"],textarea').focus(function () {
- var target = this;
- setTimeout(function(){
- target.scrollIntoViewIfNeeded();
- },400);
- });
- }
- // 添加keyWords检查输入框内是否有文字,如果有才能点击添加按钮
- $('.addkeyWord input.enterOne').on('input', function() {
- var buttonDOM = $(this).siblings().find('button')[0]
- if ($(this).val().replace(/\s+/g,"").length >= 1) {
- buttonDOM.style.opacity = 1
- buttonDOM.removeAttribute("disabled")
- } else {
- buttonDOM.style.opacity = .5
- buttonDOM.setAttribute("disabled", true)
- }
- })
-
- // 添加 按钮的点击事件
- $('.addkeyWord .btn .save-btn').on('click', function(){
- var keyWord = $('.addkeyWord input.enterOne').val()
- keyWord = keyWord.replace(/(^\s*)|(\s*$)/g, "");
- if (keyWord.length > 50) {
- // var s = keyWord.slice(0,49);
- // $('.addkeyWord input.enterOne').val(s);
- weui.toast('采购单位不能超过50字', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){}
- });
- return
- }
- buyerArr.push(keyWord);
- localStorage.setItem("buyer", buyerArr);
- var html = `<li>
- <div class="one">
- <div>
- <span>
- <p class="key">${ keyWord }</p>
- </span>
- </div>
- <button class="editKeyWord"><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="">${ keyWord }</textarea>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`
- $('.showKeyWord > ul').prepend(html)
-
- // 隐藏
- $(".enter.addkeyWord").hide();
- $(".showKeyWord").show();
- $(".addKeyWord").show();
- $('.enter.addkeyWord > input').val('')
- var buttonDOM = $('.enter.addkeyWord .btn button')[0]
- buttonDOM.style.opacity = .5
- buttonDOM.setAttribute("disabled", true)
- hasWords()
- })
- // 编辑
- $(".showKeyWord").on('click', '.editKeyWord',function(e){
- 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();
- hasWords()
- })
- // 编辑 删除
- $('.showKeyWord').on('click', '.deleteKey', function(e) {
- var buyer = $(this).parent().prev().find('.key').text();
- buyerArr.splice($.inArray(buyer, buyerArr),1);
- localStorage.buyer = buyerArr.toString();
- $(this).parents('li').remove();
- $(".addKeyWord").show();
- hasWords()
- // console.log('删除附加词:',$(this).parent().find('span').text())
- })
- // 编辑 确定
- $('.showKeyWord').on('click', '.ascertainKey', function(e) {
- var keyWord = $(this).siblings('textarea').val();
- var buyer = $(this).parent().prev().find('.key').text();
- keyWord = keyWord.replace(/(^\s*)|(\s*$)/g, "");
- if (keyWord.replace(/\s+/g,"").length < 1) {
- weui.toast('采购单位不能为空', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){
- }
- });
- return
- }else if($(this).parent().find("textarea").val().length > 50){
- // var s = $(this).parent().find("span").text().slice(0,49);
- // $(this).parent().find("span").text(s);
- weui.toast('采购单位不能超过50字', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){}
- });
- return
- }else{
- for(var i in buyerArr){
- if(keyWord !== buyer){
- if(buyerArr[i] === keyWord){
- weui.toast('采购单位重复了', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){}
- });
- return
- }
- }
- if(buyerArr[i] === buyer){
- buyerArr[i] = keyWord;
- }
- }
- localStorage.buyer = buyerArr.toString();
- $(this).parent().siblings().find('.key').text(keyWord)
- $(this).parent().hide().siblings().show()
- }
- // $(".addKeyWord").show();
- hasWords()
- })
- //去空格方法
- String.prototype.trim = function(){
- return this.replace(/(^\s*)|(\s*$)/g, ' ');
- }
- $(".close").on("click", function () {
- history.back();
- })
- });
|