outputValue.js 5.31 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: [],
    isShowService: false,
    unreadClueCount: 0,
    navBarBoxStyle: "justify-content: start;align-items: stretch",
    navTitleStyle: "width: 80%; padding: 0;",
    screenFormData: {
      partnerMerchantIds: [],
      shopMerchantIds: [],
      shopMerchantNames: '全部门店',
      startTime: '',
      endTime: '',
      sceneType: '',
      staffUUIDs: []
    },
    isShowFilterScreen: false,
    tabBoxStyle: ''
  },
  back() {
    this.setData({
      isShowFilterScreen: false
    })
    this.childEle = this.selectComponent('#screenBox')
    this.childEle.hideTypeFn()
  },
  // 切换园区
  tapPicker() {
    let { isSuper } = this.data
    isSuper &&
      this.setData({
        moveArrow: !this.data.moveArrow,
        popupShow: !this.data.popupShow
      })
  },
  navbarReady(e) {
    let { height, statusBarHeight, navigationBarHeight } = e.detail
    console.log(height, statusBarHeight, navigationBarHeight)
    this.setData({
      tabBarStyle: height / 2 + statusBarHeight,
      tabBoxStyle: `height: ${navigationBarHeight}px`,
      statusBarHeight,
      navigationBarHeight
    })
  },
  changeTabIndx(e) {
    this.setData({
      tabIndx: e.detail
    })
  },
  init() {
    this.setUserInfo()
    this.searchEvent(true, true)
  },
  // 筛选回调
  searchEvent(isNoBack = false, isInit = false) {
    console.log(this.data.screenFormData, 'screenFormData')
    if (!isNoBack) this.back()
    let merchantModule = this.selectComponent('#merchant')
    merchantModule.merchantRefresh && merchantModule.merchantRefresh(true)
    let employessModule = this.selectComponent('#employess')
    employessModule.getListData && employessModule.getListData(true, isInit)
  },
  setUserInfo() {
    let { userInfo } = wx.$storage.get()
    let { screenFormData } = this.data
    screenFormData.partnerMerchantIds = [userInfo?.subLoginUser?.merchantId]
    this.setData({
      userInfo,
      isSuper: userInfo.isSuper,
      screenFormData
    })
  },
  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
    // 判断是超管才需要切换账号
    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
            }
          })
          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() { }
})