better-staridc-MNBT
1<template>
2 <div class="td-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-format-list-bulleted"></i>订单列表</h3>
6 <p class="td-page-subtitle">查看与删除支付订单</p>
7 </div>
8 </div>
9
10 <div class="td-table-wrap">
11 <div class="td-toolbar">
12 <t-button theme="danger" variant="outline" :disabled="!selectedIds.length" @click="batchDelete">
13 <i class="mdi mdi-delete"></i> 删除选中
14 </t-button>
15 <div class="td-toolbar-spacer"></div>
16 <t-button theme="default" variant="text" @click="load">
17 <i class="mdi mdi-refresh"></i> 刷新
18 </t-button>
19 </div>
20
21 <t-table
22 row-key="id"
23 :data="rows"
24 :columns="columns"
25 :loading="loading"
26 :pagination="pagination"
27 stripe
28 bordered
29 @page-change="onPageChange"
30 @select-change="onSelectChange"
31 >
32 <template #user="{ row }">
33 <span>{{ parseUser(row.cs) || row.url || '-' }}</span>
34 </template>
35
36 <template #je="{ row }">
37 <span class="td-text-success td-text-sm">¥ {{ row.je || 0 }}</span>
38 </template>
39
40 <template #qk="{ row }">
41 <span class="td-chip td-chip-success" v-if="row.qk === true || row.qk === 'true'">
42 <i class="mdi mdi-check-circle"></i> 支付成功
43 </span>
44 <span class="td-chip td-chip-danger" v-else>
45 <i class="mdi mdi-close-circle"></i> 未支付
46 </span>
47 </template>
48
49 <template #op="{ row }">
50 <div class="td-row-actions">
51 <t-button theme="danger" variant="text" size="small" @click="deleteRow(row)">
52 <i class="mdi mdi-delete"></i> 删除
53 </t-button>
54 </div>
55 </template>
56 </t-table>
57 </div>
58 </div>
59</template>
60
61<script setup>
62import { ref, reactive, onMounted } from 'vue'
63import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
64import { listOrder, deleteOrder, deleteOrderBatch } from '@/admin/api/order'
65
66const loading = ref(false)
67const rows = ref([])
68const selectedIds = ref([])
69
70const pagination = reactive({
71 current: 1,
72 pageSize: 10,
73 total: 0,
74 showJumper: true,
75})
76
77const columns = [
78 { colKey: 'row-select', type: 'multiple', width: 50 },
79 { colKey: 'id', title: 'ID', width: 70, sorter: true },
80 { colKey: 'user', title: '发起者账号', minWidth: 130, col: 'user' },
81 { colKey: 'spname', title: '支付商品', minWidth: 140, ellipsis: true, sorter: true },
82 { colKey: 'ddh', title: '订单号', minWidth: 180, ellipsis: true, sorter: true },
83 { colKey: 'je', title: '支付金额', width: 110, sorter: true },
84 { colKey: 'zffs', title: '支付方式', width: 110, sorter: true },
85 { colKey: 'date', title: '发起时间', width: 160, sorter: true },
86 { colKey: 'ip', title: '发起者IP', width: 130 },
87 { colKey: 'qk', title: '支付情况', width: 110 },
88 { colKey: 'op', title: '操作', width: 90, fixed: 'right' },
89]
90
91function parseUser(cs) {
92 if (!cs) return ''
93 try {
94 const obj = typeof cs === 'string' ? JSON.parse(cs) : cs
95 if (obj && typeof obj === 'object') return obj.user || ''
96 } catch (_) {
97 /* ignore */
98 }
99 return ''
100}
101
102async function load() {
103 loading.value = true
104 const r = await listOrder({ page: pagination.current, limit: pagination.pageSize })
105 loading.value = false
106 if (r.ok && r.data) {
107 rows.value = r.data.rows || []
108 pagination.total = r.data.total || 0
109 }
110}
111
112function onPageChange(p) {
113 pagination.current = p.current
114 pagination.pageSize = p.pageSize
115 load()
116}
117
118function onSelectChange(selectedRowKeys) {
119 selectedIds.value = selectedRowKeys || []
120}
121
122function batchDelete() {
123 if (!selectedIds.value.length) return
124 const dialog = DialogPlugin.confirm({
125 header: '批量删除',
126 body: `确定删除选中的 ${selectedIds.value.length} 笔订单吗?此操作不可恢复。`,
127 confirmBtn: { content: '删除', theme: 'danger' },
128 onConfirm: async () => {
129 const r = await deleteOrderBatch(selectedIds.value)
130 dialog.destroy()
131 if (r.ok) {
132 MessagePlugin.success('删除成功')
133 selectedIds.value = []
134 load()
135 }
136 },
137 onClose: () => dialog.destroy(),
138 })
139}
140
141function deleteRow(row) {
142 const dialog = DialogPlugin.confirm({
143 header: '删除订单',
144 body: `确定删除订单「${row.ddh || row.id}」吗?此操作不可恢复。`,
145 confirmBtn: { content: '删除', theme: 'danger' },
146 onConfirm: async () => {
147 const r = await deleteOrder(row.id)
148 dialog.destroy()
149 if (r.ok) {
150 MessagePlugin.success('删除成功')
151 load()
152 }
153 },
154 onClose: () => dialog.destroy(),
155 })
156}
157
158onMounted(load)
159</script>