解决了点击新增与编辑以及删除,没有响应的bug
This commit is contained in:
@@ -24,30 +24,21 @@
|
|||||||
<div class="left">
|
<div class="left">
|
||||||
<el-button type="primary" @click="handleAdd" :icon="Plus">新增任务</el-button>
|
<el-button type="primary" @click="handleAdd" :icon="Plus">新增任务</el-button>
|
||||||
</div>
|
</div>
|
||||||
<TicketFilter
|
<TicketFilter :filters="filters" :operators="operators" @filter-change="handleFilterChange"
|
||||||
:filters="filters"
|
@reset="handleFilterReset" />
|
||||||
:operators="operators"
|
|
||||||
@filter-change="handleFilterChange"
|
|
||||||
@reset="handleFilterReset"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TicketList :tickets="tickets" :loading="loading" @edit="handleEdit" @delete="handleDelete" />
|
<TicketList :tickets="tickets" :loading="loading" @edit="handleEdit" @delete="handleDelete" />
|
||||||
|
|
||||||
<div class="pagination-container">
|
<div class="pagination-container">
|
||||||
<el-pagination
|
<el-pagination v-model:current-page="pagination.page" v-model:page-size="pagination.limit"
|
||||||
v-model:current-page="pagination.page"
|
:total="pagination.total" :page-sizes="[15, 30, 50, 100]" layout="total, sizes, prev, pager, next, jumper"
|
||||||
v-model:page-size="pagination.limit"
|
@size-change="handleSizeChange" @current-change="handleCurrentChange" />
|
||||||
:total="pagination.total"
|
|
||||||
:page-sizes="[15, 30, 50, 100]"
|
|
||||||
layout="total, sizes, prev, pager, next, jumper"
|
|
||||||
@size-change="handleSizeChange"
|
|
||||||
@current-change="handleCurrentChange"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TicketForm v-model="showAddDialog" :form-data="currentTicket" :operators="operators" :is-editing="isEditing" @submit="handleFormSubmit" />
|
<TicketForm v-model="showAddDialog" :form-data="currentTicket" :operators="operators" :is-editing="isEditing"
|
||||||
|
@submit="handleFormSubmit" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -125,7 +116,7 @@ const loadTickets = async () => {
|
|||||||
...filters
|
...filters
|
||||||
}
|
}
|
||||||
const response = await ticketApi.getTickets(params)
|
const response = await ticketApi.getTickets(params)
|
||||||
console.log('工单列表响应:', response)
|
// console.log('工单列表响应:', response)
|
||||||
if (response.code) {
|
if (response.code) {
|
||||||
tickets.value = response.data.data
|
tickets.value = response.data.data
|
||||||
pagination.total = response.total
|
pagination.total = response.total
|
||||||
@@ -162,10 +153,96 @@ const handleFormSubmit = async (formData) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleDelete = async (id) => {
|
const handleDelete = async (id) => {
|
||||||
// ... 删除逻辑 ...
|
try {
|
||||||
// 成功后调用 refreshAll()
|
// 1. 弹出二次确认框,防止用户点错
|
||||||
|
await ElMessageBox.confirm(
|
||||||
|
'确定要删除该工单吗?此操作不可逆',
|
||||||
|
'提示',
|
||||||
|
{
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 2. 开启 loading(如果有的话)
|
||||||
|
// loading.value = true
|
||||||
|
|
||||||
|
// 3. 调用 API 发送删除请求
|
||||||
|
const res = await ticketApi.deleteTicket(id)
|
||||||
|
// console.log('删除响应:', res)
|
||||||
|
|
||||||
|
// 4. 根据你的后端返回结构判断是否成功
|
||||||
|
// 假设后端返回 code 为 200 表示成功
|
||||||
|
if (res.code) {
|
||||||
|
ElMessage.success('删除成功')
|
||||||
|
|
||||||
|
// 5. 成功后调用刷新列表的方法
|
||||||
|
if (typeof refreshAll === 'function') {
|
||||||
|
refreshAll()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ElMessage.error(res.message || '删除失败')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 处理取消操作或接口报错
|
||||||
|
if (error !== 'cancel') {
|
||||||
|
console.error('删除出错:', error)
|
||||||
|
ElMessage.error('系统错误,删除失败')
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// loading.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增任务:清空表单并打开弹窗
|
||||||
|
*/
|
||||||
|
const handleAdd = () => {
|
||||||
|
isEditing.value = false
|
||||||
|
// 初始化一个空的工单对象
|
||||||
|
currentTicket.value = {
|
||||||
|
website: '',
|
||||||
|
operator: '',
|
||||||
|
principalpeople: '',
|
||||||
|
is_complete: '未分配'
|
||||||
|
}
|
||||||
|
showAddDialog.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑任务:克隆数据并打开弹窗
|
||||||
|
*/
|
||||||
|
const handleEdit = (row) => {
|
||||||
|
isEditing.value = true
|
||||||
|
// 使用解构赋值 {...row} 进行浅拷贝,避免修改弹窗时直接影响表格行
|
||||||
|
currentTicket.value = { ...row }
|
||||||
|
showAddDialog.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载运营人员列表(用于弹窗下拉框)
|
||||||
|
*/
|
||||||
|
const loadOperators = async () => {
|
||||||
|
try {
|
||||||
|
const response = await ticketApi.getOperators()
|
||||||
|
console.log('运营人员列表响应:', response.data)
|
||||||
|
|
||||||
|
// 这里的判断逻辑要根据你后端的实际返回结构调整
|
||||||
|
// 如果后端直接返回数组:operators.value = response
|
||||||
|
// 如果后端返回带 code 的结构:
|
||||||
|
if (response.code) {
|
||||||
|
operators.value = response.data || response
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载运营人员失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 分页逻辑
|
// 分页逻辑
|
||||||
const handleSizeChange = (val) => { pagination.limit = val; loadTickets(); }
|
const handleSizeChange = (val) => { pagination.limit = val; loadTickets(); }
|
||||||
const handleCurrentChange = (val) => { pagination.page = val; loadTickets(); }
|
const handleCurrentChange = (val) => { pagination.page = val; loadTickets(); }
|
||||||
@@ -174,21 +251,72 @@ const handleCurrentChange = (val) => { pagination.page = val; loadTickets(); }
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadTickets() // 渲染表格
|
loadTickets() // 渲染表格
|
||||||
initGlobalStats() // 锁定卡片统计
|
initGlobalStats() // 锁定卡片统计
|
||||||
// loadOperators()
|
loadOperators()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/* 保持原有样式不变 */
|
/* 保持原有样式不变 */
|
||||||
.ticket-management { padding: 20px; background-color: #f5f7fa; min-height: 100vh; }
|
.ticket-management {
|
||||||
.stats-container { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 20px; }
|
padding: 20px;
|
||||||
.stat-item { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); border-left: 5px solid #409eff; }
|
background-color: #f5f7fa;
|
||||||
.stat-item.pending { border-left-color: #909399; }
|
min-height: 100vh;
|
||||||
.stat-item.ongoing { border-left-color: #e6a23c; }
|
}
|
||||||
.stat-item.success { border-left-color: #67c23a; }
|
|
||||||
.stat-label { font-size: 14px; color: #666; }
|
.stats-container {
|
||||||
.stat-value { font-size: 26px; font-weight: bold; color: #333; margin-top: 5px; }
|
display: grid;
|
||||||
.main-content { background: white; padding: 20px; border-radius: 8px; }
|
grid-template-columns: repeat(4, 1fr);
|
||||||
.action-bar { display: flex; justify-content: space-between; margin-bottom: 20px; }
|
gap: 20px;
|
||||||
.pagination-container { margin-top: 20px; display: flex; justify-content: flex-end; }
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item {
|
||||||
|
background: white;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
|
||||||
|
border-left: 5px solid #409eff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item.pending {
|
||||||
|
border-left-color: #909399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item.ongoing {
|
||||||
|
border-left-color: #e6a23c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item.success {
|
||||||
|
border-left-color: #67c23a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-label {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
font-size: 26px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
background: white;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-bar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-container {
|
||||||
|
margin-top: 20px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user