position.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <view>
  3. <Navbar :showLogo="true" />
  4. <view class="box defaultBgc" :style="{'padding-top': navbarHeight + 'px'}">
  5. <scroll-view class="scrollBox" :scroll-y="true" :scroll-top="scrollTop" @scrolltolower="loadingMore" @scroll="onScroll" style="position:relative;">
  6. <view>
  7. <view class="commonBackground">
  8. <SwiperAd v-if="swiperAdList.length" margin="0 10px 10px 10px" :list="swiperAdList" imgUrlKey="img" :strType="false" @click="handleToDetails"></SwiperAd>
  9. </view>
  10. <!-- 五宫格菜单 -->
  11. <view>
  12. <uni-grid :column="5" @change="handleGrid" :showBorder="false">
  13. <uni-grid-item v-for="(val, index) in gridList" :index="index" :key="index">
  14. <view class="d-flex align-center flex-column justify-center" style="width: 100%; height: 100%; border: none;">
  15. <image :src="val.icon" style="width: 45px; height: 45px;"></image>
  16. <text class="grid-item-text MiSans-Normal">{{ val.label }}</text>
  17. </view>
  18. </uni-grid-item>
  19. </uni-grid>
  20. </view>
  21. <!-- 搜索条 -->
  22. <view class="whiteBgc stick">
  23. <view style="position: relative;">
  24. <uni-search-bar
  25. v-model="query.content"
  26. placeholder="输入职位/公司关键字"
  27. cancelButton="none"
  28. :focus="false"
  29. bgColor="#fbfffe"
  30. @confirm="onSearch($event.value)"
  31. @clear="query.content = ''; onSearch()"
  32. >
  33. <template v-slot:searchIcon>
  34. <uni-icons color="#0E100F" size="18" type="search" />
  35. </template>
  36. </uni-search-bar>
  37. <button class="search-btn MiSans-Medium" @tap.stop="onSearch">搜索</button>
  38. </view>
  39. </view>
  40. <view class="px-10 stickFilter ss-p-b-10">
  41. <FilterList :list="filterList" idValue="label" @change="handleSearch"></FilterList>
  42. </view>
  43. <view style="background-color: #fff;">
  44. <PositionList v-if="positionListData?.length || more !== 'loading'" :list="positionListData" :noMore="false"></PositionList>
  45. <uni-load-more :status="more" />
  46. </view>
  47. </view>
  48. </scroll-view>
  49. <AdvertisePop v-if="showAdvertisePop" />
  50. </view>
  51. </view>
  52. </template>
  53. <script setup>
  54. import { ref, reactive, nextTick, onMounted } from 'vue'
  55. import SwiperAd from '@/components/SwiperAd'
  56. import FilterList from '@/components/FilterList'
  57. import PositionList from '@/components/PositionList'
  58. import AdvertisePop from '@/components/Advertisement'
  59. import { dealDictObjData } from '@/utils/position'
  60. import { getJobAdvertisedSearch, getPromotedPosition } from '@/api/position'
  61. import { onShow, onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
  62. import Navbar from '@/components/Navbar'
  63. import { getRewardEventList } from '@/utils/eventList'
  64. import { getMorningNewsArticle } from '@/api/content'
  65. import { getWebContent } from '@/api/common'
  66. const navbarHeight = ref(0)
  67. onMounted(async () => {
  68. try {
  69. const res = await new Promise((resolve, reject) => {
  70. uni.getStorage({
  71. key: 'navbarHeight',
  72. success: (result) => resolve(result),
  73. fail: (err) => reject(err)
  74. })
  75. })
  76. navbarHeight.value = res.data
  77. console.log(navbarHeight.value, '职位列表-导航栏高度')
  78. } catch (error) {
  79. console.error('读取本地缓存出错:', error)
  80. }
  81. })
  82. onLoad(() => {
  83. wx.showShareMenu({
  84. withShareTicket: true,
  85. menus: ['shareAppMessage', 'shareTimeline']
  86. })
  87. onShareAppMessage(() => {
  88. return {
  89. title: '门墩儿 专注顶尖招聘',
  90. path: '/pages/index/position',
  91. imageUrl: '../../static/img/share-poster.jpg'
  92. }
  93. })
  94. onShareTimeline(() => {
  95. return {
  96. title: '门墩儿 专注顶尖招聘',
  97. path: '/pages/index/position',
  98. imageUrl: '../../static/img/share-poster.jpg'
  99. }
  100. })
  101. if (!uni.getStorageSync('token')) getRewardEventList()
  102. })
  103. const more = ref('more')
  104. // 轮播图-优选集团信息
  105. const preferredGroup = ref({})
  106. // 获取轮播图
  107. const showAdvertisePop = ref(false)
  108. const swiperAdList = ref([])
  109. const getSystemWebContent = async () => {
  110. const { data } = await getWebContent()
  111. swiperAdList.value = data?.appHomeCarousel || []
  112. // 是否展示弹窗广告
  113. showAdvertisePop.value = data && data.appAdvertisement && data.appAdvertisement.length ? true : false
  114. // 优选集团
  115. preferredGroup.value = data?.appPreferredGroup || {}
  116. }
  117. const filterList = ref([
  118. { label: '城市', multiple: true, dictType: 'areaTreeData', key: 'areaIds', map: { text: 'name', value: 'id' } },
  119. { label: '职位', dictType: 'positionTreeData',key: 'positionId', map: { text: 'nameCn', value: 'id' } },
  120. { label: '求职类型', dictType: 'menduner_job_type', key: 'jobType' },
  121. { label: '薪资待遇', dictType: 'menduner_pay_scope', key: 'payScope' },
  122. ])
  123. const gridList = [
  124. { label: '门墩儿猎头', icon: '/static/img/headhunting.png', path: '/pagesB/headhunting/index' },
  125. { label: '精选企业', icon: '/static/img/enterprise.png', path: '/pagesB/recommendEnterprise/index' },
  126. { label: '酒店英语', icon: '/static/img/group.png', weiXinPublicUrl: 'https://mp.weixin.qq.com/s/zta8NvNaJOFhPxq9NAE9pw' },
  127. // { label: '早报资讯', icon: '/static/img/information.png', id: 'morningNews' },
  128. { label: '招聘会', icon: '/static/img/information.png', path: '/pages/index/jobFair' },
  129. { label: '了解门墩儿', icon: '/static/img/contact.png', path: '/pagesB/about/index' }
  130. ]
  131. // 轮播图链接跳转
  132. const handleToDetails = ({ link, title }) => {
  133. if (!link) return
  134. // 公众号链接跳转
  135. if (link.includes('http')) uni.navigateTo({ url: `/pages/addWebView/index?url=${link}&title=${title || '门墩儿 专注顶尖招聘'}` })
  136. else {
  137. // 优选集团
  138. if (preferredGroup.value && Object.keys(preferredGroup.value).length > 0 && preferredGroup.value[link]) uni.navigateTo({ url: `/pagesB/preferredGroup/index?id=${link}` })
  139. // 企业详情
  140. else uni.navigateTo({ url: `/pagesB/companyDetail/index?id=${link}` })
  141. }
  142. }
  143. const handleGrid = async (e) => {
  144. const index = e.detail.index
  145. const obj = gridList[index]
  146. // 早报资讯
  147. if (obj?.id === 'morningNews') {
  148. try {
  149. const { data } = await getMorningNewsArticle()
  150. if (data && Object.keys(data).length && data.url) {
  151. uni.navigateTo({
  152. url: `/pages/addWebView/index?url=${data.url}&title=门墩儿早报`
  153. })
  154. } else uni.showToast({ icon: 'none', title: '暂无早报资讯内容' })
  155. } catch (err) {
  156. uni.showToast({ icon: 'none', title: err.msg })
  157. }
  158. }
  159. if (obj?.path) {
  160. if (obj?.path === '/pages/index/jobFair') {
  161. uni.switchTab({
  162. url: obj?.path
  163. })
  164. return
  165. }
  166. uni.navigateTo({
  167. url: obj.path
  168. })
  169. }
  170. if (obj?.weiXinPublicUrl) {
  171. uni.navigateTo({ url: `/pages/addWebView/index?url=${obj?.weiXinPublicUrl}&title=${obj?.title || obj.label}` })
  172. }
  173. }
  174. const checkValue = (obj) => {
  175. return Object.values(obj).some(value => {
  176. return value !== null && value !== undefined && value !== '' && (Array.isArray(value) ? value.length > 0 : true)
  177. })
  178. }
  179. const type = ref('recommend')
  180. const positionListData = ref([])
  181. const query = reactive({
  182. pageSize: 20,
  183. pageNo: 1,
  184. hire: false,
  185. content: '',
  186. positionId: '',
  187. areaIds: [],
  188. industryIds: [],
  189. jobType: [],
  190. payScope: ''
  191. })
  192. const getData = async () => {
  193. // 效验是否有带搜索条件
  194. const { content, areaIds, industryIds, jobType, payScope, positionId } = query
  195. const hasValue = checkValue({ content, areaIds, industryIds, jobType, payScope, positionId })
  196. // 当前接口为推荐列表时,带查询条件需返回到列表顶部
  197. if (hasValue && type.value === 'recommend') {
  198. scrollTop.value = old.value.scrollTop
  199. nextTick(() => {
  200. type.value = 'position'
  201. scrollTop.value = 0
  202. })
  203. }
  204. // 当前接口为只为列表时,清除查询条件需返回到列表顶部
  205. if (!hasValue && type.value === 'position') {
  206. scrollTop.value = old.value.scrollTop
  207. nextTick(() => {
  208. type.value = 'recommend'
  209. scrollTop.value = 0
  210. })
  211. }
  212. // 带搜索条件(除分页外)用职位搜索接口,无条件则用推荐接口
  213. const api = hasValue ? getJobAdvertisedSearch : getPromotedPosition
  214. const _query = Object.keys(query).reduce((acc, cur) => {
  215. if (!query[cur]) {
  216. return acc
  217. }
  218. acc[cur] = query[cur]
  219. return acc
  220. }, {})
  221. const params = hasValue ? _query : { pageSize: query.pageSize, pageNo: query.pageNo, hire: 0 }
  222. if (params.pageNo === 1) positionListData.value = []
  223. if (params.pageNo <= 0) return
  224. type.value = hasValue ? 'position' : 'recommend'
  225. try {
  226. more.value = 'loading'
  227. const res = await api(params)
  228. const arr = res?.data?.list || []
  229. if (!arr?.length) {
  230. more.value = 'noMore'
  231. return
  232. }
  233. // 推荐接口返回数据需要拼接
  234. const list = !hasValue ? arr.map(e => {
  235. const { anotherName, logoUrl, scale, industryId, enterpriseId, enterpriseName, ...job } = e
  236. return { job, enterprise: { anotherName, logoUrl, scale, industryId, enterpriseId, name: enterpriseName } }
  237. }) : arr
  238. positionListData.value.push(...list.map(e => {
  239. if (!e) {
  240. return e
  241. }
  242. e.job = { ...e.job, ...dealDictObjData({}, e.job) }
  243. e.enterprise = { ...e.enterprise, ...dealDictObjData({}, e.enterprise)}
  244. return e
  245. }))
  246. if (positionListData.value.length === +res.data.total) {
  247. more.value = 'noMore'
  248. return
  249. }
  250. } catch (error) {
  251. query.pageNo--
  252. more.value = 'more'
  253. }
  254. }
  255. // 设置自定义tabbar选中值
  256. onShow(() => {
  257. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  258. const currentTabBar = currentPage?.getTabBar?.();
  259. // 设置当前tab页的下标index
  260. currentTabBar?.setData({ selected: 0 });
  261. getSystemWebContent()
  262. getData()
  263. })
  264. const scrollTop = ref(0)
  265. const old = ref({
  266. scrollTop: 0
  267. })
  268. const onScroll = (e) =>{
  269. old.value.scrollTop = e.detail.scrollTop
  270. }
  271. const handleSearch = (key, value) => {
  272. query[key] = value
  273. onSearch()
  274. }
  275. const onSearch = () => {
  276. query.pageNo = 1
  277. positionListData.value = []
  278. getData()
  279. }
  280. // 加载更多
  281. const loadingMore = () => {
  282. more.value = 'loading'
  283. query.pageNo++
  284. getData()
  285. }
  286. </script>
  287. <style scoped lang="scss">
  288. .stick {
  289. z-index: 1;
  290. position: sticky;
  291. top: 0;
  292. }
  293. .stickFilter {
  294. z-index: 1;
  295. position: sticky;
  296. box-shadow: 0px 10rpx 12rpx 0px rgba(195, 195, 195, .25);
  297. top: 110rpx;
  298. background-color: #fff;
  299. }
  300. .px-0 { padding-left: 0 !important; padding-right: 0 !important; }
  301. .pb-10 {
  302. padding-bottom: 10px;
  303. }
  304. .pb-20 { padding-bottom: 20px; }
  305. .px-5 { padding-left: 5px; padding-right: 5px; }
  306. .px-10 { padding-left: 10px; padding-right: 10px; }
  307. .mx-10 { margin-left: 10px; margin-right: 10px }
  308. .mx-20 { margin-left: 20px; margin-right: 20px; }
  309. .mb-10 { margin-bottom: 10px; }
  310. .box {
  311. height: 100vh;
  312. overflow: hidden;
  313. padding-bottom: 120rpx;
  314. box-sizing: border-box;
  315. display: flex;
  316. flex-direction: column;
  317. }
  318. .grid-item-text {
  319. font-family: MiSans, MiSans;
  320. font-weight: 400;
  321. font-size: 24rpx;
  322. color: #0E100F;
  323. font-style: normal;
  324. text-transform: none;
  325. }
  326. .scrollBox{
  327. flex: 1;
  328. height: 0 !important;
  329. padding-bottom: 24rpx;
  330. box-sizing: border-box;
  331. }
  332. :deep(.uni-searchbar__box) {
  333. width: 100%;
  334. height: 80rpx !important;
  335. border: 1px solid #00B760;
  336. border-radius: 20rpx;
  337. flex: none;
  338. }
  339. .search-btn {
  340. position: absolute;
  341. right: 30rpx;
  342. top: 50%;
  343. transform: translateY(-50%);
  344. width: 100rxp;
  345. height: 60rpx;
  346. font-size: 24rpx;
  347. background-color: #00B760;
  348. color: #fff;
  349. border-radius: 20rpx;
  350. z-index: 9;
  351. }
  352. :deep(.picker-view) {
  353. padding-bottom: 80px !important;
  354. }
  355. </style>