indexStore.vue 2.84 KB
<template>
  <view class="inspection">
    <view class="store-search">
      <uv-input :placeholder="t('app.common.search')" prefixIcon="search" prefixIconStyle="font-size: 46rpx;color: #333333" border="none"
        placeholderStyle="color:#90949D;font-size:26rpx" clearable
        style="background-color: #fff;height: 68rpx;flex: none;margin-top: 16rpx;padding: 0 24rpx;"
        @input="handleSearch"></uv-input>
    </view>
    <!-- 门店列表 -->
    <view class="store-list" v-if="showMallList.length>0">
      <StoreItem v-for="sItem in showMallList" :key="sItem.id" :item="sItem" style="margin-bottom: 16rpx;"></StoreItem>
    </view>
    <view class="p-empty" style="margin-top: 280rpx;" v-else>
      <image class="p-empty-img" src="/static/common/empty.png" mode=""></image>
      <text class="p-empty-text">{{ t('maintenance.monitor.project.empty.text') }}</text>
    </view>
  </view>
</template>
<script setup>
  import {
    computed,
    ref
  } from 'vue';
  import {
    onLoad
  } from '@dcloudio/uni-app';
  import {
    doMonitorGroupApi
  } from '@/api';
  import {
    getStageObj
  } from '@/utils'
  import StoreItem from './components/StoreItem.vue'
  import {
    t
  } from '@/plugins/index.js'

  function getFormatMall(dataList, targetMallList) {
    if (dataList.malls && dataList.malls.length > 0) {
      const targetData = dataList.malls.map(item => {
        return {
          ...item,
          isFold: false,
        }
      })
      targetMallList.push(...targetData)
    }

    if (dataList.subGroups && dataList.subGroups.length > 0) {
      dataList.subGroups.forEach(item => {
        getFormatMall(item, targetMallList)
      })
    }
  }

  const mallList = ref([])

  function getMallList() {
    const accountId = getStageObj('account')?.id
    if (accountId) {
      const params = {
        accountId,
      }
      doMonitorGroupApi(params).then(res => {
        if (res.code === 200) {
          const targetList = []
          getFormatMall(res.data, targetList)

          mallList.value = targetList
        }
      })
    }
  }

  // 搜索功能
  const keyword = ref('')

  function handleSearch(value) {
    keyword.value = value
  }
  const showMallList = computed(() => {
    if (keyword.value) {
      return mallList.value.filter(item => {
        if (item.name.includes(keyword.value)) {
          return true
        } else {
          return false
        }
      })
    } else {
      return mallList.value
    }
  })

  onLoad((options) => {
    getMallList()
  })
</script>

<style lang="scss">
  .inspection {
    position: relative;
    .store-search {
      position: sticky;
      left: 0;
      top: 0;
      width: 750rpx;
      height: 100rpx;
      background-color: #f2f3f6;
      z-index: 100;
      padding: 0 20rpx;
    }

    .i-content {
      padding: 0 20rpx;
    }

  }
  .store-list{
    padding: 0 20rpx;
  }

</style>