<!--
 * @Date: 2025-10-16 15:15:47
 * @LastEditors: shirlwang
 * @LastEditTime: 2026-01-27 09:30:18
-->
<template>
  <!-- @scroll="handleScroll" @scrolltolower="scrollBottom" -->
  <!-- #ifdef MP-WEIXIN -->
  <scroll-view :scroll-y="true" class="container" :class="{'h5-pc-container': isH5}" :show-scrollbar="false" style="background-image: url(../../../packageRc/static/pageBgIndex.png);">
    <view style="padding: 40rpx 28rpx;">
         <!-- #ifdef MP-WEIXIN -->
      <view class="kinggang">
        <view @click="navTo('/packageA/pages/myResume/myResume')">
          <image src="../../../packageRc/static/kinggang1.png"/>
          <view>信息维护</view>
        </view>
        <view @click="navTo('/packageA/pages/Intendedposition/Intendedposition')">
          <image src="../../../packageRc/static/kinggang5.png"/>
          <view>投递记录</view>
        </view>
        <view @click="tiao()">
          <image src="../../../packageRc/static/kinggang2.png"/>
          <view>需求上报</view>
        </view>
        <view>
          <image @click="goAiAu" src="../../../packageRc/static/kinggang3.png"/>
          <view>虚拟面试</view>
        </view>
        <view @click="goCa">
          <image src="../../../packageRc/static/kinggang4.png"/>
          <view>素质测评</view>
        </view>
      </view>
      <!-- #endif -->
      <view class="showtab">
        <view class="tabItem" @click="changeType(1)">
          <image src="/packageRc/static/gw.png"/>
          <image v-show="tabType == 1" class="activeImg" src="/packageRc/static/activeTangle.png"/>
        </view>
        <view class="tabItem" @click="changeType(2)">
          <image src="/packageRc/static/zc.png"/>
          <image v-show="tabType == 2" class="activeImg" src="/packageRc/static/activeTangle.png"/>
        </view>
      </view>
      <template v-if="tabType == 1">
        <view class="tabs">
          <view class="tab" :class="{active: pageState.type == ''}" @click="changeJobType('')">岗位列表</view>
          <view class="tab" :class="{active: pageState.type == 2}" @click="changeJobType(2)">实习实训</view>
          <view class="tab" :class="{active: pageState.type == 3}" @click="changeJobType(3)">社区实践</view>
        </view>
        <view class="titles">
          <view class="title-item" :class="{active: activeTitle == 1}" @click="activeTitle = 1,getJobRecommed()"><view>推荐岗位</view></view>
          <view class="title-item" :class="{active: activeTitle == 2}" @click="activeTitle = 2,getJobList()"><view>热门岗位</view></view>
        </view>
          <view v-for="(item, index) in jobList" :key="index" @click="nextDetail(item)" class="job-list">
          <view class="top-line">
            <view class="salary">{{item.minSalary}}-{{item.maxSalary}}/月</view>
            <view class="time"><uni-icons color="#A2A2A2" type="info" :size="uniIconSize"></uni-icons>发布日期：{{ item.postingDate }}</view>
          </view>
          <view class="title">{{ item.jobTitle }}</view>
          <view class="infos">
            <view>
              <dict-Label dictType="education" :value="item.education"></dict-Label>
            </view>
            <view>
              <dict-Label dictType="experience" :value="item.experience"></dict-Label>
            </view>
            <view>{{ item.jobLocation }}</view>
          </view>
          <view class="bottom-line">
            <view><uni-icons color="#A2A2A2" type="person" :size="uniIconSize"></uni-icons>{{item.vacancies}}人</view>
            <view>{{ item.companyName }}</view>
          </view>
        </view>
        
        <view class="view-more-btn" @click="viewMore">查看更多内容</view>

      </template>
      <template v-else>
        <view class="titles" style="justify-content: space-between;">
          <view class="title-item active"><view>政策专区</view></view>
          <view class="more-link" @click="toPolicyList">{{'查看更多 >'}}</view>
        </view>
        <view v-for="(item, index) in policyList" :key="index" class="job-list" @click="toPolicyDetail(item)">
          <view class="sign">推荐</view>
          <view class="title">
            <image src="../../../packageRc/static/zcLeft.png"/>
            {{item.zcmc}}</view>
          <view class="infos">
            <view v-if="item.zcLevel">{{item.zcLevel}}</view>
            <view v-if="item.sourceUnit">{{item.sourceUnit}}</view>
          </view>
          <view class="bottom-line">
            <view class="time"><uni-icons color="#A2A2A2" type="info" :size="uniIconSize"></uni-icons>发布日期：{{item.createTime}}</view>
            <view><uni-icons color="#A2A2A2" type="eye" :size="uniIconSize"></uni-icons>浏览量：{{item.viewNum || 0}}</view>
          </view>
        </view>
      </template>
    </view>
  </scroll-view>
  <!-- #endif -->
  <!-- #ifdef H5 -->
  <IndexYtj />
  <!-- #endif -->
