添加需求
This commit is contained in:
parent
7e6c2a1740
commit
3bd286f50e
@ -50,22 +50,13 @@
|
||||
<button class="close-btn" @click="closeReplyModal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="add-modal-form">
|
||||
<div class="form-row">
|
||||
<span class="label">请求者:</span>
|
||||
<input class="input" placeholder="可选" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<span class="label">QQ号:</span>
|
||||
<input v-model="addForm.qq_code" class="input" placeholder="可选" />
|
||||
</div>
|
||||
|
||||
<form class="add-modal-form" @submit.prevent="submitReply">
|
||||
<div class="form-row">
|
||||
<span class="label">相关建议:</span>
|
||||
<textarea
|
||||
v-model="addForm.sendcontent"
|
||||
class="input"
|
||||
placeholder="请输入需求内容"
|
||||
placeholder="请输入相关建议"
|
||||
rows="3"
|
||||
ref="autoTextarea"
|
||||
@input="autoResize"
|
||||
@ -126,7 +117,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="no-reply">
|
||||
暂无回复
|
||||
<div v-if="selectedDemand?.sendcontent">
|
||||
<div class="reply-content">{{ selectedDemand.sendcontent }}</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
暂无回复
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -155,7 +151,7 @@
|
||||
<div class="form-row">
|
||||
<span class="label">需求内容:</span>
|
||||
<textarea
|
||||
v-model="addForm.sendcontent"
|
||||
v-model="addForm.content"
|
||||
class="input"
|
||||
placeholder="请输入需求内容"
|
||||
rows="3"
|
||||
@ -180,7 +176,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, nextTick } from 'vue'
|
||||
import axiosInstance from '../../api/axiosConfig'
|
||||
import { getDemandsList, addDemand, updateDemand } from '../../api/demands'
|
||||
|
||||
// 响应式数据
|
||||
const demands = ref([])
|
||||
@ -194,10 +190,10 @@ const showAddModal = ref(false)
|
||||
const addError = ref('')
|
||||
const addForm = ref({
|
||||
requester: '',
|
||||
sendcontent: '',
|
||||
content: '',
|
||||
reward: '',
|
||||
qq_code: ''
|
||||
qq_code: '',
|
||||
sendcontent: ''
|
||||
})
|
||||
const addLoading = ref(false)
|
||||
const autoTextarea = ref(null)
|
||||
@ -228,16 +224,7 @@ const fetchDemands = async () => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await fetch('http://zybdatasupport.online:8000/demands/getlist', {
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
if (!response.ok) {
|
||||
throw new Error(`请求失败: ${response.status}`)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const data = await getDemandsList()
|
||||
demands.value = data
|
||||
} catch (err) {
|
||||
error.value = `加载失败: ${err.message}`
|
||||
@ -273,10 +260,10 @@ const closeModal = () => {
|
||||
function openAddModal() {
|
||||
addForm.value = {
|
||||
requester: '',
|
||||
sendcontent: '',
|
||||
content: '',
|
||||
reward: '',
|
||||
qq_code: ''
|
||||
qq_code: '',
|
||||
sendcontent: ''
|
||||
}
|
||||
addError.value = ''
|
||||
showAddModal.value = true
|
||||
@ -290,7 +277,7 @@ function closeAddModal() {
|
||||
|
||||
//提交表单
|
||||
async function submitAddForm() {
|
||||
if (!addForm.value.sendcontent.trim()) {
|
||||
if (!addForm.value.content?.trim()) {
|
||||
addError.value = '需求内容不能为空';
|
||||
return;
|
||||
}
|
||||
@ -300,18 +287,18 @@ async function submitAddForm() {
|
||||
const now = new Date();
|
||||
const dateStr = `${now.getFullYear()}-${(now.getMonth()+1).toString().padStart(2,'0')}-${now.getDate().toString().padStart(2,'0')} ${now.getHours().toString().padStart(2,'0')}:${now.getMinutes().toString().padStart(2,'0')}:${now.getSeconds().toString().padStart(2,'0')}`;
|
||||
const payload = {
|
||||
requester: addForm.value.requester,
|
||||
sendcontent: addForm.value.sendcontent,
|
||||
content: addForm.value.sendcontent,
|
||||
reward: addForm.value.reward,
|
||||
requester: addForm.value.requester || '',
|
||||
sendcontent: '',
|
||||
content: addForm.value.content,
|
||||
reward: addForm.value.reward || '',
|
||||
date: dateStr,
|
||||
qq_code: addForm.value.qq_code
|
||||
qq_code: addForm.value.qq_code || ''
|
||||
};
|
||||
const response = await axiosInstance.post('/demands/add', payload);
|
||||
if (response.status === 200) {
|
||||
showAddModal.value = false;
|
||||
fetchDemands(); // 刷新列表
|
||||
}
|
||||
|
||||
console.log('提交的数据:', payload);
|
||||
await addDemand(payload);
|
||||
showAddModal.value = false;
|
||||
fetchDemands(); // 刷新列表
|
||||
} catch (e) {
|
||||
console.error('提交失败:', e);
|
||||
addError.value = e.response?.data?.detail || '提交失败,请稍后重试';
|
||||
@ -320,6 +307,38 @@ async function submitAddForm() {
|
||||
}
|
||||
}
|
||||
|
||||
// 提交回复
|
||||
const submitReply = async () => {
|
||||
if (!addForm.value.sendcontent?.trim()) {
|
||||
addError.value = '回复内容不能为空';
|
||||
return;
|
||||
}
|
||||
addLoading.value = true;
|
||||
addError.value = '';
|
||||
try {
|
||||
const now = new Date();
|
||||
const dateStr = `${now.getFullYear()}-${(now.getMonth()+1).toString().padStart(2,'0')}-${now.getDate().toString().padStart(2,'0')} ${now.getHours().toString().padStart(2,'0')}:${now.getMinutes().toString().padStart(2,'0')}:${now.getSeconds().toString().padStart(2,'0')}`;
|
||||
const payload = {
|
||||
requester: reply.value.requester || '',
|
||||
sendcontent: addForm.value.sendcontent,
|
||||
content: reply.value.content,
|
||||
reward: reply.value.reward || '',
|
||||
date: dateStr,
|
||||
qq_code: reply.value.qq_code || ''
|
||||
};
|
||||
|
||||
console.log('提交的回复数据:', payload);
|
||||
await updateDemand(reply.value.id, payload);
|
||||
replyModal.value = false;
|
||||
fetchDemands(); // 刷新列表
|
||||
} catch (e) {
|
||||
console.error('提交回复失败:', e);
|
||||
addError.value = e.response?.data?.detail || '提交失败,请稍后重试';
|
||||
} finally {
|
||||
addLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载时自动加载数据
|
||||
onMounted(() => {
|
||||
fetchDemands()
|
||||
@ -657,4 +676,17 @@ function autoResize() {
|
||||
background: #f7faff;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.no-reply .reply-content {
|
||||
text-align: left;
|
||||
padding: 10px 0;
|
||||
color: #333;
|
||||
border-left: 3px solid #2563eb;
|
||||
padding-left: 15px;
|
||||
margin: 10px 0;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
</style>
|
Loading…
x
Reference in New Issue
Block a user