<template>
  <view class="ss-m-x-20">
    <scroll-view class="scrollBox" scroll-y="true" @scrolltolower="loadingMore" style="height: 100vh;">
      <view v-if="items.length">
        <view v-for="(item, index) in items" :key="index" class="ss-m-t-20" @click="jumpToEnterpriseDetail(item.id)">
          <view style="background-color: #fff; border-radius: 12px;" class="ss-p-30">
            <view class="d-flex align-center">
              <image :src="item.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" style="width: 50px; height: 50px; object-fit: contain"></image>
              <view style="flex: 1;" class="ss-m-l-30">
                <view class="enterprise-name ellipsis">{{ formatName(item.anotherName || item.name) }}</view>
                <view class="ss-m-y-15 font-size-12">
                  <span class="tag-gap color-666">
                    <span>{{item.industryName }}</span>
                    <span class="ss-m-x-10" v-if="item.scaleName">|</span>
                    <span>{{item.scaleName }}</span>
                  </span>
                </view>
                <view>
                  <uni-tag 
                    v-for="(tag, i) in item.tagList || []"
                    :key="i"
                    class="ss-m-r-10"
                    :text="tag"
                    inverted="false"
                    size="mini"
                    custom-style="background-color: #eef1f7;color:#7f828b;border-color:#eef1f7;"
                  />
                </view>
              </view>
            </view>
          </view>
        </view>
        <uni-load-more :status="status" />
      </view>
      <view v-else class="nodata-img-parent">
        <image src="https://minio.citupro.com/dev/static/nodata.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image>
      </view>
    </scroll-view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { getSubscribeEnterprise } from '@/api/user'
import { dealDictArrayData, jumpToEnterpriseDetail } from '@/utils/position'
import { formatName } from '@/utils/getText'

const items = ref([])
const status = ref('more')
const queryParams = ref({
  pageSize: 10,
  pageNo: 1
})

const getList = async () => {
  const { data } = await getSubscribeEnterprise(queryParams.value)
  let list = data?.list || []
  if (list?.length) {
    list = dealDictArrayData([], list)
    items.value = items.value.concat(list)
  }
  status.value = items.value?.length === +data.total ? 'noMore' : 'more'
}
getList()

// 加载更多
const loadingMore = () => {
  status.value = 'loading'
  queryParams.value.pageNo++
  getList()
}
</script>

<style scoped lang="scss">
.enterprise-name {
  color: #333;
  font-weight: bold;
  font-size: 16px;
  width: 70vw;
  max-width: 70vw;
}
</style>
