/** * person.js - 人员数据管理逻辑(列表+筛选+分页 / 新增编辑弹窗 / 导入导出 / 详情) */ $(function () { renderShell('人员数据', '数据管理 / 人员数据'); renderPage(); initPage('person', function (user) { if (!checkPagePermission('person')) 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('person/list.php', params).then(function (data) { var rows = data.list || []; var html = ''; rows.forEach(function (r) { html += '' + '' + '' + r.id + '' + '' + escHtml(r.full_name) + '' + '' + escHtml(r.gender || '-') + '' + '' + escHtml(r.nationality || '-') + '' + '' + escHtml(r.work_location || '-') + '' + '' + escHtml(r.hometown || '-') + '' + '' + escHtml(r.education || '-') + '' + '' + escHtml((r.contacts || '-').substring(0, 40)) + '' + '' + fmtDate(r.created_at) + '' + '' + ' 详情' + ' 公司' + ' 产品' + ' 编辑' + ''; }); if (!rows.length) { html = '暂无数据'; } $('#person-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 () { openForm(null); }); window.editPerson = function (id) { httpGet('person/detail.php', { id: id }).then(function (d) { openForm(d.person, d.accounts); }); }; function contactsInputHtml(accounts) { accounts = accounts || []; var html = '
'; if (!accounts.length) { accounts = [{ platform: 'email', account_id: '', is_primary: 1 }]; } accounts.forEach(function (a, i) { html += '
' + '' + '' + '' + '
'; }); return html + '
' + ''; } function platformOpts(sel) { var list = ['phone', 'email', 'wechat', 'douyin', 'linkedin', 'x', 'facebook', 'instagram', 'tiktok', 'other']; var html = ''; list.forEach(function (p) { html += ''; }); return html; } function openForm(person, accounts) { var isEdit = !!person; var p = person || {}; var content = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + contactsInputHtml(accounts) + '
' + '
' + '' + '
'; var idx = Dialog.open({ title: isEdit ? '编辑人员' : '新增人员', area: ['720px', 'auto'], content: content, btn: false }); $('#form-cancel').on('click', function () { Dialog.close(idx); }); $('#add-contact').on('click', function () { $('#contacts-box').append( '
' + '' + '' + '' + '
' ); }); $('#person-form').on('submit', function (e) { e.preventDefault(); var data = {}; $(this).find('input, select').each(function () { var name = $(this).attr('name'); if (!name) return; if (name.indexOf('c-') === 0) return; if ($(this).attr('type') === 'checkbox') { data[name] = $(this).prop('checked') ? 1 : 0; } else { data[name] = $(this).val(); } }); if (!data.full_name) { Dialog.error('姓名为必填项'); return; } // 联系方式 var contacts = []; $('#contacts-box .contact-row').each(function () { var $row = $(this); var account = $.trim($row.find('input[name="c-account"]').val()); var platform = $row.find('select[name="c-platform"]').val(); var primary = $row.find('input[name="c-primary"]').prop('checked') ? 1 : 0; if (account) { contacts.push({ platform: platform, account_id: account, is_primary: primary }); } }); data.contacts = JSON.stringify(contacts); if (isEdit) data.id = p.id; httpPost(isEdit ? 'person/update.php' : 'person/add.php', data).then(function () { Dialog.success('保存成功', function () { Dialog.close(idx); loadList(currentPage); }); }); }); } /* ---------- 导入 ---------- */ $('#btn-import').on('click', function () { triggerFileInput('.csv', function (file) { var fd = new FormData(); fd.append('file', file); httpPost('person/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('person/export.php', { ids: ids.join(',') }); }); window.viewPerson = function (id) { httpGet('person/detail.php', { id: id }).then(function (d) { var p = d.person; var accountsHtml = ''; (d.accounts || []).forEach(function (a) { accountsHtml += '
' + escHtml(a.platform) + ':' + escHtml(a.account_id) + (a.is_primary ? ' 默认' : '') + '
'; }); var expHtml = ''; (d.experiences || []).forEach(function (e) { expHtml += '' + escHtml(e.display_name || '-') + '' + escHtml(e.position || '-') + '' + '' + escHtml(e.department || '-') + '' + escHtml(e.job_level || '-') + '' + '' + (e.is_current ? '在职' : fmtDate(e.start_date) + ' ~ ' + (e.end_date || '至今')) + ''; }); var html = '
' + '

' + escHtml(p.full_name) + '

' + '
' + '
性别:' + escHtml(p.gender || '-') + '
' + '
国籍:' + escHtml(p.nationality || '-') + '
' + '
证件:' + escHtml(p.id_type || '-') + ' / ' + escHtml(p.id_number || '-') + '
' + '
学历:' + escHtml(p.education || '-') + '
' + '
毕业院校:' + escHtml(p.graduated_from || '-') + '
' + '
家乡:' + escHtml(p.hometown || '-') + '
' + '
工作所在地:' + escHtml(p.work_location || '-') + '
' + '
union_id:' + escHtml(p.union_id) + '
' + '
' + '

联系方式

' + (accountsHtml || '
暂无
') + '

工作经历

' + ' ' + (expHtml || '') + '
公司职位部门级别时间
暂无
' + '
'; Dialog.open({ title: '人员详情', area: ['760px', 'auto'], content: html, btn: ['关闭'] }); }); } /* ---------- 任职公司弹窗(按人员查看任职公司,分页) ---------- */ var compPersonId = 0; window.viewCompanies = function (personId) { compPersonId = personId; var content = '
' + '
' + ' 状态:' + ' ' + ' ' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
公司名称部门岗位职级入职日期是否在岗
' + ' ' + '
'; Dialog.open({ title: '任职公司', area: ['720px', 'auto'], content: content, btn: ['关闭'] }); loadCompanies(1); $('#comp-search').on('click', function () { loadCompanies(1); }); $('#comp-reset').on('click', function () { $('#comp-cur').prop('checked', true); $('#comp-off').prop('checked', true); loadCompanies(1); }); }; function loadCompanies(page) { var params = { person_id: compPersonId, page: page, limit: 5 }; var cur = $('#comp-cur').prop('checked'); var off = $('#comp-off').prop('checked'); // 状态筛选:只勾一项则按该项过滤;都不勾视为全部 if (cur && !off) params.is_current = 1; else if (!cur && off) params.is_current = 0; httpGet('person/companies.php', params).then(function (data) { var rows = data.list || []; var html = ''; rows.forEach(function (r) { html += '' + '' + escHtml(r.company_name) + '' + '' + escHtml(r.department || '-') + '' + '' + escHtml(r.position || '-') + '' + '' + escHtml(r.job_level || '-') + '' + '' + escHtml(r.start_date || '-') + '' + '' + (r.is_current ? '在岗' : '离岗') + '' + ''; }); if (!rows.length) { html = '暂无任职记录'; } $('#comp-tbody').html(html); renderPagination($('#comp-pagination'), data, loadCompanies); }); } /* ---------- 产品品类弹窗(按人员任职公司查看产品,分页) ---------- */ var ppPersonId = 0; window.viewPersonProducts = function (personId) { ppPersonId = personId; var content = '
' + '
' + ' ' + ' ' + '
公司品类名称品类描述是否核心
' + ' ' + '
'; Dialog.open({ title: '产品品类', area: ['760px', 'auto'], content: content, btn: ['关闭'] }); loadPersonProducts(1); }; function loadPersonProducts(page) { httpGet('person/products.php', { person_id: ppPersonId, page: page, limit: 5 }).then(function (data) { var rows = data.list || []; var html = ''; rows.forEach(function (r) { html += '' + '' + escHtml(r.company_name) + '' + '' + escHtml(r.category_name) + '' + '' + escHtml(r.category_description || '-') + '' + '' + (r.is_core ? '核心' : '-') + '' + ''; }); if (!rows.length) { html = '暂无产品品类'; } $('#pp-tbody').html(html); renderPagination($('#pp-pagination'), data, loadPersonProducts); }); } });