MallSelect.nvue 4.43 KB
<template>
  <view class="mall-select-group">
    <view class="group home-group" style="display: flex;flex-direction: row;justify-content: center;align-items: center;"  v-if="isHome">
      <slot name="leftIcon"></slot>
      <uv-text @tap="handleTapToChoose"  :text="displayVal.displayValue" lines="1" style="max-width: 640rpx;" :size="fontSize + 'rpx'" :bold="true" color="#fff"></uv-text>
      <image @tap="handleTapToChoose" src="/static/tabbar/arrow-down-w.png" class="dot-img" style="width: 20rpx;min-width: 20rpx;" mode="widthFix"></image>
      <slot @tap="handleTapToChoose" name="rightIcon"></slot>
    </view>
    <view v-else @tap="handleTapToChoose" class="page-group group"
      style="display: flex;flex-direction: row;justify-content: center;align-items: center;">
      <slot name="leftIcon"></slot>
      <text class="group_text" style="font-size: 28rpx;">{{displayVal.displayValue}}</text>
      <image src="/static/tabbar/arrow-down-w.png" class="dot-img" style="width: 20rpx;min-width: 20rpx;" mode="widthFix"></image>
      <slot name="rightIcon"></slot>
    </view>
  </view>
</template>

<script setup>
  import {
    onLoad
  } from '@dcloudio/uni-app'
  import {
    getStageObj
  } from '@/utils'
  import {
    onMounted,
    ref
  } from 'vue'

  const emit = defineEmits(['change'])
  const props = defineProps({
    currentStore: {
      type: Object,
      default: () => {
        return {}
      }
    },
    chooseGroup: {
      type: String,
      default: '0'
    },
    hasStore: {
      type: String,
      default: '1'
    },
    isHome: {
      type: Boolean,
      default: false
    },
    fontSize: {
      type: Number,
      default: 32
    }
  })

  const displayVal = ref({
    accountId: '',
    groupId: '',
    displayValue: '',
    storeId: ''
  })
  // 获取当前选择的集团
  onLoad(() => {
    // 当前集团
    const account = getStageObj('account')
    // 如果有传递的门店数据,优先展示门店数据
    if (props.currentStore.id) {
      const {
        accountId,
        id,
        groupId,
        name
      } = props.currentStore
      displayVal.value = {
        accountId,
        groupId,
        displayValue: name,
        storeId: id
      }

    } else if (account.id) {
      displayVal.value = {
        accountId: account?.id,
        displayValue: account?.name
      }
    }
    emit('change', displayVal.value, 'init')

    // 选中门店 执行渲染门店相关数据
    uni.$on('mallSelect', e => {
      let params = {}
      switch (e.type) {
        case 'account': {
          params = {
            accountId: account?.id,
            groupId: '',
            storeId: ''
          }
          break
        }
        case 'group': {
          params = {
            accountId: account?.id,
            groupId: e.id,
            storeId: ''
          }
          break
        }
        case 'store': {
          params = {
            accountId: account?.id,
            groupId: e.groupId,
            storeId: e.id
          }
          uni.setStorageSync('store', JSON.stringify(e))
          emit('storeChange', e)
          break
        }
      }
      params.displayValue = e.name
      displayVal.value = params
      emit('change', displayVal.value, 'change')
    })

  })

  /********** 搜索相关 ************/
  const searchVal = ref('')


  /********** popup相关 ************/
  const accountShopRef = ref(null)
  onMounted(() => {
    // accountShopRef.value?.open('bottom')
  })
  const handleTapToChoose = () => {
    uni.navigateTo({
      url: `/subPackages/accountGroup/pages/mall-group/index?chooseGroup=${props.chooseGroup}&hasStore=${props.hasStore}`
    })
    // accountShopRef.value?.open('bottom')
  }
  const handleCloseChoose = () => {
    accountShopRef.value?.close()
  }
</script>

<style lang="scss" scoped>
  @import '@/styles/normal.scss';


  .group {
    flex-direction: row;
    align-items: center;
      /* #ifdef APP */
      lines: 1;
      /* #endif */

    &_text {

      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      color: #FFFFFF;
      font-weight: 700;
      font-size: 44rpx;
    }

  }
  .mall-select-group {
    flex: 1;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    .group{

      &_text {
        font-size: 32rpx;
        // font-family: PingFang_Medium;
      }
    }
    .dot-img{
      margin-left: 10rpx;
    }
  }
  .page-group{
    width: 680rpx;
  }
</style>