|
|
|
@ -573,6 +573,7 @@ |
|
|
|
<div class="user-info"> |
|
|
|
<span id="userRole"></span> |
|
|
|
<span id="userName"></span> |
|
|
|
<button id="applyButton" onclick="openApplyModal()" style="display: none; margin-right: 10px; padding: 5px 10px; background-color: #722ed1; color: white; border: none; border-radius: 4px; font-size: 14px; cursor: pointer;">申请管理</button> |
|
|
|
<button id="permissionButton" onclick="openPermissionModal()" style="display: none; margin-right: 10px; padding: 5px 10px; background-color: #1890ff; color: white; border: none; border-radius: 4px; font-size: 14px; cursor: pointer;">权限管理</button> |
|
|
|
<button class="logout-btn" onclick="logout()">退出登录</button> |
|
|
|
</div> |
|
|
|
@ -616,6 +617,7 @@ |
|
|
|
<div class="tab-container-scroll"> |
|
|
|
<div class="tab-container"> |
|
|
|
<button class="tab-button active" onclick="switchTab('personal', this)">个人数据</button> |
|
|
|
<button class="tab-button" onclick="switchTab('products', this)">货源浏览</button> |
|
|
|
<button class="tab-button" onclick="switchTab('public', this)">公海池数据</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
@ -688,6 +690,35 @@ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<!-- 货源浏览标签页 --> |
|
|
|
<div id="products" class="tab-content"> |
|
|
|
<div class="filter-container"> |
|
|
|
<div class="filter-bar"> |
|
|
|
<button onclick="loadProducts()" style="background-color: #1890ff; color: white; border: none; border-radius: 4px; padding: 8px 16px; cursor: pointer; font-size: 14px;">刷新货源</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="table-container"> |
|
|
|
<table id="productsTable"> |
|
|
|
<thead> |
|
|
|
<tr> |
|
|
|
<th>商品名称</th> |
|
|
|
<th>价格</th> |
|
|
|
<th>库存</th> |
|
|
|
<th>地区</th> |
|
|
|
<th>创建时间</th> |
|
|
|
<th>操作</th> |
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
<tbody id="productsBody"> |
|
|
|
</tbody> |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
<div id="productsEmpty" class="empty-state">暂无货源数据</div> |
|
|
|
<div class="pagination" id="productsPagination"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<!-- 公海池数据标签页 --> |
|
|
|
<div id="public" class="tab-content"> |
|
|
|
<div class="filter-container"> |
|
|
|
@ -758,13 +789,18 @@ |
|
|
|
var userInfo = null; |
|
|
|
var personalPage = 1; |
|
|
|
var publicPage = 1; |
|
|
|
var productsPage = 1; |
|
|
|
var personalPageSize = 10; |
|
|
|
var publicPageSize = 10; |
|
|
|
var productsPageSize = 10; |
|
|
|
var personalFilter = 'all'; // all, followed, unfollowed |
|
|
|
|
|
|
|
var managersList = []; |
|
|
|
var allPersonalData = []; |
|
|
|
var allPublicData = []; |
|
|
|
var allProducts = []; |
|
|
|
var productsTotal = 0; |
|
|
|
var productsTotalPages = 0; |
|
|
|
var isLoadingAllData = false; |
|
|
|
var currentManagerFilter = null; |
|
|
|
var currentFilterTable = 'personal'; |
|
|
|
@ -819,6 +855,7 @@ |
|
|
|
var assignButton = document.getElementById('assignButton'); |
|
|
|
var publicAssignButton = document.getElementById('publicAssignButton'); |
|
|
|
var permissionButton = document.getElementById('permissionButton'); |
|
|
|
var applyButton = document.getElementById('applyButton'); |
|
|
|
if (assignButton) { |
|
|
|
assignButton.style.display = isAdmin ? 'inline-block' : 'none'; |
|
|
|
} |
|
|
|
@ -828,6 +865,9 @@ |
|
|
|
if (permissionButton) { |
|
|
|
permissionButton.style.display = isAdmin ? 'inline-block' : 'none'; |
|
|
|
} |
|
|
|
if (applyButton) { |
|
|
|
applyButton.style.display = isAdmin ? 'inline-block' : 'none'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function switchTab(tabName, button) { |
|
|
|
@ -873,6 +913,8 @@ |
|
|
|
loadPersonalData(); |
|
|
|
} else if (tabName === 'public') { |
|
|
|
loadPublicData(); |
|
|
|
} else if (tabName === 'products') { |
|
|
|
loadProducts(); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
console.error('加载数据失败:', e); |
|
|
|
@ -1065,6 +1107,13 @@ |
|
|
|
jianDaoYunButton = '<button onclick="openJianDaoYunModal(\'' + (user.userId || '') + '\', \'' + (user.nickName || '') + '\', \'' + (user.followup || '') + '\'); event.stopPropagation();" style="padding: 4px 8px; background-color: #52c41a; color: white; border: none; border-radius: 4px; font-size: 12px;">简道云</button>'; |
|
|
|
} |
|
|
|
|
|
|
|
// 生成申请按钮,只对普通用户显示 |
|
|
|
var applyButton = ''; |
|
|
|
if (!isAdmin) { |
|
|
|
applyButton = ' <button onclick="applyCustomer(\'' + (user.userId || '') + '\', \'' + (user.nickName || '') + '\', this); event.stopPropagation();" style="padding: 4px 8px; background-color: #722ed1; color: white; border: none; border-radius: 4px; font-size: 12px; margin-right: 4px;">申请</button>'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 只有管理员显示复选框 |
|
|
|
var checkboxCell = isAdmin ? '<td><input type="checkbox" class="userCheckbox" data-userid="' + (user.userId || '') + '"></td>' : '<td style="width: 40px;"></td>'; |
|
|
|
|
|
|
|
@ -1855,6 +1904,589 @@ |
|
|
|
</style> |
|
|
|
`; |
|
|
|
|
|
|
|
// 加载货源数据 |
|
|
|
function loadProducts() { |
|
|
|
var userRole = userInfo.loginInfo.projectName; |
|
|
|
var userName = userInfo.loginInfo.userName; |
|
|
|
|
|
|
|
var url = '/KH/api/products?userName=' + encodeURIComponent(userName) + '&userRole=' + encodeURIComponent(userRole) + '&page=' + productsPage + '&size=' + productsPageSize; |
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.open('GET', url, true); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) { |
|
|
|
var data = JSON.parse(xhr.responseText); |
|
|
|
if (data.success) { |
|
|
|
allProducts = data.products || []; |
|
|
|
productsTotal = data.total || 0; |
|
|
|
productsTotalPages = data.pages || 0; |
|
|
|
displayProducts(data.products); |
|
|
|
// 确保使用当前的productsPageSize值渲染分页组件 |
|
|
|
renderProductsPagination(productsPage, productsTotalPages, productsTotal); |
|
|
|
} else { |
|
|
|
showAlert('加载货源失败: ' + data.message); |
|
|
|
} |
|
|
|
} else if (xhr.readyState == 4) { |
|
|
|
console.error('加载货源失败:', xhr.status, xhr.statusText); |
|
|
|
showAlert('加载货源失败,请刷新页面重试'); |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.send(); |
|
|
|
} |
|
|
|
|
|
|
|
// 显示货源数据 |
|
|
|
function displayProducts(products) { |
|
|
|
var productsBody = document.getElementById('productsBody'); |
|
|
|
var productsEmpty = document.getElementById('productsEmpty'); |
|
|
|
var productsPagination = document.getElementById('productsPagination'); |
|
|
|
productsBody.innerHTML = ''; |
|
|
|
|
|
|
|
if (products && products.length > 0) { |
|
|
|
productsEmpty.style.display = 'none'; |
|
|
|
productsPagination.style.display = 'flex'; |
|
|
|
|
|
|
|
for (var i = 0; i < products.length; i++) { |
|
|
|
var product = products[i]; |
|
|
|
var row = '<tr>' + |
|
|
|
'<td>' + (product.productName || '-') + '</td>' + |
|
|
|
'<td>' + (product.price || '-') + '</td>' + |
|
|
|
'<td>' + (product.quantity || '-') + '</td>' + |
|
|
|
'<td>' + (product.fullRegion || product.region || '-') + '</td>' + |
|
|
|
'<td>' + formatDateTime(product.created_at) + '</td>' + |
|
|
|
'<td><button onclick="openProductDetailModal(\'' + (product.productId || '') + '\')" style="padding: 4px 8px; background-color: #1890ff; color: white; border: none; border-radius: 4px; font-size: 12px;">查看详情</button></td>' + |
|
|
|
'</tr>'; |
|
|
|
productsBody.innerHTML += row; |
|
|
|
} |
|
|
|
} else { |
|
|
|
productsEmpty.style.display = 'block'; |
|
|
|
productsPagination.style.display = 'none'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 打开商品详情弹窗 |
|
|
|
function openProductDetailModal(productId) { |
|
|
|
var url = '/KH/api/products/detail?productId=' + encodeURIComponent(productId); |
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.open('GET', url, true); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) { |
|
|
|
var data = JSON.parse(xhr.responseText); |
|
|
|
if (data.success) { |
|
|
|
showProductDetail(data.product, data.traces); |
|
|
|
} else { |
|
|
|
showAlert('获取商品详情失败: ' + data.message); |
|
|
|
} |
|
|
|
} else if (xhr.readyState == 4) { |
|
|
|
console.error('获取商品详情失败:', xhr.status, xhr.statusText); |
|
|
|
showAlert('获取商品详情失败,请重试'); |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.send(); |
|
|
|
} |
|
|
|
|
|
|
|
// 显示商品详情 |
|
|
|
function showProductDetail(product, traces) { |
|
|
|
// 对traces数据进行分组,按用户ID分组 |
|
|
|
var groupedTraces = {}; |
|
|
|
if (traces && traces.length > 0) { |
|
|
|
traces.forEach(trace => { |
|
|
|
var key = trace.userId || (trace.phoneNumber || trace.nickName); |
|
|
|
if (!groupedTraces[key]) { |
|
|
|
groupedTraces[key] = { |
|
|
|
nickName: trace.nickName, |
|
|
|
phoneNumber: trace.phoneNumber, |
|
|
|
followup: trace.followup, |
|
|
|
responseTime: trace.responseTime, |
|
|
|
managerName: trace.managerName, |
|
|
|
operationTimes: [] |
|
|
|
}; |
|
|
|
} |
|
|
|
groupedTraces[key].operationTimes.push(trace.operationTime); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 将分组后的数据转换为数组 |
|
|
|
var mergedTraces = Object.values(groupedTraces); |
|
|
|
|
|
|
|
// 检查是否为管理员 |
|
|
|
var isAdmin = userInfo && userInfo.loginInfo && userInfo.loginInfo.projectName === '管理员'; |
|
|
|
|
|
|
|
// 创建详情弹窗 |
|
|
|
var modal = document.createElement('div'); |
|
|
|
modal.style.cssText = ` |
|
|
|
position: fixed; |
|
|
|
top: 0; |
|
|
|
left: 0; |
|
|
|
width: 100%; |
|
|
|
height: 100%; |
|
|
|
background: rgba(0,0,0,0.5); |
|
|
|
display: flex; |
|
|
|
justify-content: center; |
|
|
|
align-items: center; |
|
|
|
z-index: 1000; |
|
|
|
`; |
|
|
|
|
|
|
|
var modalContent = document.createElement('div'); |
|
|
|
modalContent.style.cssText = ` |
|
|
|
background: white; |
|
|
|
border-radius: 8px; |
|
|
|
width: 90%; |
|
|
|
max-width: 1400px; |
|
|
|
max-height: 80%; |
|
|
|
display: flex; |
|
|
|
flex-direction: column; |
|
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.15); |
|
|
|
`; |
|
|
|
|
|
|
|
// 固定导航栏 |
|
|
|
var navBar = ` |
|
|
|
<div style="padding: 16px 20px; border-bottom: 1px solid #e8e8e8; display: flex; justify-content: space-between; align-items: center; background-color: white; border-radius: 8px 8px 0 0;"> |
|
|
|
<h3 style="margin: 0; color: #1890ff;">商品详情</h3> |
|
|
|
<button onclick="this.parentElement.parentElement.parentElement.remove()" style="padding: 6px 12px; background-color: #1890ff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;"> |
|
|
|
关闭 |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
`; |
|
|
|
|
|
|
|
// 滚动内容区域 |
|
|
|
var contentArea = document.createElement('div'); |
|
|
|
contentArea.style.cssText = ` |
|
|
|
padding: 20px; |
|
|
|
overflow-y: auto; |
|
|
|
flex: 1; |
|
|
|
`; |
|
|
|
|
|
|
|
// 商品基本信息 |
|
|
|
var productInfo = ` |
|
|
|
<div style="margin-bottom: 20px;"> |
|
|
|
<h4 style="margin-bottom: 10px;">基本信息</h4> |
|
|
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px;"> |
|
|
|
<div><strong>商品名称:</strong> ${product.productName || '-'}</div> |
|
|
|
<div><strong>价格:</strong> ${product.price || '-'}</div> |
|
|
|
<div><strong>成本价:</strong> ${product.costprice || '-'}</div> |
|
|
|
<div><strong>库存:</strong> ${product.quantity || '-'}</div> |
|
|
|
<div><strong>地区:</strong> ${product.fullRegion || product.region || '-'}</div> |
|
|
|
<div><strong>分类:</strong> ${product.category || '-'}</div> |
|
|
|
<div><strong>来源类型:</strong> ${product.sourceType || '-'}</div> |
|
|
|
<div><strong>供应状态:</strong> ${product.supplyStatus || '-'}</div> |
|
|
|
<div><strong>规格:</strong> ${product.displaySpecification || product.specification || '-'}</div> |
|
|
|
<div><strong>蛋黄:</strong> ${product.displayYolk || product.yolk || '-'}</div> |
|
|
|
<div><strong>创建时间:</strong> ${formatDateTime(product.created_at)}</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div style="margin-bottom: 20px;"> |
|
|
|
<h4 style="margin-bottom: 10px;">商品描述</h4> |
|
|
|
<div style="padding: 10px; border: 1px solid #e8e8e8; border-radius: 4px; background-color: #fafafa;"> |
|
|
|
${product.description || '-'} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
`; |
|
|
|
|
|
|
|
// 浏览记录 |
|
|
|
var traceInfo = ` |
|
|
|
<div style="margin-bottom: 20px;"> |
|
|
|
<h4 style="margin-bottom: 10px;">浏览记录 (${traces ? traces.length : 0}次)</h4> |
|
|
|
${traces && traces.length > 0 ? ` |
|
|
|
<table style="width: 100%; border-collapse: collapse; font-size: 14px;"> |
|
|
|
<thead> |
|
|
|
<tr style="background-color: #f5f5f5;"> |
|
|
|
<th style="padding: 8px; border: 1px solid #e8e8e8;">昵称</th> |
|
|
|
<th style="padding: 8px; border: 1px solid #e8e8e8;">手机号</th> |
|
|
|
<th style="padding: 8px; border: 1px solid #e8e8e8;">浏览时间</th> |
|
|
|
<th style="padding: 8px; border: 1px solid #e8e8e8;">跟进内容</th> |
|
|
|
<th style="padding: 8px; border: 1px solid #e8e8e8;">响应时间</th> |
|
|
|
<th style="padding: 8px; border: 1px solid #e8e8e8;">负责人</th> |
|
|
|
<th style="padding: 8px; border: 1px solid #e8e8e8;">操作</th> |
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
<tbody> |
|
|
|
${mergedTraces.map(trace => ` |
|
|
|
<tr> |
|
|
|
<td style="padding: 8px; border: 1px solid #e8e8e8; white-space: nowrap; vertical-align: top;">${trace.nickName || '-'}</td> |
|
|
|
<td style="padding: 8px; border: 1px solid #e8e8e8; white-space: nowrap; vertical-align: top;">${trace.phoneNumber || '-'}</td> |
|
|
|
<td style="padding: 8px; border: 1px solid #e8e8e8; vertical-align: top;"> |
|
|
|
${trace.operationTimes.map(time => formatDateTime(time)).join('<br>')} |
|
|
|
</td> |
|
|
|
<td style="padding: 8px; border: 1px solid #e8e8e8; white-space: normal; word-wrap: break-word; max-width: 300px; vertical-align: top;">${trace.followup || '-'}</td> |
|
|
|
<td style="padding: 8px; border: 1px solid #e8e8e8; white-space: nowrap; vertical-align: top;">${trace.responseTime || '-'}</td> |
|
|
|
<td style="padding: 8px; border: 1px solid #e8e8e8; white-space: nowrap; vertical-align: top;">${trace.managerName || '-'}</td> |
|
|
|
<td style="padding: 8px; border: 1px solid #e8e8e8; white-space: nowrap; vertical-align: top;"> |
|
|
|
${!isAdmin ? `<button onclick="applyCustomer('${trace.userId || ''}', '${trace.nickName || ''}', this); event.stopPropagation();" style="padding: 4px 8px; background-color: #722ed1; color: white; border: none; border-radius: 4px; font-size: 12px;">申请</button>` : '-'} |
|
|
|
</td> |
|
|
|
</tr> |
|
|
|
`).join('')} |
|
|
|
</tbody> |
|
|
|
</table> |
|
|
|
` : '<div style="padding: 10px; border: 1px solid #e8e8e8; border-radius: 4px; background-color: #fafafa;">暂无浏览记录</div>'} |
|
|
|
</div> |
|
|
|
`; |
|
|
|
|
|
|
|
// 组装弹窗内容 |
|
|
|
modalContent.innerHTML = navBar; |
|
|
|
contentArea.innerHTML = productInfo + traceInfo; |
|
|
|
modalContent.appendChild(contentArea); |
|
|
|
modal.appendChild(modalContent); |
|
|
|
document.body.appendChild(modal); |
|
|
|
|
|
|
|
// 加载申请状态并更新按钮 |
|
|
|
loadApplyStatusForTraces(mergedTraces); |
|
|
|
} |
|
|
|
|
|
|
|
// 加载浏览记录中客户的申请状态 |
|
|
|
function loadApplyStatusForTraces(traces) { |
|
|
|
if (!traces || traces.length === 0) return; |
|
|
|
|
|
|
|
// 获取所有客户ID |
|
|
|
var userIds = traces.map(trace => trace.userId).filter(Boolean); |
|
|
|
if (userIds.length === 0) return; |
|
|
|
|
|
|
|
var url = '/KH/api/users/apply/list'; |
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.open('GET', url, true); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) { |
|
|
|
var applyList = JSON.parse(xhr.responseText); |
|
|
|
if (applyList && applyList.length > 0) { |
|
|
|
// 创建申请状态映射 |
|
|
|
var applyStatusMap = {}; |
|
|
|
applyList.forEach(apply => { |
|
|
|
if (apply.user_id) { |
|
|
|
applyStatusMap[apply.user_id] = apply.status; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 更新按钮状态 |
|
|
|
// 查找所有包含浏览记录的表格 |
|
|
|
var tables = document.querySelectorAll('table'); |
|
|
|
tables.forEach(table => { |
|
|
|
// 检查表格是否包含浏览记录 |
|
|
|
var header = table.querySelector('th'); |
|
|
|
if (header && header.textContent === '昵称') { |
|
|
|
var tbody = table.querySelector('tbody'); |
|
|
|
if (tbody) { |
|
|
|
var rows = tbody.querySelectorAll('tr'); |
|
|
|
rows.forEach((row, index) => { |
|
|
|
// 获取对应的trace |
|
|
|
var trace = traces[index]; |
|
|
|
if (trace && trace.userId) { |
|
|
|
var status = applyStatusMap[trace.userId]; |
|
|
|
var button = row.querySelector('button[onclick^="applyCustomer"]'); |
|
|
|
if (button && status !== undefined) { |
|
|
|
if (status === 0) { |
|
|
|
// 申请中 |
|
|
|
button.textContent = '申请中'; |
|
|
|
button.disabled = true; |
|
|
|
button.style.backgroundColor = '#faad14'; |
|
|
|
} else if (status === 1) { |
|
|
|
// 申请通过 |
|
|
|
button.textContent = '申请通过'; |
|
|
|
button.disabled = true; |
|
|
|
button.style.backgroundColor = '#52c41a'; |
|
|
|
} else if (status === 2) { |
|
|
|
// 申请失败 |
|
|
|
button.textContent = '申请失败'; |
|
|
|
button.disabled = false; |
|
|
|
button.style.backgroundColor = '#722ed1'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.send(); |
|
|
|
} |
|
|
|
|
|
|
|
// 显示提示信息 |
|
|
|
function showAlert(message) { |
|
|
|
var alert = document.createElement('div'); |
|
|
|
alert.style.cssText = ` |
|
|
|
position: fixed; |
|
|
|
top: 20px; |
|
|
|
right: 20px; |
|
|
|
background-color: #ff4d4f; |
|
|
|
color: white; |
|
|
|
padding: 12px 20px; |
|
|
|
border-radius: 4px; |
|
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.15); |
|
|
|
z-index: 1001; |
|
|
|
animation: slideIn 0.3s ease; |
|
|
|
`; |
|
|
|
alert.textContent = message; |
|
|
|
document.body.appendChild(alert); |
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
|
alert.style.animation = 'fadeOut 0.3s ease'; |
|
|
|
setTimeout(function() { |
|
|
|
alert.remove(); |
|
|
|
}, 300); |
|
|
|
}, 3000); |
|
|
|
} |
|
|
|
|
|
|
|
// 渲染商品分页控件 |
|
|
|
function renderProductsPagination(currentPage, totalPages, totalItems) { |
|
|
|
// 更新全局变量,确保事件处理函数能获取到最新值 |
|
|
|
productsTotalPages = totalPages; |
|
|
|
productsTotal = totalItems; |
|
|
|
var paginationContainer = document.getElementById('productsPagination'); |
|
|
|
paginationContainer.innerHTML = ''; |
|
|
|
paginationContainer.style.display = 'flex'; |
|
|
|
paginationContainer.style.justifyContent = 'center'; |
|
|
|
paginationContainer.style.alignItems = 'center'; |
|
|
|
paginationContainer.style.gap = '8px'; |
|
|
|
paginationContainer.style.flexWrap = 'wrap'; |
|
|
|
|
|
|
|
// 当总页数大于1时显示分页组件 |
|
|
|
// 或者当用户选择的每页显示条数不等于默认值时也显示分页组件 |
|
|
|
var defaultPageSize = 10; |
|
|
|
if (totalPages <= 1 && totalItems <= productsPageSize && productsPageSize === defaultPageSize) { |
|
|
|
paginationContainer.style.display = 'none'; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 首页按钮 |
|
|
|
var firstButton = document.createElement('button'); |
|
|
|
firstButton.textContent = '首页'; |
|
|
|
firstButton.disabled = currentPage === 1; |
|
|
|
firstButton.onclick = function() { |
|
|
|
if (productsPage > 1) { |
|
|
|
productsPage = 1; |
|
|
|
loadProducts(); |
|
|
|
} |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(firstButton); |
|
|
|
|
|
|
|
// 上一页按钮 |
|
|
|
var prevButton = document.createElement('button'); |
|
|
|
prevButton.textContent = '上一页'; |
|
|
|
prevButton.disabled = currentPage === 1; |
|
|
|
prevButton.onclick = function() { |
|
|
|
if (productsPage > 1) { |
|
|
|
productsPage = productsPage - 1; |
|
|
|
loadProducts(); |
|
|
|
} |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(prevButton); |
|
|
|
|
|
|
|
// 页码信息显示 |
|
|
|
var pageInfo = document.createElement('span'); |
|
|
|
pageInfo.textContent = '第' + currentPage + '页,共' + totalPages + '页'; |
|
|
|
pageInfo.style.margin = '0 10px'; |
|
|
|
paginationContainer.appendChild(pageInfo); |
|
|
|
|
|
|
|
// 下一页按钮 |
|
|
|
var nextButton = document.createElement('button'); |
|
|
|
nextButton.textContent = '下一页'; |
|
|
|
nextButton.disabled = currentPage === totalPages; |
|
|
|
nextButton.onclick = function() { |
|
|
|
if (productsPage < productsTotalPages) { |
|
|
|
productsPage = productsPage + 1; |
|
|
|
loadProducts(); |
|
|
|
} |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(nextButton); |
|
|
|
|
|
|
|
// 末页按钮 |
|
|
|
var lastButton = document.createElement('button'); |
|
|
|
lastButton.textContent = '末页'; |
|
|
|
lastButton.disabled = currentPage === totalPages; |
|
|
|
lastButton.onclick = function() { |
|
|
|
if (productsPage < productsTotalPages) { |
|
|
|
productsPage = productsTotalPages; |
|
|
|
loadProducts(); |
|
|
|
} |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(lastButton); |
|
|
|
|
|
|
|
// 总数显示 |
|
|
|
var totalInfo = document.createElement('span'); |
|
|
|
totalInfo.textContent = '总数:' + totalItems + '条'; |
|
|
|
totalInfo.style.margin = '0 10px'; |
|
|
|
paginationContainer.appendChild(totalInfo); |
|
|
|
|
|
|
|
// 每页显示条数选择 |
|
|
|
var pageSizeInfo = document.createElement('span'); |
|
|
|
pageSizeInfo.textContent = '每页'; |
|
|
|
paginationContainer.appendChild(pageSizeInfo); |
|
|
|
|
|
|
|
var pageSizeSelect = document.createElement('select'); |
|
|
|
var pageSizes = [10, 20, 50, 100]; |
|
|
|
for (var i = 0; i < pageSizes.length; i++) { |
|
|
|
var option = document.createElement('option'); |
|
|
|
option.value = pageSizes[i]; |
|
|
|
option.textContent = pageSizes[i] + '条'; |
|
|
|
pageSizeSelect.appendChild(option); |
|
|
|
} |
|
|
|
// 先添加option元素,然后再设置select元素的value属性 |
|
|
|
pageSizeSelect.value = productsPageSize; |
|
|
|
console.log('Setting pageSizeSelect value to:', productsPageSize); |
|
|
|
// 使用闭包确保正确获取select元素 |
|
|
|
(function(selectElement) { |
|
|
|
selectElement.onchange = function() { |
|
|
|
// 确保正确更新全局变量 |
|
|
|
var selectedSize = parseInt(selectElement.value); |
|
|
|
console.log('Selected page size:', selectedSize); |
|
|
|
productsPageSize = selectedSize; |
|
|
|
console.log('Updated productsPageSize to:', productsPageSize); |
|
|
|
productsPage = 1; // 重置为第一页 |
|
|
|
loadProducts(); |
|
|
|
}; |
|
|
|
})(pageSizeSelect); |
|
|
|
paginationContainer.appendChild(pageSizeSelect); |
|
|
|
|
|
|
|
// 跳转功能 |
|
|
|
var jumpInfo = document.createElement('span'); |
|
|
|
jumpInfo.textContent = '跳转'; |
|
|
|
jumpInfo.style.margin = '0 10px'; |
|
|
|
paginationContainer.appendChild(jumpInfo); |
|
|
|
|
|
|
|
var jumpInput = document.createElement('input'); |
|
|
|
jumpInput.type = 'number'; |
|
|
|
jumpInput.value = currentPage; |
|
|
|
jumpInput.min = 1; |
|
|
|
jumpInput.max = totalPages; |
|
|
|
jumpInput.style.width = '60px'; |
|
|
|
jumpInput.style.padding = '4px'; |
|
|
|
paginationContainer.appendChild(jumpInput); |
|
|
|
|
|
|
|
var jumpButton = document.createElement('button'); |
|
|
|
jumpButton.textContent = '确定'; |
|
|
|
jumpButton.onclick = function() { |
|
|
|
// 直接获取输入框的当前值 |
|
|
|
var jumpInputElement = document.querySelector('#productsPagination input[type="number"]'); |
|
|
|
if (jumpInputElement) { |
|
|
|
var jumpPage = parseInt(jumpInputElement.value); |
|
|
|
if (jumpPage >= 1 && jumpPage <= productsTotalPages) { |
|
|
|
productsPage = jumpPage; |
|
|
|
loadProducts(); |
|
|
|
} else { |
|
|
|
showAlert('请输入有效的页码'); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(jumpButton); |
|
|
|
} |
|
|
|
|
|
|
|
// 渲染商品分页控件(旧版,已废弃) |
|
|
|
function renderProductsPaginationOld(currentPage, totalPages, totalItems) { |
|
|
|
var paginationContainer = document.getElementById('productsPagination'); |
|
|
|
paginationContainer.innerHTML = ''; |
|
|
|
|
|
|
|
if (totalPages <= 1) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 上一页按钮 |
|
|
|
var prevButton = document.createElement('button'); |
|
|
|
prevButton.textContent = '上一页'; |
|
|
|
prevButton.disabled = currentPage === 1; |
|
|
|
prevButton.onclick = function() { |
|
|
|
if (currentPage > 1) { |
|
|
|
productsPage = currentPage - 1; |
|
|
|
loadProducts(); |
|
|
|
} |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(prevButton); |
|
|
|
|
|
|
|
// 页码按钮 |
|
|
|
var startPage = Math.max(1, currentPage - 2); |
|
|
|
var endPage = Math.min(totalPages, startPage + 4); |
|
|
|
|
|
|
|
if (startPage > 1) { |
|
|
|
var firstButton = document.createElement('button'); |
|
|
|
firstButton.textContent = '1'; |
|
|
|
firstButton.onclick = function() { |
|
|
|
productsPage = 1; |
|
|
|
loadProducts(); |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(firstButton); |
|
|
|
|
|
|
|
if (startPage > 2) { |
|
|
|
var ellipsis = document.createElement('span'); |
|
|
|
ellipsis.textContent = '...'; |
|
|
|
ellipsis.style.padding = '0 10px'; |
|
|
|
paginationContainer.appendChild(ellipsis); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (var i = startPage; i <= endPage; i++) { |
|
|
|
var pageButton = document.createElement('button'); |
|
|
|
pageButton.textContent = i; |
|
|
|
pageButton.classList.toggle('active', i === currentPage); |
|
|
|
pageButton.onclick = function() { |
|
|
|
productsPage = parseInt(this.textContent); |
|
|
|
loadProducts(); |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(pageButton); |
|
|
|
} |
|
|
|
|
|
|
|
if (endPage < totalPages) { |
|
|
|
if (endPage < totalPages - 1) { |
|
|
|
var ellipsis = document.createElement('span'); |
|
|
|
ellipsis.textContent = '...'; |
|
|
|
ellipsis.style.padding = '0 10px'; |
|
|
|
paginationContainer.appendChild(ellipsis); |
|
|
|
} |
|
|
|
|
|
|
|
var lastButton = document.createElement('button'); |
|
|
|
lastButton.textContent = totalPages; |
|
|
|
lastButton.onclick = function() { |
|
|
|
productsPage = totalPages; |
|
|
|
loadProducts(); |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(lastButton); |
|
|
|
} |
|
|
|
|
|
|
|
// 下一页按钮 |
|
|
|
var nextButton = document.createElement('button'); |
|
|
|
nextButton.textContent = '下一页'; |
|
|
|
nextButton.disabled = currentPage === totalPages; |
|
|
|
nextButton.onclick = function() { |
|
|
|
if (currentPage < totalPages) { |
|
|
|
productsPage = currentPage + 1; |
|
|
|
loadProducts(); |
|
|
|
} |
|
|
|
}; |
|
|
|
paginationContainer.appendChild(nextButton); |
|
|
|
|
|
|
|
// 显示总条数 |
|
|
|
var totalInfo = document.createElement('span'); |
|
|
|
totalInfo.textContent = '共 ' + totalItems + ' 条'; |
|
|
|
totalInfo.style.marginLeft = '20px'; |
|
|
|
totalInfo.style.fontSize = '14px'; |
|
|
|
totalInfo.style.color = '#666'; |
|
|
|
paginationContainer.appendChild(totalInfo); |
|
|
|
} |
|
|
|
|
|
|
|
// 淡入淡出动画 |
|
|
|
var style = document.createElement('style'); |
|
|
|
style.textContent = ` |
|
|
|
@keyframes slideIn { |
|
|
|
from { |
|
|
|
transform: translateX(100%); |
|
|
|
opacity: 0; |
|
|
|
} |
|
|
|
to { |
|
|
|
transform: translateX(0); |
|
|
|
opacity: 1; |
|
|
|
} |
|
|
|
} |
|
|
|
@keyframes fadeOut { |
|
|
|
from { |
|
|
|
opacity: 1; |
|
|
|
} |
|
|
|
to { |
|
|
|
opacity: 0; |
|
|
|
} |
|
|
|
} |
|
|
|
`; |
|
|
|
document.head.appendChild(style); |
|
|
|
|
|
|
|
// 将样式添加到页面头部 |
|
|
|
document.head.insertAdjacentHTML('beforeend', formHoverStyles); |
|
|
|
|
|
|
|
@ -2378,6 +3010,51 @@ |
|
|
|
</div> |
|
|
|
`; |
|
|
|
|
|
|
|
// 申请管理模态框HTML |
|
|
|
var applyModalHTML = ` |
|
|
|
<div id="applyModal" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.7) 100%); backdrop-filter: blur(5px); display: none; z-index: 1000; animation: fadeIn 0.3s ease;"> |
|
|
|
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; border-radius: 8px; width: 90%; max-width: 1000px; max-height: 80vh; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: slideIn 0.3s ease;"> |
|
|
|
<div style="padding: 16px 20px; border-bottom: 1px solid #e8e8e8; display: flex; justify-content: space-between; align-items: center; background-color: white; border-radius: 8px 8px 0 0;"> |
|
|
|
<h3 style="margin: 0; color: #722ed1;">申请管理</h3> |
|
|
|
<button onclick="closeApplyModal()" style="padding: 6px 12px; background-color: #1890ff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;"> |
|
|
|
关闭 |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
<div style="padding: 20px; overflow-y: auto; max-height: calc(80vh - 120px);"> |
|
|
|
<div class="filter-container" style="margin-bottom: 20px;"> |
|
|
|
<div class="filter-bar" style="display: flex; gap: 10px; flex-wrap: wrap;"> |
|
|
|
<button onclick="loadApplyList()" style="padding: 8px 16px; background-color: #1890ff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;">刷新申请</button> |
|
|
|
<button onclick="filterApplyList('all')" style="padding: 8px 16px; background-color: #52c41a; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;">全部</button> |
|
|
|
<button onclick="filterApplyList('0')" style="padding: 8px 16px; background-color: #faad14; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;">申请中</button> |
|
|
|
<button onclick="filterApplyList('1')" style="padding: 8px 16px; background-color: #52c41a; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;">已通过</button> |
|
|
|
<button onclick="filterApplyList('2')" style="padding: 8px 16px; background-color: #ff4d4f; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px;">已拒绝</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div id="applyList" style="overflow-x: auto;"> |
|
|
|
<table style="width: 100%; border-collapse: collapse; font-size: 14px;"> |
|
|
|
<thead> |
|
|
|
<tr style="background-color: #f5f5f5;"> |
|
|
|
<th style="padding: 12px; border: 1px solid #e8e8e8; text-align: left;">申请ID</th> |
|
|
|
<th style="padding: 12px; border: 1px solid #e8e8e8; text-align: left;">客户ID</th> |
|
|
|
<th style="padding: 12px; border: 1px solid #e8e8e8; text-align: left;">业务员</th> |
|
|
|
<th style="padding: 12px; border: 1px solid #e8e8e8; text-align: left;">申请时间</th> |
|
|
|
<th style="padding: 12px; border: 1px solid #e8e8e8; text-align: left;">状态</th> |
|
|
|
<th style="padding: 12px; border: 1px solid #e8e8e8; text-align: left;">申请理由</th> |
|
|
|
<th style="padding: 12px; border: 1px solid #e8e8e8; text-align: left;">操作</th> |
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
<tbody id="applyTableBody"> |
|
|
|
<tr> |
|
|
|
<td colspan="7" style="padding: 20px; text-align: center; color: #999;">暂无申请记录</td> |
|
|
|
</tr> |
|
|
|
</tbody> |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
`; |
|
|
|
|
|
|
|
// 权限管理模态框HTML |
|
|
|
var permissionModalHTML = ` |
|
|
|
<div id="permissionModal" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.7) 100%); backdrop-filter: blur(5px); display: none; z-index: 1000; animation: fadeIn 0.3s ease;"> |
|
|
|
@ -2465,6 +3142,7 @@ |
|
|
|
document.body.insertAdjacentHTML('beforeend', detailModalHTML); |
|
|
|
document.body.insertAdjacentHTML('beforeend', assignModalHTML); |
|
|
|
document.body.insertAdjacentHTML('beforeend', permissionModalHTML); |
|
|
|
document.body.insertAdjacentHTML('beforeend', applyModalHTML); |
|
|
|
document.body.insertAdjacentHTML('beforeend', alertModalHTML); |
|
|
|
document.body.insertAdjacentHTML('beforeend', typeHelpModalHTML); |
|
|
|
|
|
|
|
@ -4380,6 +5058,212 @@ |
|
|
|
pagination.appendChild(jumpContainer); |
|
|
|
} |
|
|
|
|
|
|
|
function applyCustomer(userId, userName, button) { |
|
|
|
// 显示确认弹窗 |
|
|
|
if (confirm('确认申请该客户吗?')) { |
|
|
|
// 获取当前按钮元素 |
|
|
|
if (button) { |
|
|
|
// 保存原始状态 |
|
|
|
button.dataset.originalText = button.textContent; |
|
|
|
button.dataset.originalDisabled = button.disabled; |
|
|
|
// 更改为申请中状态 |
|
|
|
button.textContent = '申请中'; |
|
|
|
button.disabled = true; |
|
|
|
button.style.backgroundColor = '#faad14'; |
|
|
|
} else { |
|
|
|
// 尝试通过选择器查找按钮(兼容旧格式) |
|
|
|
var buttons = document.querySelectorAll('button[onclick*="applyCustomer(\'" + userId + "\'")]'); |
|
|
|
buttons.forEach(function(btn) { |
|
|
|
// 保存原始状态 |
|
|
|
btn.dataset.originalText = btn.textContent; |
|
|
|
btn.dataset.originalDisabled = btn.disabled; |
|
|
|
// 更改为申请中状态 |
|
|
|
btn.textContent = '申请中'; |
|
|
|
btn.disabled = true; |
|
|
|
btn.style.backgroundColor = '#faad14'; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
var personnel = userInfo.personnel; |
|
|
|
var usersManagements = userInfo.usersManagements; |
|
|
|
|
|
|
|
var params = { |
|
|
|
userId: userId, |
|
|
|
salesId: personnel.managerId || usersManagements.userId || '', |
|
|
|
salesName: personnel.name || usersManagements.userName || '', |
|
|
|
reason: '申请成为该客户的负责人' |
|
|
|
}; |
|
|
|
|
|
|
|
var url = '/KH/api/users/apply'; |
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.open('POST', url, true); |
|
|
|
xhr.setRequestHeader('Content-Type', 'application/json'); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) { |
|
|
|
var data = JSON.parse(xhr.responseText); |
|
|
|
if (data.success) { |
|
|
|
showAlert('申请提交成功,请等待管理员审批'); |
|
|
|
// 保持申请中状态 |
|
|
|
} else { |
|
|
|
showAlert('申请失败: ' + data.message); |
|
|
|
// 恢复按钮状态 |
|
|
|
buttons.forEach(function(button) { |
|
|
|
button.textContent = button.dataset.originalText; |
|
|
|
button.disabled = button.dataset.originalDisabled === 'true'; |
|
|
|
button.style.backgroundColor = '#722ed1'; |
|
|
|
}); |
|
|
|
} |
|
|
|
} else if (xhr.readyState == 4) { |
|
|
|
// 请求失败,恢复按钮状态 |
|
|
|
showAlert('申请提交失败,请重试'); |
|
|
|
buttons.forEach(function(button) { |
|
|
|
button.textContent = button.dataset.originalText; |
|
|
|
button.disabled = button.dataset.originalDisabled === 'true'; |
|
|
|
button.style.backgroundColor = '#722ed1'; |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.send(JSON.stringify(params)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 申请管理相关函数 |
|
|
|
function openApplyModal() { |
|
|
|
document.getElementById('applyModal').style.display = 'block'; |
|
|
|
// 加载申请列表 |
|
|
|
loadApplyList(); |
|
|
|
} |
|
|
|
|
|
|
|
function closeApplyModal() { |
|
|
|
document.getElementById('applyModal').style.display = 'none'; |
|
|
|
} |
|
|
|
|
|
|
|
function loadApplyList() { |
|
|
|
var url = '/KH/api/users/apply/list'; |
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.open('GET', url, true); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) { |
|
|
|
var data = JSON.parse(xhr.responseText); |
|
|
|
displayApplyList(data); |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.send(); |
|
|
|
} |
|
|
|
|
|
|
|
function filterApplyList(status) { |
|
|
|
var url = '/KH/api/users/apply/list'; |
|
|
|
if (status !== 'all') { |
|
|
|
url += '?status=' + status; |
|
|
|
} |
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.open('GET', url, true); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) { |
|
|
|
var data = JSON.parse(xhr.responseText); |
|
|
|
displayApplyList(data); |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.send(); |
|
|
|
} |
|
|
|
|
|
|
|
function displayApplyList(applies) { |
|
|
|
var tbody = document.getElementById('applyTableBody'); |
|
|
|
tbody.innerHTML = ''; |
|
|
|
|
|
|
|
if (applies && applies.length > 0) { |
|
|
|
for (var i = 0; i < applies.length; i++) { |
|
|
|
var apply = applies[i]; |
|
|
|
var statusText = ''; |
|
|
|
var statusColor = ''; |
|
|
|
|
|
|
|
switch (apply.status) { |
|
|
|
case 0: |
|
|
|
statusText = '申请中'; |
|
|
|
statusColor = '#faad14'; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
statusText = '已通过'; |
|
|
|
statusColor = '#52c41a'; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
statusText = '已拒绝'; |
|
|
|
statusColor = '#ff4d4f'; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
var actionButtons = ''; |
|
|
|
if (apply.status == 0) { |
|
|
|
actionButtons = ` |
|
|
|
<button onclick="approveApply(${apply.id}, 1, '${apply.user_id}', '${apply.sales_id}');" style="padding: 4px 8px; background-color: #52c41a; color: white; border: none; border-radius: 4px; font-size: 12px; margin-right: 4px;">通过</button> |
|
|
|
<button onclick="approveApply(${apply.id}, 2, '${apply.user_id}', '${apply.sales_id}');" style="padding: 4px 8px; background-color: #ff4d4f; color: white; border: none; border-radius: 4px; font-size: 12px;">拒绝</button> |
|
|
|
`; |
|
|
|
} |
|
|
|
|
|
|
|
var row = ` |
|
|
|
<tr> |
|
|
|
<td style="padding: 10px; border: 1px solid #e8e8e8;">${apply.id}</td> |
|
|
|
<td style="padding: 10px; border: 1px solid #e8e8e8;">${apply.user_id}</td> |
|
|
|
<td style="padding: 10px; border: 1px solid #e8e8e8;">${apply.sales_name}</td> |
|
|
|
<td style="padding: 10px; border: 1px solid #e8e8e8;">${formatDateTime(apply.apply_time)}</td> |
|
|
|
<td style="padding: 10px; border: 1px solid #e8e8e8;"> |
|
|
|
<span style="display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; color: white; background-color: ${statusColor};">${statusText}</span> |
|
|
|
</td> |
|
|
|
<td style="padding: 10px; border: 1px solid #e8e8e8; white-space: normal; word-wrap: break-word; max-width: 300px;">${apply.reason}</td> |
|
|
|
<td style="padding: 10px; border: 1px solid #e8e8e8;">${actionButtons}</td> |
|
|
|
</tr> |
|
|
|
`; |
|
|
|
|
|
|
|
tbody.innerHTML += row; |
|
|
|
} |
|
|
|
} else { |
|
|
|
tbody.innerHTML = '<tr><td colspan="7" style="padding: 20px; text-align: center; color: #999;">暂无申请记录</td></tr>'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function approveApply(id, status, userId, salesId) { |
|
|
|
var action = status == 1 ? '通过' : '拒绝'; |
|
|
|
if (confirm(`确认${action}该申请吗?`)) { |
|
|
|
var reason = ''; |
|
|
|
if (status == 2) { |
|
|
|
reason = prompt('请输入拒绝原因:'); |
|
|
|
if (!reason) { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var params = { |
|
|
|
id: id, |
|
|
|
status: status, |
|
|
|
approve_by: userInfo.loginInfo.userName, |
|
|
|
reason: reason, |
|
|
|
userId: userId, |
|
|
|
salesId: salesId |
|
|
|
}; |
|
|
|
|
|
|
|
var url = '/KH/api/users/approve'; |
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.open('POST', url, true); |
|
|
|
xhr.setRequestHeader('Content-Type', 'application/json'); |
|
|
|
xhr.onreadystatechange = function() { |
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) { |
|
|
|
var data = JSON.parse(xhr.responseText); |
|
|
|
if (data.success) { |
|
|
|
showAlert(`${action}成功`); |
|
|
|
loadApplyList(); |
|
|
|
} else { |
|
|
|
showAlert(`${action}失败: ` + data.message); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.send(JSON.stringify(params)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
window.onload = init; |
|
|
|
</script> |
|
|
|
</body> |
|
|
|
|