generated from Leo_Ding/web-template
182 lines
5.8 KiB
Vue
182 lines
5.8 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 label="岗位名称" name="name">
|
|
<a-input placeholder="请输入岗位名称" v-model:value="searchFormData.name"></a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
|
|
<a-col v-bind="colSpan">
|
|
<a-form-item label="状态" name="status">
|
|
<a-select v-model:value="searchFormData.status" allowClear>
|
|
<a-select-option value="">全部</a-select-option>
|
|
<a-select-option value="enabled">启用</a-select-option>
|
|
<a-select-option value="disabled">停用</a-select-option>
|
|
</a-select>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col class="align-right" v-bind="colSpan">
|
|
<a-space>
|
|
<a-button @click="handleResetSearch">{{ $t('button.reset') }}</a-button>
|
|
<a-button ghost type="primary" @click="handleSearch">
|
|
{{ $t('button.search') }}
|
|
</a-button>
|
|
</a-space>
|
|
</a-col>
|
|
</a-row>
|
|
</a-form>
|
|
</template>
|
|
</x-search-bar> -->
|
|
<a-row :gutter="8" :wrap="false">
|
|
<a-col flex="auto">
|
|
<a-card type="flex">
|
|
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
|
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
|
|
<template #bodyCell="{ column, record }">
|
|
<template v-if="column.dataIndex === 'createdAt'">
|
|
<span>{{ dayjs(record.createdAt).format('YYYY-MM-DD HH:mm') }}</span>
|
|
</template>
|
|
</template>
|
|
</a-table>
|
|
</a-card>
|
|
</a-col>
|
|
</a-row>
|
|
<div class="exportExcel"><a-button type="primary" @click="exportExcel">导出Excel</a-button></div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import * as XLSX from "xlsx"; // 推荐用 xlsx 库导出 Excel
|
|
import { message, Modal } from 'ant-design-vue'
|
|
import { ref } from 'vue'
|
|
import apis from '@/apis'
|
|
import { config } from '@/config'
|
|
import { usePagination } from '@/hooks'
|
|
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import dayjs from 'dayjs'
|
|
defineOptions({
|
|
name: 'lotteryOrders',
|
|
})
|
|
const { t } = useI18n() // 解构出t方法
|
|
const columns = [
|
|
{ title: '奖品名称', dataIndex: 'productName' },
|
|
{ title: '所属规则', dataIndex: 'raffleName', align: 'center' },
|
|
{ title: '中奖人', dataIndex: 'customerName', align: 'center' },
|
|
{ title: '客户手机号', dataIndex: 'customerPhone', align: 'center' },
|
|
{ title: '中奖时间', dataIndex: 'createdAt', width: 180, align: 'center' },
|
|
|
|
]
|
|
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } = usePagination()
|
|
const editDialogRef = ref()
|
|
getPageList()
|
|
/**
|
|
* 获取表格数据
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async function getPageList() {
|
|
try {
|
|
showLoading()
|
|
const { pageSize, current } = paginationState
|
|
const { success, data, total } = await apis.raffleProduct
|
|
.getRaffleOrders({
|
|
pageSize,
|
|
current: current,
|
|
...searchFormData.value,
|
|
})
|
|
.catch(() => {
|
|
throw new Error()
|
|
})
|
|
hideLoading()
|
|
if (config('http.code.success') === success) {
|
|
listData.value = data
|
|
paginationState.total = total
|
|
}
|
|
} catch (error) {
|
|
hideLoading()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
function handleDelete({ id }) {
|
|
Modal.confirm({
|
|
title: t('pages.system.user.delTip'),
|
|
content: t('button.confirm'),
|
|
okText: t('button.confirm'),
|
|
onOk: () => {
|
|
return new Promise((resolve, reject) => {
|
|
; (async () => {
|
|
try {
|
|
const { success } = await apis.house.delItem(id).catch(() => {
|
|
throw new Error()
|
|
})
|
|
if (config('http.code.success') === success) {
|
|
resolve()
|
|
message.success(t('component.message.success.delete'))
|
|
await getPageList()
|
|
}
|
|
} catch (error) {
|
|
reject()
|
|
}
|
|
})()
|
|
})
|
|
},
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 分页
|
|
*/
|
|
function onTableChange({ current, pageSize }) {
|
|
paginationState.current = current
|
|
paginationState.pageSize = pageSize
|
|
getPageList()
|
|
}
|
|
|
|
/**
|
|
* 搜索
|
|
*/
|
|
function handleSearch() {
|
|
resetPagination()
|
|
getPageList()
|
|
}
|
|
/**
|
|
* 重置
|
|
*/
|
|
function handleResetSearch() {
|
|
searchFormData.value = {}
|
|
resetPagination()
|
|
getPageList()
|
|
}
|
|
/**
|
|
* 编辑完成
|
|
*/
|
|
async function onOk() {
|
|
await getPageList()
|
|
}
|
|
|
|
function exportExcel() {
|
|
// 1. 创建一个工作簿
|
|
const wb = XLSX.utils.book_new();
|
|
// 2. 创建一个工作表
|
|
const ws = XLSX.utils.json_to_sheet(listData.value);
|
|
// 3. 将工作表添加到工作簿
|
|
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
|
|
// 4. 导出 Excel 文件
|
|
XLSX.writeFile(wb, "lotteryOrders.xlsx");
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.exportExcel {
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: right;
|
|
margin: 10px;
|
|
}
|
|
</style>
|