// pages/home/components/titleItem/titleItem.js
const {
  checkPermission
} = require("../../../../utils/permission");
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    capitalList:Array,
    capitalName:String,
    capitalId:String,
    titleList: Array,
    userType:String,
    permission:Object,
    traderName: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    
  }, 
  ready(){
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /*选择资方*/
    bindCapitalList(e){ 
      this.setData({
        capitalName: this.data.capitalList[e.detail.value].name,
        capitalId:this.data.capitalList[e.detail.value].id
      })
      wx.setStorageSync('capitalId', this.data.capitalList[e.detail.value].id)
      wx.setStorageSync('capitalName', this.data.capitalList[e.detail.value].name)
      this.triggerEvent('homeStatistics','我是传递回去的参数');
    },
    /**
     * 
     * 点击子项
     * 
     * @param {*} e 1:type类型详见home页面
     */
    async _click(e) {
      //检验权限
      let perm = e.currentTarget.dataset.perm;
      if(!(await checkPermission(perm))){
        return;
      }
      this.triggerEvent('clickEvent', e.currentTarget.dataset.type) //组件通信
      if(e.currentTarget.dataset.type == 30){//质量验收
        wx.navigateTo({
          url: '/other/pages/infoList/infoList?type=' + e.currentTarget.dataset.type + "&name=" + e.currentTarget.dataset.name,
        })
        return
      }else if(e.currentTarget.dataset.type == 31){//电站整改
        wx.navigateTo({
          url: '/other/pages/rectification/rectification',
        })
        return
      }
      wx.navigateTo({
        url: '/home/pages/infoRegistration/infoRegistration?type=' + e.currentTarget.dataset.type + "&name=" + e.currentTarget.dataset.name,
      })
    },
    
/**
     * 
     * 选择代理商
     * 
     * @param {*} e 
     */
    async changeTrader(e) {
      wx.navigateTo({
        url: '/pages/traderList/traderList?type=' + e.currentTarget.dataset.type + "&name=" + e.currentTarget.dataset.name,
      })
    },

    /**
     * 
     * 新增bt业务
     * 
     * @param {*} e 1.bt业务与普通业务信息录入时为两套代码
     */
    async _BTBusiness(e) {
      // wx.showLoading({
      //   title: "加载中"
      // })
      // etEmpCountByRole({
      //   traderId: wx.getStorageSync('userId')
      // }).then((res) => {
      //   wx.hideLoading()
      //   if (res.code == 200) {
      //     if (res.data >= 8) {
      //       wx.navigateTo({
      //         url: '/home/pages/entryInfoBT/entryInfoBT',
      //       })
      //     } else {
      //       wx.showToast({
      //         title: '施工团队人员不可低于8人！',
      //         icon:'none'
      //       })
      //     }
      //   }
      // })
      
      //检验权限
      let perm = e.currentTarget.dataset.perm;
      if(!(await checkPermission(perm))){
        return;
      }
      wx.navigateTo({
        url: '/home/pages/entryInfoBT/entryInfoBT?type=' + 0,
      })
    }

  }
})