index.js 3.37 KB
import {
  setSessionId,
  setUserInfo
} from '~/utils/cache/storageApi'
import USERAPI from '~/api/usersApi/index'
import ActivityApi from '~/api/activityApi/index'
const setRouteData = targetPath => {
  let [url, query] = targetPath.split('?'),
    obj = {}
  if (query) {
    let arr = query.split('&')
    arr.forEach(el => {
      const [key, val] = el.split('=')
      Object.assign(obj, {
        [key]: val
      })
    })
    // const [key, val] = query.split('=')
    // obj = {
    //   [key]: val
    // }
  }
  return {
    url,
    obj
  }
}
/**选择账号登录 */
const selectAccountLogin = ({
  id,
  sessionId,
  missionId,
  tab,
  merchantId,
  pages,
  tabType,
  isGH,
  ghPhone
}) => {
  let para = {
    id,
    sessionId,
  }
  let apiName = 'selectAccountLogin'
  if (ghPhone) {
    para.phone = ghPhone
    apiName = 'selectAccountLoginByPassword'
  }
  USERAPI[apiName](para).then(({
    code,
    data,
    message
  }) => {
    if (code == '0') {
      const userInfo = wx.$storage.get('userInfo') || {},
        [info] = data.loginUserInfoList
      if (userInfo.merchantId == info.merchantId && userInfo.uuid == info.uuid && userInfo.boutiqueCoupon_myself_status) info.boutiqueCoupon_myself_status = true
      setLoginInfo(info, data.sessionId, missionId, tab, merchantId, pages, tabType, isGH)
    } else wx.$api.showToast(message || '系统异常')
  })
}
/**设置登录信息 */
const setLoginInfo = (userInfo, sessionId, missionId, tab, merchantId, pages, tabType, isGH) => {
  setUserInfo(userInfo)
  setSessionId(sessionId)
  if (isGH) {
    console.log(userInfo);
    ActivityApi.findStaff({ staffUuid: userInfo.uuid }).then(res => {
      if (res && res.length) {
        const roleName = res[0].roleName
        const merchantId = res[0].merchantNo
        if (roleName === '售后专员') {
          wx.navigateTo({
            url: '/packageStoreAssistant/packageAuth/pages/GHStaff/StoreNote/index?merchantId='+merchantId,
          });
        } else if(roleName === '续保专员'){
          wx.navigateTo({
            url: '/packageStoreAssistant/packageAuth/pages/GHStaff/EquityRegister/index',
          });
        }else{
          wx.$api.showToast('请使用有效账号进行登录')
        }
      } else {
        wx.$api.showToast('请使用有效账号进行登录')
      }
    })

    return
  }
  loginSuccess(missionId, tab, merchantId, pages, tabType)
}
/**成功跳转 */
const loginSuccess = (missionId, tab, merchantId, pages, tabType) => {
  const {
    options: {
      targetPath
    }
  } = wx.$router.getPageInstance()
  if (targetPath || missionId || pages) {
    if (missionId) {
      wx.nextTick(() => {
        wx.$router.reLaunch('/packageStoreAssistant/packageActivity/pages/taskDetail/taskDetail', {
          missionId,
          tabType,
          isCard:true
        })
      })
      return
    }
    if (pages == 'addFLG' || pages == 'addFLGStep' || pages == 'myFollow') {
      wx.nextTick(() => {
        wx.$router.reLaunch(`/packageStoreAssistant/packageActivity/pages/${pages}/index`, {
          open: 1
        })
      })
      return
    }
    const {
      url,
      obj
    } = setRouteData(targetPath)
    wx.$router.reLaunch(url, obj)
  } else wx.$router.reLaunch('/pages/tab/storeAssistant/index', {
    notIntercept: true,
    tab,
    merchantId
  })
}

module.exports = {
  selectAccountLogin,
  loginSuccess,
  setRouteData,
  setLoginInfo
}