position.vue 11 KB

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