<template>
  <view>
    <CuNavbar title="升职申请">  </CuNavbar>
    <uv-sticky bgColor="#fff">
      <uv-tabs
        :activeStyle="{ color: '#ee2c37' }"
        :scrollable="false"
        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 :type="0" :item="item" :options="[1]"> </Item>
          </view>
        </view>
      </template>
    </MescrollItem>
    <MescrollItem
      ref="mescrollItem1"
      :top="88"
      :i="1"
      :index="tabIndex"
      :apiUrl="tabList[1].apiUrl"
    >
      <template v-slot="{ list }">
        <view class="space-y-15rpx p-base">
          <view v-for="(item, i) in list" :key="i">
            <Item :type="1" :item="item" :options="[2]"> </Item>
          </view>
        </view>
      </template>
    </MescrollItem>
    <MescrollItem
      ref="mescrollItem2"
      :top="88"
      :i="2"
      :index="tabIndex"
      :apiUrl="tabList[2].apiUrl"
      :params="tabList[2].params"
    >
      <template v-slot="{ list }">
        <view class="space-y-15rpx p-base">
          <view v-for="(item, i) in list" :key="i">
            <Item
              :type="2"
              :subject_type="tabList[2].params.subject_type"
              :item="item"
            ></Item>
          </view>
        </view>
      </template>
    </MescrollItem>
  </view>
</template>
<script setup>
import CuNavbar from '@/components/cu-navbar/index'
import { ref } from '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'
import Item from './components/item.vue'
import { onLoad } from '@dcloudio/uni-app'
const tabList = ref([
  {
    name: '申请列表',
    apiUrl: '/hr/promotion/apply',
  },
  {
    name: '推荐列表',
    apiUrl: '/hr/promotion/apply',
  },
  {
    name: '审核列表',
    apiUrl: '/workflow',
    params: {
      subject_type: 'employee_promotions',
    },
  },
])
const mescrollItem0 = ref(null)
const mescrollItem1 = ref(null)
const mescrollItem2 = ref(null)

const mescrollItems = [mescrollItem0, mescrollItem1, mescrollItem2]
const { tabIndex, getMescroll, scrollToLastY } = useMescrollMore(
  mescrollItems,
  onPageScroll,
  onReachBottom
)

onLoad(() => {
  uni.$on('work:submit', getMescroll(tabIndex.value))
})

const goPath = (url) => {
  uni.navigateTo({
    url,
  })
}
const tabChange = ({ index }) => {
  tabIndex.value = index
  scrollToLastY()
}
</script>
