position.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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: 'https://minio.menduner.com/dev/89f171b91e3056a700d80b26a9dbb4cd6e9677b3f3b4f036a2127f5d5023e9d3.jpg'
  92. }
  93. })
  94. onShareTimeline(() => {
  95. return {
  96. title: '门墩儿 专注顶尖招聘',
  97. path: '/pages/index/position',
  98. imageUrl: 'https://minio.menduner.com/dev/89f171b91e3056a700d80b26a9dbb4cd6e9677b3f3b4f036a2127f5d5023e9d3.jpg'
  99. }
  100. })
  101. if (!uni.getStorageSync('token')) getRewardEventList()
  102. })
  103. const more = ref('more')
  104. const total = ref(0)
  105. // 轮播图-优选集团信息
  106. const preferredGroup = ref({})
  107. // 获取轮播图
  108. const showAdvertisePop = ref(false)
  109. const swiperAdList = ref([])
  110. const getSystemWebContent = async () => {
  111. const { data } = await getWebContent()
  112. swiperAdList.value = data?.appHomeCarousel || []
  113. // 是否展示弹窗广告
  114. showAdvertisePop.value = data && data.appAdvertisement && data.appAdvertisement.length ? true : false
  115. // 优选集团
  116. preferredGroup.value = data?.appPreferredGroup || {}
  117. }
  118. const filterList = ref([
  119. { label: '城市', multiple: true, dictType: 'areaTreeData', key: 'areaIds', map: { text: 'name', value: 'id' } },
  120. { label: '职位', dictType: 'positionTreeData',key: 'positionId', map: { text: 'nameCn', value: 'id' } },
  121. { label: '求职类型', dictType: 'menduner_job_type', key: 'jobType' },
  122. { label: '薪资待遇', dictType: 'menduner_pay_scope', key: 'payScope' },
  123. ])
  124. const gridList = [
  125. { label: '门墩儿猎头', icon: 'https://minio.menduner.com/dev/05655df27929e1420a78d6c97fa3747e17f0cdbd57ae9f816550d498ccf74a7d.png', path: '/pagesB/headhunting/index' },
  126. { label: '精选企业', icon: 'https://minio.menduner.com/dev/0b107bc7b6f48d689a2fff9807c43bfe5e09e4de0858ca6fe69bbc8219681901.png', path: '/pagesB/recommendEnterprise/index' },
  127. { label: '酒店英语', icon: 'https://minio.menduner.com/dev/b9c388263ada5ab63f901a2bf27adabc2660664660cb5898cf0bbc3f7416c510.png', weiXinPublicUrl: 'https://mp.weixin.qq.com/s/zta8NvNaJOFhPxq9NAE9pw' },
  128. // { label: '早报资讯', icon: 'https://minio.menduner.com/dev/b598bf9c973161e090d784ca2df6f7784593d972ce015c475d1c6dcb108c9610.png', id: 'morningNews' },
  129. { label: '招聘会', icon: 'https://minio.menduner.com/dev/b598bf9c973161e090d784ca2df6f7784593d972ce015c475d1c6dcb108c9610.png', path: '/pages/index/jobFair' },
  130. { label: '了解门墩儿', icon: 'https://minio.menduner.com/dev/028e33e10569238d6f78bd89668f6387f8af60503b71639491e1640e53614411.png', path: '/pagesB/about/index' }
  131. ]
  132. // 轮播图链接跳转
  133. const handleToDetails = ({ link, title }) => {
  134. if (!link) return
  135. // 公众号链接跳转
  136. if (link.includes('http')) uni.navigateTo({ url: `/pages/addWebView/index?url=${link}&title=${title || '门墩儿 专注顶尖招聘'}` })
  137. else {
  138. // 优选集团
  139. if (preferredGroup.value && Object.keys(preferredGroup.value).length > 0 && preferredGroup.value[link]) uni.navigateTo({ url: `/pagesB/preferredGroup/index?id=${link}` })
  140. // 企业详情
  141. else uni.navigateTo({ url: `/pagesB/companyDetail/index?id=${link}` })
  142. }
  143. }
  144. const handleGrid = async (e) => {
  145. const index = e.detail.index
  146. const obj = gridList[index]
  147. // 早报资讯
  148. if (obj?.id === 'morningNews') {
  149. try {
  150. const { data } = await getMorningNewsArticle()
  151. if (data && Object.keys(data).length && data.url) {
  152. uni.navigateTo({
  153. url: `/pages/addWebView/index?url=${data.url}&title=门墩儿早报`
  154. })
  155. } else uni.showToast({ icon: 'none', title: '暂无早报资讯内容' })
  156. } catch (err) {
  157. uni.showToast({ icon: 'none', title: err.msg })
  158. }
  159. }
  160. if (obj?.path) {
  161. if (obj?.path === '/pages/index/jobFair') {
  162. uni.switchTab({
  163. url: obj?.path
  164. })
  165. return
  166. }
  167. uni.navigateTo({
  168. url: obj.path
  169. })
  170. }
  171. if (obj?.weiXinPublicUrl) {
  172. uni.navigateTo({ url: `/pages/addWebView/index?url=${obj?.weiXinPublicUrl}&title=${obj?.title || obj.label}` })
  173. }
  174. }
  175. const checkValue = (obj) => {
  176. return Object.values(obj).some(value => {
  177. return value !== null && value !== undefined && value !== '' && (Array.isArray(value) ? value.length > 0 : true)
  178. })
  179. }
  180. const type = ref('recommend')
  181. const positionListData = ref([])
  182. const query = reactive({
  183. pageSize: 20,
  184. pageNo: 1,
  185. hire: false,
  186. content: '',
  187. positionId: '',
  188. areaIds: [],
  189. industryIds: [],
  190. jobType: [],
  191. payScope: ''
  192. })
  193. const getData = async () => {
  194. // 效验是否有带搜索条件
  195. const { content, areaIds, industryIds, jobType, payScope, positionId } = query
  196. const hasValue = checkValue({ content, areaIds, industryIds, jobType, payScope, positionId })
  197. // 当前接口为推荐列表时,带查询条件需返回到列表顶部
  198. if (hasValue && type.value === 'recommend') {
  199. scrollTop.value = old.value.scrollTop
  200. nextTick(() => {
  201. type.value = 'position'
  202. scrollTop.value = 0
  203. })
  204. }
  205. // 当前接口为只为列表时,清除查询条件需返回到列表顶部
  206. if (!hasValue && type.value === 'position') {
  207. scrollTop.value = old.value.scrollTop
  208. nextTick(() => {
  209. type.value = 'recommend'
  210. scrollTop.value = 0
  211. })
  212. }
  213. // 带搜索条件(除分页外)用职位搜索接口,无条件则用推荐接口
  214. const api = hasValue ? getJobAdvertisedSearch : getPromotedPosition
  215. const _query = Object.keys(query).reduce((acc, cur) => {
  216. if (!query[cur]) {
  217. return acc
  218. }
  219. acc[cur] = query[cur]
  220. return acc
  221. }, {})
  222. const params = hasValue ? _query : { pageSize: query.pageSize, pageNo: query.pageNo, hire: 0 }
  223. if (params.pageNo === 1) positionListData.value = []
  224. if (params.pageNo <= 0) return
  225. type.value = hasValue ? 'position' : 'recommend'
  226. try {
  227. more.value = 'loading'
  228. const res = await api(params)
  229. const arr = res?.data?.list || []
  230. if (!arr?.length) {
  231. more.value = 'noMore'
  232. return
  233. }
  234. // 推荐接口返回数据需要拼接
  235. const list = !hasValue ? arr.map(e => {
  236. const { anotherName, logoUrl, scale, industryId, enterpriseId, enterpriseName, ...job } = e
  237. return { job, enterprise: { anotherName, logoUrl, scale, industryId, enterpriseId, name: enterpriseName } }
  238. }) : arr
  239. positionListData.value.push(...list.map(e => {
  240. if (!e) {
  241. return e
  242. }
  243. e.job = { ...e.job, ...dealDictObjData({}, e.job) }
  244. e.enterprise = { ...e.enterprise, ...dealDictObjData({}, e.enterprise)}
  245. return e
  246. }))
  247. total.value = res?.data?.total || 0
  248. if (positionListData.value.length === total.value) {
  249. more.value = 'noMore'
  250. return
  251. }
  252. } catch (error) {
  253. query.pageNo--
  254. more.value = 'more'
  255. }
  256. }
  257. // 设置自定义tabbar选中值
  258. onShow(() => {
  259. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  260. const currentTabBar = currentPage?.getTabBar?.();
  261. // 设置当前tab页的下标index
  262. currentTabBar?.setData({ selected: 0 });
  263. getSystemWebContent()
  264. getData()
  265. })
  266. const scrollTop = ref(0)
  267. const old = ref({
  268. scrollTop: 0
  269. })
  270. const onScroll = (e) =>{
  271. old.value.scrollTop = e.detail.scrollTop
  272. }
  273. const handleSearch = (key, value) => {
  274. query[key] = value
  275. onSearch()
  276. }
  277. const onSearch = () => {
  278. query.pageNo = 1
  279. positionListData.value = []
  280. getData()
  281. }
  282. // 加载更多
  283. const loadingMore = () => {
  284. if (total.value <= 0) return
  285. more.value = 'loading'
  286. query.pageNo++
  287. getData()
  288. }
  289. </script>
  290. <style scoped lang="scss">
  291. .stick {
  292. z-index: 1;
  293. position: sticky;
  294. top: 0;
  295. }
  296. .stickFilter {
  297. z-index: 1;
  298. position: sticky;
  299. box-shadow: 0px 10rpx 12rpx 0px rgba(195, 195, 195, .25);
  300. top: 110rpx;
  301. background-color: #fff;
  302. }
  303. .px-0 { padding-left: 0 !important; padding-right: 0 !important; }
  304. .pb-10 {
  305. padding-bottom: 10px;
  306. }
  307. .pb-20 { padding-bottom: 20px; }
  308. .px-5 { padding-left: 5px; padding-right: 5px; }
  309. .px-10 { padding-left: 10px; padding-right: 10px; }
  310. .mx-10 { margin-left: 10px; margin-right: 10px }
  311. .mx-20 { margin-left: 20px; margin-right: 20px; }
  312. .mb-10 { margin-bottom: 10px; }
  313. .box {
  314. height: 100vh;
  315. overflow: hidden;
  316. padding-bottom: 120rpx;
  317. box-sizing: border-box;
  318. display: flex;
  319. flex-direction: column;
  320. }
  321. .grid-item-text {
  322. font-family: MiSans, MiSans;
  323. font-weight: 400;
  324. font-size: 24rpx;
  325. color: #0E100F;
  326. font-style: normal;
  327. text-transform: none;
  328. }
  329. .scrollBox{
  330. flex: 1;
  331. height: 0 !important;
  332. padding-bottom: 24rpx;
  333. box-sizing: border-box;
  334. }
  335. :deep(.uni-searchbar__box) {
  336. width: 100%;
  337. height: 80rpx !important;
  338. border: 1px solid #00B760;
  339. border-radius: 20rpx;
  340. flex: none;
  341. }
  342. .search-btn {
  343. position: absolute;
  344. right: 30rpx;
  345. top: 50%;
  346. transform: translateY(-50%);
  347. width: 100rxp;
  348. height: 60rpx;
  349. font-size: 24rpx;
  350. background-color: #00B760;
  351. color: #fff;
  352. border-radius: 20rpx;
  353. z-index: 9;
  354. }
  355. :deep(.picker-view) {
  356. padding-bottom: 80px !important;
  357. }
  358. </style>