<template>
  <view>
    <CuNavbar title="报销管理">
      <template #right>
        <view
          @click="goPath('/pages/expense-account/submit')"
          class="text-24rpx text-white"
          >申请</view
        >
      </template>
    </CuNavbar>
    <uv-sticky bgColor="#fff">
      <uv-tabs
        :activeStyle="{ color: '#ee2c37' }"
        :scrollable="false"
        lineColor="#ee2c37"
        :list="tabList"
        :current="tabIndex"
        @change="tabChange"
      ></uv-tabs>
    </uv-sticky>
    <view class="">
      <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 in list" :key="item.id">
              <Item :item="item" />
            </view>
          </view>
        </template>
      </MescrollItem>
      <MescrollItem
        ref="mescrollItem1"
        :i="1"
        :top="88"
        :index="tabIndex"
        :apiUrl="tabList[1].apiUrl"
        :params="tabList[1].params"
      >
        <template v-slot="{ list }">
          <view class="space-y-15rpx p-base">
            <view v-for="item in list" :key="item.id">
              <Item
                :item="item"
                :type="tabList[1].params.subject_type"
                status="statusExpense"
              /> </view
          ></view>
        </template>
      </MescrollItem>
    </view>
  </view>
</template>
<script setup>
import CuNavbar from '@/components/cu-navbar/index'
import { ref } from 'vue'
import { onPageScroll, onReachBottom } 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 './item.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: '/reimbursements',
  },
  {
    name: '报销审核',
    apiUrl: '/workflow',
    params: { subject_type: 'reimbursements', include: 'employee,store,type' },
  },
])

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

const goPath = (url) => {
  uni.navigateTo({
    url,
  })
}
</script>
