主包体积太大,相关代码迁移

This commit is contained in:
francis-fh
2026-06-06 19:14:01 +08:00
parent 087c686d81
commit b4ff618477
104 changed files with 7336 additions and 8973 deletions

View File

@@ -0,0 +1,363 @@
<template>
<AppLayout back-gorund-color="#F4F4F4">
<!-- 编辑头像 -->
<view class="avatar-section btn-feel" @click="editAvatar">
<view class="avatar-label">编辑信息</view>
<view class="avatar-container">
<image class="company-avatar" :src="companyInfo.avatar || '/static/imgs/avatar.jpg'"></image>
<!-- <uni-icons color="#A2A2A2" type="right" size="16"></uni-icons> -->
</view>
</view>
<!-- 企业详细信息 -->
<view class="info-section">
<view class="info-item btn-feel" @click="editInfo('name')">
<view class="info-label">企业名称</view>
<view class="info-content">
<text class="info-value">{{ companyInfo.name || '暂无公司名称' }}</text>
<!-- <uni-icons color="#A2A2A2" type="right" size="16"></uni-icons> -->
</view>
</view>
<view class="info-item btn-feel" @click="editInfo('code')">
<view class="info-label">统一社会代码</view>
<view class="info-content">
<text class="info-value">{{ companyInfo.socialCode || '暂无统一社会代码' }}</text>
<!-- <uni-icons color="#A2A2A2" type="right" size="16"></uni-icons> -->
</view>
</view>
<view class="info-item btn-feel" @click="editInfo('location')">
<view class="info-label">企业注册地点</view>
<view class="info-content">
<text class="info-value">{{ companyInfo.location || '暂无注册地点' }}</text>
<!-- <uni-icons color="#A2A2A2" type="right" size="16"></uni-icons> -->
</view>
</view>
<view class="info-item btn-feel" @click="editInfo('description')">
<view class="info-label">企业信息介绍</view>
<view class="info-content">
<text class="info-value">{{ companyInfo.description || '暂无企业介绍' }}</text>
<!-- <uni-icons color="#A2A2A2" type="right" size="16"></uni-icons> -->
</view>
</view>
<view class="info-item btn-feel" @click="editInfo('legalPerson')">
<view class="info-label">企业法人姓名</view>
<view class="info-content">
<text class="info-value">{{ companyInfo.legalPerson || '暂无法人信息' }}</text>
<!-- <uni-icons color="#A2A2A2" type="right" size="16"></uni-icons> -->
</view>
</view>
<!-- 企业联系人管理 -->
<view class="contact-management-section">
<view class="contact-section-header">
<view class="contact-section-title">企业联系人</view>
<view class="edit-contacts-btn btn-feel" @click="editContacts">
<uni-icons type="compose" size="16" color="#256BFA"></uni-icons>
<text class="edit-text">编辑联系人</text>
</view>
</view>
<!-- 联系人列表展示 -->
<view v-for="(contact, index) in companyInfo.companyContactList" :key="contact.id || index" class="contact-display-item">
<view class="contact-display-title">联系人{{ index + 1 }}</view>
<view class="contact-display-content">
<view class="contact-field">
<text class="field-label">姓名</text>
<text class="field-value">{{ contact.contactPerson || '暂无' }}</text>
</view>
<view class="contact-field">
<text class="field-label">电话</text>
<text class="field-value">{{ contact.contactPersonPhone || '暂无' }}</text>
</view>
</view>
</view>
<!-- 如果没有联系人显示提示 -->
<view v-if="!companyInfo.companyContactList || companyInfo.companyContactList.length === 0" class="no-contacts">
<text class="no-contacts-text">暂无联系人信息</text>
</view>
</view>
</view>
</AppLayout>
</template>
<script setup>
import { reactive, inject, onMounted } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import AppLayout from '@/components/AppLayout/AppLayout.vue';
const { $api, navTo } = inject('globalFunction');
// 企业信息数据
const companyInfo = reactive({
name: '',
avatar: '/static/imgs/avatar.jpg',
completeness: '65%',
socialCode: '',
location: '',
description: '',
legalPerson: '',
companyContactList: [], // 企业联系人列表
isVerified: false // 实名状态
});
function editAvatar() {
// 编辑头像逻辑
// uni.chooseImage({
// count: 1,
// success: (res) => {
// // 上传头像
// uploadAvatar(res.tempFilePaths[0]);
// }
// });
}
function uploadAvatar(filePath) {
// 上传头像到服务器
uni.uploadFile({
url: '/api/upload/avatar',
filePath: filePath,
name: 'avatar',
success: (res) => {
const data = JSON.parse(res.data);
if (data.success) {
companyInfo.avatar = data.data.url;
uni.showToast({
title: '头像更新成功',
icon: 'success'
});
}
}
});
}
function editInfo(type) {
// 根据类型跳转到不同的编辑页面
const editPages = {
name: '/pages/mine/edit-company-name',
code: '/pages/mine/edit-company-code',
location: '/pages/mine/edit-company-location',
description: '/pages/mine/edit-company-description',
legalPerson: '/pages/mine/edit-legal-person'
};
if (editPages[type]) {
navTo(editPages[type]);
}
}
function editContacts() {
// 跳转到联系人编辑页面
navTo('/packageA/pages/company-mine/edit-company-contacts');
}
onShow(() => {
// 获取企业信息
getCompanyInfo();
});
// 从缓存获取公司信息
function getCompanyInfo() {
try {
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
// console.log('缓存中的userInfo:', cachedUserInfo);
// 检查是否有company字段
if (cachedUserInfo.company) {
const company = cachedUserInfo.company;
// 基本信息
companyInfo.name = company.name || '';
companyInfo.socialCode = company.code || '';
companyInfo.location = company.registeredAddress || '';
companyInfo.description = company.description || '';
companyInfo.legalPerson = company.legalPerson || '';
// 联系人信息 - 直接使用companyContactList数组
companyInfo.companyContactList = company.companyContactList || [];
// 判断是否实名legalIdCard字段有值则表示已实名
companyInfo.isVerified = !!(company.legalIdCard && company.legalIdCard.trim());
console.log('公司名称:', companyInfo.name);
console.log('实名状态:', companyInfo.isVerified);
console.log('legalIdCard值:', company.legalIdCard);
} else {
console.log('缓存中没有company字段');
// 保持默认值
}
} catch (error) {
console.error('获取公司信息失败:', error);
// 保持默认值
}
}
function goBack() {
uni.navigateBack();
}
</script>
<style lang="stylus" scoped>
.avatar-section {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx;
background: #FFFFFF;
margin: 20rpx;
border-radius: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
.avatar-label {
font-size: 28rpx;
color: #333333;
}
.avatar-container {
display: flex;
align-items: center;
.company-avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
margin-right: 16rpx;
}
}
}
.info-section {
background: #FFFFFF;
margin: 0 20rpx 40rpx;
border-radius: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
.info-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx;
border-bottom: 1rpx solid #F5F5F5;
&:last-child {
border-bottom: none;
}
.info-label {
font-size: 28rpx;
color: #6C7282;
min-width: 200rpx;
}
.info-content {
display: flex;
align-items: center;
flex: 1;
.info-value {
font-size: 28rpx;
color: #333333;
flex: 1;
text-align: right;
margin-right: 16rpx;
word-break: break-all;
}
}
}
}
.btn-feel {
transition: transform 0.2s ease;
&:active {
transform: scale(0.98);
}
}
.contact-management-section {
border-top: 20rpx solid #F4F4F4;
.contact-section-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 30rpx;
background: #F8F8F8;
border-bottom: 1rpx solid #F5F5F5;
.contact-section-title {
font-size: 24rpx;
color: #999999;
}
.edit-contacts-btn {
display: flex;
align-items: center;
padding: 8rpx 16rpx;
background: #E6F7FF;
border-radius: 8rpx;
.edit-text {
font-size: 24rpx;
color: #256BFA;
margin-left: 8rpx;
}
}
}
.contact-display-item {
padding: 20rpx 30rpx;
border-bottom: 1rpx solid #F5F5F5;
&:last-child {
border-bottom: none;
}
.contact-display-title {
font-size: 26rpx;
font-weight: 600;
color: #333333;
margin-bottom: 16rpx;
}
.contact-display-content {
.contact-field {
display: flex;
align-items: center;
margin-bottom: 12rpx;
&:last-child {
margin-bottom: 0;
}
.field-label {
font-size: 26rpx;
color: #6C7282;
min-width: 120rpx;
}
.field-value {
font-size: 26rpx;
color: #333333;
flex: 1;
}
}
}
}
.no-contacts {
padding: 40rpx 30rpx;
text-align: center;
.no-contacts-text {
font-size: 26rpx;
color: #999999;
}
}
}
</style>

