Mini Shell
| Direktori : / |
|
|
| Current File : //device-query-test.html |
<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #f5f5f5;
padding: 20px;
}
.container {
max-width: 400px;
margin: 0 auto;
background: white;
border-radius: 12px;
padding: 20px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}
.title {
text-align: center;
font-size: 20px;
font-weight: 600;
color: #333;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #333;
}
.form-group input {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 8px;
font-size: 16px;
}
.form-group input:focus {
outline: none;
border-color: #1989fa;
}
.btn {
width: 100%;
padding: 12px;
background: #1989fa;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: background 0.3s;
}
.btn:hover {
background: #1976d2;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.result {
margin-top: 20px;
padding: 15px;
border-radius: 8px;
display: none;
}
.result.success {
background: #f0f9ff;
border: 1px solid #1989fa;
color: #1976d2;
}
.result.error {
background: #fff5f5;
border: 1px solid #f56565;
color: #e53e3e;
}
.device-card {
background: #f8f9fa;
border-radius: 8px;
padding: 15px;
margin-top: 15px;
border-left: 4px solid #1989fa;
}
.device-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.device-name {
font-weight: 600;
color: #333;
}
.device-status {
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
}
.device-status.online {
background: #d4edda;
color: #155724;
}
.device-status.offline {
background: #f8d7da;
color: #721c24;
}
.device-info {
font-size: 14px;
color: #666;
line-height: 1.5;
}
.loading {
text-align: center;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h1 class="title">净水器设备查询</h1>
<form id="queryForm">
<div class="form-group">
<label for="phone">手机号</label>
<input type="tel" id="phone" placeholder="请输入手机号" maxlength="11" required>
</div>
<button type="submit" class="btn" id="submitBtn">查询设备</button>
</form>
<div id="result" class="result"></div>
</div>
<script>
const form = document.getElementById('queryForm');
const phoneInput = document.getElementById('phone');
const submitBtn = document.getElementById('submitBtn');
const resultDiv = document.getElementById('result');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const phone = phoneInput.value.trim();
// 验证手机号
if (!phone) {
showResult('请输入手机号', 'error');
return;
}
if (!/^1[3-9]\d{9}$/.test(phone)) {
showResult('手机号格式不正确', 'error');
return;
}
// 开始查询
submitBtn.disabled = true;
submitBtn.textContent = '查询中...';
showResult('正在查询设备信息...', 'loading');
try {
const response = await fetch(`/Tapp/admin/api/user/get_devices_by_phone.php?phone=${phone}`);
const data = await response.json();
if (data.code === 0) {
displayDevices(data.data);
} else {
showResult(`查询失败: ${data.message}`, 'error');
}
} catch (error) {
console.error('查询失败:', error);
showResult('查询失败,请稍后再试', 'error');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = '查询设备';
}
});
function showResult(message, type) {
resultDiv.className = `result ${type}`;
resultDiv.innerHTML = message;
resultDiv.style.display = 'block';
}
function displayDevices(data) {
const { phone, user_info, devices, device_count } = data;
let html = `<h3>查询结果</h3>`;
html += `<p><strong>手机号:</strong> ${phone}</p>`;
if (user_info) {
html += `<p><strong>用户姓名:</strong> ${user_info.name}</p>`;
html += `<p><strong>注册时间:</strong> ${user_info.create_date}</p>`;
}
html += `<p><strong>设备数量:</strong> ${device_count} 台</p>`;
if (devices && devices.length > 0) {
devices.forEach(device => {
html += `
<div class="device-card">
<div class="device-header">
<div class="device-name">${device.device_name}</div>
<div class="device-status ${device.is_online ? 'online' : 'offline'}">
${device.network_status_text}
</div>
</div>
<div class="device-info">
<p><strong>设备编号:</strong> ${device.device_number}</p>
<p><strong>设备状态:</strong> ${device.device_status_text}</p>
<p><strong>绑定状态:</strong> ${device.bind_status_text}</p>
<p><strong>原水TDS:</strong> ${device.raw_water_value}</p>
<p><strong>净水TDS:</strong> ${device.purification_water_value}</p>
<p><strong>剩余水量:</strong> ${device.surplus_flow}L</p>
<p><strong>累计过滤:</strong> ${device.cumulative_filtration_flow}L</p>
<p><strong>水质等级:</strong> ${device.water_quality.quality_level}</p>
${device.activate_date ? `<p><strong>激活时间:</strong> ${device.activate_date}</p>` : ''}
${device.update_date ? `<p><strong>更新时间:</strong> ${device.update_date}</p>` : ''}
</div>
</div>
`;
});
} else {
html += `<p style="color: #666; text-align: center; margin-top: 20px;">该手机号未绑定任何设备</p>`;
}
showResult(html, 'success');
}
// 测试数据按钮
const testPhones = ['18876237339', '18296537854', '18760447656'];
testPhones.forEach(phone => {
const btn = document.createElement('button');
btn.textContent = `测试 ${phone}`;
btn.style.cssText = 'margin: 5px; padding: 5px 10px; background: #f0f0f0; border: 1px solid #ddd; border-radius: 4px; cursor: pointer; font-size: 12px;';
btn.onclick = () => {
phoneInput.value = phone;
form.dispatchEvent(new Event('submit'));
};
document.body.appendChild(btn);
});
</script>
</body>
</html>