225 lines
11 KiB
HTML
225 lines
11 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}任务详情 - 信息收集{% endblock %}
|
|
{% block content %}
|
|
<div style="margin-bottom:16px;">
|
|
<a href="/tasks/" style="font-size:13px;">← 返回任务列表</a>
|
|
</div>
|
|
|
|
<div class="card" id="taskInfoCard">
|
|
<div class="card-header">
|
|
<span id="taskName"></span>
|
|
<span id="taskMeta" style="font-size:13px; font-weight:400; color:var(--text-light);"></span>
|
|
</div>
|
|
<div class="card-body">
|
|
<div id="taskDescription" class="prose"></div>
|
|
|
|
<hr style="border:none; border-top:1px solid var(--border); margin:20px 0;">
|
|
|
|
<h4 style="margin-bottom:12px;">提交信息</h4>
|
|
<form id="submitForm" method="post" style="display:flex; gap:8px;">
|
|
<input type="text" name="content" class="form-control" placeholder="请输入要提交的信息..." required>
|
|
<button type="submit" class="btn btn-primary">提交</button>
|
|
</form>
|
|
<div id="submitError" style="color:var(--danger); font-size:13px; margin-top:8px; display:none;"></div>
|
|
<div id="submitSuccess" style="color:var(--success); font-size:13px; margin-top:8px; display:none;"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="margin-top:12px;">
|
|
<button class="btn btn-sm" onclick="toggleMySubmissions()">📋 我的提交 (<span id="mySubCount">0</span>)</button>
|
|
</div>
|
|
|
|
<div id="mySubmissionsPanel" style="display:none; margin-top:12px;">
|
|
<div class="card">
|
|
<div class="card-header"><span>我的提交记录</span></div>
|
|
<div class="card-body" style="padding:0;" id="mySubmissionsBody">
|
|
<div class="empty-state">暂无提交记录</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">同部门组员完成情况</div>
|
|
<div class="card-body" style="padding:0;" id="statsBody">
|
|
<div class="empty-state">暂无提交记录</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var taskId = {{ task_id }};
|
|
|
|
function loadTaskDetail() {
|
|
fetch('/api/tasks/' + taskId + '/')
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
if (!res.success) return;
|
|
var task = res.task;
|
|
document.getElementById('taskName').textContent = task.name;
|
|
document.getElementById('taskMeta').textContent = '创建者: ' + task.creator_name + ' | ' + task.created_at;
|
|
var desc = document.getElementById('taskDescription');
|
|
if (task.description) {
|
|
desc.innerHTML = task.description;
|
|
} else {
|
|
desc.innerHTML = '<p style="color:var(--text-light);">暂无任务简介</p>';
|
|
}
|
|
|
|
document.getElementById('submitForm').action = '/tasks/' + task.id + '/submit/';
|
|
document.getElementById('mySubCount').textContent = res.my_submissions.length;
|
|
|
|
var myBody = document.getElementById('mySubmissionsBody');
|
|
if (res.my_submissions && res.my_submissions.length) {
|
|
var html = '<table style="width:100%; border-collapse:collapse;"><thead><tr style="background:#f8fafc; border-bottom:2px solid var(--border);"><th style="padding:10px 16px; text-align:left; font-size:13px;">提交内容</th><th style="padding:10px 16px; text-align:left; font-size:13px;">提交时间</th><th style="padding:10px 16px; text-align:center; font-size:13px; width:120px;">操作</th></tr></thead><tbody>';
|
|
res.my_submissions.forEach(function(sub) {
|
|
html += '<tr style="border-bottom:1px solid var(--border);"><td style="padding:10px 16px;"><span id="sub-content-' + sub.id + '">' + sub.content + '</span><div id="sub-edit-' + sub.id + '" style="display:none;"><input type="text" class="form-control" value="' + sub.content + '" style="font-size:13px; padding:4px 8px;"></div></td>';
|
|
html += '<td style="padding:10px 16px; font-size:13px; color:var(--text-light);">' + sub.created_at + '</td>';
|
|
html += '<td style="padding:10px 16px; text-align:center; font-size:13px; white-space:nowrap;">';
|
|
html += '<button class="btn btn-sm" onclick="editSubmission(' + sub.id + ')" id="edit-btn-' + sub.id + '">编辑</button> ';
|
|
html += '<button class="btn btn-sm btn-danger" onclick="deleteSubmission(' + sub.id + ')">删除</button> ';
|
|
html += '<button class="btn btn-sm btn-primary" onclick="saveSubmission(' + sub.id + ')" id="save-btn-' + sub.id + '" style="display:none;">保存</button> ';
|
|
html += '<button class="btn btn-sm" onclick="cancelEdit(' + sub.id + ')" id="cancel-btn-' + sub.id + '" style="display:none;">取消</button>';
|
|
html += '</td></tr>';
|
|
});
|
|
html += '</tbody></table>';
|
|
myBody.innerHTML = html;
|
|
} else {
|
|
myBody.innerHTML = '<div class="empty-state">暂无提交记录</div>';
|
|
}
|
|
|
|
var statsBody = document.getElementById('statsBody');
|
|
if (res.stats && res.stats.length) {
|
|
var html2 = '<table style="width:100%; border-collapse:collapse;"><thead><tr style="background:#f8fafc; border-bottom:2px solid var(--border);"><th style="padding:12px 16px; text-align:left; font-size:13px;">用户名</th><th style="padding:12px 16px; text-align:center; font-size:13px;">提交次数</th></tr></thead><tbody>';
|
|
res.stats.forEach(function(s) {
|
|
html2 += '<tr style="border-bottom:1px solid var(--border);"><td style="padding:12px 16px;"><a href="javascript:void(0)" onclick="viewUserSubmissions(\'' + s.name + '\')" style="font-weight:500;">' + s.name + '</a></td><td style="padding:12px 16px; text-align:center;"><span class="badge badge-primary">' + s.count + '</span></td></tr>';
|
|
});
|
|
html2 += '</tbody></table>';
|
|
statsBody.innerHTML = html2;
|
|
} else {
|
|
statsBody.innerHTML = '<div class="empty-state">暂无提交记录</div>';
|
|
}
|
|
});
|
|
}
|
|
|
|
loadTaskDetail();
|
|
|
|
document.getElementById('submitForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
var form = this;
|
|
var data = new FormData(form);
|
|
data.append('csrf_token', CSRF_TOKEN);
|
|
var errDiv = document.getElementById('submitError');
|
|
var sucDiv = document.getElementById('submitSuccess');
|
|
errDiv.style.display = 'none';
|
|
sucDiv.style.display = 'none';
|
|
fetch(form.action, { method: 'POST', body: data })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
if (res.error) {
|
|
errDiv.textContent = res.error;
|
|
errDiv.style.display = 'block';
|
|
} else {
|
|
sucDiv.textContent = '提交成功!';
|
|
sucDiv.style.display = 'block';
|
|
form.querySelector('input[name="content"]').value = '';
|
|
setTimeout(function() { loadTaskDetail(); }, 800);
|
|
}
|
|
});
|
|
});
|
|
|
|
function toggleMySubmissions() {
|
|
var panel = document.getElementById('mySubmissionsPanel');
|
|
panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
|
|
}
|
|
|
|
function viewUserSubmissions(username) {
|
|
var title = document.getElementById('userSubTitle');
|
|
var list = document.getElementById('userSubList');
|
|
title.textContent = username + ' 的提交记录';
|
|
list.innerHTML = '<div style="text-align:center;padding:20px;color:var(--text-light);">加载中...</div>';
|
|
document.getElementById('userSubModal').style.display = 'flex';
|
|
|
|
fetch('/tasks/' + taskId + '/user-submissions/?username=' + encodeURIComponent(username))
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
if (res.error) {
|
|
list.innerHTML = '<div style="text-align:center;padding:20px;color:var(--danger);">' + res.error + '</div>';
|
|
return;
|
|
}
|
|
if (res.submissions.length === 0) {
|
|
list.innerHTML = '<div class="empty-state">暂无提交记录</div>';
|
|
return;
|
|
}
|
|
var html = '<table style="width:100%;border-collapse:collapse;">';
|
|
html += '<thead><tr style="background:#f8fafc;border-bottom:2px solid var(--border);">';
|
|
html += '<th style="padding:10px 16px;text-align:left;font-size:13px;">提交内容</th>';
|
|
html += '<th style="padding:10px 16px;text-align:left;font-size:13px;">提交时间</th>';
|
|
html += '</tr></thead><tbody>';
|
|
res.submissions.forEach(function(sub) {
|
|
html += '<tr style="border-bottom:1px solid var(--border);">';
|
|
html += '<td style="padding:10px 16px;">' + sub.content + '</td>';
|
|
html += '<td style="padding:10px 16px;font-size:13px;color:var(--text-light);">' + sub.created_at + '</td>';
|
|
html += '</tr>';
|
|
});
|
|
html += '</tbody></table>';
|
|
list.innerHTML = html;
|
|
});
|
|
}
|
|
|
|
function editSubmission(id) {
|
|
document.getElementById('sub-content-' + id).style.display = 'none';
|
|
document.getElementById('sub-edit-' + id).style.display = 'block';
|
|
document.getElementById('edit-btn-' + id).style.display = 'none';
|
|
document.getElementById('save-btn-' + id).style.display = 'inline-block';
|
|
document.getElementById('cancel-btn-' + id).style.display = 'inline-block';
|
|
}
|
|
|
|
function cancelEdit(id) {
|
|
document.getElementById('sub-content-' + id).style.display = 'block';
|
|
document.getElementById('sub-edit-' + id).style.display = 'none';
|
|
document.getElementById('edit-btn-' + id).style.display = 'inline-block';
|
|
document.getElementById('save-btn-' + id).style.display = 'none';
|
|
document.getElementById('cancel-btn-' + id).style.display = 'none';
|
|
}
|
|
|
|
function saveSubmission(id) {
|
|
var input = document.querySelector('#sub-edit-' + id + ' input');
|
|
var content = input.value.trim();
|
|
if (!content) { alert('内容不能为空'); return; }
|
|
|
|
var data = new FormData();
|
|
data.append('content', content);
|
|
data.append('csrf_token', CSRF_TOKEN);
|
|
|
|
fetch('/tasks/submission/' + id + '/edit/', { method: 'POST', body: data })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
if (res.error) { alert(res.error); return; }
|
|
document.getElementById('sub-content-' + id).textContent = content;
|
|
cancelEdit(id);
|
|
});
|
|
}
|
|
|
|
function deleteSubmission(id) {
|
|
if (!confirm('确定要删除这条提交记录吗?')) return;
|
|
var fd = new FormData();
|
|
fd.append('csrf_token', CSRF_TOKEN);
|
|
fetch('/tasks/submission/' + id + '/delete/', { method: 'POST', body: fd })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
if (res.error) { alert(res.error); return; }
|
|
loadTaskDetail();
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<!-- 查看他人提交弹窗 -->
|
|
<div id="userSubModal" style="display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:999; align-items:center; justify-content:center;">
|
|
<div style="background:#fff; border-radius:8px; width:600px; max-width:90%; max-height:80vh; padding:24px; overflow-y:auto;">
|
|
<h3 id="userSubTitle" style="margin-bottom:16px;"></h3>
|
|
<div id="userSubList"></div>
|
|
<div style="display:flex; gap:8px; justify-content:flex-end; margin-top:16px;">
|
|
<button type="button" class="btn" onclick="document.getElementById('userSubModal').style.display='none'">关闭</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|