position.vue 11 KB

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