output.js 4.36 KB
// pages/tab/output/output.js
import { getSessionId, setSessionId } from '~/utils/cache/storageApi'
import USERAPI from '~/api/usersApi/index'
import { IMG_URL } from '~/utils/constantData'
import { getMockData } from '~/api/api'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMG_URL,
    navStyle: 'background-color: rgba(0,0,0,0);',
    loginType: 0,
    agree: true,
    tabIndx: 0,
    // tabList: ['我的客户', '我的门店', '我的员工'],
    tabList: ['我的门店', '我的员工'],
    popupShow: false,
    subIndex: -1,
    merchantList: [
      {
        merchantId: 0,
        merchantName: 'string',
        show: true
      },
      {
        merchantId: 1,
        merchantName: 'test',
        show: true
      }
    ],
    isShowService: false,
  },
  // 切换园区
  tapPicker() {
    // let { isSuper } = this.data
    // isSuper &&
    this.setData({
      moveArrow: !this.data.moveArrow,
      popupShow: !this.data.popupShow
    })
  },
  navbarReady(e) {
    let { height, statusBarHeight } = e.detail
    this.setData({
      tabBarStyle: height / 2 + statusBarHeight
    })
    // console.log(e)
  },
  changeTabIndx(e) {
    const { idx } = e.currentTarget.dataset
    this.setData({
      tabIndx: idx
    })
  },
  init() {
    this.setUserInfo()
    this.getMerchantRange()
    this.getMockInfo()
  },
  setUserInfo() {
    let { userInfo } = wx.$storage.get()
    // console.log(userInfo)
    this.setData({
      userInfo,
      isSuper: userInfo.isSuper
    })
  },
  async getMockInfo() {
    let { serviceMerchatList } = await getMockData() || { serviceMerchatList: [] }
    this.setData({
      isShowService: serviceMerchatList.includes(this.data.userInfo.merchantId + '')
    })
  },
  getMerchantRange(e) {
    // 重新刷新
    // let { detail } = e || null
    // console.log(detail)
    // console.log(e)
    if (e) {
      this.setUserInfo()
      let clientModule = this.selectComponent('#client')
      // let merchantModule = this.selectComponent('#merchant')
      clientModule.getClientApi && clientModule.clientRefresh()
      clientModule.getBusinessData && clientModule.getBusinessData()
      // merchantModule.init && merchantModule.init()
    }
    let { isSuper, userInfo } = this.data
    console.log(isSuper)
    // 判断是超管才需要切换账号
    if (isSuper) {
      USERAPI.adminSelectLogin()
        .then(result => {
          // console.log(result)
          let { merchantList: merchantRange } = result
          // console.log(merchantRange)
          let subIndex = -1
          merchantRange.forEach((item, index) => {
            item.show = true
            if (item.merchantId == userInfo.subLoginUser.merchantId) {
              subIndex = index
              item.act = true
            }
          })
          console.log(subIndex)
          this.setData({
            merchantRange,
            subIndex
          })
        })
        .catch(err => { })
    } else {
      let merchantRange = [{ merchantId: userInfo.subLoginUser.merchantId, merchantName: userInfo.subLoginUser.merchantName }]
      console.log('merchantRange', merchantRange)
      this.setData({
        merchantRange,
        subIndex: 0
      })
    }
  },

  onRoute(options) {
    if (!options || wx.$util.isEmptyObj(options)) return
    let { page = 'client', refresh = true } = options
    if (page == 'client' && refresh) {
      let clientModule = this.selectComponent('#client')
      clientModule.getClientApi && clientModule.clientRefresh()
      clientModule.getBusinessData && clientModule.getBusinessData()
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.init()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    // console.log(getTextWidth('随后获取dom元素的clientWidth 随后获取dom元素的clientWidth随后获取dom元素的clientWidth随后获取dom元素的clientWidth', '12px'))
  },

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

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

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

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

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

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