// packageA/hotel/HotelManage/HotelManage.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    language: '',
    thumb: '',
    name: '',
    total: '',
    sure: '',
    hotel_id: 0,
    title: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.title) {
      this.setData({
        title: decodeURIComponent(options.title)
      });
      wx.setNavigationBarTitle({
        title: this.data.title
      });
    }
    this.checkrouter();
    this.getData();
  },
  checkrouter() {
    // 推广中心是否开启该功能，没开启跳转到指定路径
    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] == 'HotelManage') {
        console.log(basic_info.popularize_page.mini.mini_url + "跳转的路径");
        wx.showToast({
          title: '未开启推广权限',
          duration: 1000,
          icon: 'none',
          success: function () {
            setTimeout(() => {
              wx.redirectTo({
                url: basic_info.popularize_page.mini.mini_url,
              });
            }, 1000);
          }
        });
        return;
      }
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en });
  },

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

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

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

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () { },
  onShareTimeline:function(){},
  getData() {
    let that = this;
    let url = '';
    if (this.data.title == '收银台') {
      url = 'plugin.hotel.frontend.cashier.center.index';
    } else {
      url = 'plugin.hotel.frontend.hotel.center.index';
    }
    let urlStr = app.getNetAddresss(url);
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let [thumb, name, total, sure] = [
            res.data.hotel.thumb,
            res.data.hotel.name,
            res.data.income.money_total,
            res.data.income.sure_withdraw_money
          ];
          that.setData({
            thumb: thumb,
            name: name,
            total: total,
            sure: sure
          });
          that.data.hotel_id = res.data.hotel.hotel_id;
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  gotoRecharge() {
    wx.navigateTo({
      url: '/packageA/member/withdrawal/withdrawal'
    });
  },
  gotoOrder() {
    if (this.data.title == '收银台') {
      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=hotelcashier'
      });
    } else {
      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=hotel_center'
      });
    }
  },
  gotoStat() {
    wx.navigateTo({
      url: '/packageC/cashier/cashier_stat/cashier_stat?hotel_id=' + this.data.hotel_id + '&tag=hotel'
    });
  },
  gotoRecord() {
    wx.navigateTo({
      url: '/packageA/member/presentationRecord_v2/presentationRecord_v2' + '?type=hotel'
    });
  },
  gotoCode() {
    wx.navigateTo({
      url: '/packageC/cashier/cashier_qr/cashier_qr?hotel_id=' + this.data.hotel_id + '&tag=hotel'
    });
  }
});