View File

@@ -0,0 +1,577 @@
<template>
<AppLayout back-gorund-color="#F4F4F4">
<!-- 自定义tabbar -->
<CustomTabBar :currentPage="4" />
<!-- 企业信息卡片 -->
<view class="company-info-card btn-feel" @click="goToCompanyInfo">
<view class="company-avatar">
<image class="company-avatar-img" :src="companyInfo.avatar || '/static/imgs/avatar.jpg'"></image>
</view>
<view class="company-details">
<view class="company-name">{{ companyInfo.name || '暂无公司名称' }}</view>
<view class="company-completeness">
信息完整度 {{ companyInfo.completeness || '100%' }}
<text class="verification-status" :class="{ 'verified': companyInfo.isVerified, 'unverified': !companyInfo.isVerified }">
{{ companyInfo.isVerified ? '已实名' : '未实名' }}
</text>
</view>
</view>
<view class="company-arrow">
<uni-icons color="#A2A2A2" type="right" size="16"></uni-icons>
</view>
</view>
<!-- 服务专区 -->
<view class="service-zone-card">
<view class="service-title">服务专区</view>
<view class="service-item btn-feel">
<view class="service-left">
<uni-icons type="contact" size="20" color="#256BFA"></uni-icons>
<text class="service-text">实名认证</text>
</view>
<view class="service-status" :class="{ 'verified': companyInfo.isVerified, 'unverified': !companyInfo.isVerified }">
{{ companyInfo.isVerified ? '已通过' : '未认证' }}
</view>
</view>
<view class="service-item btn-feel" @click="goToMessage">
<view class="service-left">
<uni-icons type="chat" size="20" color="#256BFA"></uni-icons>
<text class="service-text">消息</text>
</view>
<view class="service-status">
<uni-icons type="right" size="14" color="#909090"></uni-icons>
</view>
</view>
<view class="service-item btn-feel" @click="openReminderSettings">
<view class="service-left">
<uni-icons type="notification" size="20" color="#256BFA"></uni-icons>
<text class="service-text">通知与提醒</text>
</view>
<view class="service-status">
<switch class="reminder-switch" :checked="reminderEnabled" @change="toggleReminder"></switch>
</view>
</view>
<view class="service-item btn-feel" @click="openFeedbackPopup">
<view class="service-left">
<uni-icons type="chat" size="20" color="#256BFA"></uni-icons>
<text class="service-text">评论与反馈</text>
</view>
<view class="service-status">
<uni-icons type="right" size="14" color="#909090"></uni-icons>
</view>
</view>
<view class="service-item btn-feel" @click="handleInstitutionClick(1)">
<view class="service-left">
<uni-icons type="compose" size="20" color="#256BFA"></uni-icons>
<text class="service-text">培训机构维护</text>
</view>
<view class="service-status">修改</view>
</view>
<view class="service-item btn-feel" @click="handleInstitutionClick(2)">
<view class="service-left">
<uni-icons type="compose" size="20" color="#256BFA"></uni-icons>
<text class="service-text">评价机构维护</text>
</view>
<view class="service-status">修改</view>
</view>
<view class="service-item btn-feel" @click="handleInstitutionClick(3)">
<view class="service-left">
<uni-icons type="paperplane" size="20" color="#256BFA"></uni-icons>
<text class="service-text">培训公告发布</text>
</view>
<view class="service-status">发布</view>
</view>
<view class="service-item btn-feel" @click="handleInstitutionClick(4)">
<view class="service-left">
<uni-icons type="paperplane" size="20" color="#256BFA"></uni-icons>
<text class="service-text">评价公告发布</text>
</view>
<view class="service-status">发布</view>
</view>
</view>
<!-- 退出登录按钮 -->
<view class="logout-btn btn-feel" @click="logOut">
退出登录
</view>
<!-- 退出确认弹窗 -->
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog
mode="base"
title="确定退出登录吗?"
type="info"
:duration="2000"
:before-close="true"
@confirm="confirm"
@close="close"
></uni-popup-dialog>
</uni-popup>
<!-- 提醒设置弹窗 -->
<uni-popup ref="reminderPopup" type="center">
<view class="reminder-popup">
<view class="reminder-popup-title">提醒设置</view>
<view class="reminder-popup-content">
<view class="reminder-item" v-for="(item, index) in reminderOptions" :key="index">
<view class="reminder-item-label">{{ item.label }}</view>
<radio :value="item.value" :checked="reminderFrequency === item.value" @change="handleFrequencyChange"></radio>
</view>
</view>
<view class="reminder-popup-footer">
<button class="reminder-popup-btn" @click="closeReminderPopup">确定</button>
</view>
</view>
</uni-popup>
<!-- 评论与反馈弹窗 -->
<uni-popup ref="feedbackPopup" type="center">
<view class="feedback-popup">
<view class="feedback-popup-title">评论与反馈</view>
<view class="feedback-popup-content">
<textarea class="feedback-textarea" v-model="feedbackContent" placeholder="请输入您的评论或反馈..."></textarea>
<view class="feedback-rating">
<text class="feedback-rating-label">满意度评分</text>
<view class="feedback-stars">
<text class="feedback-star" v-for="i in 5" :key="i" @click="setRating(i)" :class="{ 'active': rating >= i }"></text>
</view>
</view>
</view>
<view class="feedback-popup-footer">
<button class="feedback-popup-btn" @click="submitFeedback">提交</button>
</view>
</view>
</uni-popup>
</AppLayout>
</template>
<script setup>
import { reactive, inject, ref, onMounted, onUnmounted } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import useUserStore from '@/stores/useUserStore';
const { $api, navTo } = inject('globalFunction');
const popup = ref(null);
const reminderPopup = ref(null);
const feedbackPopup = ref(null);
// 提醒设置
const reminderEnabled = ref(true);
const reminderFrequency = ref('realtime');
const reminderOptions = ref([
{ label: '实时提醒', value: 'realtime' },
{ label: '每小时提醒', value: 'hourly' },
{ label: '每天提醒', value: 'daily' }
]);
// 评论与反馈
const feedbackContent = ref('');
const rating = ref(0);
// 企业信息数据
const companyInfo = reactive({
name: '',
avatar: '/static/imgs/avatar.jpg',
completeness: '100%',
isVerified: false // 实名状态
});
function goToCompanyInfo() {
navTo('/packageA/pages/company-mine/company-info');
}
function handleInstitutionClick(i){
if(i==1){
navTo('/packageB/institution/trainingInstitutionMaintenance');
}else if(i==2){
navTo('/packageB/institution/evaluationAgencyMaintenance');
}else if(i==3){
navTo('/packageB/notice/trainingAnnouncement/postedList');
}else if(i==4){
navTo('/packageB/notice/evaluateAnnouncement/evaluateList');
}
}
// 跳转到消息页面
function goToMessage() {
navTo('/pages/msglog/msglog');
}
function logOut() {
popup.value.open();
}
function close() {
popup.value.close();
}
function confirm() {
useUserStore().logOut(false); // 不显示登录弹窗
// 跳转到首页
uni.reLaunch({
url: '/pages/index/index'
});
}
onShow(() => {
// 获取企业信息
getCompanyInfo();
});
// 监听退出登录事件,显示微信登录弹窗
onMounted(() => {
uni.$on('showLoginModal', () => {
// 这里可以显示微信登录弹窗
// 跳转到微信登录页面
uni.navigateTo({
url: '/packageA/pages/login/wx-login'
});
});
});
onUnmounted(() => {
uni.$off('showLoginModal');
});
// 从缓存获取公司信息
function getCompanyInfo() {
try {
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
// console.log('缓存中的userInfo:', cachedUserInfo);
// 检查是否有company字段
if (cachedUserInfo.company) {
companyInfo.name = cachedUserInfo.company.name || '';
// 判断是否实名legalIdCard字段有值则表示已实名
companyInfo.isVerified = !!(cachedUserInfo.company.legalIdCard && cachedUserInfo.company.legalIdCard.trim());
console.log('公司名称:', companyInfo.name);
console.log('实名状态:', companyInfo.isVerified);
console.log('legalIdCard值:', cachedUserInfo.company.legalIdCard);
} else {
console.log('缓存中没有company字段');
companyInfo.name = '';
companyInfo.isVerified = false;
}
} catch (error) {
console.error('获取公司信息失败:', error);
companyInfo.name = '';
companyInfo.isVerified = false;
}
}
// 切换提醒开启/关闭状态
function toggleReminder(e) {
reminderEnabled.value = e.detail.value;
}
// 打开提醒设置弹窗
function openReminderSettings() {
reminderPopup.value.open();
}
// 关闭提醒设置弹窗
function closeReminderPopup() {
reminderPopup.value.close();
}
// 处理提醒频率变化
function handleFrequencyChange(e) {
reminderFrequency.value = e.detail.value;
}
// 打开评论与反馈弹窗
function openFeedbackPopup() {
feedbackPopup.value.open();
}
// 关闭评论与反馈弹窗
function closeFeedbackPopup() {
feedbackPopup.value.close();
}
// 设置评分
function setRating(score) {
rating.value = score;
}
// 提交反馈
function submitFeedback() {
// 模拟提交成功
uni.showToast({
title: '反馈提交成功',
icon: 'success'
});
// 清空表单
feedbackContent.value = '';
rating.value = 0;
// 延迟关闭弹窗,确保用户能看到成功提示
setTimeout(() => {
closeFeedbackPopup();
}, 1000);
}
</script>
<style lang="stylus" scoped>
.company-info-card {
display: flex;
align-items: center;
padding: 30rpx;
background: #FFFFFF;
margin: 20rpx;
border-radius: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
.company-avatar {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
overflow: hidden;
margin-right: 24rpx;
.company-avatar-img {
width: 100%;
height: 100%;
}
}
.company-details {
flex: 1;
.company-name {
font-size: 36rpx;
font-weight: 600;
color: #333333;
margin-bottom: 8rpx;
}
.company-completeness {
font-size: 28rpx;
color: #6C7282;
display: flex;
align-items: center;
gap: 16rpx;
.verification-status {
font-size: 24rpx;
padding: 4rpx 12rpx;
border-radius: 12rpx;
&.verified {
background-color: #E8F5E8;
color: #52C41A;
}
&.unverified {
background-color: #FFF2E8;
color: #FA8C16;
}
}
}
}
.company-arrow {
margin-left: 20rpx;
}
}
.service-zone-card {
background: #FFFFFF;
margin: 0 20rpx 20rpx;
border-radius: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
padding: 32rpx;
.service-title {
font-size: 32rpx;
font-weight: 600;
color: #000000;
margin-bottom: 32rpx;
}
.service-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 0;
border-bottom: 1rpx solid #F5F5F5;
&:last-child {
border-bottom: none;
}
.service-left {
display: flex;
align-items: center;
.service-text {
font-size: 28rpx;
color: #333333;
margin-left: 16rpx;
}
}
.service-status {
font-size: 28rpx;
color: #6E6E6E;
&.verified {
color: #52C41A;
}
&.unverified {
color: #FA8C16;
}
}
}
}
.logout-btn {
height: 96rpx;
background: #FFFFFF;
margin: 0 20rpx 40rpx;
border-radius: 20rpx;
text-align: center;
line-height: 96rpx;
font-size: 28rpx;
color: #256BFA;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
}
.btn-feel {
transition: transform 0.2s ease;
&:active {
transform: scale(0.98);
}
}
// 提醒开关样式
.reminder-switch {
transform: scale(0.8);
}
// 提醒设置弹窗样式
.reminder-popup {
width: 600rpx;
background: #FFFFFF;
border-radius: 20rpx;
padding: 32rpx;
.reminder-popup-title {
font-size: 32rpx;
font-weight: 600;
color: #333333;
text-align: center;
margin-bottom: 32rpx;
}
.reminder-popup-content {
margin-bottom: 40rpx;
.reminder-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 24rpx 0;
border-bottom: 1rpx solid #F0F0F0;
&:last-child {
border-bottom: none;
}
.reminder-item-label {
font-size: 28rpx;
color: #333333;
}
}
}
.reminder-popup-footer {
display: flex;
justify-content: center;
.reminder-popup-btn {
width: 100%;
height: 80rpx;
background: #256BFA;
color: #FFFFFF;
font-size: 28rpx;
font-weight: 500;
border-radius: 10rpx;
border: none;
}
}
}
// 评论与反馈弹窗样式
.feedback-popup {
width: 600rpx;
background: #FFFFFF;
border-radius: 20rpx;
padding: 32rpx;
.feedback-popup-title {
font-size: 32rpx;
font-weight: 600;
color: #333333;
text-align: center;
margin-bottom: 32rpx;
}
.feedback-popup-content {
margin-bottom: 40rpx;
.feedback-textarea {
width: 100%;
height: 200rpx;
border: 1rpx solid #E5E5E5;
border-radius: 10rpx;
padding: 20rpx;
font-size: 28rpx;
color: #333333;
resize: none;
margin-bottom: 32rpx;
box-sizing: border-box;
}
.feedback-rating {
display: flex;
align-items: center;
.feedback-rating-label {
font-size: 28rpx;
color: #333333;
margin-right: 20rpx;
}
.feedback-stars {
display: flex;
.feedback-star {
font-size: 40rpx;
color: #E5E5E5;
margin-right: 16rpx;
cursor: pointer;
&.active {
color: #FFD700;
}
}
}
}
}
.feedback-popup-footer {
display: flex;
justify-content: center;
.feedback-popup-btn {
width: 100%;
height: 80rpx;
background: #256BFA;
color: #FFFFFF;
font-size: 28rpx;
font-weight: 500;
border-radius: 10rpx;
border: none;
}
}
}
</style>

