<template>
  <div class="page-content">
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh" v-if="list.length > 0">
      <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"
        :immediate-check="false">
        <van-cell v-for="item in list" :key="item.id"
          @click="$router.push({ name: 'flow-detail', query: { id: item.id } })">
          <div class="text-start"><van-tag type="primary" size="large">{{ item.followType }}</van-tag></div>
          <van-text-ellipsis class="text-start mt-10" :content="item.introduce" rows="3" expand-text="展开"
            collapse-text="收起" @click-action="showOrHiddenText" />
          <div>{{ item.sysDate }}</div>
        </van-cell>
      </van-list>
    </van-pull-refresh>
    <van-empty v-else />
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router'
let pageContent = ref(null)
const scrollPosition = ref(0)
const route = useRoute()
const router = useRouter()
let stockCode: any = ref('')
const refresh = () => {
  if (route.query && route.query.stockCode) {
    stockCode.value = route.query.stockCode
    onRefresh()
  } else {
    router.push({ name: '404' })
  }
}
import { stockCompanyFlowInfoList } from '@/utils/api'
const getData = async () => {
  const { data }: any = await stockCompanyFlowInfoList({
    stockCode: stockCode.value,
    curPage: curPage.value,
    limit: 20
  })
  data.list.map((ele: any) => {
    ele.playFlag = false
  })
  return data
}
const showOrHiddenText = (event: any) => {
  event.stopPropagation()
}
import { listLoadAndRefresh } from '@/mixins/list-load-and-refresh'
const { refreshing, finished, loading, curPage, list, onLoad, onRefresh } = listLoadAndRefresh(getData, 'stock')
import { scrollList } from '@/mixins/scroll-list'
const { setScrollTop, setScrollPositionAndRefreshFlag } = scrollList(pageContent, scrollPosition, refresh)

setScrollTop()
onBeforeRouteLeave((to, from) => {
  setScrollPositionAndRefreshFlag(to, 'track-detail')
})
</script>

<style lang='scss' scoped></style>