</template>

<script setup>
import { reactive, inject, watch, ref, onMounted, watchEffect, nextTick } from 'vue';
const { $api, navTo, vacanciesTo, formatTotal, config } = inject('globalFunction');

const isH5 = ref(false);
const uniIconSize = ref(18);
// #ifdef H5
isH5.value = true;
uniIconSize.value = 20;
// #endif

import { getPolicyList } from '@/packageRc/apiRc/policy';
let policyList = ref([])
function getPolicy() {
  getPolicyList({pageNum: 1, pageSize: 10,zclx:'1'}).then(res => {
    policyList.value = res.rows
  })
}
let tabType = ref(1)
function changeType(type) {
  tabType.value = type
}
function toPolicyList() {
  navTo(`/packageRc/pages/policy/policyList?zclx=1`)
}
function toPolicyDetail(item) {
  navTo(`/packageRc/pages/policy/policyDetail?id=${item.id}`)
}
let activeTab = ref(1)
let activeTitle = ref(1)

function back() {
  uni.navigateBack({
    delta: 1
  })
}
onMounted(()=>{
  getJobRecommed()
  getPolicy();
})



function goCa(){
    if (checkLogin()) {
        const userInfo = uni.getStorageSync('userInfo')
		navTo(`/packageCa/search/search?userId=${userInfo.userId}&name=${userInfo.name}`);
    }
}
// 跳转AI智能面试
function goAiAu(){
    if (checkLogin()) {
        const userInfo = uni.getStorageSync('userInfo')
		navTo(`/packageCa/search/AIAudition?userId=${userInfo.userId}&name=${userInfo.name}`);
    }
}

function viewMore() {
    navTo(`/packageRc/pages/jobList/jobList`);
}
function tiao(){
  console.log('尝试导航到待办详情页面');
  // 尝试直接使用uni.navigateTo，使用正确的格式
  uni.navigateTo({
    url: `/packageRc/pages/needs/personNeeds`,
    success: function() {
      console.log('导航成功');
    },
    fail: function(err) {
      console.error('导航失败:', err);
    }
  });
}
import useUserStore from '@/stores/useUserStore';
const conditionSearch = ref({});
const pageState = reactive({
    page: 0,
    total: 0,
    maxPage: 2,
    pageSize: 10,
    search: {
        order: 0,
    },
    type:'',
});
let jobList = ref([])
// 获取推荐岗位
function getJobRecommed(){
    let params = {
      education: '3,4,5,6',
      pageSize: pageState.pageSize,
      sessionId: useUserStore().seesionId,
      ...pageState.search,
      ...conditionSearch.value,
      isPublish: 1,
      type:pageState.type
    };
    $api.createRequest('/app/job/recommend', params).then((resData) => {
        jobList.value = resData.data
        pageState.total = 0;
    });
}

