position.vue 11 KB

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