generated from Leo_Ding/web-template
170 lines
4.9 KiB
Vue
170 lines
4.9 KiB
Vue
<template>
|
|
<x-search-bar class="mb-8-2">
|
|
<template #default="{ gutter, colSpan }">
|
|
<a-form :model="searchFormData" layout="inline">
|
|
<a-row :gutter="gutter">
|
|
<a-col v-bind="colSpan">
|
|
<a-form-item name="username" label="用户名">
|
|
<a-input v-model:value="searchFormData.username"></a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col v-bind="colSpan">
|
|
<a-form-item label="手机号" title="phone">
|
|
<a-input v-model:value="searchFormData.phone"></a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col class="align-left" v-bind="colSpan">
|
|
<a-space>
|
|
<a-button @click="handleResetSearch">{{ $t('button.reset') }}</a-button>
|
|
<a-button ghost type="primary" @click="handleSearch">
|
|
搜索
|
|
</a-button>
|
|
</a-space>
|
|
</a-col>
|
|
</a-row>
|
|
</a-form>
|
|
</template>
|
|
</x-search-bar>
|
|
<a-card>
|
|
<!-- <p><a-button type="primary" @click="$refs.editDialogRef.handleCreate()">新增</a-button></p> -->
|
|
<a-table :columns="columns" :data-source="listData" :loading="loading" bordered :pagination="paginationState"
|
|
:size="size" row-key="id" @change="onTableChange">
|
|
<template #bodyCell="{ column, record }">
|
|
<template v-if="'action' === column.dataIndex">
|
|
<x-action-button @click="$refs.editDialogRef.handleEdit(record)">新增</x-action-button>
|
|
<!-- <x-action-button @click="handleDelete(record)">删除</x-action-button> -->
|
|
</template>
|
|
</template>
|
|
</a-table>
|
|
</a-card>
|
|
<edit-dialog ref="editDialogRef" @ok="onOk" />
|
|
</template>
|
|
|
|
<script setup>
|
|
import { message, Modal } from 'ant-design-vue'
|
|
import { ref } from 'vue'
|
|
import apis from '@/apis'
|
|
import { config } from '@/config'
|
|
import { usePagination } from '@/hooks'
|
|
import EditDialog from './components/EditDialog.vue'
|
|
|
|
defineOptions({
|
|
name: 'listTable',
|
|
})
|
|
|
|
const columns = [
|
|
{ title: '用户名', dataIndex: 'userName' },
|
|
{ title: '手机号', dataIndex: 'phone' },
|
|
{ title: '变更前', dataIndex: 'pointsBeforeChange' },
|
|
{ title: '变更后', dataIndex: 'remainingPoints' },
|
|
{ title: '变更量', dataIndex: 'changeValue' },
|
|
{ title: '变更时间', dataIndex: 'lastChangeTime' },
|
|
{ title: '变更类型', dataIndex: 'changeType' },
|
|
{ title: '操作', dataIndex: 'action',align:'center' },
|
|
]
|
|
const { listData, paginationState, loading, showLoading, hideLoading, resetPagination, searchFormData } =usePagination()
|
|
const editDialogRef = ref()
|
|
const searchBarExpand = ref(false)
|
|
const size = ref('default')
|
|
|
|
getPageList()
|
|
|
|
/**
|
|
* 获取分页列表
|
|
*/
|
|
async function getPageList() {
|
|
try {
|
|
showLoading()
|
|
const { pageSize, current } = paginationState
|
|
const { success,total, data } = await apis.vouchers
|
|
.getPointList({
|
|
pageSize,
|
|
current: current,
|
|
...searchFormData.value
|
|
})
|
|
.catch(() => {
|
|
throw new Error()
|
|
})
|
|
hideLoading()
|
|
if (success) {
|
|
listData.value = data
|
|
paginationState.total =total
|
|
}
|
|
} catch (error) {
|
|
hideLoading()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索
|
|
*/
|
|
function handleSearch() {
|
|
resetPagination()
|
|
getPageList()
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
function handleDelete({ id }) {
|
|
Modal.confirm({
|
|
title: '删除提示',
|
|
content: '确认删除?',
|
|
onOk: () => {
|
|
return new Promise((resolve, reject) => {
|
|
; (async () => {
|
|
try {
|
|
const { success } = await apis.vouchers.deleteVouchers(id).catch(() => {
|
|
throw new Error()
|
|
})
|
|
if (success) {
|
|
resolve()
|
|
message.success('删除成功')
|
|
await getPageList()
|
|
}
|
|
} catch (error) {
|
|
reject()
|
|
}
|
|
})()
|
|
})
|
|
},
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 密度
|
|
* @param {string} key
|
|
*/
|
|
function handleSize({ key }) {
|
|
size.value = key
|
|
}
|
|
|
|
/**
|
|
* 表格发生改变
|
|
* @param current
|
|
* @param pageSize
|
|
*/
|
|
function onTableChange({ current, pageSize }) {
|
|
paginationState.current = current
|
|
paginationState.pageSize = pageSize
|
|
getPageList()
|
|
}
|
|
|
|
/**
|
|
* 完成
|
|
*/
|
|
function onOk() {
|
|
getPageList()
|
|
}
|
|
/**
|
|
* 重置
|
|
*/
|
|
function handleResetSearch() {
|
|
searchFormData.value = {}
|
|
resetPagination()
|
|
getPageList()
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped></style>
|