// 获取岗位列表
function getJobList(){
  let params = {
    education: '3,4,5,6',
    current: pageState.page,
    pageSize: pageState.pageSize,
    ...pageState.search,
    // ...conditionSearch.value,
    type:pageState.type
  };
  $api.createRequest('/app/job/list', params).then((resData) => {
        jobList.value = resData.rows
        pageState.total = 0;
    });
}
// 更改实习实训等
function changeJobType(val){
  pageState.type = val
  if(activeTitle.value == 1){
    getJobRecommed()
  }else{
    getJobList()
  }
}
// 登录检查函数
import { storeToRefs } from 'pinia';
import IndexYtj from './indexYtj.vue';
const { userInfo, hasLogin, token } = storeToRefs(useUserStore());
const checkLogin = () => {
    const tokenValue = uni.getStorageSync('token') || '';
    if (!tokenValue || !hasLogin.value) {
        // 未登录，打开授权弹窗
        wxAuthLoginRef.value?.open();
        return false;
    }
    return true;
};
// 跳转到详情页面
function nextDetail(job) {
    // 登录检查
    if (checkLogin()) {
        navTo(`/packageA/pages/post/post?jobId=${encodeURIComponent(job.jobId)}&encryptJobId=${job.encryptJobId}`);
    }
}



</script>

