StoreItem.vue 3.52 KB
<template>
  <view class="store-list-item">
    <view class="store-header" @click="toggleFold(item)">
      <view class="header-left-part">
        <uv-image src="/static/inspection/store-black-2x.png" width="40rpx" height="40rpx"
          style="margin-right: 16rpx;"></uv-image>
        <view class="store-name">
          <uv-text :lines="1" :text="item[options.label]" color="#202328" :bold="true" size="28rpx">
          </uv-text>
        </view>
      </view>

      <view class="header-right-part" style="display: flex;flex-direction: row;align-items: center;">
        <view class="store-number">
          <text class="store-number-text">
            {{getMonitorTotal(item)}}
          </text>
        </view>
        <view class="fold-sign">
          <uv-icon :name="item.isFold?'arrow-down':'arrow-up'" size="26rpx" color="#90949D"></uv-icon>
        </view>
      </view>
    </view>

    <view class="store-body" :class="item.isFold ? 'store-body-hidden' : 'store-body-show'">
      <view v-if="item?.mallOrgs?.length>0">
        <view v-for="orgItem in item.mallOrgs" style="border-bottom: 1px dashed rgba(144, 148, 157, 0.3);margin-bottom: 22rpx;">
          <view class="s-b-title">
            <text class="s-b-title_text">{{orgItem.name}}</text>
          </view>
          <StoreItemVideo :list="orgItem?.patrolGates||[]"></StoreItemVideo>
        </view>
      </view>
      <!-- 区域列表 -->
      <view class="s-b-title" v-if="item?.mallOrgs?.length>0 && item[options.children].length>0">
        <text class="s-b-title_text">{{ t('app.title.defaultVideoGroup') }}</text>
      </view>
      <StoreItemVideo :list="item[options.children]"></StoreItemVideo>
    </view>
  </view>

</template>
<script setup>
  import StoreItemVideo from './StoreItemVideo.vue'
  const props = defineProps({
    item: {
      type: Object,
      required: true
    },
    options: {
      type: Object,
      default: () => ({
        label: 'name',
        children: 'patrolGates'
      })
    }
  })
  // 折叠
  function toggleFold(data) {
    data.isFold = !data.isFold
  }
  
  const getMallOrgsPatrolGates = (data)=>{
   if(data.mallOrgs){
     return data.mallOrgs.map(item=>item.patrolGates).flat(1)
   } 
   return []
  }

  function getMonitorTotal(data) {
    if (data.patrolGates) {
      const list = [...getMallOrgsPatrolGates(data),...data.patrolGates]
      
      // 1 在线;0 离线
      // const onlineNum = list.map(item => item.status === 1).length
      const onlineNum = list.filter(item => item.status === 1).length
      return `${onlineNum}/${list.length}`
    } else {
      return ''
    }
  }
</script>

<style lang="scss" scoped>
  .store-list-item {
    background-color: #FFF;
    border-radius: 16rpx;
  }

  .store-number {
    margin-right: 14rpx;

    .store-number-text {
      color: #90949D;
      font-size: 28rpx;
    }
  }


  .store-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding: 0px 10px;
    height: 46px;
    align-items: center;
    border-bottom: 1px solid #EEF0F3;
    font-size: 14px;

    .header-left-part {
      display: flex;
      flex-direction: row;
      flex: 1;

      .store-icon {
        margin-right: 6px;
      }

      .store-name {
        flex: 1;
      }
    }
  }

  .store-body.store-body-hidden {
    padding: 0;
    height: 0;
    overflow: hidden;
  }

  .store-body {
    padding: 24rpx 24rpx 8rpx;
    .s-b-title{
      &_text{
        margin-bottom: 22rpx;
        font-weight: bold;
        font-size: 26rpx;
        color: #202328;
      }
    }
  }
</style>