<template>
  <view class="defaultBgc ss-p-x-20" style="height: 100vh; position: relative;">
    <scroll-view v-if="showList" class="scrollBox" scroll-y="true" @scrolltolower="loadingMore">
      <view v-if="list.length > 0">
        <view v-for="(item, index) in list" :key="index" class="ss-m-t-20" @click="jumpToEnterpriseDetail(item.enterprise.id)">
          <view class="sub-li-bottom">
            <view class="avatarBox">
              <image class="r-avatar" :src="getUserAvatar(item.contact.avatar, item.contact.sex)"></image>
            </view>
            <view class="ss-m-l-30">
              <span>{{ item.contact?.name }}</span>
              <span class="ss-m-x-10" v-if="item.contact?.name && item.contact?.nameCn"> | </span>
              <span>{{ item.post?.nameCn }}</span>
            </view>
          </view>
          <view style="background-color: #fff; border-radius: 0 0 12px 12px;" class="ss-p-30">
            <view class="d-flex align-center">
              <image :src="item.enterprise.logoUrl" style="width: 50px; height: 50px;"></image>
              <view style="flex: 1;" class="ss-m-l-30">
                <view class="enterprise-name ellipsis">{{ formatName(item.enterprise.anotherName || item.enterprise.name) }}</view>
                <!-- 行业规模 -->
                <view class="ss-m-y-15 font-size-12">
                  <span class="tag-gap color-666">
                    <span>{{item.enterprise.industryName }}</span>
                    <span class="ss-m-x-10" v-if="item.enterprise.industryName && item.enterprise.scaleName">|</span>
                    <span>{{item.enterprise.scaleName }}</span>
                  </span>
                </view>
                <!-- 标签 -->
                <view>
                  <uni-tag 
                    v-for="(tag, i) in item.enterprise.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 class="color-666 font-size-13 ss-m-t-20">查看时间：{{ timesTampChange(item.updateTime) }}</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 v-else class="noviewlist">
		<view v-if="userInfo?.vipExpireDate > Date.now() && !userInfo?.entitlement?.viewersList">
			当前会员套餐的权益不包含谁关注我，<span class="text-line" @tap.stop="handleToBuyVip">点击去升级</span>
		</view>
		<view v-if="!userInfo?.vipExpireDate || (userInfo?.vipExpireDate && userInfo?.vipExpireDate < Date.now())">
			谁关注我为会员权益内容，<span class="text-line" @tap.stop="handleToBuyVip">点击去开通</span>
		</view>
	</view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue'
import { getInterestedMePage } from '@/api/user'
import { dealDictObjData, jumpToEnterpriseDetail } from '@/utils/position'
import { getUserAvatar } from '@/utils/avatar'
import { timesTampChange } from '@/utils/date'
import { formatName } from '@/utils/getText'
import { userStore } from '@/store/user'
import { onShow } from '@dcloudio/uni-app'

const status = ref('more')
const queryParams = ref({
  pageNo: 1,
  pageSize: 10
})
const useUserStore = userStore()
const userInfo = computed(() => useUserStore?.userInfo)
// 当前会员套餐是否可查看此模块
const showList = computed(() => (new Date().getTime() < useUserStore?.userInfo?.vipExpireDate) && useUserStore?.userInfo?.entitlement?.viewersList)

const list = ref([])
const getList = async () => {
  const res = await getInterestedMePage(queryParams.value)
  const arr = res?.data?.list || []
  if (arr?.length) {
    arr.forEach(e => {
      e.enterprise = dealDictObjData({}, e.enterprise)
    })
    list.value = list.value.concat(arr)
  }
  status.value = list.value?.length === +res.data.total ? 'noMore' : 'more'
}

onShow(() => {
	// 有会员权益能查看才请求接口
	if (showList.value) getList()
})

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

// 跳转会员套餐
const handleToBuyVip = () => {
	uni.navigateTo({
		url: '/pagesA/vipPackage/index'
	})
}
</script>

<style scoped lang="scss">
.sub-li-bottom {
  display: flex;
  align-items: center;
  background: linear-gradient(90deg, #f5fcfc 0, #fcfbfa 100%);
  font-size: 13px;
  padding: 5px 30rpx;
  border-radius: 12px 12px 0 0;
  .avatarBox {
    max-width: 40px;
    max-height: 40px;
  }
}
.enterprise-name {
  color: #333;
  font-weight: bold;
  font-size: 16px;
  width: 70vw;
  max-width: 70vw;
}
.noviewlist {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 98%;
	text-align: center;
	transform: translate(-50%, -50%);
	color: #666;
}
.text-line {
	color: #00B760;
	font-weight: bold;
	padding-bottom: 2px;
	border-bottom: 1px solid #00B760;
}
</style>
