<template>
	<layout-page>
		<view >
      <view style="padding: 15px;">
				<uni-segmented-control 
					:current="current"
					:values="tabList"
					@clickItem="changeControl"
					styleType="text"
					activeColor="#00B760"
				></uni-segmented-control>
			</view>

			<!-- 职位推荐 -->
			<view v-if="current === 0">
				<RecommendPage :jobList="jobList" />
			</view>
			<!-- 条件筛选 -->
			<view v-else>条件</view>

    </view>
	</layout-page>
</template>

<script setup>
import layoutPage from '@/layout'
import { ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getAccessToken } from '@/utils/request'
import { showAuthModal } from '@/hooks/useModal'
import { getJobAdvertised, getPersonRecommendPage } from '@/api/search'
import { dealDictArrayData } from '@/utils/position'
import { formatName } from '@/utils/getText'
import RecommendPage from './components/recommend.vue'

const current = ref(0)
const tabList = ['职位推荐', '条件筛选']

// 职位列表
const jobList = ref([])
const getJobList = async () => {
  const { data } = await getJobAdvertised({ status: 0 })
  if (data.length) {
    const list = dealDictArrayData([], data)
    jobList.value = list.map(e => {
      return { text: `${formatName(e.name)}_${e.areaName ? e.area?.str : '全国'}`, value: e.id, data: e }
    })
  }
}

onShow(() => {
	// 设置自定义tabbar选中值
  const currentPage = getCurrentPages()[0]  // 获取当前页面实例
  const currentTabBar = currentPage?.getTabBar?.()

  // 设置当前tab页的下标index
  currentTabBar?.setData({ selected: 0 })

	if (!getAccessToken()) return showAuthModal()

	getJobList()
})

const changeControl = (e) =>{
  current.value = e.currentIndex
}
</script>

<style scoped lang="scss">

</style>
