TabMine.js 5.27 KB
// components/tabMine/TabMine.js
import api from '~/pages/tabMine/api'
const app = getApp()
import constantData from '~/pages/constant/data'
import { withTabRefreshInFlight } from '../../services/tabRefreshService.js'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/mine/'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    navBarHeight: {
      type: Number,
      value: 0
    },
    // 是否显示工资绩效
    showCollege: {
      type: Boolean,
      value: false
    },
    /** Tab4 可见性:true 时刷新我的页银行卡/版本信息 */
    show: {
      type: Boolean,
      observer(n) {
        if (n) this.refreshOnShow()
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    isYqdSuper: '',
    selectedSceneName: '',
    userInfo: {},
    staffBankFlag: false,
    isForbidden: false,
  },

  lifetimes: {
    ready() {
      this.applyMineUserInfo()
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /** 从本地 userInfo 同步展示字段(ready 与每次 Tab 显示时调用) */
    applyMineUserInfo() {
      const userInfo = wx.$util.getUserInfo()
      const payload = {
        isForbidden: !wx.$hasPermission?.canSelectMultiStore?.(userInfo),
        isYqdSuper: app.globalData.isYqdSuper,
        selectedSceneName: constantData?.sceneList?.filter(val => val.sceneType == userInfo?.sceneType)[0]?.sceneName,
        selectedSceneDesc: constantData?.sceneList?.filter(val => val.sceneType == userInfo?.sceneType)[0]?.sceneDesc,
        userInfo
      }
      if (userInfo.createdDate) {
        let date = userInfo.createdDate + ''
        date = date.replace(/-/g, '/').split(' ')[0]
        payload['userInfo.createdTime'] = date
      }
      this.setData(payload)
    },
    /**
     * Tab 切到我的时的统一入口;合并同 tick 并发。
     * @returns {Promise<void>}
     */
    refreshOnShow() {
      return withTabRefreshInFlight('mine', () => this.refreshMineTab())
    },
    /** 刷新用户信息展示 + getStaffBankList + getVersionInfo */
    async refreshMineTab() {
      this.applyMineUserInfo()
      await Promise.all([this.getStaffBankList(), this.getVersionInfo()])
    },
    /**跳转至银行卡 */
    toAddBankAccount(e) {
      const {
        score,
        user
      } = this.data
      this.setData({
        showAccountModal: false
      }, () => {
        wx.$router.go('integration.detail', {
          score
        })
      })
    },
    async getStaffBankList() {
      let userInfo = wx.$util.getUserInfo(),
        res = await api.getStaffBankList({
          uuid: userInfo.uuid
        })
      console.log(res)
      if (res.data && res.data.length) {
        this.data.staffBankFlag = true
        const [staffBankInfo] = res.data
        if (staffBankInfo.state == 2 && !this.staffBankInfo) {
          this.staffBankInfo = staffBankInfo
          this.setData({
            showAccountErrorModal: true
          })
        }
      }
    },
    //我的积分
    toPoint() {
      console.log(999)
      //判断是否添加银行卡
      if (!this.data.staffBankFlag) {
        this.setData({
          showAccountModal: true
        })
        return
      }
      // 新的积分兑换页面
      wx.$router.go('integration.index')
    },
    toCloseModal(e) {
      const {
        name
      } = e.currentTarget.dataset
      this.setData({
        [name]: false
      });
    },
    //收款账户
    jumpAccount() {
      const {
        score,
        user
      } = wx.$router.getPageInstance()
      wx.$router.go('integration.list', {
        score,
        user
      })

    },
    // 跳转到工资绩效
    jump(e) {
      let { url } = e.currentTarget.dataset
      const baseUrl = 'https://img01.glsx.com.cn/weapp/resource/saas/scrm/html/'
      const path = `${baseUrl}${url}.html`
      wx.navigateTo({
        url: `/pages/webView/webView?url=${encodeURIComponent(path)}`
      })
    },
    // 跳转到商学院
    goCollegeScene() {
      wx.$router.go('packageEquity.collegeScene')
      console.log('跳转到工资绩效')
    },
    // 获取版本信息
    async getVersionInfo() {
      const versionData = await getApp().getVersionInfo()
      this.setData({
        versionData
      })
    },
    // 更新日志
    goVersionPage() {
      wx.$router.go('tabMine.log')
    },
    // 切换场景
    changeScene() {
      wx.$util.pointRecord(31)
      wx.$router.go('pages.changeScene')
    },

    // 切换账号
    changeAccount() {
      wx.$router.reLaunch('pages.accountItems')
    },
    // 退出登录
    logout() {
      let _this = this
      wx.showModal({
        title: '温馨提示',
        content: '是否退出当前账号?',
        confirmColor: '#347BFF',
        success(res) {
          if (res.confirm) {
            _this.setData({
              flag: true
            })
            wx.showLoading()
            api.logout().then(_res_ => {
              let { code, message } = _res_
              if (code == 0) {
                wx.$storage.rm('abnormalFlowPop')
                app.login(false)
              } else {
                _this.setData({
                  flag: false
                })
                wx.showToast(message)
              }
            })
          }
        }
      })
    }
  }
})