CustomerManagement.js 5.5 KB
// pages/CustomerManagement/CustomerManagement.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 2,
    Status: '',
    KeyWord: '',
    list: '',
    mainid: '',
    vip_state: false
  },

  //点击切换
  tabCharge(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
      that.getInfo()
    }
  },

  //设置查询的关键词
  setKeyWord(e) {
    let that = this;
    that.setData({
      KeyWord: e.detail.value
    })
  },

  //获取客户管理页面信息
  getInfo() {
    let that = this;
    let url = 'counselor/familylist';
    let param = {
      UserId: app.globalData.UserId,
      Status: that.data.currentTab,
      KeyWord: that.data.KeyWord
    }
    app.post(url, param).then((res) => {
      console.log(res)
      if (res.data.code == 200) {
        that.setData({
          list: res.data.data.list,
          // cid: res.data.data.list[0].users[0].cid,
          KeyWord: '',
          // vip_state: true
        })

        // if (res.data.data.type == '-13') {
        //   wx.showToast({
        //     title: '会员到期,请充值',
        //     icon: 'none'
        //   }, 2000)
        //   that.setData({
        //     vip_state: false
        //   })
        // } else if (res.data.data.type == '-12') {
        //   wx.showToast({
        //     title: '您已经被禁用,请联系管理员',
        //     icon: 'none'
        //   }, 2000)
        //   that.setData({
        //     vip_state: false
        //   })
        // } else if (res.data.data.type == '-11') {
        //   wx.showToast({
        //     title: '您的权限不足',
        //     icon: 'none'
        //   }, 2000)
        //   that.setData({
        //     vip_state: false
        //   })
        // } else if (res.data.data.type == '1') {
        //   that.setData({
        //     list: res.data.data.list,
        //     // cid: res.data.data.list[0].users[0].cid,
        //     KeyWord: '',
        //     // vip_state: true
        //   })
        //   if (res.data.data.list[0].users[0].cid != '') {
        //     that.setData({
        //       cid: res.data.data.list[0].users[0].cid,
        //     })
        //   }
        // }
      }
    }).catch((errMsg) => {
      // console.log(errMsg)
    })
  },


  //获取客户管理页面信息
  getdata() {
    let that = this;
    let url = 'pubilc/UserType';
    let param = {
      UserId: app.globalData.UserId,
    }
    app.post(url, param).then((res) => {
      console.log(res, res.data.data.type)
      if (res.data.code == 200) {
        if (res.data.data.type == 5) {
          wx.showToast({
            title: '会员到期,请充值',
            icon: 'none'
          }, 2000)
          that.setData({
            vip_state: false
          })
        } else if (res.data.data.type == 2) {
          wx.showToast({
            title: '您的权限不足',
            icon: 'none'
          }, 2000)
          that.setData({
            vip_state: false
          })
        } else{
          that.setData({
            list: res.data.data.list,
            KeyWord: '',
            vip_state: true
          })
          if (res.data.data.list[0].users[0].cid != '') {
            that.setData({
              cid: res.data.data.list[0].users[0].cid,
            })
          }
        }
      }
    }).catch((errMsg) => {
      // console.log(errMsg)
    })
  },



  //家庭信息
  familyData(e) {
    var that = this
    let familyid = e.currentTarget.dataset.familyid;
    let list = that.data.list;
    // console.log(list)
    for (let items of list) {
      if (items.family_id == familyid) {
        for (let j in items.users) {
          if (items.users[j].user_family == 1) {
            that.setData({
              mainid: items.users[j].id, //户主ID
              cid: items.users[j].cid //顾问ID
            })
          }
        }
      }
    }
    wx.navigateTo({
      url: '../remind/remind?cid=' + this.data.cid + '&mainid=' + this.data.mainid,
    })
  },

  //个人信息详情
  infoDetail(e) {
    // wx.navigateTo({
    //   url: '../personInfo/personInfo?DefId=' + e.currentTarget.dataset.id,
    // })
    wx.navigateTo({
      url: '/pages/index/EntryInformation2/EntryInformation2?DefId=' + e.currentTarget.dataset.id,
    })
  },

  //创建新家庭
  addFamily() {
    var flag = true
    wx.navigateTo({
      url: '../addNewFamily/addNewFamily?flag=' + flag,
    })
  },

  //管理成员
  addPerson(e) {
    let familyid = e.currentTarget.dataset.familyid;
    wx.navigateTo({
      url: '../addNewFamily/addNewFamily?familyid=' + familyid,
    })
  },

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

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

  },

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

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})