View File

@@ -0,0 +1,470 @@
<template>
<AppLayout back-gorund-color="#F4F4F4">
<!-- 联系人列表 -->
<view class="contacts-section">
<view v-for="(contact, index) in contactList" :key="contact.tempId || contact.id" class="contact-item">
<view class="contact-header">
<text class="contact-title">联系人{{ index + 1 }}</text>
<view class="contact-actions" v-if="contactList.length > 1">
<view class="action-btn delete-btn" @click="deleteContact(index)">
<uni-icons type="trash" size="16" color="#FF4D4F"></uni-icons>
<text class="action-text">删除</text>
</view>
</view>
</view>
<view class="contact-form">
<view class="form-item">
<view class="form-label">联系人姓名</view>
<input
class="form-input"
v-model="contact.contactPerson"
placeholder="请输入联系人姓名"
@blur="validateContactName(index)"
/>
</view>
<view class="form-item">
<view class="form-label">联系电话</view>
<input
class="form-input"
v-model="contact.contactPersonPhone"
placeholder="请输入联系电话"
type="number"
@blur="validateContactPhone(index)"
/>
</view>
</view>
</view>
</view>
<!-- 添加联系人按钮 -->
<view class="add-contact-section" v-if="contactList.length < 3">
<view class="add-contact-btn btn-feel" @click="addContact">
<uni-icons type="plus" size="20" color="#256BFA"></uni-icons>
<text class="add-text">添加联系人</text>
</view>
</view>
<!-- 保存按钮 -->
<view class="save-section">
<view class="save-btn btn-feel" @click="saveContacts">
<text class="save-text">保存联系人</text>
</view>
</view>
<!-- 提示信息 -->
<view class="tips-section">
<view class="tips-title">温馨提示</view>
<view class="tips-content">
<text class="tips-item"> 至少需要保留一个联系人最多可添加3个联系人</text>
<text class="tips-item"> 联系人姓名和电话为必填项</text>
<text class="tips-item"> 联系电话请填写正确的手机号码</text>
</view>
</view>
</AppLayout>
</template>
<script setup>
import { reactive, inject, ref, onMounted } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import AppLayout from '@/components/AppLayout/AppLayout.vue';
import { createRequest } from '@/utils/request.js';
const { navTo } = inject('globalFunction');
// 联系人列表数据
const contactList = reactive([]);
let tempIdCounter = 0; // 用于生成临时ID
// 页面加载时获取联系人数据
onLoad((options) => {
// 从缓存获取企业联系人信息
loadContactsFromCache();
});
// 从缓存加载联系人数据
function loadContactsFromCache() {
try {
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
if (cachedUserInfo.company && cachedUserInfo.company.companyContactList) {
const contacts = cachedUserInfo.company.companyContactList;
// 如果联系人列表为空,至少添加一个空联系人
if (contacts.length === 0) {
contactList.push(createEmptyContact());
} else {
// 为每个联系人添加临时ID如果没有ID的话
contacts.forEach(contact => {
if (!contact.tempId) {
contact.tempId = `temp_${++tempIdCounter}`;
}
contactList.push({ ...contact });
});
}
} else {
// 如果没有联系人数据,创建一个空联系人
contactList.push(createEmptyContact());
}
} catch (error) {
console.error('加载联系人数据失败:', error);
// 出错时至少创建一个空联系人
contactList.push(createEmptyContact());
}
}
// 创建空联系人
function createEmptyContact() {
return {
id: '',
contactPerson: '',
contactPersonPhone: '',
tempId: `temp_${++tempIdCounter}`
};
}
// 添加联系人
function addContact() {
if (contactList.length >= 3) {
uni.showToast({
title: '最多只能添加3个联系人',
icon: 'none'
});
return;
}
contactList.push(createEmptyContact());
}
// 删除联系人
function deleteContact(index) {
if (contactList.length <= 1) {
uni.showToast({
title: '至少需要保留一个联系人',
icon: 'none'
});
return;
}
uni.showModal({
title: '确认删除',
content: '确定要删除这个联系人吗?',
success: (res) => {
if (res.confirm) {
contactList.splice(index, 1);
}
}
});
}
// 验证联系人姓名
function validateContactName(index) {
const contact = contactList[index];
if (!contact.contactPerson || contact.contactPerson.trim() === '') {
uni.showToast({
title: '请输入联系人姓名',
icon: 'none'
});
return false;
}
return true;
}
// 验证联系人电话
function validateContactPhone(index) {
const contact = contactList[index];
if (!contact.contactPersonPhone || contact.contactPersonPhone.trim() === '') {
uni.showToast({
title: '请输入联系电话',
icon: 'none'
});
return false;
}
// 简单的手机号验证
const phoneRegex = /^1[3-9]\d{9}$/;
if (!phoneRegex.test(contact.contactPersonPhone)) {
uni.showToast({
title: '请输入正确的手机号码',
icon: 'none'
});
return false;
}
return true;
}
// 验证所有联系人
function validateAllContacts() {
for (let i = 0; i < contactList.length; i++) {
if (!validateContactName(i) || !validateContactPhone(i)) {
return false;
}
}
return true;
}
// 保存联系人
async function saveContacts() {
// 验证所有联系人信息
if (!validateAllContacts()) {
return;
}
try {
uni.showLoading({
title: '保存中...',
mask: true
});
// 获取companyId
const companyId = getCompanyIdFromCache();
if (!companyId) {
uni.showToast({
title: '获取企业信息失败,请重新登录',
icon: 'none'
});
return;
}
// 准备API数据移除临时ID添加companyId
const apiData = contactList.map(contact => ({
id: contact.id || '',
contactPerson: contact.contactPerson.trim(),
contactPersonPhone: contact.contactPersonPhone.trim(),
companyId: companyId
}));
// 调用API保存联系人
const response = await createRequest(
'/app/companycontact/batchInsertUpdate',
{
companyContactList: apiData
},
'POST',
false
);
if (response.code === 200) {
// 保存成功,更新本地缓存
updateLocalCache(apiData);
uni.showToast({
title: '保存成功',
icon: 'success'
});
// 延迟返回上一页
setTimeout(() => {
goBack();
}, 1500);
} else {
uni.showToast({
title: response.msg || '保存失败',
icon: 'none'
});
}
} catch (error) {
console.error('保存联系人失败:', error);
uni.showToast({
title: '保存失败,请重试',
icon: 'none'
});
} finally {
uni.hideLoading();
}
}
// 从缓存获取companyId
function getCompanyIdFromCache() {
try {
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
if (cachedUserInfo.company && cachedUserInfo.company.companyId) {
return cachedUserInfo.company.companyId;
}
return null;
} catch (error) {
console.error('获取companyId失败:', error);
return null;
}
}
// 更新本地缓存
function updateLocalCache(contactData) {
try {
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
if (cachedUserInfo.company) {
cachedUserInfo.company.companyContactList = contactData;
uni.setStorageSync('userInfo', cachedUserInfo);
}
} catch (error) {
console.error('更新本地缓存失败:', error);
}
}
// 返回上一页
function goBack() {
uni.navigateBack();
}
</script>
<style lang="stylus" scoped>
.save-section {
margin: 0 20rpx 20rpx;
.save-btn {
display: flex;
align-items: center;
justify-content: center;
height: 88rpx;
background: #256BFA;
border-radius: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(37, 107, 250, 0.3);
.save-text {
font-size: 32rpx;
color: #FFFFFF;
font-weight: 600;
}
}
}
.contacts-section {
margin: 20rpx;
.contact-item {
background: #FFFFFF;
border-radius: 20rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
.contact-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx 30rpx 20rpx;
border-bottom: 1rpx solid #F5F5F5;
.contact-title {
font-size: 28rpx;
font-weight: 600;
color: #333333;
}
.contact-actions {
display: flex;
align-items: center;
.action-btn {
display: flex;
align-items: center;
padding: 8rpx 16rpx;
border-radius: 8rpx;
&.delete-btn {
background: #FFF2F0;
.action-text {
font-size: 24rpx;
color: #FF4D4F;
margin-left: 8rpx;
}
}
}
}
}
.contact-form {
padding: 20rpx 30rpx 30rpx;
.form-item {
margin-bottom: 30rpx;
&:last-child {
margin-bottom: 0;
}
.form-label {
font-size: 26rpx;
color: #6C7282;
margin-bottom: 16rpx;
}
.form-input {
width: 100%;
height: 80rpx;
background: #F8F9FA;
border: 1rpx solid #E9ECEF;
border-radius: 12rpx;
padding: 0 20rpx;
font-size: 28rpx;
color: #333333;
box-sizing: border-box;
&:focus {
border-color: #256BFA;
background: #FFFFFF;
}
}
}
}
}
}
.add-contact-section {
margin: 0 20rpx 20rpx;
.add-contact-btn {
display: flex;
align-items: center;
justify-content: center;
height: 88rpx;
background: #FFFFFF;
border: 2rpx dashed #256BFA;
border-radius: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
.add-text {
font-size: 28rpx;
color: #256BFA;
margin-left: 12rpx;
}
}
}
.tips-section {
margin: 0 20rpx 40rpx;
padding: 30rpx;
background: #F8F9FA;
border-radius: 20rpx;
.tips-title {
font-size: 26rpx;
font-weight: 600;
color: #333333;
margin-bottom: 20rpx;
}
.tips-content {
.tips-item {
display: block;
font-size: 24rpx;
color: #6C7282;
line-height: 1.6;
margin-bottom: 8rpx;
&:last-child {
margin-bottom: 0;
}
}
}
}
.btn-feel {
transition: transform 0.2s ease;
&:active {
transform: scale(0.98);
}
}
</style>