<style lang="less" scoped>
/* 隐藏滚动条 */
::-webkit-scrollbar {
  display: none;
  width: 0 !important;
  height: 0 !important;
  -webkit-appearance: none;
  background: transparent;
}
view{box-sizing: border-box;display: block;}
.container{
  background-color: #F4F4F4;background-position: top center;background-size: 100% auto;
  height: 100vh;
  min-width: 100vw;
  padding-bottom: 0;
  background-repeat: no-repeat;
  box-sizing: border-box;
}
.kinggang{ 
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 16rpx 16rpx 32rpx 16rpx;
  font-size: 24rpx;
  background: #FFFFFF;
  border-radius: 16rpx;
  margin-bottom: 24rpx;
  >view{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
  }
  image{
    width: 78rpx;
    // margin-bottom: 15rpx;
    height: 78rpx;
  }
}
.tabs{
  margin-bottom: 29rpx;

	border-radius: 16rpx;
	display: flex;
	background: #fff;
	color: #878787;
	text-align: center;
	width: 100%;
	.tab{
		width: 50%;
		border: 4rpx solid transparent;
		border-radius: 16rpx;
		line-height: 64rpx;
		position: relative;
		&.active{
      border: 4rpx solid #fff;
			color: #fff;
			background: linear-gradient(180deg, #79AFFF 1%, #A2B3FE 100%);
      box-shadow: 0px 4rpx 10rpx 0px rgba(40, 102, 194, 0.4);
		}
	}
}
.titles{
  display: flex;
  margin-bottom: 44rpx;
  .title-item{
    font-size: 32rpx;
    font-weight: bold;
    color: #282828;
    margin-right: 32rpx;
    position: relative;
    >view{
      position: relative;
      z-index: 2;
      padding: 0 16rpx;
    }
    &.active::after{
      content: '';
      position: absolute;
      z-index: 1;
      bottom: -12rpx;
      left: 0;
      width: 120%;
      height: 24rpx;
      border-radius: 50px 0px 0px 50px;
      background: linear-gradient(90deg, #78AEFF 0%, rgba(120, 174, 255, 0.31) 52%, rgba(24, 116, 255, 0) 100%);
    }
  }
}
.job-list{
  width: 100%;
  margin: 0 auto;
  color: #333333;
  border-radius: 24rpx;
  background: #FFFFFF;
  padding: 32rpx;
  margin-bottom: 24rpx;
  position: relative;
  .sign{
    position: absolute;
    font-size: 28rpx;
    right: 0;
    top: 0;
    padding: 8rpx 20rpx;
    border: 1rpx solid #EC4827;
    background: rgba(227, 79, 49, 0.09);
    border-top-right-radius: 24rpx;
    border-bottom-left-radius: 24rpx;
    color: #EC4827;
  }
  .top-line{
    display: flex;
    justify-content: space-between;
    font-size: 24rpx;
    color: #A2A2A2;
    margin-bottom: 16rpx;
    .salary{
      font-size: 32rpx;
      color: #4C6EFB;
      font-weight: bold;
    }
  }
  .title{
    font-size: 32rpx;
    font-weight: bold;
    color: #282828;
    margin-bottom: 16rpx;
    display: flex;
    image{
      width: 46rpx;
      height: 46rpx;
      margin-right: 11rpx;
    }
  }
  .infos{
    display: flex;
    flex-wrap: wrap;
    font-size: 24rpx;
    margin-bottom: 16rpx;
    line-height: 42rpx;
    view{
      padding: 0 16rpx;
      margin-right: 10rpx;
      background: #F2F2F2;
    }
  }
  .bottom-line{
    display: flex;
    justify-content: space-between;
    font-size: 24rpx;
    color: #A2A2A2;
    margin-top: 12rpx;
  }
}
.view-more-btn{ 
  padding: 10rpx 56rpx;
  background: #FFFFFF;
  color: #4C6EFB;
  border: 1rpx solid #4C6EFB;
  text-align: center;
  border-radius: 40rpx;
  width: fit-content;
  margin: 0 auto;
  margin-bottom: 20rpx;
}
.showtab{
  display: flex;
  justify-content: space-between;
  margin-bottom: 40rpx;
  .tabItem{
    position: relative;
    width: calc(50% - 8rpx);
    height: 144rpx;
  }
  .activeImg{
    position: absolute;
    width: 143rpx;
    height: 18rpx;
    bottom: -24rpx;
    right: 50%;
    transform: translateX(50%);
  }
}

/* #ifdef H5 */
.h5-pc-container {
  & > view {
    width: 100% !important;
    margin: 0 auto !important;
    padding-left: 32px !important;
    padding-right: 32px !important;
    padding-top: 0 !important; /* 彻底移除顶部补白 */
    box-sizing: border-box !important;
  }

  .showtab {
    margin-top: 0 !important; /* 移除卡片顶部间距 */
    margin-bottom: 120rpx;
    height: 340rpx;
    .tabItem {
      height: 340rpx !important;
      image:first-child {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
    }
    .activeImg {
      width: 160rpx !important;
      height: 20rpx !important;
      bottom: -40rpx !important;
    }
  }

  .tabs {
    margin-bottom: 80rpx;
    height: 120rpx;
    border-radius: 20rpx !important;
    background: #f8faff !important;
    box-shadow: 0px 4rpx 15rpx rgba(0, 0, 0, 0.04);
    .tab {
      width: 33.3% !important;
      line-height: 120rpx !important;
      font-size: 20px !important;
      border-radius: 16rpx !important;
    }
  }

  .titles {
    margin-top: 40rpx;
    margin-bottom: 60rpx;
    .title-item {
      font-size: 24px !important;
      font-weight: 600;
      margin-right: 100rpx !important;
      >view {
        padding: 0 16rpx !important;
      }
      &::after {
        height: 24rpx !important;
        bottom: -12rpx !important;
        width: 110% !important;
      }
    }
    .more-link {
       font-size: 20px !important;
       color: #A2A2A2;
    }
  }

  .job-list {
    padding: 48rpx 40rpx !important;
    margin-bottom: 32rpx !important;
    border-radius: 24rpx !important;
    border: 1px solid #f0f0f0;
    box-shadow: 0px 2rpx 10rpx rgba(0, 0, 0, 0.02);
    .sign {
      font-size: 20px !important;
      padding: 8rpx 20rpx !important;
    }
  }

  .title {
    font-size: 24px !important;
    font-weight: 600;
    margin-bottom: 24rpx !important;
  }
  .infos view {
    font-size: 20px !important;
    line-height: 1.5 !important;
    padding: 10rpx 24rpx !important;
    margin-bottom: 12rpx;
    background: #f5f5f5 !important;
    border-radius: 12rpx !important;
  }
  .salary {
    font-size: 24px !important;
    font-weight: 600;
  }
  .time {
    font-size: 20px !important; /* 发布日期字号放大 */
  }
  .bottom-line {
    font-size: 20px !important;
    margin-top: 20rpx !important;
  }
  .view-more-btn {
    font-size: 24px !important; /* 查看更多字号放大 */
    padding: 20rpx 80rpx !important;
    border-radius: 60rpx !important;
  }
}
/* #endif */
</style>