// packageE/membertool/membertool.js
var app = getApp();
Component({
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    },
    notShow: {
      type: null
    },
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png',

    activeNames: true,
    TemplateArray:[]
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {},
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {
  },

  methods: {
    errorFunction(event) {
      let index = event.currentTarget.dataset.index;
      let img = 'datas.show_list[' + index + '].image';
      this.setData({
        [img]: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png'
      });
    },   
    //获取模板id
    getTemplate() {
      let urlStr = app.getNetAddresss("member.member.getMiniTemplateCorrespond");
      let that = this;
      app._getNetWork({
        url: urlStr,
        data: {
          small_type: 6
        },
        success: function(resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            let array = [];
            for (let i = 0; i < res.data.length; i++) {
              array.push(res.data[i].template_id);
            }
            that.setData({
              TemplateArray: array
            });
            wx.requestSubscribeMessage({
              tmplIds: that.data.TemplateArray,
              success(res) {
                wx.navigateTo({
                  url: '/packageD/directSeeding/helperLiveList/helperLiveList'
                });
              },
              fail(){
                wx.navigateTo({
                  url: '/packageD/directSeeding/helperLiveList/helperLiveList'
                });
              }
            });
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 1500
            });
          }
        },
        fail: function(res) {
          console.log(res);
        }
      });
    },
    //根据后台返回名字做跳转
    pluginGoto(e) {
      let item = e.currentTarget.dataset.item;
      let url = item.url;
      // 爱心值函数调用
      // if (item.url == 'love_index') {
      // 	this.golove_index();
      // 	return;
      // }
      // // 冻结币函数调用
      // if (item.url == 'FrozenCoin') {
      // 	this.goFrozenCoin();
      // 	return;
      // }
      // // 华侨币函数调用
      // if (item.url == 'overseas_index') {
      // 	this.gooverseas_index();
      // 	return;
      // }
      // // 跳转收银台函数
      // if (item.url == 'cashier') {
      // 	this.gocashier();
      // 	return;
      // }
      // // 跳转微店中心函数调用
      // if (item.url == 'microShop_home') {
      // 	this.gomicroShop_home()
      // 	return
      // }
      // // 跳转帮助函数调用
      // if (item.url == 'helpcenter') {
      // 	this.gohelpcenter();
      // 	return;
      // }
      // //跳转到我要开店
      // if (item.url == 'microShop_apply') {
      // 	this.gomicroShop_apply()
      // 	return;
      // }
      // //跳转到门店管理
      // if (item.url == 'storeManage') {
      // 	this.gostoreManage()
      // 	return;
      // }

      //跳转到推广中心
      if (item.url == 'extension') {
        this.goextension();
        return;
      }

      //跳转到 消息
      // if (item.url == 'stationNotice') {
      // 	wx.navigateTo({
      // 		url: '/packageE/stationNotice/stationNotice'
      // 	})
      // 	return;
      // }

      if (item.name == "courier") {
        wx.setStorage({
          key: 'couriername',
          data: item.title
        });
        wx.navigateTo({
          url: '/packageA/member/' + url + '/' + url
        });
      } else if (item.name == "supplier") {
        wx.navigateTo({
          url: '/packageA/member/' + url + '/' + url + '?uid=' + this.data.supplier_id
        });
      } else if (item.url == "HotelManage") {
        wx.navigateTo({
          url: '/packageA/hotel/HotelManage/HotelManage?title=' +
					encodeURIComponent("酒店管理")
        });
      } else if (item.url == 'findpwd') {
        wx.navigateTo({
          url: '/packageE/findpwd/findpwd'
        });
      } else if (item.url == 'aftersaleslist') {
        this.goaftersaleslist();
      } else if (item.url == 'helperLiveList') {
        this.getTemplate();
      } else {
        wx.navigateTo({
          url: item.mini_url
        });
      }

      // if (item.name == 'universal_card') {
      // 	// 跳转到一卡通页面
      // 	wx.navigateTo({
      // 		url: '/packageB/member/CardIndex/CardIndex'
      // 	})
      // } else if (item.name == "supplier") {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/' + url + '/' + url + '?uid=' + this.data.supplier_id
      // 	})
      // } else if (item.url == 'creditInfo') {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/' + url + '/' + url
      // 	})
      // } else if (item.url == 'Integral_love') {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/' + url + '/' + url
      // 	})
      // } else if (item.url == 'hotelApply') {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/storeApply/storeApply?name=hotelApply'
      // 	})
      // } else if (item.url == "HotelManage") {
      // 	wx.navigateTo({
      // 		url: '/packageA/hotel/HotelManage/HotelManage?title=' +
      // 			encodeURIComponent("酒店管理")
      // 	})
      // } else if (item.url == "CardCenter") {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/business_card/CardCenter/CardCenter'
      // 	})
      // } else if (item.url == "materialCenter") {
      // 	wx.navigateTo({
      // 		url: '/packageA/others/materialCenter/materialCenter'
      // 	})
      // } else if (item.url == 'DistributionOrders') {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/DistributionOrders/DistributionOrders'
      // 	})
      // } else if (item.url == 'MyGroups') {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/group/MyGroups/MyGroups'
      // 	})
      // } else if (item.url == 'quickIndex') {
      // 	wx.navigateTo({
      // 		url: '/packageD/quickPay/quick_index/quick_index'
      // 	})
      // } else if (item.url == 'aftersaleslist') {
      // 	this.goaftersaleslist()
      // } else if (item.url == 'collection') {
      // 	this.gocollection()
      // } else if (item.url == 'footprint') {
      // 	this.gofootprint()
      // } else if (item.url == 'myEvaluation') {
      // 	this.gomyEvaluation()
      // } else if (item.url == 'myRelationship') {
      // 	this.gomyRelationship();
      // } else if (item.url == 'address') {
      // 	this.goaddress()
      // } else if (item.url == 'coupon') {
      // 	this.gocoupon();
      // } else if (item.url == 'info') {
      // 	this.goinfo()
      // } else if (item.url == 'sign') {
      // 	this.gosign()
      // }  else if (item.url == 'helperLiveList') {
      // 	let that =this;
      // 	that.getTemplate();
      // }  else {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/' + url + '/' + url
      // 	})
      // }
    },
    goaftersaleslist: function() {
      wx.navigateTo({
        url: '/packageD/member/myOrder/Aftersaleslist/Aftersaleslist'
      });

    },
    //跳到收藏页面
    gocollection(e) {
      wx.navigateTo({
        url: '/packageD/member/collection/collection'
      });
    },
    //跳转到足迹
    gofootprint(e) {
      wx.navigateTo({
        url: '/packageD/member/footprint/footprint'
      });

    },
    //跳转到评论页
    gomyEvaluation(e) {
      wx.navigateTo({
        url: '/packageD/member/myEvaluation/myEvaluation'
      });
    },
    //跳转到客户
    gomyRelationship(e) {
      //myRelationship
      wx.navigateTo({
        url: '/packageD/member/myRelationship/myRelationship'
      });
    },
    //跳转到地址
    goaddress(e) {
      wx.navigateTo({
        url: '/packageD/member/addressList/addressList'
      });
    },
    //跳转到优惠
    gocoupon(e) {
      wx.navigateTo({
        url: '/packageA/member/coupon_v2/coupon_v2'
      });
    },
    //跳转到设置
    goinfo(e) {
      wx.navigateTo({
        url: '/packageA/member/info/info'
      });
    },
    //跳到签到页面
    gosign() {
      //sign
      wx.navigateTo({
        url: '/packageA/member/sign/sign'
      });
    },
    //跳转到收银台
    gocashier() {
      wx.navigateTo({
        url: '/packageC/cashier/cashier/cashier'
      });
    },
    //跳转到微店
    gomicroShop_home() {
      wx.navigateTo({
        url: '/packageC/microshop/microShop_home/microShop_home'
      });
      //microShop_home
    },
    //跳转到我要开店
    gomicroShop_apply() {
      //microShop_apply
      wx.navigateTo({
        url: '/packageC/microshop/microShop_apply/microShop_apply'
      });
    },
    //跳转到华侨币
    gooverseas_index() {
      //overseas_index
      wx.navigateTo({
        url: '/packageB/member/overseas_index/overseas_index'
      });
    },
    //跳转到门店管理
    gostoreManage() {
      wx.navigateTo({
        url: '/packageC/o2o/storeManage/storeManage'
      });
      //storeManage
    },
    //跳装到帮助页面
    gohelpcenter() {
      wx.navigateTo({
        url: '/packageB/member/helpcenter/helpcenter'
      });

    },
    //跳装到冻结币
    goFrozenCoin() {
      //FrozenCoin
      wx.navigateTo({
        url: '/packageB/member/FrozenCoin/FrozenCoin'
      });
    },
    //跳到爱心兑换值
    golove_index: function() {
      //love_index
      wx.navigateTo({
        url: '/packageB/member/love/Love_index/Love_index'
      });
    },
    goextension: function() {
      //extension
      wx.reLaunch({
        url: '/packageG/pages/member/extension/extension'
      });
    },
    gotoUrl(e) {
      let url = e.currentTarget.dataset.item.h5_link;
      try {
        wx.navigateTo({
          url: url
        });
      } catch (e) {
        wx.showToast({
          title: '链接设置错误',
          icon: 'none',
          duration: 2000
        });
      }
    },
    onChange(event) {
      this.setData({
        activeNames: !this.data.activeNames
      });
    },
  }
});
