/** * company.js - 企业数据管理逻辑(列表+筛选+分页 / 新增编辑弹窗 / 产品 / 官媒 / 导入导出 / 详情) * v1.0.18: * - 检索区:筛选字段下拉(全部字段/指定字段,与检索词联动)+ 行业下拉 + 企业类型下拉(去掉国家/地区框) * - 新增/编辑:Tab 卡改为 基本信息|财务信息|资质认证;基本信息内左侧文字锚导航(工商信息/联系方式/行业归属/业务类型/来源) * - 表单字段:公司名称→企业名称、法律形式→企业类型(字典下拉)、删除英文名称;资质认证增加 级别/颁证机构 * - 产品弹窗:展示 产品品类/基本定位/包含系列/状态/更新日期 + 新增产品按钮(EAV 参数) * - 新增「官媒」入口:公司媒体清单 + 新增官媒按钮 */ $(function () { renderShell('企业数据', '数据管理 / 企业数据'); renderPage(); initPage('company', function (user) { if (!checkPagePermission('company')) return; loadDicts().then(function (dicts) { window._companyDicts = dicts; fillSearchDicts(dicts); loadList(1); }).catch(function () { loadList(1); }); }); var currentPage = 1; /** 渲染页面内容(工具栏+表格+分页) */ function renderPage() { $('#page-content').html( '
' + '
' + ' ' + '
' + ' ' + ' ' + ' ' + '
' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
ID企业名称行业行业细分国家业务角色注册号法人上市创建时间操作
' + ' ' + '
' ); $('#check-all').on('change', function () { $('.row-check').prop('checked', this.checked); }); } /** 填充检索区字典下拉(行业/企业类型) */ function fillSearchDicts(dicts) { var indHtml = ''; (dicts.industries || []).forEach(function (i) { indHtml += ''; }); $('#search-industry').html(indHtml); var ctHtml = ''; (dicts.company_types || []).forEach(function (t) { ctHtml += ''; }); $('#search-company-type').html(ctHtml); } /* ---------- 列表 ---------- */ var companyFilters = { logic: 'and', conditions: [] }; // 筛选弹窗条件(多字段 + 且/或) function loadList(page) { currentPage = page; var params = { field: $('#search-field').val(), keyword: $.trim($('#search-keyword').val()), industry: $('#search-industry').val(), company_type: $('#search-company-type').val(), page: page, limit: PAGE_SIZE }; // 筛选弹窗条件(多字段 + 逻辑关系) if (companyFilters.conditions.length) { params.filters = JSON.stringify(companyFilters.conditions); params.filter_logic = companyFilters.logic; } // 空值不传 Object.keys(params).forEach(function (k) { if (params[k] === '') delete params[k]; }); 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 || '-') + '' + '' + 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); }); $('#search-keyword').on('keydown', function (e) { if (e.keyCode === 13) loadList(1); }); $('#search-industry, #search-company-type').on('change', function () { loadList(1); }); $('#btn-reset').on('click', function () { $('#search-field').val(''); $('#search-keyword').val(''); $('#search-industry').val(''); $('#search-company-type').val(''); companyFilters = { logic: 'and', conditions: [] }; loadList(1); }); /* ---------- 筛选弹窗:多字段条件 + 且/或 逻辑关系 ---------- */ var FILTER_FIELDS = [ ['name_zh', '企业名称'], ['registration_number', '注册号'], ['legal_representative', '法定代表人'], ['address', '注册地址'], ['country', '国家/地区'], ['industry', '行业'], ['industry_subdivision', '行业细分'], ['legal_form', '企业类型'], ['business_role', '业务角色'], ['website', '官网'], ['source_channel', '来源渠道'], ['source_detail', '来源详情'], ['business_scope', '经营范围'], ['stock_code', '股票代码'], ['established_date', '成立日期'], ['latest_employee_count', '最新员工数'], ['latest_annual_revenue', '最新年营收'] ]; var FILTER_OPS = [ ['contains', '包含'], ['eq', '等于'], ['neq', '不等于'], ['starts_with', '开头是'], ['ends_with', '结尾是'], ['gt', '大于'], ['lt', '小于'], ['gte', '大于等于'], ['lte', '小于等于'], ['is_empty', '为空'], ['is_not_empty', '不为空'] ]; function filterFieldOptions(cur) { var h = ''; FILTER_FIELDS.forEach(function (f) { h += ''; }); return h; } function filterOpOptions(cur) { var h = ''; FILTER_OPS.forEach(function (o) { h += ''; }); return h; } function filterRowHtml(c) { c = c || {}; var valInput = (c.op === 'is_empty' || c.op === 'is_not_empty') ? '' : ''; return '
' + ' ' + ' ' + valInput + ' ' + '
'; } window.openFilterDialog = function () { var logicHtml = '' + ''; var rowsHtml = ''; if (companyFilters.conditions.length) { companyFilters.conditions.forEach(function (c) { rowsHtml += filterRowHtml(c); }); } else { rowsHtml = filterRowHtml(null); } var content = '
' + '
每个字段是一个筛选条件,不同条件之间可为「且」「或」关系:
' + '
' + logicHtml + '
' + '
' + rowsHtml + '
' + ' ' + '
' + ''; var idx = Dialog.open({ title: '设置筛选条件', area: ['620px', 'auto'], content: content, btn: false }); $('#btn-add-filter').on('click', function () { $('#filter-rows').append(filterRowHtml(null)); }); $('#filter-cancel').on('click', function () { Dialog.close(idx); }); $('#filter-apply').on('click', function () { var logic = $('input[name="f-logic"]:checked').val() || 'and'; var conds = []; $('#filter-rows .filter-row').each(function () { var field = $(this).find('.f-field').val(); var op = $(this).find('.f-op').val(); var value = $.trim($(this).find('input[type="text"]').val()); if (!field || !op) return; if (op !== 'is_empty' && op !== 'is_not_empty' && value === '') return; // 无值且需要值的条件跳过 conds.push({ field: field, op: op, value: value }); }); companyFilters = { logic: logic, conditions: conds }; Dialog.close(idx); loadList(1); }); }; $('#btn-filter').on('click', function () { openFilterDialog(); }); /* ---------- 新增/编辑 ---------- */ $('#btn-add').on('click', function () { httpGet('company/cert_types.php').then(function (d) { loadDicts().then(function (dicts) { window._companyDicts = dicts; openForm(null, [], [], [], d.types || [], dicts); }); }); }); window.editCompany = function (id) { httpGet('company/detail.php', { id: id }).then(function (d) { loadDicts().then(function (dicts) { window._companyDicts = dicts; openForm(d.company, d.financials, d.certifications, d.accounts || [], d.certification_types, dicts); }); }); }; /** 拉取数据字典(国家/行业/来源渠道/企业类型),供表单与检索使用 */ function loadDicts() { return httpGet('common/dicts.php', { type: 'all' }).catch(function () { return { countries: [], industries: [], source_channels: [], company_types: [] }; }); } /** 生成下拉选项:value 与当前值匹配则选中;若当前值不在字典中则追加一个选项保留原值 */ function dictOptions(list, cur, labelKey) { var html = ''; var found = false; (list || []).forEach(function (item) { var name = item[labelKey || 'name']; var sel = (String(name) === String(cur)) ? ' selected' : ''; if (sel) found = true; html += ''; }); if (cur && !found) { html += ''; } return html; } /* ============================================================ * 新增/编辑弹窗:Tab = 基本信息 | 财务信息 | 资质认证 * 基本信息内左侧文字锚导航:工商信息 / 联系方式 / 行业归属 / 业务类型 / 来源 * ============================================================ */ function openForm(company, financials, certifications, accounts, certTypes, dicts) { var isEdit = !!company; var c = company || {}; financials = financials || []; certifications = certifications || []; accounts = accounts || []; certTypes = certTypes || []; dicts = dicts || {}; // ---- 基本信息 Tab(含左侧锚导航 + 5 个分区) ---- var secBiz = '
' + '
工商信息
' + '
' + '
' + '
' + ' ' + ' ' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; // 联系方式(social_accounts,整表替换) var accountRowsHtml = ''; if (!accounts.length) { accountRowsHtml = accountRowHtml(null); } else { accounts.forEach(function (a) { accountRowsHtml += accountRowHtml(a); }); } var secContact = '
' + '
联系方式' + '
' + '
' + accountRowsHtml + '
' + '
如:官网、公众号、微博、抖音、领英等平台账号
' + '
'; var secIndustry = '
' + '
行业归属
' + '
' + '
' + '
' + '
' + '
'; var secBizType = '
' + '
业务类型
' + '
' + '
' + '
'; var secSource = '
' + '
来源
' + '
' + '
' + '
' + '
'; var bizHtml = '
' + '
' + ' 工商信息' + ' 联系方式' + ' 行业归属' + ' 业务类型' + ' 来源' + '
' + '
' + secBiz + secContact + secIndustry + secBizType + secSource + '
' + '
'; // ---- 财务信息 Tab(保持不变) ---- var finRowsHtml = ''; if (!financials.length) { finRowsHtml = finRowHtml(null); } else { financials.forEach(function (f) { finRowsHtml += finRowHtml(f); }); } var finHtml = '
' + '
' + '
' + '
' + '
' + '
' + '
' + ' 年度财务明细(单位:万元)' + ' ' + '
' + '
' + ' ' + ' ' + finRowsHtml + '' + '
财年员工数总营收净利润总资产总负债所有者权益毛利率(%)净利率(%)资产负债率(%)财务报表链接数据来源操作
'; // ---- 资质认证 Tab(含级别/颁证机构) ---- 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: ['860px', 'auto'], content: content, btn: false }); bindAnchorNav(); $('#form-cancel').on('click', function () { Dialog.close(idx); }); $('#add-fin-row').on('click', function () { $('#fin-tbody').append(finRowHtml(null)); }); $('#add-cert-row').on('click', function () { $('#cert-rows').append(certRowHtml(null, certTypes)); }); $('#add-account-row').on('click', function () { $('#account-rows').append(accountRowHtml(null)); }); // 工商查询按钮(预留:后续接入工商查询API自动填写) $('#btn-gongshang-query').on('click', function () { Dialog.alert('工商查询API预留中,接入后可通过企业名称自动查询并填写企业名称、注册号、注册地址等信息'); }); // 是否上市 → 股票代码 联动:非上市(否/空白)时禁用股票代码 function syncStockCodeDisabled() { var listed = $('#company-is-listed').val() === '1'; $('#company-stock-code').prop('disabled', !listed); } $('#company-is-listed').on('change', syncStockCodeDisabled); syncStockCodeDisabled(); $('#company-form').on('submit', function (e) { e.preventDefault(); var fd = new FormData(this); var nameZh = fd.get('name_zh'); if (isEdit) fd.delete('display_name'); // 编辑不允许改显示名称 if (isEdit) fd.append('id', company.id); // 编辑必须带 id,否则 update.php 报参数错误 if (!nameZh) { Dialog.error('企业名称为必填项'); return; } if ($('#company-is-listed').val() !== '1') { fd.set('stock_code', ''); // 非上市不允许有股票代码,提交空值由后端清空 } // 年度财务明细(整表替换) var financials = []; $('#fin-tbody .fin-row').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(), level: $r.find('[name="cert-level"]').val(), issuing_authority: $r.find('[name="cert-issuer"]').val(), issue_date: $r.find('[name="cert-issue"]').val(), expiry_date: $r.find('[name="cert-expiry"]').val() }); }); fd.append('certifications', JSON.stringify(certs)); // 联系方式(整表替换) var accounts = []; $('#account-rows .account-row').each(function () { var $r = $(this); var platform = $.trim($r.find('[name="acc-platform"]').val()); var accountId = $.trim($r.find('[name="acc-account"]').val()); if (!platform || !accountId) return; accounts.push({ platform: platform, account_id: accountId, profile_url: $r.find('[name="acc-url"]').val(), remark: $r.find('[name="acc-remark"]').val(), is_active: $r.find('[name="acc-active"]').val(), is_defult: $r.find('[name="acc-defult"]').prop('checked') ? 1 : 0 }); }); fd.append('accounts', JSON.stringify(accounts)); 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 bindAnchorNav() { $('.form-anchor-nav .anchor-link').off('click').on('click', function (e) { e.preventDefault(); var $target = $($(this).attr('href')); var $body = $target.closest('.edit-pane'); // 若锚点所在分区不在当前可见 Tab,先切到对应 Tab if (!$body.is(':visible')) { var tab = $body.attr('id').replace('edit-pane-', ''); var $tabEl = $('.edit-tabs-head .edit-tab[data-tab="' + tab + '"]'); if ($tabEl.length) switchEditTab($tabEl[0]); } var offset = $target.offset(); if (offset) { $('.edit-tabs-body').animate({ scrollTop: $target.offset().top - $('.edit-tabs-body').offset().top + $('.edit-tabs-body').scrollTop() }, 200); } $('.form-anchor-nav .anchor-link').removeClass('active'); $(this).addClass('active'); }); // 滚动时高亮当前分区 var $secs = $('.form-anchor-body .form-sec'); $('.edit-tabs-body').off('scroll.anchor').on('scroll.anchor', function () { var top = $(this).scrollTop() + 60; var currentId = null; $secs.each(function () { if ($(this).position().top <= top) currentId = $(this).attr('id'); }); if (currentId) { $('.form-anchor-nav .anchor-link').removeClass('active'); $('.form-anchor-nav .anchor-link[href="#' + currentId + '"]').addClass('active'); } }); } /** 年度财务明细行模板(列表形式,一行一个财年) */ function finRowHtml(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 '
' + '' + '' + '' + '' + '' + '' + '' + '
'; } /** 联系方式行模板(企业 social_accounts) */ function accountRowHtml(a) { a = a || {}; var empty = function (v) { return (v === null || v === undefined) ? '' : v; }; var platOpts = ['', '官网', '微信公众号', '微信', '微博', '抖音', '快手', 'B站', '小红书', '领英', 'Facebook', 'Twitter/X', 'YouTube', 'Instagram', '其他']; var platHtml = ''; platOpts.forEach(function (p) { platHtml += ''; }); 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; // 联系方式列表(social_accounts 中属于该公司的记录,仅展示) var accountsHtml = ''; (d.accounts || []).forEach(function (a) { var tag = ''; if (a.is_defult) tag = ' 常用'; else if (a.is_primary) tag = ' 默认'; accountsHtml += '' + '' + escHtml(a.platform || '-') + '' + '' + escHtml(a.account_id || '-') + '' + '' + (a.profile_url ? '打开' : '-') + '' + '' + escHtml(a.remark || '-') + '' + '' + (a.is_active ? '启用' : '停用') + tag + '' + ''; }); var accountsSection = accountsHtml ? '' + accountsHtml + '
平台账号/号码主页链接备注状态
' : '
暂无联系方式
'; var html = '
' + '

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

' + '
' + detailRow('企业名称', c.name_zh) + detailRow('企业类型', c.legal_form) + 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) + detailRow('来源渠道', c.source_channel) + detailRow('来源详情', c.source_detail) + '
' + '

经营范围

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

联系方式

' + accountsSection + '
'; Dialog.open({ title: '企业详情', area: ['820px', 'auto'], content: html, btn: ['关闭'] }); }); }; function detailRow(label, val) { return '
' + label + ':' + escHtml(val || '-') + '
'; } /* ---------- 员工列表弹窗(按公司查看员工,分页 + 姓名/职级筛选) ---------- */ 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 = '
' + '
' + ' 共 0 条产品记录' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
产品品类基本定位包含系列状态更新日期参数
' + ' ' + '
'; Dialog.open({ title: '产品列表', area: ['860px', 'auto'], content: content, btn: ['关闭'] }); loadProducts(1); $('#btn-add-product').on('click', function () { openProductForm(null); }); }; function loadProducts(page) { httpGet('company/products.php', { company_id: prodCompanyId, page: page, limit: 5 }).then(function (data) { $('#prod-total').text(data.total); var rows = data.list || []; var html = ''; rows.forEach(function (r) { var attrHtml = (r.attrs && r.attrs.length) ? r.attrs.map(function (a) { return '
' + escHtml(a.attr_name) + (a.unit ? '(' + escHtml(a.unit) + ')' : '') + ':' + escHtml(a.value) + '
'; }).join('') : '-'; html += '' + '' + escHtml(r.category_name) + '' + '' + escHtml((r.positioning || '-').substring(0, 24)) + '' + '' + escHtml(r.series || '-') + '' + '' + (r.is_active ? '在产' : '停产') + '' + '' + fmtDate(r.updated_at || r.created_at) + '' + '' + attrHtml + '' + ''; }); if (!rows.length) { html = '暂无产品,点击右上角「+ 新增产品」添加'; } $('#prod-tbody').html(html); renderPagination($('#prod-pagination'), data, loadProducts); }); } /** 新增产品弹窗(含 EAV 参数,按企业所属行业加载参数属性定义) */ function openProductForm() { // 获取企业行业 httpGet('company/detail.php', { id: prodCompanyId }).then(function (d) { var industry = (d.company && d.company.industry) || ''; var content = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + ' 产品参数' + (industry ? '(' + escHtml(industry) + ')' : '') + '' + '
' + '
' + '' + '
'; var idx = Dialog.open({ title: '新增产品', area: ['640px', 'auto'], content: content, btn: false }); $('#prod-form-cancel').on('click', function () { Dialog.close(idx); }); // 加载该行业参数属性定义(EAV) if (industry) { httpGet('company/product_attrs.php', { industry: industry }).then(function (rd) { var attrs = rd.attrs || []; var html = ''; attrs.forEach(function (a) { html += '
' + '' + '
'; }); if (!attrs.length) { html = '
该行业暂无参数属性定义(可在 company_products_attr 表中维护)
'; } $('#product-attr-rows').html(html); }).catch(function () {}); } $('#product-form').on('submit', function (e) { e.preventDefault(); var data = {}; $(this).find('input, select, textarea').each(function () { var name = $(this).attr('name'); if (name) data[name] = $(this).val(); }); if (!data.category_name) { Dialog.error('产品品类为必填项'); return; } // 收集 EAV 参数值 var attrs = []; $('#product-attr-rows input[data-attr-id]').each(function () { var $this = $(this); var val = $.trim($this.val()); if (!val) return; attrs.push({ attr_id: $this.data('attr-id'), value: val }); }); data.company_id = prodCompanyId; data.attrs = JSON.stringify(attrs); httpPost('company/product_add.php', data).then(function () { Dialog.success('新增成功', function () { Dialog.close(idx); loadProducts(1); }); }); }); }); } /* ---------- 官媒弹窗(该公司媒体清单 + 新增官媒) ---------- */ var mediaCompanyId = 0; window.viewOfficialMedia = function (companyId) { mediaCompanyId = companyId; var content = '
' + '
' + ' 共 0 条官媒记录' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
平台账号名称ID主页链接状态更新日期
' + ' ' + '
'; Dialog.open({ title: '官媒列表', area: ['820px', 'auto'], content: content, btn: ['关闭'] }); loadOfficialMedia(1); $('#btn-add-media').on('click', function () { openOfficialMediaForm(); }); }; function loadOfficialMedia(page) { httpGet('company/official_media_list.php', { company_id: mediaCompanyId, page: page, limit: 5 }).then(function (data) { $('#media-total').text(data.total); var rows = data.list || []; var html = ''; rows.forEach(function (r) { html += '' + '' + escHtml(r.platform || '-') + '' + '' + escHtml(r.account_id || '-') + '' + '' + r.id + '' + '' + (r.profile_url ? '打开' : '-') + '' + '' + (r.is_active ? '启用' : '停用') + '' + '' + fmtDate(r.updated_at || r.created_at) + '' + ''; }); if (!rows.length) { html = '暂无官媒,点击右上角「+ 新增官媒」添加'; } $('#media-tbody').html(html); renderPagination($('#media-pagination'), data, loadOfficialMedia); }); } /** 产业链(占位:入口先行,功能后续迭代实现) */ window.viewIndustryChain = function (companyId) { Dialog.alert('产业链功能建设中,敬请期待'); }; /** 新增官媒弹窗 */ function openOfficialMediaForm() { var content = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '
'; var idx = Dialog.open({ title: '新增官媒', area: ['620px', 'auto'], content: content, btn: false }); $('#media-form-cancel').on('click', function () { Dialog.close(idx); }); $('#media-form').on('submit', function (e) { e.preventDefault(); var data = {}; $(this).find('input, select').each(function () { var name = $(this).attr('name'); if (name) data[name] = $(this).val(); }); if (!data.platform || !data.account_id) { Dialog.error('平台与账号名称为必填项'); return; } data.company_id = mediaCompanyId; httpPost('company/official_media_add.php', data).then(function () { Dialog.success('新增成功', function () { Dialog.close(idx); loadOfficialMedia(1); }); }); }); } });