$(function(){
  // 移动端 菜单
  $('.menuImg').click(function(){
    let id = $(this).attr('data-id');
    if(id == '1'){
      $('.menuBox ul').hide()
    }else{
      $('.menuBox ul').show()
    }
    $(this).hide();
    $(this).siblings().show()
  })

// 详情页字体大小
  $('.timename .fontSize').click(function(){
    let size = $(this).attr('data-id');
    $(this).attr('class','fontSize active');
    $(this).siblings().attr('class','fontSize')
    $('.contentBox .content').css('fontSize',size+'px')
  })
  // 订阅 图片上传
  $('.inputFile').change(function(file){
    console.log(file);
    var uploadImg = this.files[0];
    console.log(uploadImg)
    var formdata = new FormData();
    formdata.append("file",uploadImg);
    $.ajax({
      type: "post",
      url: "/upload?p=file",
      data: formdata,
      processData: false,
      contentType: false,
      dataType: "json",
      success: function(data) {
        if (data.status) {
          console.log(data);
        $('.uploadBox').hide()
        $('.uploadImgBox').show()
        $('.uploadImg').attr('src',data.url);
        $('.fileUrl').val(data.url)
        $('.inputFile').val(data.url)
        } else {
          alert(data.msg)
        }
      }
      })
    
  })
  $('.removeImg').click(function(){
    $('.uploadBox').show()
    $('.uploadImgBox').hide();
    $('.fileUrl').val('')
  })
  let hytbtitleId;
  $('.hytbtitle').click(function(){
    hytbtitleId = $(this).attr('data-id');
    c_id = $(this).attr('c_id');
    // 用 hytbtitleId 判断是哪个栏目 0 行业动态、 1特别报道
    let clas = '',clas2 = ''
    if(hytbtitleId == 0){
      clas = 'point'
    }else{
      clas2 = 'point'
    }
    document.getElementById("more").href="/shipinjie/newsList/"+c_id;
    $(this).attr('class','hytbtitle active '+clas);
    $(this).siblings('.hytbtitle').attr('class','hytbtitle '+clas2);
    $('.hytbMain').hide();
    $('.hytbMain'+hytbtitleId).css('display','flex');
    $('.hytbBotm'+hytbtitleId).show()

  })
  
    //let length = $('.dftsTotal').val();

  let num = 0; 
  let length = $('.dftsMainBox .box').length;
  console.log(length)
  function dftsFun() {
      if(length == 6){
         $('.dftsBtn button').prop('disabled', true);
         $('.dftsBtn button').find('span').attr('class', '');
      }
    $('.dftsMainBox .box').hide()
    for (let index = num * 6; index < (num + 1) * 6; index++) {
      $('.dftsMainBox .box').eq(index).show()
    }
  }
  dftsFun()
  $('.dftsBtn button').click(function () {
    let id = $(this).attr('data-id');
    num = num + Number(id);
    console.log(num)
    if (num == (Math.ceil(length / 6) - 1) || num == 0) {
      $(this).find('span').attr('class', '');
      $(this).prop('disabled', true)
      $(this).siblings().find('span').attr('class', 'active')
      $(this).siblings().prop('disabled', false)
    } else {
      $(this).find('span').attr('class', 'active');
      $(this).prop('disabled', false)
      $(this).siblings().find('span').attr('class', 'active');
      $(this).siblings().prop('disabled', false)
    }
    $('.dftsMainBox .box').hide()
    for (let index = num * 6; index < (num + 1) * 6; index++) {
      $('.dftsMainBox .box').eq(index).show()
    }    
  })
  $('.searchData').click(function(){
    var searchContent=$('input[name=searchContent]').val();
    if(!searchContent){
      alert('请输入内容搜索');
      return false;
    }
    window.location.href="/shipinjie/search?content="+searchContent
  })
})