// pages/cashier/cashier.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    store: {
      name: '',
      thumb: ''
    },
    income: {
      money_total: 0.0,
      sure_withdraw_money: 0.0
    },
    store_set: {
      is_cash_pay: '',
      is_open_cashier: '',
      is_write_information: ''
    },
    title: '',
    vedioSrc: '',
    storeManageOpen:true
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.checkrouter();
    this.getStoreInfo();
  },
  checkrouter() {
    try {
      // 推广中心是否开启该功能，没开启跳转到指定路径
      let basic_info = wx.getStorageSync("yz_basic_info");
      let stop_info = basic_info.popularize_page.mini.vue_route;
      for (let i = 0; i < stop_info.length; i++) {
        if (stop_info[i] == 'cashier') {
          console.log(basic_info.popularize_page.mini.mini_url + "跳转的路径");
          this.setData({
            storeManageOpen:false
          });
          if(!basic_info.popularize_page.mini.mini_url){
            wx.showModal({
              content: '未开启推广权限',
              showCancel:false,
              success:function(res){
                if(res.confirm){
                  wx.navigateBack({
                    delta: 1
                  });
                }
              }
            });
          }else{
            wx.showToast({
              title: '未开启推广权限',
              duration: 2000,
              icon: 'none',
              success: function() {
                setTimeout(() => {
                  wx.redirectTo({
                    url: basic_info.popularize_page.mini.mini_url,
                  });
                }, 1000);
              }
            });
          }
        }
      }
    } catch (e) {
      console.log(e);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {},

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {},

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {},

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {},

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {},

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {},
  getStoreInfo() {
    var that = this;
    let urlStr = app.getNetAddresss('plugin.store-cashier.frontend.cashier.center.index');
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            store: res.data.store,
            income: res.data.income,
            store_set: res.data.store_set
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  gowithdrawal() {
    wx.navigateTo({
      url: '/packageA/member/withdrawal/withdrawal'
    });
  },
  toPage(e) {
    let str = e.currentTarget.dataset.message;
    if (str === 'cashierOrderlist') {
      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2?status=0' + '&orderType=cashier'
      });
      return;
    }
    if (str === 'presentationRecord') {
      wx.navigateTo({
        url: '/packageA/member/presentationRecord_v2/presentationRecord_v2?i=' + this.data.store.store_id +
					'&type=store_cashier'
      });
      return;
    }
    if (str === 'income_breakdown') {
      wx.navigateTo({
        url: '/packageC/cashier/cashierIncome/cashierIncome'
      });
      return;
    }
    wx.navigateTo({
      url: '/packageC/cashier/' + str + '/' + str
    });
  }
});
