-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty_repair.html
More file actions
324 lines (296 loc) · 22.4 KB
/
property_repair.html
File metadata and controls
324 lines (296 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!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, viewport-fit=cover">
<title>物业维修 - 幸福小区</title>
<script src="js/Taildwind-browser@4.js"></script>
<script src="js/lucide.js"></script>
<script src="js/jquery-3.7.1.min.js"></script>
<style>
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.modal-enter { animation: modalIn 0.2s ease-out forwards; }
.modal-leave { animation: modalOut 0.2s ease-in forwards; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes modalOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.95); } }
/* 星级评分样式 */
.star-rating input { display: none; }
.star-rating label {
cursor: pointer;
color: #cbd5e1;
transition: all 0.2s;
padding: 0 4px;
}
.star-rating label:hover,
.star-rating label:hover ~ label,
.star-rating input:checked ~ label {
color: #fbbf24;
transform: scale(1.1);
}
</style>
</head>
<body class="bg-[#F5F7FA] font-sans text-slate-800 min-h-screen select-none relative">
<header class="px-6 pt-12 pb-6 flex justify-between items-center sticky top-0 bg-[#F5F7FA] z-10">
<div class="flex items-center gap-2">
<button onclick="history.back()" class="p-1 -ml-1 text-slate-400 active:text-slate-600 transition-colors">
<i data-lucide="chevron-left" width="28" height="28"></i>
</button>
<h1 class="text-3xl font-bold text-slate-900">物业维修</h1>
</div>
<div class="w-10 h-10 rounded-full overflow-hidden border-2 border-white shadow-md">
<img id="user-avatar" class="w-full h-full object-cover"
src="img/default_avatar.png"
onerror="this.src='img/default_avatar.png'"
alt="Profile">
</div>
</header>
<main class="px-6 fade-in pb-28">
<div id="repair-list" class="space-y-4">
<div class="bg-white rounded-[1.5rem] p-6 shadow-sm animate-pulse h-24"></div>
</div>
<div id="empty-state" class="hidden text-center mt-20 text-slate-400">
<div class="flex justify-center mb-4 opacity-50"><i data-lucide="clipboard-list" width="64" height="64"></i></div>
<p class="text-lg font-medium">暂无维修申请</p>
</div>
</main>
<div class="fixed bottom-24 right-6 z-40">
<button onclick="openCreateModal()" class="w-14 h-14 bg-[#3B82F6] rounded-full shadow-lg shadow-blue-500/40 flex items-center justify-center text-white active:scale-90 transition-transform">
<i data-lucide="plus" width="32" height="32"></i>
</button>
</div>
<div class="fixed bottom-6 left-6 right-6 z-30">
<nav class="bg-white/95 backdrop-blur-md rounded-[2rem] shadow-[0_8px_30px_rgb(0,0,0,0.08)] px-6 py-3 flex justify-between items-center border border-white/50">
<a href="index.html#home" class="flex flex-col items-center gap-1 w-12 text-gray-400"><i data-lucide="home" width="24"></i><span class="text-[10px] font-medium">首页</span></a>
<a href="javascript:;" class="flex flex-col items-center gap-1 w-12 text-[#3B82F6] -translate-y-1"><i data-lucide="smile" width="24" stroke-width="2.5"></i><span class="text-[10px] font-medium">生活</span><span class="absolute -bottom-2 w-1 h-1 bg-[#3B82F6] rounded-full"></span></a>
<a href="index.html#community" class="flex flex-col items-center gap-1 w-12 text-gray-400"><i data-lucide="users" width="24"></i><span class="text-[10px] font-medium">社区</span></a>
<a href="index.html#me" class="flex flex-col items-center gap-1 w-12 text-gray-400"><i data-lucide="user" width="24"></i><span class="text-[10px] font-medium">我的</span></a>
</nav>
</div>
<div id="create-modal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/40 backdrop-blur-sm transition-opacity" onclick="closeCreateModal()"></div>
<div class="absolute bottom-0 left-0 right-0 bg-white rounded-t-[2rem] p-6 max-h-[85vh] overflow-y-auto modal-enter">
<div class="w-12 h-1.5 bg-gray-200 rounded-full mx-auto mb-6"></div>
<h3 class="text-xl font-bold text-slate-900 mb-6">新建维修申请</h3>
<form onsubmit="submitRepair(event)">
<div class="space-y-4">
<div><label class="block text-sm font-medium text-gray-700 mb-1">标题</label><input type="text" name="title" class="w-full bg-gray-50 border-0 rounded-xl p-3 text-sm focus:ring-2 focus:ring-blue-500" required></div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">类型</label>
<select name="repair_type" class="w-full bg-gray-50 border-0 rounded-xl p-3 text-sm focus:ring-2 focus:ring-blue-500"><option value="electrical">电力</option><option value="plumbing">水路</option><option value="door_window">门窗</option><option value="elevator">电梯</option><option value="other">其他</option></select>
</div>
<div><label class="block text-sm font-medium text-gray-700 mb-1">描述</label><textarea name="description" rows="2" class="w-full bg-gray-50 border-0 rounded-xl p-3 text-sm focus:ring-2 focus:ring-blue-500" required></textarea></div>
<div><label class="block text-sm font-medium text-gray-700 mb-1">位置</label><input type="text" name="location" class="w-full bg-gray-50 border-0 rounded-xl p-3 text-sm focus:ring-2 focus:ring-blue-500" required></div>
<div><label class="block text-sm font-medium text-gray-700 mb-1">电话</label><input type="tel" id="contact_phone" name="contact_phone" class="w-full bg-gray-50 border-0 rounded-xl p-3 text-sm focus:ring-2 focus:ring-blue-500" required></div>
</div>
<div class="mt-8 mb-4">
<button type="submit" class="w-full bg-[#3B82F6] text-white font-bold py-4 rounded-xl shadow-lg active:scale-[0.98] transition-all">提交申请</button>
</div>
</form>
</div>
</div>
<div id="detail-modal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/40 backdrop-blur-sm transition-opacity" onclick="closeDetailModal()"></div>
<div class="absolute bottom-0 left-0 right-0 bg-white rounded-t-[2rem] p-6 h-[85vh] flex flex-col modal-enter">
<div class="w-12 h-1.5 bg-gray-200 rounded-full mx-auto mb-4 shrink-0"></div>
<div class="flex justify-between items-start mb-4 shrink-0">
<div>
<h3 id="detail-title" class="text-xl font-bold text-slate-900 leading-tight">加载中...</h3>
<div class="flex items-center gap-2 mt-1">
<span id="detail-no" class="text-xs text-gray-400 font-mono">REP...</span>
<span id="detail-type" class="text-[10px] px-2 py-0.5 rounded bg-gray-100 text-gray-600 font-medium">--</span>
</div>
</div>
<button onclick="closeDetailModal()" class="p-2 bg-gray-50 rounded-full text-gray-500"><i data-lucide="x" width="20"></i></button>
</div>
<div id="detail-content-area" class="flex-1 overflow-y-auto space-y-6 pb-20 pr-1">
<div class="grid grid-cols-2 gap-3">
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400">状态</p><p id="detail-status-text" class="font-bold text-slate-800">--</p></div>
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400">紧急度</p><p id="detail-urgency" class="font-bold text-slate-800">--</p></div>
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400">位置</p><p id="detail-location" class="font-bold text-slate-800 truncate">--</p></div>
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400">时间</p><p id="detail-date" class="font-bold text-slate-800 text-xs">--</p></div>
</div>
<div><h4 class="font-bold text-slate-900 mb-2 text-sm">故障描述</h4><div id="detail-desc" class="bg-gray-50 p-4 rounded-xl text-sm text-slate-600 leading-relaxed">--</div></div>
<div id="process-section" class="hidden">
<h4 class="font-bold text-slate-900 mb-2 text-sm">维修反馈</h4>
<div class="bg-indigo-50 border border-indigo-100 p-4 rounded-xl space-y-2">
<div class="flex justify-between text-xs"><span class="text-indigo-400">指派时间</span><span id="detail-assigned-at" class="text-indigo-900 font-mono">--</span></div>
<div class="flex justify-between text-xs"><span class="text-indigo-400">完成时间</span><span id="detail-completed-at" class="text-indigo-900 font-mono">--</span></div>
<div class="pt-2 border-t border-indigo-100 mt-2">
<span class="text-indigo-400 text-xs block mb-1">维修备注</span>
<p id="detail-notes" class="text-sm text-indigo-900 font-medium">--</p>
</div>
</div>
</div>
<div id="evaluation-section" class="hidden pt-4 border-t border-dashed border-gray-200">
<h4 class="font-bold text-slate-900 mb-4 text-lg flex items-center gap-2">
<i data-lucide="star" class="text-yellow-500" width="20"></i> 服务评价
</h4>
<div id="evaluation-display" class="hidden bg-yellow-50 border border-yellow-100 p-5 rounded-2xl text-center">
<div class="flex justify-center gap-1 text-yellow-500 mb-3" id="display-stars"></div>
<p id="display-comment" class="text-sm text-slate-700 italic">--</p>
<p class="text-xs text-yellow-600/60 mt-2">感谢您的评价!</p>
</div>
<div id="evaluation-form-container" class="hidden">
<input type="hidden" id="eval-repair-id"><input type="hidden" id="selected-rating" value="5">
<div class="flex justify-center mb-6">
<div class="star-rating flex flex-row-reverse gap-3">
<input type="radio" name="rating" id="star5" value="5" checked onchange="updateRating(5)"><label for="star5" title="5星"><i data-lucide="star" width="40" fill="currentColor"></i></label>
<input type="radio" name="rating" id="star4" value="4" onchange="updateRating(4)"><label for="star4" title="4星"><i data-lucide="star" width="40" fill="currentColor"></i></label>
<input type="radio" name="rating" id="star3" value="3" onchange="updateRating(3)"><label for="star3" title="3星"><i data-lucide="star" width="40" fill="currentColor"></i></label>
<input type="radio" name="rating" id="star2" value="2" onchange="updateRating(2)"><label for="star2" title="2星"><i data-lucide="star" width="40" fill="currentColor"></i></label>
<input type="radio" name="rating" id="star1" value="1" onchange="updateRating(1)"><label for="star1" title="1星"><i data-lucide="star" width="40" fill="currentColor"></i></label>
</div>
</div>
<div class="mb-5"><textarea id="eval-text" class="w-full bg-slate-50 border border-slate-200 rounded-xl p-4 text-sm focus:ring-2 focus:ring-blue-500 outline-none resize-none" rows="3" placeholder="说说您的感受..."></textarea></div>
<button type="button" onclick="submitEvaluation()" id="btn-submit-eval" class="w-full bg-[#3B82F6] hover:bg-blue-600 text-white font-bold text-lg py-4 rounded-xl shadow-lg active:scale-[0.98] transition-all flex items-center justify-center gap-2"><span>确认评价</span><i data-lucide="send" width="20"></i></button>
</div>
</div>
<div class="h-10"></div>
</div>
</div>
</div>
<script>
const API_BASE = 'https://happy.kudosd.icu/api/v1';
const DEBUG_MODE = false;
const STATUS_MAP = {
'submitted': { text: '已提交', class: 'text-blue-600' },
'assigned': { text: '已指派', class: 'text-indigo-600' },
'processing': { text: '维修中', class: 'text-yellow-600' },
'completed': { text: '已完成', class: 'text-green-600' },
'cancelled': { text: '已取消', class: 'text-gray-500' },
'rejected': { text: '已驳回', class: 'text-red-600' }
};
const TYPE_MAP = { 'electrical': '电力', 'plumbing': '水路', 'elevator': '电梯', 'door_window': '门窗', 'other': '其他' };
const URGENCY_MAP = { 'low': '普通', 'medium': '中等', 'high': '重要', 'emergency': '紧急' };
const AppStorage = {
setItem: (k,v) => window.plus ? plus.storage.setItem(k,String(v)) : localStorage.setItem(k,v),
getItem: (k) => window.plus ? plus.storage.getItem(k) : localStorage.getItem(k),
removeItem: (k) => window.plus ? plus.storage.removeItem(k) : localStorage.removeItem(k)
};
// 新增:头像URL处理函数
function getAvatarUrl(url) {
if (!url) return 'img/default_avatar.png';
if (url.startsWith('http') || url.startsWith('data:')) return url;
// 处理相对路径
const prefix = API_BASE.endsWith('/') ? API_BASE : (API_BASE + '/');
const cleanUrl = url.startsWith('/') ? url.substring(1) : url;
return prefix + cleanUrl;
}
const request = async (endpoint, method = 'GET', data = null) => {
const token = AppStorage.getItem('token');
if (!token) { window.location.href = 'index.html'; throw new Error("Unauthorized"); }
if (DEBUG_MODE) { console.log(`>>> [Request] ${method} ${API_BASE}${endpoint}`); if (data) console.log('>>> [Request Body]:', JSON.stringify(data, null, 2)); }
return $.ajax({
url: `${API_BASE}${endpoint}`,
method: method,
contentType: 'application/json',
headers: { 'Authorization': `Bearer ${token}` },
data: data ? JSON.stringify(data) : undefined
}).then(res => {
if (DEBUG_MODE) console.log(`<<< [Response Success] ${method} ${endpoint}`, res);
return res;
}).catch(err => {
if (DEBUG_MODE) console.error(`<<< [Response Error] ${method} ${endpoint}`, err);
if (err.status === 401) { AppStorage.removeItem('token'); window.location.href = 'index.html'; }
throw err;
});
};
$(document).ready(function() {
if (window.lucide) lucide.createIcons();
if (window.plus) {
initPage();
} else {
document.addEventListener('plusready', initPage, false);
if (navigator.userAgent.indexOf("Html5Plus") === -1) initPage();
}
});
async function initPage() {
loadUserProfile();
loadRepairList();
const urlParams = new URLSearchParams(window.location.search);
const openId = urlParams.get('id');
if (openId) openDetailModal(openId);
}
async function loadUserProfile() {
try {
const res = await request('/auth/me');
const user = res.data.user || res.data; // 兼容
// 修复:处理头像
const avatarUrl = getAvatarUrl(user.avatar_url);
$('#user-avatar').attr('src', avatarUrl);
if (user.phone) $('#contact_phone').val(user.phone);
} catch(e) {}
}
async function loadRepairList() {
try {
const res = await request('/repairs?page=1&page_size=50');
const list = res.data.items || [];
const $container = $('#repair-list');
$container.empty();
if (list.length === 0) { $('#empty-state').removeClass('hidden'); return; }
else { $('#empty-state').addClass('hidden'); }
list.forEach((item) => {
let statusColor = 'bg-gray-100 text-gray-600';
let statusText = STATUS_MAP[item.status] ? STATUS_MAP[item.status].text : item.status;
let typeText = TYPE_MAP[item.repair_type] || '其他';
if(item.status === 'completed') statusColor = 'bg-green-100 text-green-700';
else if(item.status === 'processing') statusColor = 'bg-yellow-100 text-yellow-700';
else if(item.status === 'submitted') statusColor = 'bg-blue-100 text-blue-700';
const html = `<div onclick="openDetailModal(${item.id})" class="bg-white rounded-[1.5rem] p-5 shadow-sm mb-4 active:scale-[0.99] transition-transform cursor-pointer flex justify-between items-start"><div><div class="flex items-center gap-2 mb-1"><span class="text-xs font-bold px-2 py-0.5 rounded bg-gray-100 text-gray-600">${typeText}</span><span class="text-gray-400 text-xs">${item.created_at.split('T')[0]}</span></div><h4 class="font-bold text-slate-900 text-lg">${item.title}</h4></div><span class="px-3 py-1 rounded-full text-xs font-bold ${statusColor}">${statusText}</span></div>`;
$container.append(html);
});
} catch(e) { console.error(e); }
}
window.openDetailModal = async function(id) {
$('#detail-modal').removeClass('hidden'); $('body').addClass('overflow-hidden');
$('#detail-title').text('加载中...'); $('#process-section, #evaluation-section, #evaluation-display, #evaluation-form-container').addClass('hidden');
try {
const res = await request(`/repairs/${id}`); const data = res.data;
$('#detail-title').text(data.title); $('#detail-no').text(data.repair_no);
const statusInfo = STATUS_MAP[data.status] || { text: data.status, class: 'text-gray-600' };
$('#detail-status-text').text(statusInfo.text).attr('class', `font-bold ${statusInfo.class}`);
$('#detail-type').text(TYPE_MAP[data.repair_type] || '其他');
const urgInfo = URGENCY_MAP[data.urgency] || { text: '普通', class: '' };
$('#detail-urgency').text(urgInfo.text).attr('class', `font-bold text-xs ${urgInfo.class}`);
$('#detail-location').text(data.location); $('#detail-desc').text(data.description);
$('#detail-date').text(data.created_at.split('T')[0]); $('#detail-phone').text(data.contact_phone);
if (data.status === 'completed' || data.status === 'processing') {
$('#process-section').removeClass('hidden');
$('#detail-assigned-at').text(data.assigned_at ? data.assigned_at.replace('T', ' ') : '-');
$('#detail-completed-at').text(data.actual_completion ? data.actual_completion.replace('T', ' ') : '-');
$('#detail-notes').text(data.completion_notes || '暂无备注');
}
if (data.status === 'completed') {
$('#evaluation-section').removeClass('hidden');
if (data.rating) {
$('#evaluation-display').removeClass('hidden');
let stars = ''; for(let i=0; i<data.rating; i++) stars += '<i data-lucide="star" class="fill-current" width="24"></i>';
$('#display-stars').html(stars); $('#display-comment').text(data.evaluation || "默认好评");
} else {
$('#evaluation-form-container').removeClass('hidden'); $('#eval-repair-id').val(data.id);
$('#selected-rating').val(5); $('#eval-text').val(''); $('input[name="rating"][value="5"]').prop('checked', true);
setTimeout(() => { const container = document.getElementById('detail-content-area'); container.scrollTop = container.scrollHeight; }, 100);
}
}
if (window.lucide) lucide.createIcons();
} catch (e) { alert('加载详情失败'); closeDetailModal(); }
};
window.updateRating = function(val) { $('#selected-rating').val(val); };
window.submitEvaluation = async function() {
const id = $('#eval-repair-id').val(); const rating = $('#selected-rating').val(); const text = $('#eval-text').val();
if (!id) return alert("工单ID丢失");
const payload = { rating: parseInt(rating), evaluation: text || "默认好评" };
const $btn = $('#btn-submit-eval'); const originText = $btn.html();
$btn.prop('disabled', true).html('<span class="animate-pulse">提交中...</span>');
try { await request(`/repairs/${id}/evaluate`, 'POST', payload); if (window.plus) plus.nativeUI.toast("评价成功"); else alert("评价成功"); closeDetailModal(); loadRepairList(); } catch (err) { alert(err.responseJSON?.message || '评价提交失败'); } finally { $btn.prop('disabled', false).html(originText); }
};
window.closeDetailModal = function() { $('#detail-modal').addClass('hidden'); $('body').removeClass('overflow-hidden'); };
window.openCreateModal = function() { $('#create-modal').removeClass('hidden'); };
window.closeCreateModal = function() { $('#create-modal').addClass('hidden'); };
window.submitRepair = async function(e) { e.preventDefault(); const formData = new FormData(e.target); try { await request('/repairs', 'POST', Object.fromEntries(formData)); alert('提交成功'); closeCreateModal(); loadRepairList(); } catch(e) { alert('提交失败'); } };
</script>
</body>
</html>