accountList.vue 4.68 KB
<template>
  <div class="layout">
    <div class="title">请选择登录商户号</div>
    <div class="box">
      <template v-for="(item,index) in accountList">
        <div
          :key="index"
          class="item"
          @click="choose(item)"
        >
          <div class="name">
            {{item.merchantName}}
            <span class="type text-center">{{merchantEnum[item.accountLevel]}}</span>
          </div>
          <div class="num">商户编号:{{item.merchantId}}</div>
          <div class="icon y-center">
            <img src="@/assets/images/icon/arrow.png">
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
import { ssoApi } from '@/api'
import store from '@/store'
import { Dialog } from 'vant'
export default {
  name: 'accountList',
  data () {
    return {
      accountList: [],
      merchantEnum: {
        1: '工厂',
        2: '省代',
        3: '市代',
        4: '门店'
      },
      testView: ''
    }
  },
  mounted () {
    this.accountList = this.getLocalStorage('dj_scrm_accountList')
  },
  // watch: {
  //   watchFlag: {
  //     immediate: true,
  //     handler(newval) {
  //       this.testView = newval
  //     }
  //   }
  // },
  // computed: {
  //   watchFlag() {
  //     return this.$store.state.app.testView
  //   }
  // },
  methods: {
    choose (e) {
      this.showLoading(
        '',
        () => {
          let loginToken = this.getLocalStorage('dj_scrm_loginToken')
          let { merchantId, accountName } = e
          let loginAccount = accountName
          ssoApi
            .selectAccount({
              loginAccount,
              merchantId,
              loginToken
            })
            .then(({ code, data }) => {
              this.hideLoading()
              this.removeLocalStorage('dj_scrm_loginToken')
              if (code == '0') {
                if (data) {
                  if (data.status != 2) {
                    this.$router.replace({ name: 'common.overdue' })
                    return
                  }
                  let { lastPath } = this.getQuery()
                  let redirect_uri = this.getLocalStorage('dj_scrm_redirect_uri')
                  this.setLocalStorage('dj_scrm_userInfo', data)
                  this.setSessionId(data.sessionId)
                  let { corpId, agentId } = this.getLocalStorage('dj_scrm_corpId')
                  store.dispatch('registerHttp', data.sessionId)
                  this.removeLocalStorage('dj_scrm_redirect_uri')
                  this.showLoading('登录成功', () => {
                    this.hideLoading()
                    if (redirect_uri) {
                      let [URL, query] = decodeURIComponent(redirect_uri).split('?')
                      URL = `${URL}?sessionId=${data.sessionId}&corpId=${corpId}`
                      if(agentId) URL = `${URL}&agentId=${agentId}`
                      if (query) URL = `${URL}&${query}`
                      window.location.href = URL
                    }
                    else this.$router.replace({ name: lastPath || 'home' })
                  })
                }
              } else {
                this.hideLoading()
                Dialog.alert({
                  title: '温馨提示',
                  message: '登录失败,请重试',
                  confirmButtonColor: '#FF7336',
                  confirmButtonText: '重试'
                }).then(() => {
                  store.dispatch('navigation')
                })
              }
            })
        },
        true
      )
    }
  }
}
</script>

<style scoped lang='scss'>
.layout {
  padding: 0 16px 32px;
  .title {
    font-size: 20px;
    color: #3a3a3a;
    font-weight: 500;
    padding: 75px 0 40px;
    text-align: center;
  }
  .item {
    padding: 16px 16px 16px 27px;
    background: #fafafa;
    border-radius: 4px;
    margin-bottom: 16px;
    position: relative;
    .name {
      width: 277px;
      line-height: 20px;
      font-size: 14px;
      color: #6b6b6b;
      word-break: break-all;
      position: relative;
      &::after {
        position: absolute;
        top: 6px;
        left: -11px;
        width: 6px;
        height: 6px;
        background: var(--themeColor);
        border-radius: 100%;
        content: '';
      }
      .type {
        display: inline-flex !important;
        width: 34px;
        height: 14px;
        border: 1px solid var(--themeColor);
        border-radius: 4px;
        font-size: 10px;
        color: #837aff;
        vertical-align: middle;
      }
    }
    .num {
      font-size: 12px;
      color: #666666;
      margin-top: 10px;
    }
    .icon {
      right: 16px;
      width: 7px;
      height: 10px;
    }
  }
}
</style>