// packageG/mycomponent/storebalance/storebalance.js
const app = getApp();
Component({
  /**
     * 组件的属性列表
     */
  properties: {
    datas: {
      type: null,
    },
    store_id: {
      type: null,
    },
  },

  /**
     * 组件的初始数据
     */
  data: {
    language: '',
  },
  lifetimes: {
    attached() {
      let language = wx.getStorageSync('langIndex');
      this.setData({
        'language': language.en
      });
      this.getBalance();
    }
  },
  /**
     * 组件的方法列表
     */
  methods: {
    toStoreBalance(e){
      let key = e.currentTarget.dataset.key;
      if(key == 'balance'){
        wx.navigateTo({
          url: '/packageI/independenceBalance/storeBalance/balance_recharge?store_id='+this.data.store_id,
        });
      }else{
        wx.navigateTo({
          url: '/packageI/independenceBalance/independenceBalance?store_id='+this.data.store_id,
        });
      }
    },
    getBalance() {
      let urlStr = app.getNetAddresss("plugin.store-cashier.frontend.store.balance.setting.index");
      app._postNetWork({
        url: urlStr,
        data: {
          store_id: this.data.store_id,
        },
        success: (resdata) => {
          console.log(resdata);
          let res = resdata.data;
          this.setData({
            is_open: res.data.is_open,
            balanceTitle: res.data.title,
            member_balance: res.data.member_balance,
            show_button: res.data.show_button,
          });
        },
        fail: function (res) {
          wx.showToast({
            title: res.data.msg,
            duration: 1000,
            icon: 'none'
          });
        }
      });
    }
  }
});