import apiAddr from '../../api/base';
import { setData } from '../../utils/index';

Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    nav_list:[],
    foot_width:'20%',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getFootnav(){
      let _that = this;
      wx.request({
        url: apiAddr.footer_nav_list,
        method: 'post',
        header: { 'Content-type': 'application/x-www-form-urlencoded' },
        data: {},
        dataType: 'json',
        success: (result) => {  
   

           result.data[0].url = "/pages/index/newIndex/newIndex"
           result.data[1].url = "/pages/device/device"
           result.data[2].nav_name = "手机通行"
           result.data[2].url = "/pages/phoneGo/phoneGo"
        //    result.data[3].url = `/packages/community/communityList/index?communityId=${communityIdArr}`
           result.data[3].url = `/packages/community/communityList/index`
           result.data[4].url = "/pages/index/index"

           result.data.splice(1, 2);

          setData(_that,'nav_list', result.data); 
          setData(_that,'foot_width', (100/result.data.length).toFixed(2)+'%'); 
        }, 
      });
    },
    //暂未开通
    NotOpen(){
        wx.showModal({
          title: '提示',
          content: '此功能暂未开通！',
          showCancel:false,
          complete: (res) => {
            if (res.cancel) {
              
            }
          }
        })
    },
    jump(e){
      const ctoken = wx.getStorageSync('ctoken');
      const authen = ['/pages/index/newIndex/newIndex', '/pages/index/index'];
      // 除首页及个人中心页不需要鉴定ctoken， 其他tab页均需存在登录态才可访问
      if (authen.includes(e.currentTarget.dataset.url)) {
        wx.redirectTo({
          url: e.currentTarget.dataset.url,
        })
        return
      }
      if (!ctoken) {
        wx.redirectTo({
          url: '/pages/login/login',
        })
        return;
      }
      wx.redirectTo({
        url: e.currentTarget.dataset.url,
      })
    },

  },

  lifetimes: {
    attached: function () {
      // 组件被添加到页面节点树时执行
      this.getFootnav();
    },
  },
})