MerchantList.vue 5.28 KB
<template>
  <view class="box" :key="selectMerchantId">
    <template v-if="flag">
      <template v-if="loginUserInfoList.length">
        <template v-for="(item, index) in loginUserInfoList">
          <view :key="index" :class="['items', { active: item.active }]" @click="chooseAccount(item)">
            <view class="right">
              <view class="sprite-icon icon-store"></view>
            </view>
            <view class="left">
              <view class="text_box">
                <view class="name">{{ item.merchantName }}</view>
                <view class="text_no">商户号:{{ item.merchantId }}</view>
              </view>
            </view>
          </view>
        </template>
      </template>
      <template v-else>
        <no-data />
      </template>
    </template>
  </view>
</template>

<script type="text/ecmascript-6">
import NoData from './NoData.vue'

export default {
  name: 'MerchantList',
  data () {
    return {
      loginUserInfoList: [],
      copyLoginUserInfoList: [],
      showSelect: false,
      openSceneArr: [],
      flag: false,
      userInfo: {},
      selectMerchantId: ''
    }
  },
  components: {
    NoData
  },
  methods: {
    init (userInfo) {
      uni.$logger.info(`进入选择4s店页面!`)
      this.userInfo = userInfo
      this.getSceneArr()
    },
    getSceneArr () {
      let { userInfo } = this
      // 超管开通全部场景
      if (userInfo?.isSuper) return this.getMerchantList()
      // 获取4s店关联场景数据
      uni.$api.userApi.getYqMerchantSceneConfigAPI({
        yqMerchantId: userInfo?.subLoginUser?.merchantId,
        merchantId: userInfo?.shopMerchantId
      }).then(result => {
        uni.hideLoading()
        this.openSceneArr = result.map(val => { if (val.sceneOpenFlag == 0) return val.scene }) || []
        this.getMerchantList()
      }).catch(err => {
        this.getMerchantList()
      })
    },
    getMerchantList () {
      this.loginUserInfoList = []
      this.copyLoginUserInfoList = []
      this.flag = false
      uni.showLoading({
        mask: true
      })
      let { userInfo } = this
      let params = {
        merchantId: userInfo?.isSuper ? '' : userInfo?.merchantId,
        staffUUID: userInfo?.isSuper ? '' : userInfo?.uuid
      }
      uni.$api.userApi.getSceneMerchantRefStoreList(params).then(result => {
        uni.hideLoading()
        this.loginUserInfoList = result
        this.copyLoginUserInfoList = result
        this.flag = true
        if (result && result.length == 1) this.chooseAccount(result[0])
      }).catch(err => {
        uni.hideLoading()
        console.log(err)
      })
    },
    chooseAccount (item) {
      uni.$logger.info(`选择4s店${item.merchantName}!`)
      uni.showLoading({
        mask: true
      })
      let { loginUserInfoList } = this
      let listArr = loginUserInfoList
      listArr.map(i => {
        i.active = false
        if (i.merchantId == item?.merchantId) {
          i.active = true
        }
        return i
      })
      this.loginUserInfoList = listArr
      this.selectMerchantId = item.merchantId
      this.jumpPage(item)
    },
    async jumpPage (item) {
      let { openSceneArr } = this,
        { merchantName: shopMerchantName, merchantId: shopMerchantId } = item,
        { userInfo } = this
      if (!openSceneArr?.length && !userInfo?.isSuper) {
        uni.hideLoading()
        uni.showToast({
          title: '暂无开通业务,请联系总部管理员',
          icon: 'none'
        })
        return
      }
      this.$emit('chooseMerchant', {
        ...userInfo,
        shopMerchantName,
        shopMerchantId,
        default4SStoreInfo: {
          merchantId: shopMerchantId,
          merchantName: shopMerchantName
        },
        default4SStoreInfo_crowdFunding: {
          merchantId: shopMerchantId,
          merchantName: shopMerchantName
        },
        default4SStoreInfo_newCarConversion: {
          merchantId: shopMerchantId,
          merchantName: shopMerchantName
        }
      })
      uni.hideLoading()
    },
    searchEvent (searchValue) {
      let { copyLoginUserInfoList, selectMerchantId } = this
      copyLoginUserInfoList.map(val => {
        val.active = false
        if (val.merchantId == selectMerchantId) 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
    },
  }
}
</script>

<style scoped lang="scss">
.box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 0 toRpx(48);
  gap: toRpx(48);
  .items {
    width: calc(50% - #{toRpx(24)});
    height: toRpx(160);
    background: #ffffff;
    border-radius: toRpx(16);
    padding: toRpx(32);
    display: flex;
    align-items: center;
    box-sizing: border-box;
    border: toRpx(4) solid transparent;
    .right {
      margin-right: toRpx(28);
      flex-shrink: 0;
    }
    .left {
      flex: 1;
      .name {
        font-weight: 500;
        font-size: toRpx(32);
        color: #181a1f;
        margin-bottom: toRpx(12);
      }
      .text_no {
        font-size: toRpx(28);
        color: #999ea8;
      }
    }
  }
  .active {
    border: toRpx(4) solid #347bff;
  }
}
</style>