// packageE/stationNotice/stationNoticeSetting/stationNoticeSetting.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    checked2: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSetting();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

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

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

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

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

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

  getSetting() {
    let urlStr = app.getNetAddresss(
      "plugin.instation-message.api.message.get-member-set"
    );
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result != 1) return this.tips(res.msg);
        if (res.data["disturb"] && res.data["disturb"] == 1) {
          this.setData({
            checked2: true,
          });
        }
      },
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  onChange({ detail }) {
    this.setData({ checked2: detail });
    this.setSetting();
  },
  setSetting() {
    let urlStr = app.getNetAddresss(
      "plugin.instation-message.api.message.set-member-set"
    );
    app._getNetWork({
      url: urlStr,
      data: {
        disturb: this.data.checked2 ? 1 : 0,
      },
      success: (resdata) => {
        var res = resdata.data;
        this.tips(res.msg);
      },
    });
  },
  tips(msg) {
    wx.showToast({
      title: msg,
      icon: "none",
      duration: 2000,
    });
    return false;
  },
});
