output.js 5.46 KB
// pages/tab/output/output.js
import USERAPI from '~/api/usersApi/index'
import util from '~/utils/util'
import {
  IMG_URL
} from '~/utils/constantData'
import {
  getMockData
} from '~/api/api'
import {
  wyMerchantId
} from '~/utils/request/environment'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMG_URL,
    isShow: true,
    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) {
    this.setData({
      tabIndx: e.detail
    })
  },
  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)
    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
      }]
      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) {
    if (wyMerchantId.includes(+wx.$storage.get().userInfo.merchantId)) {
      this.setData({
        isWy: true
      })
      this.getTabBar().setData({
        active: 2,
        isShow:false
      })
    }
    const {
      merchantId,
      type,
      merchantName,
      usedCarFlag
    } = options
    if (merchantId) {
      wx.navigateTo({
        url: `/packagesList/outDetail/index?merchantId=${merchantId}&type=${type}&merchantName=${merchantName}&usedCarFlag=${usedCarFlag}`,
      })
      this.setData({
        isShow: false
      }, () => {
        setTimeout(() => {
          this.setData({
            isShow: true
          })
        }, 1000)
      })

    }
    this.init()
  },

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let title = '看产值'
    if (typeof this.getTabBar === 'function') {
      this.getTabBar((tabBar) => {
        const list = util.deepClone(tabBar.data.initList)

        if (wyMerchantId.includes(+wx.$storage.get().userInfo.merchantId)) {
            list.splice(1, 1);
            title = wx.$storage.get().userInfo.merchantName
        }
        tabBar.setData({
          active: 0,list
        })
      })
    }
    this.setData({title})
  },

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

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

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

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

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