import common from '../../utils/util';
import main from '../../utils/main';

const app = getApp();

Page({
  data: {
  },
  onLoad: function () {
    var that = this;
    that.setData({
      Containnerheight: main.getWindowHeight(),
    });
    this.init();
  },
  onPullDownRefresh:function(){
    this.init();
    var that = this;
    that.setData({
      SearchInfo: "",
    });
    wx.stopPullDownRefresh();
  },
  init: function () {
    wx.showLoading({
      title: '请稍候',
    });
    var that = this;
    main.getData("GetApprovalUserList", function (data) {
      wx.hideLoading();
      that.setData({
        List: data,
      });
    });
  },
  switch2Change: function (e) {
    var id = e.currentTarget.dataset.id;
    var isMember = 0;
    if (e.detail.value)
      isMember = 1;

    main.getData("UpdateUserMemberInfo?UserID=" + id + "&IsMember=" + isMember, function (data) {
      var title = "权限已关";
      if (isMember == 1)
        title = "权限已开";
      wx.showToast({
        title: title,
      });
    });
  },
  onKeyInput: function (e) {
    var search = e.detail.value;
    var that = this;
    that.setData({
      SearchInfo: search,
    });
  },
  search: function () {
    if (this.data.SearchInfo) {
      var list = [];
      for (var i = 0; i < this.data.List.length; i++) {
        if (this.data.List[i].NickName.indexOf(this.data.SearchInfo) >= 0) {
          list.push(this.data.List[i]);
        }
      }
      this.setData({
        List: list,
      });
    }
    else {
      this.init();
    }
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})
