<template>
  <view>
    <CuNavbar title="我的任务"></CuNavbar>
    <uv-sticky bgColor="#fff">
      <uv-tabs
        height="44"
        :activeStyle="{ color: '#ee2c37' }"
        :scrollable="false"
        :current="tabIndex"
        lineColor="#ee2c37"
        :list="tabList"
        @change="tabChange"
      ></uv-tabs>
    </uv-sticky>

    <MescrollItem
      ref="mescrollItem0"
      :top="88"
      :i="0"
      :index="tabIndex"
      :apiUrl="tabList[0].apiUrl"
    >
      <template v-slot="{ list }">
        <view class="space-y-15rpx p-base">
          <view v-for="(item, i) in list" :key="i">
            <Item :item="item"></Item>
          </view>
        </view>
      </template>
    </MescrollItem>
    <MescrollItem
      ref="mescrollItem1"
      :i="1"
      :top="88"
      :index="tabIndex"
      :apiUrl="tabList[1].apiUrl"
      :params="tabList[1].params"
    ></MescrollItem>
  </view>
</template>
<script setup>
import CuNavbar from '@/components/cu-navbar/index'
import { computed, reactive, ref } from 'vue'
import Item from './components/item.vue'
import { onPageScroll, onReachBottom, onShow } from '@dcloudio/uni-app'
import useMescrollMore from '@/uni_modules/mescroll-uni/hooks/useMescrollMore.js'
import MescrollItem from '@/components/mescroll-api/more.vue'

const mescrollItem0 = ref(null)
const mescrollItem1 = ref(null)

const mescrollItems = [mescrollItem0, mescrollItem1]
const { tabIndex, getMescroll, scrollToLastY } = useMescrollMore(
  mescrollItems,
  onPageScroll,
  onReachBottom
)
const tabList = ref([
  {
    name: '任务列表',
    apiUrl: '/tasks',
  },
  {
    name: '任务审核',
    apiUrl: '/workflow',
    params: {
      // aaa:111
    },
  },
])

const tabChange = ({ index }) => {
  tabIndex.value = index
  scrollToLastY()
}
</script>
