/** * company.js - 企业数据管理逻辑(列表+筛选+分页 / 新增编辑弹窗 / 导入导出 / 详情) */ $(function () { renderShell('企业数据', '数据管理 / 企业数据'); renderPage(); initPage('company', function (user) { if (!checkPagePermission('company')) return; loadList(1); }); var currentPage = 1; /** 渲染页面内容(工具栏+表格+分页) */ function renderPage() { $('#page-content').html( '
' + '
' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
ID公司名称行业行业细分国家业务角色注册号法人上市创建时间操作
' + ' ' + '
' ); $('#check-all').on('change', function () { $('.row-check').prop('checked', this.checked); }); } /* ---------- 列表 ---------- */ function loadList(page) { currentPage = page; var params = buildFilterParam(); params.page = page; params.limit = PAGE_SIZE; httpGet('company/list.php', params).then(function (data) { var rows = data.list || []; var html = ''; rows.forEach(function (r) { html += '' + '' + '' + r.id + '' + '' + escHtml(r.name_zh || r.name_en || '-') + '' + '' + escHtml(r.industry || '-') + '' + '' + escHtml(r.industry_subdivision || '-') + '' + '' + escHtml(r.country || '-') + '' + '' + escHtml(r.business_role || '-') + '' + '' + escHtml(r.registration_number || '-') + '' + '' + escHtml(r.legal_representative || '-') + '' + '' + (r.is_listed ? '上市' : '-') + '' + '' + fmtDate(r.created_at) + '' + '' + ' 详情' + ' 员工' + ' 产品' + ' 编辑' + ''; }); if (!rows.length) { html = '暂无数据'; } $('#company-tbody').html(html); renderPagination($('#pagination'), data, loadList); }); } /* ---------- 筛选 ---------- */ $('#btn-search').on('click', function () { loadList(1); }); $('#btn-reset').on('click', function () { $('.toolbar [data-filter]').val(''); loadList(1); }); /* ---------- 新增/编辑 ---------- */ $('#btn-add').on('click', function () { httpGet('company/cert_types.php').then(function (d) { openForm(null, [], [], d.types || []); }); }); window.editCompany = function (id) { httpGet('company/detail.php', { id: id }).then(function (d) { openForm(d.company, d.financials, d.certifications, d.certification_types); }); }; function openForm(company, financials, certifications, certTypes) { var isEdit = !!company; var c = company || {}; financials = financials || []; certifications = certifications || []; certTypes = certTypes || []; // Tab1 工商信息 var bizHtml = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; // Tab2 财务信息:最新冗余字段 + 年度财务明细列表 var finRowsHtml = ''; if (!financials.length) { finRowsHtml = finYearRowHtml(null); } else { financials.forEach(function (f) { finRowsHtml += finYearRowHtml(f); }); } var finHtml = '
' + '
' + '
' + '
' + '
' + ' 年度财务明细' + ' ' + '
' + '
' + finRowsHtml + '
'; // Tab3 资质认证:列表形式(瞪羚企业等) var certRowsHtml = ''; if (!certifications.length) { certRowsHtml = certRowHtml(null, certTypes); } else { certifications.forEach(function (ct) { certRowsHtml += certRowHtml(ct, certTypes); }); } var certHtml = '
' + ' 资质认证' + ' ' + '
' + '
' + certRowsHtml + '
' + '
如:瞪羚企业、国家高新技术企业、专精特新企业、ISO9001认证等
'; var content = '
' + '
' + '
' + ' 工商信息' + ' 财务信息' + ' 资质认证' + '
' + '
' + '
' + bizHtml + '
' + ' ' + ' ' + '
' + '
' + '' + '
'; var idx = Dialog.open({ title: isEdit ? '编辑企业' : '新增企业', area: ['820px', 'auto'], content: content, btn: false }); $('#form-cancel').on('click', function () { Dialog.close(idx); }); $('#add-fin-row').on('click', function () { $('#fin-rows').append(finYearRowHtml(null)); }); $('#add-cert-row').on('click', function () { $('#cert-rows').append(certRowHtml(null, certTypes)); }); $('#company-form').on('submit', function (e) { e.preventDefault(); var fd = new FormData(this); var nameZh = fd.get('name_zh'); var nameEn = fd.get('name_en'); if (isEdit) fd.delete('display_name'); // 编辑不允许改显示名称 if (!isEdit && !nameZh && !nameEn) { Dialog.error('公司名称或英文名称至少填写一项'); return; } // 年度财务明细(整表替换) var financials = []; $('#fin-rows .fin-year').each(function () { var $y = $(this); var year = $.trim($y.find('[name="fin-fiscal_year"]').val()); if (!year) return; financials.push({ fiscal_year: year, employee_count: $y.find('[name="fin-employee_count"]').val(), total_revenue: $y.find('[name="fin-total_revenue"]').val(), net_profit: $y.find('[name="fin-net_profit"]').val(), total_assets: $y.find('[name="fin-total_assets"]').val(), total_liabilities: $y.find('[name="fin-total_liabilities"]').val(), owner_equity: $y.find('[name="fin-owner_equity"]').val(), gross_margin: $y.find('[name="fin-gross_margin"]').val(), net_margin: $y.find('[name="fin-net_margin"]').val(), debt_ratio: $y.find('[name="fin-debt_ratio"]').val(), financial_report_url: $y.find('[name="fin-financial_report_url"]').val(), data_source: $y.find('[name="fin-data_source"]').val() }); }); fd.append('financials', JSON.stringify(financials)); // 资质认证(整表替换) var certs = []; $('#cert-rows .cert-row').each(function () { var $r = $(this); var tid = $r.find('[name="cert-type"]').val(); if (!tid) return; certs.push({ certification_type_id: tid, certificate_number: $r.find('[name="cert-number"]').val(), issue_date: $r.find('[name="cert-issue"]').val(), expiry_date: $r.find('[name="cert-expiry"]').val() }); }); fd.append('certifications', JSON.stringify(certs)); httpPost(isEdit ? 'company/update.php' : 'company/add.php', fd, true).then(function () { Dialog.success('保存成功', function () { Dialog.close(idx); loadList(currentPage); }); }); }); } /* ---------- 编辑弹窗 Tab 切换 ---------- */ window.switchEditTab = function (el) { var $tabs = $(el).closest('.edit-tabs'); $tabs.find('.edit-tab').removeClass('active'); $(el).addClass('active'); $tabs.find('.edit-pane').hide(); $('#edit-pane-' + $(el).data('tab')).show(); }; /** 年度财务明细行模板 */ function finYearRowHtml(f) { f = f || {}; var empty = function (v) { return (v === null || v === undefined) ? '' : v; }; return '
' + '
' + ' 财年 ' + ' ' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; } /** 资质认证行模板 */ function certRowHtml(ct, certTypes) { ct = ct || {}; var opts = ''; certTypes.forEach(function (t) { opts += ''; }); return '
' + '' + '' + '' + '' + '' + '
'; } function roleOptions(sel) { var opts = ['', 'manufacturer', 'integrator', 'distributor', 'brand_operator', 'others']; var labels = { 'manufacturer': '生产型', 'integrator': '集成商', 'distributor': '代理商', 'brand_operator': '品牌运营', 'others': '其他' }; var html = ''; opts.forEach(function (v) { if (v === '') return; html += ''; }); return html; } /* ---------- 导入 ---------- */ $('#btn-import').on('click', function () { triggerFileInput('.csv', function (file) { var fd = new FormData(); fd.append('file', file); httpPost('company/import.php', fd, true).then(function (d) { Dialog.alert('导入结果:成功 ' + d.inserted + ' 条,失败 ' + d.failed + ' 条', function () { loadList(1); }); }); }); }); /* ---------- 导出(仅导出勾选的企业,未勾选弹窗提醒) ---------- */ $('#btn-export').on('click', function () { var ids = []; $('.row-check:checked').each(function () { ids.push($(this).val()); }); if (!ids.length) { layer.alert('请先选择需要导出的企业数据', { icon: 2, title: '提示' }); return; } download('company/export.php', { ids: ids.join(',') }); }); /* ---------- 详情 ---------- */ window.viewCompany = function (id) { httpGet('company/detail.php', { id: id }).then(function (d) { var c = d.company; var html = '
' + '

' + escHtml(c.name_zh || c.name_en || '企业 #' + c.id) + '

' + '
' + detailRow('公司名称', c.name_zh) + detailRow('英文名称', c.name_en) + detailRow('业务角色', c.business_role) + detailRow('国家/地区', c.country) + detailRow('注册号', c.registration_number) + detailRow('地址', c.address) + detailRow('法定代表人', c.legal_representative) + detailRow('行业', c.industry) + detailRow('行业细分', c.industry_subdivision) + detailRow('官网', c.website) + detailRow('注册资本', c.registered_capital) + detailRow('成立日期', c.established_date) + detailRow('员工数', c.latest_employee_count) + detailRow('年营收', c.latest_annual_revenue) + detailRow('是否上市', c.is_listed ? '是' : '否') + detailRow('股票代码', c.stock_code) + '
' + '

经营范围

' + escHtml(c.business_scope || '-') + '
' + '

关联需求

' + miniTable(['联系人', '需求大类', '意向品类', '场景'], d.needs.map(function (n) { return [n.contact_person || '-', n.need_category || '-', n.target_product_category || '-', n.application_scenario || '-']; })) + '
'; Dialog.open({ title: '企业详情', area: ['820px', 'auto'], content: html, btn: ['关闭'] }); }); }; function detailRow(label, val) { return '
' + label + ':' + escHtml(val || '-') + '
'; } function miniTable(headers, rows) { if (!rows.length) return '
暂无数据
'; var html = ''; html += '' + headers.map(function (h) { return ''; }).join('') + ''; rows.forEach(function (r) { html += '' + r.map(function (v) { return ''; }).join('') + ''; }); return html + '
' + h + '
' + escHtml(v) + '
'; } /* ---------- 员工列表弹窗(按公司查看员工,分页 + 姓名/职级筛选) ---------- */ var empCompanyId = 0; var empPage = 1; window.viewEmployees = function (companyId) { empCompanyId = companyId; empPage = 1; var content = '
' + '
' + ' ' + ' ' + ' 状态:' + ' ' + ' ' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
姓名联系方式邮箱职级部门岗位入职日期状态
' + ' ' + '
'; var idx = Dialog.open({ title: '员工列表', area: ['920px', 'auto'], content: content, btn: ['关闭'] }); window.__empDialogIdx = idx; loadEmployees(1); $('#emp-search').on('click', function () { loadEmployees(1); }); $('#emp-reset').on('click', function () { $('#emp-keyword').val(''); $('#emp-level').val(''); $('#emp-cur').prop('checked', true); $('#emp-off').prop('checked', true); loadEmployees(1); }); }; function loadEmployees(page) { empPage = page; var params = { company_id: empCompanyId, page: page, limit: 5 }; var kw = $.trim($('#emp-keyword').val()); var lv = $('#emp-level').val(); var cur = $('#emp-cur').prop('checked'); var off = $('#emp-off').prop('checked'); if (kw) params.keyword = kw; if (lv) params.job_level = lv; // 状态筛选:只勾一项则按该项过滤;都不勾视为全部 if (cur && !off) params.is_current = 1; else if (!cur && off) params.is_current = 0; httpGet('company/employees.php', params).then(function (data) { var rows = data.list || []; var html = ''; rows.forEach(function (r) { html += '' + '' + escHtml(r.full_name) + '' + '' + escHtml(r.phone || '-') + '' + '' + escHtml(r.email || '-') + '' + '' + escHtml(r.job_level || '-') + '' + '' + escHtml(r.department || '-') + '' + '' + escHtml(r.position || '-') + '' + '' + escHtml(r.start_date || '-') + '' + '' + (r.is_current ? '在职' : '离职') + '' + ''; }); if (!rows.length) { html = '暂无员工'; } $('#emp-tbody').html(html); // 职级下拉(仅首次填充) var $lv = $('#emp-level'); if ($lv.find('option').length <= 1) { var optHtml = ''; (data.levels || []).forEach(function (l) { optHtml += ''; }); $lv.html(optHtml); } renderPagination($('#emp-pagination'), data, loadEmployees); }); } /* ---------- 产品品类弹窗(按企业查看产品品类,分页) ---------- */ var prodCompanyId = 0; window.viewProducts = function (companyId) { prodCompanyId = companyId; var content = '
' + '
' + ' ' + ' ' + '
品类名称品类描述是否核心状态
' + ' ' + '
'; Dialog.open({ title: '产品品类', area: ['720px', 'auto'], content: content, btn: ['关闭'] }); loadProducts(1); }; function loadProducts(page) { httpGet('company/products.php', { company_id: prodCompanyId, page: page, limit: 5 }).then(function (data) { var rows = data.list || []; var html = ''; rows.forEach(function (r) { html += '' + '' + escHtml(r.category_name) + '' + '' + escHtml(r.category_description || '-') + '' + '' + (r.is_core ? '核心' : '-') + '' + '' + (r.is_active ? '在产' : '停产') + '' + ''; }); if (!rows.length) { html = '暂无产品品类'; } $('#prod-tbody').html(html); renderPagination($('#prod-pagination'), data, loadProducts); }); } });