console
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>计算表格</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<style>
@charset "UTF-8";
* {margin: 0;padding: 0;box-sizing: border-box;font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;}
body {padding: 15px;background-color: #f8f9fa;color: #333;transition: overflow-y 0.3s;}
h1 {text-align: center;margin: 15px 0;font-size: 1.2rem;font-weight: 600;color: #333;}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.3);
z-index: 9;
display: none;
animation: fadeIn 0.3s;
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
.custom-select {
position: fixed;
width: calc(100% - 30px);
max-width: 200px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
overflow: hidden;
z-index: 10;
display: none;
transform-origin: top center;
transition: transform 0.2s ease, opacity 0.2s ease, max-height 0.3s ease;
}
.custom-select.active {
transform: scale(1);
opacity: 1;
}
.custom-select-header {
padding: 12px 15px;
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
border-bottom: 1px solid #e9ecef;
}
.custom-select-value {
font-size: 0.95rem;
font-weight: 500;
}
.custom-select-arrow {
width: 16px;
height: 16px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
transition: transform 0.3s;
}
.custom-select.active .custom-select-arrow {
transform: rotate(180deg);
}
.custom-select-options {
overflow: hidden;
transition: max-height 0.3s ease-out;
}
.custom-select-option {
padding: 12px 15px;
font-size: 0.95rem;
cursor: pointer;
border-bottom: 1px solid #f1f3f5;
transition: background-color 0.2s;
}
.custom-select-option:last-child {
border-bottom: none;
}
.custom-select-option:hover {
background-color: #f8f9fa;
}
.custom-select-option.selected {
background-color: #e9f7ef;
font-weight: 500;
}
.custom-select-placeholder {
width: 100%;
max-width: 200px;
height: 48px;
margin: 0 auto 15px;
position: relative;
cursor: pointer;
}
.custom-select-visible {
width: 100%;
height: 100%;
background-color: white;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
padding: 12px 15px;
display: flex;
justify-content: space-between;
align-items: center;
border: 1px solid #e9ecef;
transition: all 0.2s;
}
.custom-select-visible:hover {
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
border-color: #d8d8d8;
}
.custom-select-visible:active {
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.table-container {
width: 100%;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
table {
min-width: 700px;
border-collapse: collapse;
table-layout: fixed;
}
th, td {
padding: 10px 12px;
text-align: center;
border: 1px solid #e9ecef;
word-break: break-all;
white-space: normal;
vertical-align: middle;
}
th {
background-color: #f1f3f5;
font-weight: 500;
font-size: 0.9rem;
}
th:nth-child(1), td:nth-child(1) {width: 80px;}
th:nth-child(2), td:nth-child(2) {width: 60px;}
th:nth-child(3), td:nth-child(3) {width: 120px;}
th:nth-child(4), td:nth-child(4) {width: 80px;}
th:nth-child(5), th:nth-child(6), th:nth-child(7), th:nth-child(8), th:nth-child(9) {
width: 70px;
}
.editable-cell {padding: 0;position: relative;}
.editable-cell input {
width: 100%;
padding: 8px 10px;
border: none;
border-bottom: 1px solid #dee2e6;
background-color: transparent;
font-size: 0.9rem;
outline: none;
transition: border-color 0.2s;
text-align: center;
}
.editable-cell input:focus {border-bottom-color: #4CAF50;}
.non-editable-cell {
background-color: #f9f9f9;
font-style: italic;
font-size: 0.9rem;
color: #6c757d;
text-align: center;
}
.weight-summary {
background-color: #f1f8e9;
color: #388e3c;
font-style: normal;
text-align: left;
padding: 10px;
border-radius: 4px;
}
.weight-item {
display: flex;
justify-content: space-between;
padding: 2px 0;
font-size: 0.9rem;
}
.weight-label {
font-weight: 500;
}
.weight-value {
font-weight: normal;
}
.radio-container, .checkbox-container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
min-height: 40px;
}
@media only screen and (max-device-width: 768px) and (-webkit-min-device-pixel-ratio: 2) {
.radio-container input[type="radio"],
.checkbox-container input[type="checkbox"] {
-webkit-appearance: none;
appearance: none;
margin: 0;
position: relative;
width: 18px;
height: 18px;
vertical-align: middle;
}
.radio-container input[type="radio"] {
border-radius: 50%;
border: 1px solid #ccc;
}
.radio-container input[type="radio"]:checked {
border-color: #4CAF50;
}
.radio-container input[type="radio"]:checked::after {
content: '';
position: absolute;
top: 3px;
left: 3px;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #4CAF50;
}
.checkbox-container input[type="checkbox"] {
border: 1px solid #ccc;
border-radius: 2px;
}
.checkbox-container input[type="checkbox"]:checked {
border-color: #4CAF50;
background-color: #4CAF50;
}
.checkbox-container input[type="checkbox"]:checked::after {
content: '';
position: absolute;
top: 1px;
left: 5px;
width: 4px;
height: 9px;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
}
.action-buttons {
display: flex;
justify-content: center;
gap: 12px;
margin: 20px 0;
}
.button {
padding: 10px 18px;
border: none;
border-radius: 6px;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
min-width: 100px;
transition: all 0.2s;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.save-button {
background-color: #4CAF50;
color: white;
}
.save-button:hover {
background-color: #45a049;
transform: translateY(-1px);
box-shadow: 0 3px 8px rgba(76, 175, 80, 0.2);
}
.reset-button {
background-color: #f44336;
color: white;
}
.reset-button:hover {
background-color: #d32f2f;
transform: translateY(-1px);
box-shadow: 0 3px 8px rgba(244, 67, 54, 0.2);
}
.status-message {
text-align: center;
margin: 15px 0;
font-weight: 500;
color: #4CAF50;
display: none;
padding: 10px;
background-color: rgba(76, 175, 80, 0.1);
border-radius: 4px;
font-size: 0.9rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
@media (max-width: 480px) {
th, td {
padding: 8px 8px;
font-size: 0.85rem;
}
.editable-cell input {
padding: 6px 8px;
font-size: 0.85rem;
}
.button {
padding: 8px 16px;
font-size: 0.85rem;
min-width: 90px;
}
.weight-summary {
font-size: 0.8rem;
}
}
</style>
</head>
<body>
<div class="custom-select-placeholder" id="selectPlaceholder">
<div class="custom-select-visible">
<div class="custom-select-value-visible" id="weightColValueVisible">选择权重列</div>
<div class="custom-select-arrow-visible">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6 9L12 15L18 9" stroke="#666" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
</div>
</div>
<div class="overlay" id="overlay"></div>
<div class="custom-select" id="weightColSelect">
<div class="custom-select-header">
<div class="custom-select-value" id="weightColValue">选择权重列</div>
<div class="custom-select-arrow"></div>
</div>
<div class="custom-select-options" id="weightColOptions">
<div class="custom-select-option" data-value="1">权重1</div>
<div class="custom-select-option" data-value="2">权重2</div>
<div class="custom-select-option" data-value="3">权重3</div>
<div class="custom-select-option" data-value="4">权重4</div>
<div class="custom-select-option" data-value="5">权重5</div>
</div>
</div>
<div class="table-container">
<table id="editableTable">
<thead>
<tr>
<th>产品</th>
<th>+15</th>
<th>系数</th>
<th>输出值</th>
<th>权重1</th>
<th>权重2</th>
<th>权重3</th>
<th>权重4</th>
<th>权重5</th>
</tr>
</thead>
<tbody>
<tr>
<td class="editable-cell"><input type="text" placeholder="输入产品值"></td>
<td class="editable-cell">
<div class="radio-container">
<input type="radio" name="coefficient" value="15">
</div>
</td>
<td class="editable-cell">
<div class="radio-container">
1<input type="radio" name="coeffValue1" value="1">
1.1<input type="radio" checked name="coeffValue1" value="1.1">
1.2<input type="radio" name="coeffValue1" value="1.2">
</div>
</td>
<td class="non-editable-cell"></td>
<td class="editable-cell"><input type="text" readonly value="0.28"></td>
<td class="editable-cell"><input type="text" readonly value="0.39"></td>
<td class="editable-cell"><input type="text" readonly value="0.19"></td>
<td class="editable-cell"><input type="text" readonly value="0.14"></td>
<td class="editable-cell"><input type="text" readonly value="0.0"></td>
</tr>
<tr>
<td class="editable-cell"><input type="text" placeholder="输入产品值"></td>
<td class="editable-cell">
<div class="radio-container">
<input type="radio" name="coefficient" value="15">
</div>
</td>
<td class="editable-cell">
<div class="radio-container">
1<input type="radio" name="coeffValue2" value="1">
1.1<input type="radio" checked name="coeffValue2" value="1.1">
1.2<input type="radio" name="coeffValue2" value="1.2">
</div>
</td>
<td class="non-editable-cell"></td>
<td class="editable-cell"><input type="text" readonly value="0"></td>
<td class="editable-cell"><input type="text" readonly value="0.05"></td>
<td class="editable-cell"><input type="text" readonly value="0.23"></td>
<td class="editable-cell"><input type="text" readonly value="0.31"></td>
<td class="editable-cell"><input type="text" readonly value="0.41"></td>
</tr>
<tr>
<td class="editable-cell"><input type="text" placeholder="输入产品值"></td>
<td class="editable-cell">
<div class="radio-container">
<input type="radio" name="coefficient" value="15">
</div>
</td>
<td class="editable-cell">
<div class="radio-container">
1<input type="radio" name="coeffValue3" value="1">
1.1<input type="radio" checked name="coeffValue3" value="1.1">
1.2<input type="radio" name="coeffValue3" value="1.2">
</div>
</td>
<td class="non-editable-cell"></td>
<td class="editable-cell"><input type="text" readonly value="0.18"></td>
<td class="editable-cell"><input type="text" readonly value="0.47"></td>
<td class="editable-cell"><input type="text" readonly value="0.26"></td>
<td class="editable-cell"><input type="text" readonly value="0.09"></td>
<td class="editable-cell"><input type="text" readonly value="0.0"></td>
</tr>
<tr>
<td class="editable-cell"><input type="text" placeholder="输入产品值"></td>
<td class="editable-cell">
<div class="radio-container">
<input type="radio" name="coefficient" value="15">
</div>
</td>
<td class="editable-cell">
<div class="radio-container">
1<input type="radio" name="coeffValue4" value="1">
1.1<input type="radio" checked name="coeffValue4" value="1.1">
1.2<input type="radio" name="coeffValue4" value="1.2">
</div>
</td>
<td class="non-editable-cell"></td>
<td class="editable-cell"><input type="text" readonly value="0"></td>
<td class="editable-cell"><input type="text" readonly value="0.03"></td>
<td class="editable-cell"><input type="text" readonly value="0.21"></td>
<td class="editable-cell"><input type="text" readonly value="0.35"></td>
<td class="editable-cell"><input type="text" readonly value="0.41"></td>
</tr>
<tr>
<td class="editable-cell"><input type="text" placeholder="输入产品值"></td>
<td class="editable-cell">
<div class="radio-container">
<input type="radio" name="coefficient" value="15">
</div>
</td>
<td class="editable-cell">
<div class="radio-container">
1<input type="radio" name="coeffValue5" value="1">
1.1<input type="radio" checked name="coeffValue5" value="1.1">
1.2<input type="radio" name="coeffValue5" value="1.2">
</div>
</td>
<td class="non-editable-cell"></td>
<td class="editable-cell"><input type="text" readonly value="0.06"></td>
<td class="editable-cell"><input type="text" readonly value="0.06"></td>
<td class="editable-cell"><input type="text" readonly value="0.19"></td>
<td class="editable-cell"><input type="text" readonly value="0.32"></td>
<td class="editable-cell"><input type="text" readonly value="0.35"></td>
</tr>
<tr>
<td colspan="4" class="weight-summary">
<div class="weight-item"><span class="weight-label">总计:</span><span class="weight-value"></span></div>
<div class="weight-item"><span class="weight-label">权重1:</span><span class="weight-value1"></span></div>
<div class="weight-item"><span class="weight-label">权重2:</span><span class="weight-value2"></span></div>
<div class="weight-item"><span class="weight-label">权重3:</span><span class="weight-value3"></span></div>
<div class="weight-item"><span class="weight-label">权重4:</span><span class="weight-value4"></span></div>
<div class="weight-item"><span class="weight-label">权重5:</span><span class="weight-value5"></span></div>
</td>
<td colspan="5" class="editable-cell"></td>
</tr>
</tbody>
</table>
</div>
<div class="action-buttons">
<button id="calculateButton" class="button save-button">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19 3H5C3.89 3 3 3.89 3 5V19C3 20.11 3.89 21 5 21H19C20.11 21 21 20.11 21 19V5C21 3.89 20.11 3 19 3ZM19 19H5V5H19V19Z" fill="currentColor"/>
<path d="M14 7H10V13H14V7ZM7 7H3V17H7V7Z" fill="currentColor"/>
</svg>
计算
</button>
<button id="resetButton" class="button reset-button">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 11H7.83L10.91 8.91C11.3 8.52 11.3 7.89 10.91 7.5C10.52 7.11 9.89 7.11 9.5 7.5L4.5 12.5C4.11 12.89 4.11 13.52 4.5 13.91L9.5 18.91C9.89 19.3 10.52 19.3 10.91 18.91C11.3 18.52 11.3 17.89 10.91 17.5L7.83 14.41H20C20.55 14.41 21 13.96 21 13.41V12.41C21 11.86 20.55 11.41 20 11.41V11Z" stroke="white" stroke-width="1.5"/>
</svg>
<span>重置</span>
</button>
</div>
<div id="statusMessage" class="status-message">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 16L16 12L12 8" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
计算完成
</div>
<script>
const calculateButton = document.getElementById('calculateButton');
const statusMessage = document.getElementById('statusMessage');
const customSelect = document.getElementById('weightColSelect');
const selectHeader = customSelect.querySelector('.custom-select-header');
const selectOptions = customSelect.querySelector('.custom-select-options');
const selectValue = customSelect.querySelector('.custom-select-value');
const optionElements = customSelect.querySelectorAll('.custom-select-option');
const overlay = document.getElementById('overlay');
const selectPlaceholder = document.getElementById('selectPlaceholder');
const selectValueVisible = document.getElementById('weightColValueVisible');
let selectedWeightCol = 1;
selectValue.textContent = `权重${selectedWeightCol}`;
selectValueVisible.textContent = `权重${selectedWeightCol}`;
optionElements[0].classList.add('selected');
let selectPosition = { top: 0, left: 0 };
function updateSelectPosition() {
const rect = selectPlaceholder.getBoundingClientRect();
selectPosition = {
top: rect.top + window.scrollY,
left: rect.left + window.scrollX
};
customSelect.style.top = `${selectPosition.top}px`;
customSelect.style.left = `${selectPosition.left}px`;
}
window.addEventListener('load', updateSelectPosition);
window.addEventListener('resize', updateSelectPosition);
window.addEventListener('scroll', updateSelectPosition);
function showSelect() {
updateSelectPosition();
customSelect.style.display = 'block';
setTimeout(() => {
customSelect.classList.add('active');
}, 10);
}
function hideSelect() {
customSelect.classList.remove('active');
setTimeout(() => {
customSelect.style.display = 'none';
}, 300);
}
selectPlaceholder.addEventListener('click', function() {
if (customSelect.classList.contains('active')) {
hideSelect();
overlay.style.display = 'none';
document.body.style.overflow = '';
} else {
showSelect();
overlay.style.display = 'block';
document.body.style.overflow = 'hidden';
}
});
optionElements.forEach(option => {
option.addEventListener('click', function() {
optionElements.forEach(o => o.classList.remove('selected'));
this.classList.add('selected');
selectedWeightCol = parseInt(this.dataset.value);
selectValue.textContent = `权重${selectedWeightCol}`;
selectValueVisible.textContent = `权重${selectedWeightCol}`;
hideSelect();
overlay.style.display = 'none';
document.body.style.overflow = '';
});
});
overlay.addEventListener('click', function() {
hideSelect();
overlay.style.display = 'none';
document.body.style.overflow = '';
});
document.addEventListener('click', function(event) {
if (!customSelect.contains(event.target) && !selectPlaceholder.contains(event.target)) {
hideSelect();
overlay.style.display = 'none';
document.body.style.overflow = '';
}
});
function getSelectedCoefficientRow() {
const radios = document.getElementsByName('coefficient');
for (let i = 0; i < radios.length; i++) {
if (radios[i].checked) {
return i + 1;
}
}
return 0;
}
function getSelectedCoeffValueRow(row) {
const radios = document.getElementsByName('coeffValue' + row);
for (let i = 0; i < radios.length; i++) {
if (radios[i].checked) {
return radios[i].value;
}
}
return 1;
}
function getCheckedCoeffValues() {
const checkboxes = document.querySelectorAll('input[name="coeffValue"]:checked');
return Array.from(checkboxes).map(checkbox => parseInt(checkbox.value));
}
function calculateOutput() {
if (selectedWeightCol < 1 || selectedWeightCol > 5) {
showStatusMessage('请选择有效的权重列(1-5)');
return;
}
let totalOutput = 0;
var coefficientIndex = getSelectedCoefficientRow();
let maxTotal1 = 0;
let maxTotal2 = 0;
let maxTotal3 = 0;
let maxTotal4 = 0;
let maxTotal5 = 0;
for (let row = 1; row <= 5; row++) {
const productValue = parseFloat($(`tbody tr:nth-child(${row}) td:nth-child(1) input`).val() || 0);
let baseValue = 0;
if(coefficientIndex == row){
baseValue = 15;
}
var coeffValue = getSelectedCoeffValueRow(row);
console.log(coeffValue);
const totalBase = productValue + baseValue;
const weightColIndex = 4 + selectedWeightCol;
const weightValue = parseFloat($(`tbody tr:nth-child(${row}) td:nth-child(${weightColIndex}) input`).val() || 0);
const outputValue = totalBase * coeffValue * weightValue;
const formattedOutput = outputValue.toFixed(2);
$(`tbody tr:nth-child(${row}) td:nth-child(4)`).text(formattedOutput);
totalOutput += outputValue;
for(let weight = 1; weight <= 5; weight++){
var weightColIndex2 = 4 + weight;
var weightValue2 = parseFloat($(`tbody tr:nth-child(${row}) td:nth-child(${weightColIndex2}) input`).val() || 0);
var outputValue2 = totalBase * coeffValue * weightValue2;
if(weight == 1){
maxTotal1 += outputValue2;
}else if(weight == 2){
maxTotal2 += outputValue2;
}else if(weight == 3){
maxTotal3 += outputValue2;
}else if(weight == 4){
maxTotal4 += outputValue2;
}else if(weight == 5){
maxTotal5 += outputValue2;
}
}
}
$(".weight-value").text(totalOutput.toFixed(2));
$(".weight-value1").text(maxTotal1.toFixed(2));
$(".weight-value2").text(maxTotal2.toFixed(2));
$(".weight-value3").text(maxTotal3.toFixed(2));
$(".weight-value4").text(maxTotal4.toFixed(2));
$(".weight-value5").text(maxTotal5.toFixed(2));
console.log(`权重列计算结果 - 权重列:${selectedWeightCol}, 总计:${totalOutput}`);
}
calculateButton.addEventListener('click', calculateOutput);
$('#resetButton').click(resetForm);
$('input').on('input', function() {
this.value = this.value.replace(/[^0-9.-]/g, '');
});
document.addEventListener('DOMContentLoaded', function() {
selectValueVisible.textContent = `权重${selectedWeightCol}`;
});
function resetForm() {
$('input[type="text"]').each(function() {
if (!$(this).attr('readonly')) {
$(this).val('');
}
});
$('input[type="checkbox"], input[type="radio"]').prop('checked', false);
$('input[value="1.1"][name="coeffValue1"]').prop('checked', true);
$('input[value="1.1"][name="coeffValue2"]').prop('checked', true);
$('input[value="1.1"][name="coeffValue3"]').prop('checked', true);
$('input[value="1.1"][name="coeffValue4"]').prop('checked', true);
$('input[value="1.1"][name="coeffValue5"]').prop('checked', true);
$('.output-cell').text('');
$('.total-cell').text('');
$('.recommendation-cell').text('推荐:');
$('.recommendation-cell, .output-cell, .total-cell').removeClass('result-highlight recommendation-highlight');
$(".weight-value").text('');
$(".weight-value1").text('');
$(".weight-value2").text('');
$(".weight-value3").text('');
$(".weight-value4").text('');
$(".weight-value5").text('');
for (let row = 1; row <= 5; row++) {
$(`tbody tr:nth-child(${row}) td:nth-child(4)`).text('');
}
showStatusMessage('已重置');
}
$('.custom-select-option').click(function() {
const value = $(this).data('value');
const text = $(this).text();
$('.custom-select-option').removeClass('selected');
$(this).addClass('selected');
$('#weightColValue').text(text);
$('#weightColValueVisible').text(text);
selectedWeightCol = parseInt(value);
hideSelect();
calculateOutput();
});
function showStatusMessage(message) {
const statusMessage = $('#statusMessage');
statusMessage.text(message);
statusMessage.fadeIn(300);
setTimeout(() => {
statusMessage.fadeOut(500);
}, 2000);
}
function isIOS() {
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
|| (navigator.userAgent.includes('Mac') && 'ontouchend' in document);
}
if (isIOS()) {
document.body.classList.add('ios-device');
}
</script>
</body>
</html>