AccountList.vue 6.04 KB
<template>
  <view
    class="box"
    :key="selectedUuid"
    v-if="flag"
  >
    <template v-if="loginUserInfoList.length">
      <template v-for="(item,index) in loginUserInfoList">
        <view
          :key="index"
          :class="['items', `${item.active ? 'active' : ''}` ]"
          @click="chooseAccount(item)"
        >
          <view class="right">
            <view :class="['midle', midle(item)]">
              {{item.isSuper==true?'超管':item.userType==1?'商户':(item.loginRole == 3 ? '督导' : item.loginRole == 4 ? '驻店' : '员工')}}
            </view>
          </view>
          <view class="left">
            <view class="name">
              {{item.merchantName}}
            </view>
            <view class="shop_no">
              商户号:{{item.merchantId}}
            </view>
          </view>
        </view>
      </template>
    </template>
    <template v-else>
      <view class="list-not">
        暂无内容
      </view>
    </template>

  </view>
</template>

<script type='text/ecmascript-6'>
import { loginMixin } from '@/mixin/index'
export default {
  mixins: [loginMixin],
  name: '',
  data () {
    return {
      copyLoginUserInfoList: [],
      loginRole: {
        1: '超管',
        2: '商户号',
        3: '区域督导',
        4: '驻店负责人'
      },
      selectedUuid: '',
      requestFlag: false,
      loginUserInfoList: [],
      flag: false
    }
  },
  mounted () {
    this.getListSelectAccount()
  },
  methods: {
    getListSelectAccount () {
      uni.showLoading()
      uni.$api.userApi.getListSelectAccount().then(res => {
        uni.hideLoading()
        let { code, data, message } = res
        if (code == 21) uni.reLaunch({
          url: "/pages/common/login",
        })
        else {
          if (code == 0) {
            let { loginUserInfoList, sessionId } = data
            uni.$storage.set('sessionId', sessionId);
            this.loginUserInfoList = loginUserInfoList
            this.copyLoginUserInfoList = loginUserInfoList
          } else uni.showToast({
            title: message,
            icon: 'none',
          });
          this.flag = true
        }
      })
    },
    chooseAccount (item) {
      let { loginUserInfoList } = this
      loginUserInfoList.map(i => {
        i.active = false
        if (i.uuid == item?.uuid) i.active = true
        return i
      })
      this.loginUserInfoList = loginUserInfoList
      this.selectedUuid = item.uuid
      this.choiceAccountLogin()
    },
    async choiceAccountLogin () {
      let { loginUserInfoList } = this,
        id = null

      loginUserInfoList.map(e => {
        if (e.active) id = e.uuid
      })

      if (!id) {
        uni.showToast({
          title: '请选择账号',
          icon: 'none',
        });
        return
      }
      // 清空4s店数据
      // app.globalData.storeListRange = []
      this.selectAccountLogin(id)
    },
    selectAccountLogin (id) {
      if (this.requestFlag) return
      this.requestFlag = true
      uni.showLoading()
      uni.$api.userApi.selectAccountLogin({ id }).then(res => {
        uni.hideLoading()
        this.requestFlag = false
        let { data, message } = res,
          [userInfo] = data.loginUserInfoList
        if (data && userInfo) this.get4SStoreList(userInfo)
        else uni.showToast({
          title: message,
          icon: 'none',
        })
      })
    },
    // 搜索过滤
    searchEvent (searchValue) {
      let { copyLoginUserInfoList, selectedUuid } = this
      copyLoginUserInfoList.map(val => {
        val.active = false
        if (val.uuid == selectedUuid) val.active = true
        return val
      })
      let filterArr = copyLoginUserInfoList.filter(val => val.merchantName.includes(searchValue) || val.merchantId == searchValue) || []
      this.loginUserInfoList = filterArr
      if (!searchValue) this.loginUserInfoList = copyLoginUserInfoList
    },
    midle (item) {
      return item.isSuper == true ? 'midle_1' : item.userType == 1 ? 'midle_2' : (item.loginRole == 3 ? 'midle_3' : item.loginRole == 4 ? 'midle_4' : 'midle_5')
    },
  }
}
</script>

<style scoped lang='scss'>
.box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 0 48rpx;
  gap: 48rpx;

  .items {
    width: calc(50% - 24rpx);
    height: 160rpx;
    background: #ffffff;
    border-radius: 16rpx;
    padding: 32rpx;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    border: 4rpx solid transparent;
    .left {
      width: 65%;
      display: flex;
      flex-flow: column;
      justify-content: center;
      .name {
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 32rpx;
        color: #181a1f;
      }
      .shop_no {
        font-weight: 400;
        font-size: 28rpx;
        margin-top: 12rpx;
        color: #999ea8;
      }
    }
    .right {
      flex-shrink: 0;
      display: flex;
      align-items: center;
      .midle {
        font-size: 28rpx;
        font-weight: 700;
        width: 96rpx;
        height: 96rpx;
        border-radius: 8rpx;
        margin-right: 28rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
      }
      .midle_1 {
        color: #f24724;
        background-color: #f247241a;
      }
      .midle_2 {
        color: #ff9d0a;
        /* border: var(--fontSize2) solid #FF9D0A; */
        background-color: #ff9d0a1a;
      }
      .midle_3 {
        color: #347bff;
        /* border: var(--fontSize2) solid #347BFF; */
        background-color: #347bff1a;
      }
      .midle_4 {
        color: #35c376;
        /* border: var(--fontSize2) solid #35C376; */
        background-color: #35c3761a;
      }
      .midle_5 {
        color: #35c376;
        /* border: var(--fontSize2) solid #35C376; */
        background-color: #35c3761a;
      }
      .icon {
        width: 40rpx;
        height: 40rpx;
      }
    }
  }
  .active {
    border: 4rpx solid #347bff;
  }
  .list-not {
    font-size: 28rpx;
    color: #999999;
    margin: auto;
  }
}
</style>