/** * 企业详情组件 * 提供企业详情查询和侧边栏显示功能 */ Vue.component('company-detail', { data() { return { // 当前查看的企业详情 currentCompany: null, // 企业详情侧边栏索引 companySidebarIndex: null, // 是否正在加载 loading: false }; }, methods: { /** * 获取企业详情 * @param {number} companyId 企业ID * @returns {Promise} 企业详情对象,获取失败则返回null */ getCompanyDetail: async function(companyId) { if (this.loading) return null; this.loading = true; try { const loadIndex = layer.load(2, { shade: [0.3, '#0000001f'] }); const { data: res } = await axios.get('/api/web/system-web-company/get-company-info', { params: { id: companyId } }); layer.close(loadIndex); if (!res.success) { this.popWarningMsg(res.msg || '获取企业详情失败'); return null; } return res.data; } catch (error) { console.error('获取企业详情失败:', error); this.popErrorMsg('获取企业详情失败,请重试'); return null; } finally { this.loading = false; } }, /** * 显示企业详情侧边栏 * @param {number} companyId 企业ID */ showCompanyDetail: async function(companyId) { // 先获取企业详情 const companyDetail = await this.getCompanyDetail(companyId); if (!companyDetail) return; this.currentCompany = companyDetail; // 渲染企业详情到侧边栏 const that = this; this.companySidebarIndex = layer.open({ type: 1, title: '企业详情', area: ['400px', '100%'], offset: 'r', move: false, anim: 5, shadeClose: true, content: `

{{ currentCompany ? currentCompany.name : '' }}

ID: {{ currentCompany ? currentCompany.id : '' }}

邀请码: {{ currentCompany.code || '未设置' }}
联系电话: {{ currentCompany.phone || '未设置' }}
联系邮箱: {{ currentCompany.email || '未设置' }}
联系地址: {{ currentCompany.address || '未设置' }}
官网地址: {{ currentCompany.website || '未设置' }}
认证状态: {{ currentCompany.authStatus ? '已认证' : '未认证' }}
创建时间: {{ window.util.timeAgo(currentCompany.createTime) }}
企业简介:
{{ currentCompany.description || '暂无企业简介' }}
`, end: function() { // 重置组件状态 that.currentCompany = null; }, success: function(layero, index) { // 设置初始样式 layero.css({ 'border-radius': '0', 'overflow': 'hidden', }); $(layero).find('.layui-layer-content').css({ 'overflow': 'hidden', }); $(layero).find('.layui-layer-title').css({ 'background-color': '#f8f8f8', 'border-bottom': '1px solid #eee' }); new Vue({ 'el': '#tl-rtc-app-company-detail', data: that.$data, methods: that.$options.methods, }) } }); }, }, mounted() { window.subModule.$on('show-company-detail', this.showCompanyDetail); }, beforeDestroy() { window.subModule.$off('show-company-detail', this.showCompanyDetail); } });