var WxParse = null;
var app = getApp()
var that=null
var that0=null
var t=1
Page( {
  data: {
    loadingHidden:false,
    nodataHidden:true,
    bodyHidden:true,
    Start: 0,
    helps:[],
    title:"",
    body:"",
    video:"",
    videoCtx:null 
  },onShow: function () {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      that0=this;
      var userId = wx.getStorageSync("userId")
      var userInfodata = wx.getStorageSync("userInfo")
        var sel=1;
        var ifsel=0;
        if(userId&&userInfodata){
          var userInfo = JSON.parse(userInfodata)
         
            ifsel=userInfo.bdshEnable;
        }
        
        if(ifsel==1){
        that0.getTabBar().setData({
        "list": [
          {
            "pagePath": "/pages/index/index",
            "text": "首页",
            "iconPath": "/images/footer-icon-001.png",
            "selectedIconPath": "/images/footer-icon-001-active.png"
          },
          {
            "pagePath": "/pages/news/index",
            "iconPath": "/images/footer-icon-008.png",
            "selectedIconPath": "/images/footer-icon-008-active.png",
            "text": "资讯"
          },
     
          {
            "pagePath": "/pages/my/index",
            "text": "我的",
            "iconPath": "/images/footer-icon-004.png",
            "selectedIconPath": "/images/footer-icon-004-active.png"
          }
        ]
        })
      }else{
        that0.getTabBar().setData({
          "list": [
            {
              "pagePath": "/pages/index/index",
              "text": "首页",
              "iconPath": "/images/footer-icon-001.png",
              "selectedIconPath": "/images/footer-icon-001-active.png"
            },
            {
              "pagePath": "/pages/news/index",
              "iconPath": "/images/footer-icon-008.png",
              "selectedIconPath": "/images/footer-icon-008-active.png",
              "text": "资讯"
            },
            {
              "pagePath": "/pages/business/index",
              "iconPath": "/images/footer-icon-005.png",
              "selectedIconPath": "/images/footer-icon-005-active.png",
              "text": "健康驿站"
            },
  
            {
              "pagePath": "/pages/my/index",
              "text": "我的",
              "iconPath": "/images/footer-icon-004.png",
              "selectedIconPath": "/images/footer-icon-004-active.png"
            }
          ]
          })
        }
        that0.getTabBar().setData({
          selected: sel
        })
    }
  }, 
  onLoad: function(options) {
    that = this
    WxParse = require('../../wxParse/wxParse.js')
    that.setData({
       videoCtx:wx.createVideoContext('myVideo', this)
    })
    that.getlist();//第一次加载数据
    }, getlist: function () {
  
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      wx.request({
        url: app.globalData.apiurl + "/xapiajax.ashx", 
        data: {
          action:"getxsxtlist",
           userId:(!userId?"":userId),
           LoginId:(!LoginId?"":LoginId),
           Start:that.data.Start
        },
        method:"GET",
        dataType:"json", 
        header: { 
          "content-type": "application/json" // 默认值
        },
        success (res) {
              that.setData({
                  helps: res.data.xsxtlb,
                  loadingHidden:true
              })
              
                  if(res.data.xsxtlb.length==0){
                      that.setData({
                          nodataHidden:false
                      })
                  }else{
                    that.setData({
                      nodataHidden:true
                  })
                  }
             
          }
      })
  },
    
    // 下拉刷新
    onPullDownRefresh: function () {
        that.clearCache();
       that.getlist();//第一次加载数据
    },
 // 清缓存
 clearCache:function(){
    that.setData({
         helps: [],
         Start: 0,
         loadingHidden:false
    }); 
},ondetail:function(e) {
  var id = e.currentTarget.dataset.id
     wx.navigateTo({  
       url: "../articledetail/index?id="+id
     })
      /*that.setData({
         loadingHidden:false
      })
      var id = e.currentTarget.dataset.id
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      wx.request({
        url: app.globalData.apiurl + "/xapiajax.ashx", 
        data: { 
          action:"getnewdetail",
           userId:(!userId?"":userId),
           LoginId:(!LoginId?"":LoginId),
           id:id
        },
        method:"POST",
        dataType:"json", 
        header: { 
          "content-type": "application/x-www-form-urlencoded" // 默认值
        },
        success (res) { 

          if(res.data.status==1){
            WxParse.wxParse('body', 'html', res.data.content, that);
             that.setData({
                title:res.data.title,
                video:res.data.video,
                bodyHidden:false
             })
             

          }else{
             wx.showToast({
              title: res.data.msg,
              icon: "none",
              duration: 3000
             })
          }
           that.setData({
              loadingHidden:true
           })
          }
      })*/

},closeserver:function(e) {
  that.data.videoCtx.stop()
  that.setData({
    bodyHidden:true
 })
},inserver :function(e) {
   
}

})
