<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>备案主体信息管理</title>
<style>
body { font-family: sans-serif; line-height: 1.6; }
.container { max-width: 1000px; margin: 20px auto; padding: 20px; border: 1px solid #ccc; border-radius: 8px; }
h2, h3 { border-bottom: 2px solid #eee; padding-bottom: 5px; margin-top: 20px; }
table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
.btn { padding: 8px 12px; margin-right: 5px; cursor: pointer; border: none; border-radius: 4px; }
.btn-primary { background-color: #5cb85c; color: white; }
.btn-danger { background-color: #d9534f; color: white; }
.btn-secondary { background-color: #f0ad4e; color: white; }
.btn-info { background-color: #337ab7; color: white; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: bold; }
.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group select,
.form-group textarea { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
.beneficial-owner-section { border: 1px dashed #ccc; padding: 15px; margin-bottom: 15px; background-color: #f9f9f9; position: relative; }
.beneficial-owner-section h4 { margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 5px; }
.beneficial-owner-section .btn-danger { position: absolute; top: 10px; right: 10px; padding: 4px 8px; }
.hidden { display: none; }
.error { color: red; font-size: 0.9em; }
</style>
</head>
<body>
<div class="container">
<h2>备案主体列表</h2>
<button class="btn btn-primary" id="add-entity-btn">新增备案主体</button>
<table id="entities-table">
<thead>
<tr>
<th>统一社会信用代码</th>
<th>备案主体(机构)名称</th>
<th>备案主体类型</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<!-- Entity rows will be populated here -->
</tbody>
</table>
<div id="entity-form-section" class="hidden">
<hr>
<h2 id="form-title">新增备案主体</h2>
<form id="entity-form">
<input type="hidden" id="entity-index">
<h3>备案主体信息</h3>
<div class="form-group">
<label for="uscc">统一社会信用代码:</label>
<input type="text" id="uscc" required>
<span class="error" id="uscc-error"></span>
</div>
<div class="form-group">
<label for="orgNm">备案主体(机构)名称:</label>
<input type="text" id="orgNm" required>
<span class="error" id="orgNm-error"></span>
</div>
<div class="form-group">
<label for="orgTp">备案主体类型:</label>
<select id="orgTp" required>
<option value="">请选择</option>
<!-- Options will be populated by JS -->
</select>
<span class="error" id="orgTp-error"></span>
</div>
<h3>受益所有人及受益所有权信息</h3>
<div id="beneficial-owners-container">
<!-- Beneficial owner forms will be populated here -->
</div>
<button type="button" class="btn btn-secondary" id="add-owner-btn">新增受益所有人</button>
<hr>
<button type="submit" class="btn btn-primary">保存备案主体</button>
<button type="button" class="btn btn-secondary" id="cancel-edit-btn">取消</button>
</form>
</div>
</div>
<script>
// Data storage in memory
let entities = [];
let currentEntityIndex = null; // Used for editing
// Enumerations
const enums = {
OrgTp: {
"1": "公司",
"2": "合伙企业",
"3": "外国公司分支机构",
"4": "豁免主体"
},
Gender: {
"MALE": "男性",
"FMLE": "女性",
"OTHR": "其它"
},
Ntlty: {
"004": "阿富汗",
"008": "阿尔巴尼亚",
"156": "中国",
// ... add more nations as needed ...
"965": "土布艾群岛"
},
IdTp: {
"10": "中华人民共和国居民身份证",
"20": "中华人民共和国军官证",
"30": "中华人民共和国警官证",
"40": "外国(地区)护照",
"51": "香港特别行政区护照",
"52": "香港(永久性)居民身份证",
"53": "澳门特别行政区护照",
"54": "澳门(永久性)居民身份证",
"55": "港澳居民来往内地通行证",
"56": "台湾居民身份证",
"57": "台湾居民来往大陆通行证",
"58": "台湾农民身份有关证明",
"60": "户口薄",
"61": "外国人永久居留身份证",
"62": "华侨护照",
"63": "港澳居民居住证",
"64": "台湾居民居住证",
"90": "其他有效身份证件"
},
YesNoCode: {
"Y": "是",
"N": "否"
},
ActCtrlCpnyCode: {
"2": "协议约定形式",
"3": "其他形式"
},
ActCtrlCnttCode: {
"0": "决定法定代表人、董事、监事、高级管理人员的任免",
"1": "决定公司或者合伙企业重大经营、管理决策的制定或者执行",
"2": "决定公司公司或者合伙企业的财务收支",
"3": "长期实际支配使用公司公司或者合伙企业重要资产或者主要资金"
},
SeniorMgrPosCode: {
"10": "法定代表人",
"11": "董事长",
"12": "经理",
"13": "董事",
"14": "执行合伙事务的自然人(执行事务合伙人或者代表执行事务合伙人执行合伙事务的自然人)",
"15": "其他人员"
},
SeniorMgrPosCNCode: {
"0": "分支机构负责人",
"1": "其他高级管理人员"
}
};
// DOM Elements
const entitiesTableBody = document.querySelector('#entities-table tbody');
const entityFormSection = document.getElementById('entity-form-section');
const entityForm = document.getElementById('entity-form');
const formTitle = document.getElementById('form-title');
const entityIndexInput = document.getElementById('entity-index');
const usccInput = document.getElementById('uscc');
const orgNmInput = document.getElementById('orgNm');
const orgTpSelect = document.getElementById('orgTp');
const beneficialOwnersContainer = document.getElementById('beneficial-owners-container');
const addEntityBtn = document.getElementById('add-entity-btn');
const addOwnerBtn = document.getElementById('add-owner-btn');
const cancelEditBtn = document.getElementById('cancel-edit-btn');
// Populate static select options
function populateSelectOptions(selectElement, enumData) {
for (const key in enumData) {
const option = document.createElement('option');
option.value = key;
option.textContent = enumData[key];
selectElement.appendChild(option);
}
}
populateSelectOptions(orgTpSelect, enums.OrgTp);
// --- Rendering Functions ---
function renderEntityList() {
entitiesTableBody.innerHTML = '';
if (entities.length === 0) {
entitiesTableBody.innerHTML = '<tr><td colspan="4" style="text-align:center;">暂无备案主体信息</td></tr>';
return;
}
entities.forEach((entity, index) => {
const row = entitiesTableBody.insertRow();
row.innerHTML = `
<td>${entity.Uscc}</td>
<td>${entity.OrgNm}</td>
<td>${enums.OrgTp[entity.OrgTp] || entity.OrgTp}</td>
<td>
<button class="btn btn-info btn-sm view-edit-btn" data-index="${index}">查看/编辑</button>
<button class="btn btn-danger btn-sm delete-btn" data-index="${index}">删除</button>
</td>
`;
});
}
function renderBeneficialOwnerForm(owner, ownerIndex) {
const ownerDiv = document.createElement('div');
ownerDiv.classList.add('beneficial-owner-section');
ownerDiv.dataset.index = ownerIndex; // Use data attribute to link to owner index
// Generate HTML for each owner/ownership field
ownerDiv.innerHTML = `
<h4>受益所有人 ${ownerIndex + 1} <button type="button" class="btn btn-danger btn-sm remove-owner-btn">移除</button></h4>
<!-- 受益所有人信息 -->
<div class="form-group"><label>姓名:</label><input type="text" class="owner-Name" value="${owner.Name || ''}" required></div>
<div class="form-group"><label>性别:</label><select class="owner-Gender" required>${generateOptions(enums.Gender, owner.Gender)}</select></div>
<div class="form-group"><label>国籍:</label><select class="owner-Ntlty" required>${generateOptions(enums.Ntlty, owner.Ntlty)}</select></div>
<div class="form-group"><label>出生日期:</label><input type="date" class="owner-BirthDt" value="${owner.BirthDt || ''}" required></div>
<div class="form-group"><label>经常居住地或工作单位地址:</label><input type="text" class="owner-Addr" value="${owner.Addr || ''}" required></div>
<div class="form-group"><label>身份证件或身份证明文件类型:</label><select class="owner-IdTp" required>${generateOptions(enums.IdTp, owner.IdTp)}</select></div>
<div class="form-group"><label>身份证件或身份证明文件号码:</label><input type="text" class="owner-IdNb" value="${owner.IdNb || ''}" required></div>
<div class="form-group"><label>身份证件或身份证明文件有效期限:</label><input type="date" class="owner-IdDate" value="${owner.IdDate || ''}"></div>
<div class="form-group"><label>联系电话(手机):</label><input type="text" class="owner-MobNo1" value="${owner.MobNo1 || ''}"></div>
<div class="form-group"><label>联系电话(固定电话):</label><input type="text" class="owner-MobNo2" value="${owner.MobNo2 || ''}"></div>
<!-- 受益所有权信息 -->
<div class="form-group"><label>直接或间接拥有25%以上股权、股份份额、合伙权益:</label><select class="owner-ActCtrl" required>${generateOptions(enums.YesNoCode, owner.ActCtrl)}</select></div>
<div class="form-group act-ctrl-fields ${owner.ActCtrl !== 'Y' ? 'hidden' : ''}">
<div class="form-group"><label>持有股权、股份、合伙权益的比例(%):</label><input type="number" step="0.01" min="0" max="100" class="owner-ActHdRat" value="${owner.ActHdRat || ''}"></div>
<div class="form-group"><label>受益所有权形成日期(25%以上股权、股份):</label><input type="date" class="owner-ShareRatioStartDate" value="${owner.ShareRatioStartDate || ''}"></div>
<div class="form-group"><label>受益所有权终止日期(25%以上股权、股份):</label><input type="date" class="owner-ShareRatioEndDate" value="${owner.ShareRatioEndDate || ''}"></div>
</div>
<div class="form-group"><label>实际控制公司、合伙企业:</label><select class="owner-ActCtrlCpny">${generateOptions(enums.ActCtrlCpnyCode, owner.ActCtrlCpny, true)}</select></div>
<div class="act-ctrl-cpny-fields ${!owner.ActCtrlCpny ? 'hidden' : ''}">
<div class="form-group act-ctrl-type-group ${owner.ActCtrlCpny !== '2' ? 'hidden' : ''}">
<label>实施实际控制的内容/方式:</label>
<select class="owner-ActCtrlType" ${owner.ActCtrlCpny === '2' ? 'required' : ''}>${generateOptions(enums.ActCtrlCnttCode, owner.ActCtrlType, true)}</select>
</div>
<div class="form-group act-other-forms-group ${owner.ActCtrlCpny !== '3' ? 'hidden' : ''}">
<label>其他形式的具体内容:</label>
<textarea class="owner-ActOtherForms" ${owner.ActCtrlCpny === '3' ? 'required' : ''}>${owner.ActOtherForms || ''}</textarea>
</div>
<div class="form-group"><label>受益所有权形成日期(实施实际控制):</label><input type="date" class="owner-ObtainActDate" value="${owner.ObtainActDate || ''}"></div>
<div class="form-group"><label>受益所有权终止日期(实施实际控制):</label><input type="date" class="owner-TerminationActDate" value="${owner.TerminationActDate || ''}"></div>
</div>
<div class="form-group"><label>是否存在上一层备案主体:</label><select class="owner-ActConUpperMarket" required>${generateOptions(enums.YesNoCode, owner.ActConUpperMarket)}</select></div>
<div class="act-con-upper-fields ${owner.ActConUpperMarket !== 'Y' ? 'hidden' : ''}">
<div class="form-group"><label>实际控制备案主体的上一层备案主体名称:</label><input type="text" class="owner-ActConUpperEntName" value="${owner.ActConUpperEntName || ''}"></div>
<div class="form-group"><label>实际控制备案主体的统一社会信用代码:</label><input type="text" class="owner-ActConUniScid" value="${owner.ActConUniScid || ''}"></div>
</div>
<div class="form-group"><label>可最终获得25%以上收益权,表决权:</label><select class="owner-PriBenfit" required>${generateOptions(enums.YesNoCode, owner.PriBenfit)}</select></div>
<div class="pri-benfit-fields ${owner.PriBenfit !== 'Y' ? 'hidden' : ''}">
<div class="form-group"><label>收益权比例(%):</label><input type="number" step="0.01" min="0" max="100" class="owner-ActOwnerProfitRatio" value="${owner.ActOwnerProfitRatio || ''}"></div>
<div class="form-group"><label>受益所有权形成日期(收益权):</label><input type="date" class="owner-ProfitRatioStartDate" value="${owner.ProfitRatioStartDate || ''}"></div>
<div class="form-group"><label>受益所有权终止日期(收益权):</label><input type="date" class="owner-ProfitRatioEndDate" value="${owner.ProfitRatioEndDate || ''}"></div>
<div class="form-group"><label>表决权比例(%):</label><input type="number" step="0.01" min="0" max="100" class="owner-ActOwnerProfitRatioVote" value="${owner.ActOwnerProfitRatioVote || ''}"></div>
<div class="form-group"><label>受益所有权形成日期(表决权):</label><input type="date" class="owner-ProfitRatioVoteStartDate" value="${owner.ProfitRatioVoteStartDate || ''}"></div>
<div class="form-group"><label>受益所有权终止日期(表决权):</label><input type="date" class="owner-ProfitRatioVoteEndDate" value="${owner.ProfitRatioVoteEndDate || ''}"></div>
</div>
<div class="form-group"><label>负责日常经营管理的(高级管理)人员:</label><select class="owner-SeniorMgr" required>${generateOptions(enums.YesNoCode, owner.SeniorMgr)}</select></div>
<div class="senior-mgr-fields ${owner.SeniorMgr !== 'Y' ? 'hidden' : ''}">
<div class="form-group"><label>负责日常经营管理的(高级管理)人员职位:</label><select class="owner-SeniorMgrPos" required>${generateOptions(enums.SeniorMgrPosCode, owner.SeniorMgrPos, true)}</select></div>
<div class="form-group owner-daily-mgmt-post-other-group ${owner.SeniorMgrPos !== '15' ? 'hidden' : ''}">
<label>公司章程规定的其他(高级管理)人员的具体职位:</label>
<input type="text" class="owner-ActDailyMgmtPostOther" value="${owner.ActDailyMgmtPostOther || ''}" ${owner.SeniorMgrPos === '15' ? 'required' : ''}>
</div>
</div>
<div class="form-group"><label>在华最高层级的高级管理人员:</label><select class="owner-SeniorMgrCN" required>${generateOptions(enums.YesNoCode, owner.SeniorMgrCN)}</select></div>
<div class="senior-mgr-cn-fields ${owner.SeniorMgrCN !== 'Y' ? 'hidden' : ''}">
<div class="form-group"><label>在华最高层级的高级管理人员职位:</label><select class="owner-SeniorMgrPosCN" required>${generateOptions(enums.SeniorMgrPosCNCode, owner.SeniorMgrPosCN, true)}</select></div>
<div class="form-group owner-right-mgmt-post-other-group ${owner.SeniorMgrPosCN !== '1' ? 'hidden' : ''}">
<label>在华最高层级的高级管理其他职位:</label>
<input type="text" class="owner-OwnerRightMgmtPostOther" value="${owner.OwnerRightMgmtPostOther || ''}" ${owner.SeniorMgrPosCN === '1' ? 'required' : ''}>
</div>
</div>
`;
// Add event listeners for conditional fields within this owner form
addOwnerFormListeners(ownerDiv);
return ownerDiv;
}
function renderEntityForm(entity = { beneficialOwners: [] }, index = null) {
currentEntityIndex = index;
formTitle.textContent = index === null ? '新增备案主体' : '编辑备案主体';
entityIndexInput.value = index;
// Populate main entity fields
usccInput.value = entity.Uscc || '';
orgNmInput.value = entity.OrgNm || '';
orgTpSelect.value = entity.OrgTp || '';
// Clear and render beneficial owner forms
beneficialOwnersContainer.innerHTML = '';
entity.beneficialOwners.forEach((owner, ownerIndex) => {
const ownerFormElement = renderBeneficialOwnerForm(owner, ownerIndex);
beneficialOwnersContainer.appendChild(ownerFormElement);
});
// Show the form
entityFormSection.classList.remove('hidden');
// Scroll to the form
entityFormSection.scrollIntoView({ behavior: 'smooth' });
// Clear validation errors
clearErrors();
}
// --- Helper Functions ---
function generateOptions(enumData, selectedValue, addEmpty = false) {
let options = addEmpty ? '<option value="">请选择</option>' : '';
for (const key in enumData) {
const selected = selectedValue === key ? 'selected' : '';
options += `<option value="${key}" ${selected}>${enumData[key]}</option>`;
}
return options;
}
function collectOwnerData(ownerFormElement) {
const data = {};
const inputs = ownerFormElement.querySelectorAll('input, select, textarea');
inputs.forEach(input => {
const fieldName = input.classList.value.split(' ').find(cls => cls.startsWith('owner-')).replace('owner-', '');
if (input.type === 'number') {
data[fieldName] = input.value === '' ? null : parseFloat(input.value); // Store numbers or null
} else if (input.type === 'date') {
data[fieldName] = input.value || null; // Store date string or null
}
else if (input.tagName === 'TEXTAREA') {
data[fieldName] = input.value || null; // Store text or null
}
else {
data[fieldName] = input.value || null; // Store string or null
}
});
return data;
}
function addOwnerFormListeners(ownerFormElement) {
const actCtrlSelect = ownerFormElement.querySelector('.owner-ActCtrl');
const actCtrlFields = ownerFormElement.querySelector('.act-ctrl-fields');
const actCtrlCpnySelect = ownerFormElement.querySelector('.owner-ActCtrlCpny');
const actCtrlCpnyFields = ownerFormElement.querySelector('.act-ctrl-cpny-fields');
const actCtrlTypeGroup = ownerFormElement.querySelector('.act-ctrl-type-group');
const actCtrlTypeSelect = ownerFormElement.querySelector('.owner-ActCtrlType');
const actOtherFormsGroup = ownerFormElement.querySelector('.act-other-forms-group');
const actOtherFormsTextarea = ownerFormElement.querySelector('.owner-ActOtherForms');
const actConUpperMarketSelect = ownerFormElement.querySelector('.owner-ActConUpperMarket');
const actConUpperFields = ownerFormElement.querySelector('.act-con-upper-fields');
const priBenfitSelect = ownerFormElement.querySelector('.owner-PriBenfit');
const priBenfitFields = ownerFormElement.querySelector('.pri-benfit-fields');
const seniorMgrSelect = ownerFormElement.querySelector('.owner-SeniorMgr');
const seniorMgrFields = ownerFormElement.querySelector('.senior-mgr-fields');
const seniorMgrPosSelect = ownerFormElement.querySelector('.owner-SeniorMgrPos');
const ownerDailyMgmtPostOtherGroup = ownerFormElement.querySelector('.owner-daily-mgmt-post-other-group');
const ownerDailyMgmtPostOtherInput = ownerFormElement.querySelector('.owner-ActDailyMgmtPostOther');
const seniorMgrCNSelect = ownerFormElement.querySelector('.owner-SeniorMgrCN');
const seniorMgrCNFields = ownerFormElement.querySelector('.senior-mgr-cn-fields');
const seniorMgrPosCNSelect = ownerFormElement.querySelector('.owner-SeniorMgrPosCN');
const ownerRightMgmtPostOtherGroup = ownerFormElement.querySelector('.owner-right-mgmt-post-other-group');
const ownerRightMgmtPostOtherInput = ownerFormElement.querySelector('.owner-OwnerRightMgmtPostOther');
actCtrlSelect.addEventListener('change', (e) => {
if (e.target.value === 'Y') {
actCtrlFields.classList.remove('hidden');
} else {
actCtrlFields.classList.add('hidden');
// Clear values if hidden
actCtrlFields.querySelectorAll('input').forEach(input => input.value = '');
}
});
actCtrlCpnySelect.addEventListener('change', (e) => {
const val = e.target.value;
if (val) {
actCtrlCpnyFields.classList.remove('hidden');
} else {
actCtrlCpnyFields.classList.add('hidden');
// Clear values
actCtrlTypeSelect.value = '';
actCtrlTypeSelect.required = false;
actOtherFormsTextarea.value = '';
actOtherFormsTextarea.required = false;
actCtrlCpnyFields.querySelectorAll('input[type="date"]').forEach(input => input.value = '');
}
// Conditional logic for ActCtrlType and ActOtherForms
if (val === '2') {
actCtrlTypeGroup.classList.remove('hidden');
actCtrlTypeSelect.required = true;
actOtherFormsGroup.classList.add('hidden');
actOtherFormsTextarea.value = '';
actOtherFormsTextarea.required = false;
} else if (val === '3') {
actOtherFormsGroup.classList.remove('hidden');
actOtherFormsTextarea.required = true;
actCtrlTypeGroup.classList.add('hidden');
actCtrlTypeSelect.value = '';
actCtrlTypeSelect.required = false;
} else { // value is empty or other cases not '2' or '3'
actCtrlTypeGroup.classList.add('hidden');
actCtrlTypeSelect.value = '';
actCtrlTypeSelect.required = false;
actOtherFormsGroup.classList.add('hidden');
actOtherFormsTextarea.value = '';
actOtherFormsTextarea.required = false;
}
});
actConUpperMarketSelect.addEventListener('change', (e) => {
if (e.target.value === 'Y') {
actConUpperFields.classList.remove('hidden');
} else {
actConUpperFields.classList.add('hidden');
actConUpperFields.querySelectorAll('input').forEach(input => input.value = '');
}
});
priBenfitSelect.addEventListener('change', (e) => {
if (e.target.value === 'Y') {
priBenfitFields.classList.remove('hidden');
} else {
priBenfitFields.classList.add('hidden');
priBenfitFields.querySelectorAll('input').forEach(input => input.value = '');
}
});
seniorMgrSelect.addEventListener('change', (e) => {
if (e.target.value === 'Y') {
seniorMgrFields.classList.remove('hidden');
} else {
seniorMgrFields.classList.add('hidden');
seniorMgrFields.querySelectorAll('select').forEach(select => select.value = '');
seniorMgrFields.querySelectorAll('input').forEach(input => input.value = '');
seniorMgrPosSelect.required = false;
ownerDailyMgmtPostOtherInput.required = false;
ownerDailyMgmtPostOtherGroup.classList.add('hidden'); // Hide other text field
}
});
seniorMgrPosSelect.addEventListener('change', (e) => {
if (e.target.value === '15') {
ownerDailyMgmtPostOtherGroup.classList.remove('hidden');
ownerDailyMgmtPostOtherInput.required = true;
} else {
ownerDailyMgmtPostOtherGroup.classList.add('hidden');
ownerDailyMgmtPostOtherInput.value = '';
ownerDailyMgmtPostOtherInput.required = false;
}
});
seniorMgrCNSelect.addEventListener('change', (e) => {
if (e.target.value === 'Y') {
seniorMgrCNFields.classList.remove('hidden');
} else {
seniorMgrCNFields.classList.add('hidden');
seniorMgrCNFields.querySelectorAll('select').forEach(select => select.value = '');
seniorMgrCNFields.querySelectorAll('input').forEach(input => input.value = '');
seniorMgrPosCNSelect.required = false;
ownerRightMgmtPostOtherInput.required = false;
ownerRightMgmtPostOtherGroup.classList.add('hidden'); // Hide other text field
}
});
seniorMgrPosCNSelect.addEventListener('change', (e) => {
if (e.target.value === '1') { // Note: The description says "1:其他高级管理人员" maps to ActDailyMgmtPostOther. Assuming this is a typo and it should map to OwnerRightMgmtPostOther
ownerRightMgmtPostOtherGroup.classList.remove('hidden');
ownerRightMgmtPostOtherInput.required = true;
} else {
ownerRightMgmtPostOtherGroup.classList.add('hidden');
ownerRightMgmtPostOtherInput.value = '';
ownerRightMgmtPostOtherInput.required = false;
}
});
}
function clearErrors() {
document.querySelectorAll('.error').forEach(span => span.textContent = '');
document.querySelectorAll('.form-group input, .form-group select, .form-group textarea').forEach(input => input.classList.remove('error-border')); // Remove error class if any
}
function validateForm() {
clearErrors();
let isValid = true;
// Validate main entity fields
const requiredEntityFields = [usccInput, orgNmInput, orgTpSelect];
requiredEntityFields.forEach(input => {
if (!input.value) {
document.getElementById(`${input.id}-error`).textContent = '此字段为必填项';
input.classList.add('error-border');
isValid = false;
}
});
// Validate beneficial owner fields
const ownerSections = beneficialOwnersContainer.querySelectorAll('.beneficial-owner-section');
if (ownerSections.length === 0) {
// Decide if at least one owner is required. Assuming yes for now.
// If not required, remove this check.
console.error("至少需要添加一个受益所有人信息"); // Log error for developer
alert("请至少添加一个受益所有人信息."); // Alert user
isValid = false;
} else {
ownerSections.forEach(ownerSection => {
const requiredInputs = ownerSection.querySelectorAll('input[required], select[required], textarea[required]');
requiredInputs.forEach(input => {
if (!input.value) {
// Find a place to display error, or just rely on browser's default validation
// For this example, we'll rely on browser or a simple alert
console.error(`Owner form ${ownerSection.dataset.index}: Field ${input.className} is required.`);
input.classList.add('error-border'); // Add a visual indicator
isValid = false;
}
});
// Check conditional required fields
// ActCtrlType required if ActCtrlCpny is '2'
const actCtrlCpnySelect = ownerSection.querySelector('.owner-ActCtrlCpny');
const actCtrlTypeSelect = ownerSection.querySelector('.owner-ActCtrlType');
if(actCtrlCpnySelect.value === '2' && !actCtrlTypeSelect.value) {
console.error(`Owner form ${ownerSection.dataset.index}: ActCtrlType is required when ActCtrlCpny is '2'.`);
actCtrlTypeSelect.classList.add('error-border');
isValid = false;
}
// ActOtherForms required if ActCtrlCpny is '3'
const actOtherFormsTextarea = ownerSection.querySelector('.owner-ActOtherForms');
if(actCtrlCpnySelect.value === '3' && !actOtherFormsTextarea.value) {
console.error(`Owner form ${ownerSection.dataset.index}: ActOtherForms is required when ActCtrlCpny is '3'.`);
actOtherFormsTextarea.classList.add('error-border');
isValid = false;
}
// ActDailyMgmtPostOther required if SeniorMgrPos is '15'
const seniorMgrPosSelect = ownerSection.querySelector('.owner-SeniorMgrPos');
const dailyMgmtOtherInput = ownerSection.querySelector('.owner-ActDailyMgmtPostOther');
if(seniorMgrPosSelect.value === '15' && !dailyMgmtOtherInput.value) {
console.error(`Owner form ${ownerSection.dataset.index}: ActDailyMgmtPostOther is required when SeniorMgrPos is '15'.`);
dailyMgmtOtherInput.classList.add('error-border');
isValid = false;
}
// OwnerRightMgmtPostOther required if SeniorMgrPosCN is '1'
const seniorMgrPosCNSelect = ownerSection.querySelector('.owner-SeniorMgrPosCN');
const ownerRightMgmtOtherInput = ownerSection.querySelector('.owner-OwnerRightMgmtPostOther');
if(seniorMgrPosCNSelect.value === '1' && !ownerRightMgmtOtherInput.value) {
console.error(`Owner form ${ownerSection.dataset.index}: OwnerRightMgmtPostOther is required when SeniorMgrPosCN is '1'.`);
ownerRightMgmtOtherInput.classList.add('error-border');
isValid = false;
}
});
}
if (!isValid) {
alert('请检查表单中的错误并更正.'); // Alert user if validation failed
}
return isValid;
}
// --- Event Handlers ---
addEntityBtn.addEventListener('click', () => {
renderEntityForm();
});
cancelEditBtn.addEventListener('click', () => {
entityFormSection.classList.add('hidden');
entityForm.reset();
currentEntityIndex = null;
clearErrors(); // Clear errors on cancel
});
addOwnerBtn.addEventListener('click', () => {
// Add a new empty owner object to the current entity's beneficialOwners array
// If it's a new entity being created, the array is already initialized
if (currentEntityIndex === null) { // Adding to a new entity not yet in entities[]
// Need a temporary entity object if it's 'new'
if (!entityForm.dataset.tempEntity) {
entityForm.dataset.tempEntity = JSON.stringify({ beneficialOwners: [] });
}
let tempEntity = JSON.parse(entityForm.dataset.tempEntity);
tempEntity.beneficialOwners.push({}); // Add new empty owner
entityForm.dataset.tempEntity = JSON.stringify(tempEntity); // Update temp storage
// Re-render owners based on temp storage
beneficialOwnersContainer.innerHTML = ''; // Clear current owners
tempEntity.beneficialOwners.forEach((owner, ownerIndex) => {
const ownerFormElement = renderBeneficialOwnerForm(owner, ownerIndex);
beneficialOwnersContainer.appendChild(ownerFormElement);
});
} else { // Adding to an existing entity being edited
entities[currentEntityIndex].beneficialOwners.push({});
// Re-render owners for the current entity
beneficialOwnersContainer.innerHTML = ''; // Clear current owners
entities[currentEntityIndex].beneficialOwners.forEach((owner, ownerIndex) => {
const ownerFormElement = renderBeneficialOwnerForm(owner, ownerIndex);
beneficialOwnersContainer.appendChild(ownerFormElement);
});
}
});
// Event delegation for removing owner buttons (since they are added dynamically)
beneficialOwnersContainer.addEventListener('click', (e) => {
if (e.target.classList.contains('remove-owner-btn')) {
const ownerSection = e.target.closest('.beneficial-owner-section');
const ownerIndexToRemove = parseInt(ownerSection.dataset.index);
if (currentEntityIndex === null) { // Removing from a new entity (temp storage)
if (entityForm.dataset.tempEntity) {
let tempEntity = JSON.parse(entityForm.dataset.tempEntity);
tempEntity.beneficialOwners.splice(ownerIndexToRemove, 1);
entityForm.dataset.tempEntity = JSON.stringify(tempEntity);
// Re-render owners based on temp storage
beneficialOwnersContainer.innerHTML = '';
tempEntity.beneficialOwners.forEach((owner, ownerIndex) => {
const ownerFormElement = renderBeneficialOwnerForm(owner, ownerIndex);
beneficialOwnersContainer.appendChild(ownerFormElement);
});
}
} else { // Removing from an existing entity
if (confirm('确定要移除此受益所有人吗?')) {
entities[currentEntityIndex].beneficialOwners.splice(ownerIndexToRemove, 1);
// Re-render owners for the current entity
beneficialOwnersContainer.innerHTML = '';
entities[currentEntityIndex].beneficialOwners.forEach((owner, ownerIndex) => {
const ownerFormElement = renderBeneficialOwnerForm(owner, ownerIndex);
beneficialOwnersContainer.appendChild(ownerFormElement);
});
}
}
}
});
entityForm.addEventListener('submit', (e) => {
e.preventDefault();
if (!validateForm()) {
return; // Stop if validation fails
}
const newEntity = {
Uscc: usccInput.value,
OrgNm: orgNmInput.value,
OrgTp: orgTpSelect.value,
beneficialOwners: [] // This will be populated from the current form state
};
// Collect data from all beneficial owner forms
const ownerSections = beneficialOwnersContainer.querySelectorAll('.beneficial-owner-section');
ownerSections.forEach(ownerSection => {
newEntity.beneficialOwners.push(collectOwnerData(ownerSection));
});
if (currentEntityIndex === null) {
// Add new entity
entities.push(newEntity);
} else {
// Update existing entity
entities[currentEntityIndex] = newEntity;
}
// Reset form and hide it
entityForm.reset();
entityFormSection.classList.add('hidden');
currentEntityIndex = null;
delete entityForm.dataset.tempEntity; // Clear temp storage
clearErrors();
// Re-render the list
renderEntityList();
alert('备案主体信息已保存!');
});
// Event delegation for view/edit and delete buttons
entitiesTableBody.addEventListener('click', (e) => {
const index = e.target.dataset.index;
if (e.target.classList.contains('view-edit-btn')) {
const entityToEdit = entities[index];
renderEntityForm(entityToEdit, index);
} else if (e.target.classList.contains('delete-btn')) {
if (confirm(`确定要删除备案主体 "${entities[index].OrgNm}" 吗?`)) {
entities.splice(index, 1);
renderEntityList();
alert('备案主体信息已删除!');
// If the deleted entity was currently being edited, hide the form
if (currentEntityIndex === parseInt(index)) {
entityFormSection.classList.add('hidden');
entityForm.reset();
currentEntityIndex = null;
delete entityForm.dataset.tempEntity;
clearErrors();
} else if (currentEntityIndex !== null && parseInt(index) < currentEntityIndex) {
// If a preceding entity was deleted, update the current index
currentEntityIndex--;
entityIndexInput.value = currentEntityIndex;
}
}
}
});
// --- Initial Setup ---
// Add some initial dummy data
entities = [
{
Uscc: "91110105XXXXYYYYZZ",
OrgNm: "示例公司A",
OrgTp: "1", // 公司
beneficialOwners: [
{
Name: "张三",
Gender: "MALE",
Ntlty: "156", // 中国
BirthDt: "1980-01-15",
Addr: "北京市海淀区xx街道xx号",
IdTp: "10", // 居民身份证
IdNb: "11010119800115xxxx",
IdDate: "2030-01-15",
MobNo1: "138xxxx0001",
MobNo2: null,
ActCtrl: "Y", // 直接或间接拥有25%以上
ActHdRat: 40, // 股权比例
ShareRatioStartDate: "2018-05-20",
ShareRatioEndDate: null, // 持续拥有
ActCtrlCpny: null, // 非协议/其他形式控制
ActCtrlType: null,
ObtainActDate: null,
TerminationActDate: null,
ActOtherForms: null,
ActConUpperMarket: "N", // 无上一层主体
ActConUpperEntName: null,
ActConUniScid: null,
PriBenfit: "Y", // 可最终获得25%以上收益/表决权
ActOwnerProfitRatio: 40, // 收益权比例
ProfitRatioStartDate: "2018-05-20",
ProfitRatioEndDate: null,
ActOwnerProfitRatioVote: 45, // 表决权比例
ProfitRatioVoteStartDate: "2018-05-20",
ProfitRatioVoteEndDate: null,
SeniorMgr: "Y", // 是高级管理人员
SeniorMgrPos: "10", // 法定代表人
ActDailyMgmtPostOther: null,
SeniorMgrCN: "Y", // 是在华最高层级高级管理人员
SeniorMgrPosCN: "0", // 分支机构负责人 (Note: OrgTp is 1, so this might be inconsistent with real data validation, but follows example structure)
OwnerRightMgmtPostOther: null
},
{
Name: "李四",
Gender: "FMLE",
Ntlty: "156", // 中国
BirthDt: "1990-03-22",
Addr: "上海市浦东新区yy街道yy号",
IdTp: "10", // 居民身份证
IdNb: "31010119900322xxxx",
IdDate: "2035-03-22",
MobNo1: "139xxxx0002",
MobNo2: null,
ActCtrl: "N", // 不直接或间接拥有25%以上
ActHdRat: 15, // 股权比例小于25%
ShareRatioStartDate: null,
ShareRatioEndDate: null,
ActCtrlCpny: null, // 非协议/其他形式控制
ActCtrlType: null,
ObtainActDate: null,
TerminationActDate: null,
ActOtherForms: null,
ActConUpperMarket: "N", // 无上一层主体
ActConUpperEntName: null,
ActConUniScid: null,
PriBenfit: "N", // 不可最终获得25%以上收益/表决权
ActOwnerProfitRatio: 15, // 收益权比例
ProfitRatioStartDate: null,
ProfitRatioEndDate: null,
ActOwnerProfitRatioVote: 10, // 表决权比例
ProfitRatioVoteStartDate: null,
ProfitRatioVoteEndDate: null,
SeniorMgr: "N", // 不是高级管理人员
SeniorMgrPos: null,
ActDailyMgmtPostOther: null,
SeniorMgrCN: "N", // 不是在华最高层级高级管理人员
SeniorMgrPosCN: null,
OwnerRightMgmtPostOther: null
}
]
},
{
Uscc: "93310110ZZZZWWWWVV",
OrgNm: "示例合伙企业B",
OrgTp: "2", // 合伙企业
beneficialOwners: [
{
Name: "王五",
Gender: "MALE",
Ntlty: "156", // 中国
BirthDt: "1975-07-01",
Addr: "广东省深圳市zz街道zz号",
IdTp: "10", // 居民身份证
IdNb: "44030119750701xxxx",
IdDate: "2028-07-01",
MobNo1: "137xxxx0003",
MobNo2: "0755-xxxxxxx",
ActCtrl: "Y", // 直接或间接拥有25%以上
ActHdRat: 60, // 合伙权益比例
ShareRatioStartDate: "2020-01-01",
ShareRatioEndDate: null,
ActCtrlCpny: "2", // 协议约定形式
ActCtrlType: "0", // 决定任免
ObtainActDate: "2020-01-01",
TerminationActDate: null,
ActOtherForms: null,
ActConUpperMarket: "N", // 无上一层主体
ActConUpperEntName: null,
ActConUniScid: null,
PriBenfit: "Y", // 可最终获得25%以上收益/表决权
ActOwnerProfitRatio: 60,
ProfitRatioStartDate: "2020-01-01",
ProfitRatioEndDate: null,
ActOwnerProfitRatioVote: 60,
ProfitRatioVoteStartDate: "2020-01-01",
ProfitRatioVoteEndDate: null,
SeniorMgr: "Y", // 是高级管理人员
SeniorMgrPos: "14", // 执行合伙事务的自然人
ActDailyMgmtPostOther: null,
SeniorMgrCN: "Y", // 是在华最高层级高级管理人员
SeniorMgrPosCN: "1", // 其他高级管理人员
OwnerRightMgmtPostOther: "合伙人代表" // 其他职位具体内容
}
]
}
];
// Initial render
renderEntityList();
</script>
</body>
</html>