企业收藏功能开发

This commit is contained in:
FengHui
2026-02-09 12:25:43 +08:00
parent 4261ecafbc
commit b84fa36e20

View File

@@ -1,16 +1,11 @@
<template>
<AppLayout title="" :use-scroll-view="false">
<AppLayout title="单位详情" :use-scroll-view="false">
<template #headerleft>
<view class="btnback">
<image src="@/static/icon/back.png" @click="navBack"></image>
</view>
</template>
<template #headerright>
<view class="btn mar_ri10">
<image src="@/static/icon/collect3.png" v-if="!companyInfo?.isCollection"></image>
<image src="@/static/icon/collect2.png" v-else></image>
</view>
</template>
<view class="content">
<view class="content-top">
<view class="companyinfo-left">
@@ -22,6 +17,10 @@
{{ getScaleLabel(companyInfo?.scale) }}
</view>
</view>
<view class="companyinfo-collect" @click="toggleCollection">
<image src="@/static/icon/collect3.png" v-if="!companyInfo?.isCollection"></image>
<image src="@/static/icon/collect2.png" v-else></image>
</view>
</view>
<view class="conetent-info" :class="{ expanded: isExpanded }">
<view class="info-title">公司介绍</view>
@@ -372,6 +371,37 @@
navTo(`/packageA/pages/post/post?jobId=${encodeURIComponent(jobId)}`);
}
}
// 收藏和取消收藏企业
function toggleCollection() {
const companyId = companyInfo.value.id || companyInfo.value.companyId;
if (!companyId) {
$api.msg('获取公司信息失败,无法操作');
return;
}
const isCollection = companyInfo.value.isCollection;
const method = isCollection ? 'DELETE' : 'POST';
const apiUrl = `/app/company/collection/${companyId}`;
uni.showLoading({
title: '操作中'
});
$api.createRequest(apiUrl, {}, method).then((resData) => {
uni.hideLoading();
if (resData && resData.code === 200) {
companyInfo.value.isCollection = !isCollection;
$api.msg(isCollection ? '取消收藏成功' : '收藏成功');
} else {
$api.msg((resData && resData.msg) || (isCollection ? '取消收藏失败' : '收藏失败'));
}
}).catch((error) => {
uni.hideLoading();
console.error('API error when toggling collection:', error);
$api.msg('网络请求失败,请检查网络连接');
});
}
</script>
<style lang="stylus" scoped>
@@ -399,33 +429,47 @@
flex-direction: column;
.content-top {
padding: 28rpx;
padding-top: 50rpx;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
padding: 28rpx;
padding-top: 50rpx;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
.companyinfo-left {
width: 96rpx;
height: 96rpx;
margin-right: 24rpx;
}
.companyinfo-right {
.row1 {
font-weight: 500;
font-size: 32rpx;
color: #333333;
.companyinfo-left {
width: 96rpx;
height: 96rpx;
margin-right: 24rpx;
}
.row2 {
font-weight: 400;
font-size: 28rpx;
color: #6C7282;
line-height: 45rpx;
.companyinfo-right {
flex: 1;
.row1 {
font-weight: 500;
font-size: 32rpx;
color: #333333;
}
.row2 {
font-weight: 400;
font-size: 28rpx;
color: #6C7282;
line-height: 45rpx;
}
}
.companyinfo-collect {
width: 52rpx;
height: 52rpx;
margin-left: 20rpx;
image {
width: 100%;
height: 100%;
}
}
}
}
.conetent-info {
padding: 0 28rpx;