Vue.component('company-component', { props: { isLogin: { type: Boolean, required: true } }, data() { return { companyTable: null, // 企业表格实例 companyDialog: null, // 企业编辑对话框 companyForm: { // 企业表单数据 id: 0, // 0表示新增,其他表示编辑 code: '', name: '', address: '', phone: '', email: '', website: '', logo: '', description: '', expiredStatus: false, authStatus: false, createTime: '' }, companySearch: { // 企业搜索条件 keyword: '', } }; }, methods: { /** * 初始化企业管理模块 */ init: async function() { if (!this.isLogin) return; try { await this.initCompanyTable(); this.$nextTick(() => { form.render(); }); } catch (error) { console.error('初始化企业管理失败:', error); this.popErrorMsg('初始化企业管理失败,请刷新重试'); } }, /** * 初始化企业管理表格 */ initCompanyTable: function() { if (this.companyTable) { this.companyTable.reload(); return; } const that = this; this.companyTable = table.render({ elem: '#company-table', url: '/api/web/system-web-company/get-company-list', method: 'get', where: { keyword: this.companySearch.keyword }, page: true, cols: [[ {field: 'id', title: 'ID', width: 60, sort: true, fixed: 'left'}, {field: 'code', title: '邀请码', width: 120, fixed: 'left'}, {field: 'name', title: '企业名称', width: 250}, {field: 'phone', title: '联系电话', width: 150}, {field: 'email', title: '企业邮箱', width: 150}, {field: 'website', title: '企业网站', width: 150}, {field: 'description', title: '企业描述', width: 180}, // { // field: 'authStatus', // title: '认证状态', // width: 100, // templet: function(d){ // return ` // // `; // } // }, { field: 'createTime', title: '创建时间', sort: true, templet: function(d) { return window.util.timeAgo(d.createTime); } }, {fixed: 'right', title: '操作', toolbar: '#company-table-ops', width: 90} ]], parseData: function(res) { if (!res.success) { this.popErrorMsg(res.msg || '获取企业列表失败'); return { "code": 1, "msg": res.msg || '获取企业列表失败', "count": 0, "data": [] }; } return { "code": 0, "msg": "", "count": res.data.count, "data": res.data.list }; }, }); // 监听表格工具条 table.on('tool(company-table)', function(obj) { const data = obj.data; const event = obj.event; if (event === 'edit') { that.showEditCompanyDialog(data); } else if (event === 'del') { that.deleteCompany(data.id); } }); // 监听认证状态切换 form.on('switch(company-auth-filter)', function(data) { const companyId = parseInt(data.value); const checked = data.elem.checked; that.updateCompanyAuthStatus(companyId, checked); }); }, /** * 搜索企业 */ searchCompanies: function() { if (!this.companyTable) { this.initCompanyTable(); return; } this.companyTable.reload({ where: { keyword: this.companySearch.keyword }, page: { curr: 1 } }); }, /** * 显示添加企业对话框 */ showAddCompanyDialog: function() { // 重置表单 this.companyForm = { id: 0, code: '', name: '', address: '', phone: '', email: '', website: '', logo: '', description: '', expiredStatus: false, authStatus: false }; this.showCompanyDialog('添加企业'); }, /** * 显示编辑企业对话框 * @param {Object} company 企业数据 */ showEditCompanyDialog: function(company) { // 填充表单 this.companyForm = { id: company.id, code: company.code, name: company.name, address: company.address || '', phone: company.phone || '', email: company.email || '', website: company.website || '', logo: company.logo || '', description: company.description || '', authStatus: company.authStatus || false, expiredStatus: company.expiredStatus || false }; this.showCompanyDialog('编辑企业'); }, /** * 显示企业对话框(添加/编辑) * @param {string} title 对话框标题 */ showCompanyDialog: function(title) { const that = this; let isAdd = this.companyForm.id === 0; this.companyDialog = layer.open({ type: 1, title: title, shadeClose: 1, area: ['630px', '660px'], content: `