// shoppingGuid/page/pages/selectUsers/selectUsers.js
const wxService = require('../../../../utils/wxService')
wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    navBar: [{ name: '自动标签', type: 1, isActive: true }, { name: '手动标签', type: 2, isActive: false }],
    current: 1,
    isOpen : false,
    groups : [],
    tags : []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 一进来先获取一下自动标签的数据
    this.getMemberTagGroups();
  },

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

  },

  //点击事件
  onTapExpandOrInpand(e){
    this.setData({
      isOpen: !this.data.isOpen
    })
  },
  //跳转到标签下用户列表
  onTapToTagUserList(e){
    let id = 11;
    wx.navigateTo({
      url: '/shoppingGuid/page/pages/userList/userList?id=' + id,
    });
  },
  //tab 切换
  onTopBarTap(e){
    let index = e.currentTarget.dataset.index,
      item = e.currentTarget.dataset.item;
    this.data.navBar.forEach(nav => {
      nav.isActive = false;
    });

    this.data.navBar[index].isActive = true;
    this.data.current = this.data.navBar[index].type;
    this.setData({
      navBar: this.data.navBar,
      current: this.data.current
    });
  },
  //获取标签分组
  getMemberTagGroups(){
    wxService.post(`/marketing/memberTagGroup/findPage?pageSize=10000&pageNo=1&type=${this.data.current}`).then(res => {
      console.log(res)
      let groups = res.data.data.content ? res.data.data.content : [];
      groups.forEach(item => {
        item.isActive = false;
      });

      this.data.groups = groups;
      this.setData({
        groups: this.data.groups
      });
    });
  },

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

  },

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

  },
});