You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
12 KiB

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>用户公司信息管理</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: #f5f5f5;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 28px;
margin-bottom: 10px;
}
.table-container {
padding: 20px;
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #e0e0e0;
}
th {
background-color: #f8f9fa;
font-weight: 600;
color: #333;
}
tr:hover {
background-color: #f8f9fa;
}
.search-btn {
padding: 6px 16px;
background: #667eea;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background 0.3s;
}
.search-btn:hover {
background: #5568d3;
}
/* 弹窗样式 */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: white;
margin: 5% auto;
padding: 0;
border-radius: 8px;
width: 90%;
max-width: 800px;
max-height: 80vh;
overflow: hidden;
display: flex;
flex-direction: column;
}
.modal-header {
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-header h2 {
margin: 0;
font-size: 20px;
}
.close {
color: white;
font-size: 28px;
font-weight: bold;
cursor: pointer;
line-height: 1;
}
.close:hover {
opacity: 0.7;
}
.modal-body {
padding: 20px;
overflow-y: auto;
flex: 1;
}
.company-list {
list-style: none;
padding: 0;
}
.company-item {
padding: 15px;
border: 1px solid #e0e0e0;
border-radius: 4px;
margin-bottom: 10px;
cursor: pointer;
transition: all 0.3s;
}
.company-item:hover {
background-color: #f8f9fa;
border-color: #667eea;
}
.company-name {
font-weight: 600;
color: #333;
margin-bottom: 5px;
}
.company-info {
font-size: 13px;
color: #666;
}
.loading {
text-align: center;
padding: 40px;
color: #999;
}
.no-results {
text-align: center;
padding: 40px;
color: #999;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>用户公司信息管理</h1>
<p>管理用户的公司信息</p>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>ID</th>
<th>用户姓名</th>
<th>公司名称</th>
<th>关联公司ID</th>
<th>操作</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr data-user-id="{{ $user->id }}">
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td class="company-name-cell">{{ $user->company_name }}</td>
<td>{{ $user->company_id ?? '-' }}</td>
<td>
<button class="search-btn" onclick="openSearchModal({{ $user->id }}, '{{ addslashes($user->company_name) }}')">搜索公司</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<!-- 搜索弹窗 -->
<div id="searchModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>搜索公司</h2>
<span class="close" onclick="closeModal()">&times;</span>
</div>
<div class="modal-body">
<div style="margin-bottom: 20px;">
<input
type="text"
id="searchCompanyInput"
placeholder="请输入公司名称..."
style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px;"
onkeypress="if(event.key === 'Enter') searchCompany()"
>
<button
class="search-btn"
onclick="searchCompany()"
style="margin-top: 10px; width: 100%;"
>
查询
</button>
</div>
<div id="companyListContainer">
<div class="loading">请输入公司名称进行查询</div>
</div>
</div>
</div>
</div>
<script>
let currentUserId = null;
function openSearchModal(userId, currentCompanyName) {
currentUserId = userId;
document.getElementById('searchModal').style.display = 'block';
document.getElementById('searchCompanyInput').value = currentCompanyName;
document.getElementById('companyListContainer').innerHTML = '<div class="loading">请输入公司名称进行查询</div>';
}
function closeModal() {
document.getElementById('searchModal').style.display = 'none';
currentUserId = null;
}
// 点击弹窗外部关闭
window.onclick = function(event) {
const modal = document.getElementById('searchModal');
if (event.target == modal) {
closeModal();
}
}
function searchCompany() {
const companyName = document.getElementById('searchCompanyInput').value.trim();
if (!companyName) {
alert('请输入公司名称');
return;
}
const container = document.getElementById('companyListContainer');
container.innerHTML = '<div class="loading">查询中...</div>';
fetch(`/api/mobile/other/company?company_name=${encodeURIComponent(companyName)}`)
.then(response => response.json())
.then(data => {
let companies = null;
if (Array.isArray(data)) {
companies = data;
} else if (data.code === 200 && Array.isArray(data.data)) {
companies = data.data;
} else {
container.innerHTML = '<div class="no-results">查询失败,请稍后重试</div>';
return;
}
if (companies && companies.length > 0) {
displayCompanies(companies);
} else {
container.innerHTML = '<div class="no-results">未找到相关公司信息</div>';
}
})
.catch(error => {
container.innerHTML = '<div class="no-results">查询失败,请稍后重试</div>';
console.error('Error:', error);
});
}
function displayCompanies(companies) {
const container = document.getElementById('companyListContainer');
let html = '<ul class="company-list">';
companies.forEach(company => {
const companyName = company.name || '';
html += `
<li class="company-item" onclick="selectCompany('${escapeHtml(companyName)}')">
<div class="company-name">${escapeHtml(companyName)}</div>
<div class="company-info">
${company.creditCode ? '统一社会信用代码: ' + escapeHtml(company.creditCode) + '<br>' : ''}
${company.operName ? '法人代表: ' + escapeHtml(company.operName) + '<br>' : ''}
${company.status ? '注册状态: ' + escapeHtml(company.status) : ''}
</div>
</li>
`;
});
html += '</ul>';
container.innerHTML = html;
}
function selectCompany(companyName) {
if (!currentUserId) {
alert('用户ID不存在');
return;
}
if (!confirm(`确定要将公司名称更新为"${companyName}"吗?`)) {
return;
}
// 调用更新接口
fetch('/company/update-user-company', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || ''
},
body: JSON.stringify({
user_id: currentUserId,
company_name: companyName
})
})
.then(response => response.json())
.then(data => {
if (data.code === 200) {
// 更新页面上的数据
const row = document.querySelector(`tr[data-user-id="${currentUserId}"]`);
if (row) {
const companyNameCell = row.querySelector('.company-name-cell');
const companyIdCell = companyNameCell.nextElementSibling;
companyNameCell.textContent = companyName;
companyIdCell.textContent = '-';
}
alert('更新成功');
closeModal();
} else {
alert('更新失败: ' + (data.msg || data.message || '未知错误'));
}
})
.catch(error => {
console.error('Error:', error);
alert('更新失败,请稍后重试');
});
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
</script>
</body>
</html>