diff --git a/src/api/modules/statistics.ts b/src/api/modules/statistics.ts index 52a901b..4577c31 100644 --- a/src/api/modules/statistics.ts +++ b/src/api/modules/statistics.ts @@ -53,4 +53,12 @@ export const taskRankList = params => { "/adminapi/Statistical/task_statistics", { params } ); +}; +// 中奖记录统计 +export const getLuckyRank = params => { + return http.request( + "get", + "/adminapi/Lottery/record_list", + { params } + ); }; \ No newline at end of file diff --git a/src/views/Statistical/luckycoinRank/hook.tsx b/src/views/Statistical/luckycoinRank/hook.tsx new file mode 100644 index 0000000..186f997 --- /dev/null +++ b/src/views/Statistical/luckycoinRank/hook.tsx @@ -0,0 +1,162 @@ +import { ref, h } from "vue"; +import { + getLuckyRank +} from "@/api/modules/statistics"; +import { utils, writeFile } from "xlsx"; +import ExportForm from '@/components/exportDialog/index.vue'; +import { addDialog } from "@/components/ReDialog"; +import { message } from "@/utils/message"; +export function useData() { + const loading = ref(true); + const tableList = ref([]); + const isShow = ref(false); + const pagination = ref({ + total: 0, + pageSize: 10, + pageSizes: [10, 20, 50, 100, 500, 1000, 2000], + currentPage: 1, + background: true + }); + const searchForm = ref({ + stime: "", + etime: "" + }); + const searchLabel = ref([ + { label: "开始时间", prop: "stime", type: "date" }, + { label: "结束时间", prop: "etime", type: "date" }, + ]); + const tableLabel = ref([ + { + label: "用户名称", + prop: "nickname" + }, + { + label: "中奖类型", + prop: "prize_type_str" + }, + { + label: "中奖比例(%)", + prop: "radio" + }, + { + label: "中奖金额", + prop: "prize_amount" + }, + { + label: "开奖时奖金总金额", + prop: "pool_amount" + }, + { + label: "剩余金额", + prop: "release_amount" + }, + { + label: "生成时间", + prop: "createtime" + } + ]); + const onSearch = async (formData) => { + loading.value = true; + searchForm.value = { ...formData } + const { data, code } = await getLuckyRank({ + ...formData, + page: pagination.value.currentPage, + page_limit: pagination.value.pageSize, + + }); + if (code) { + tableList.value = data.lists.map(ele => { + return { + ...ele, + pool_amount: parseFloat(ele.pool_amount), + prize_amount: parseFloat(ele.prize_amount) + } + }); + pagination.value.currentPage = parseFloat(data.page); + } + loading.value = false; + }; + const handleSizeChange = (val: number) => { + pagination.value.pageSize = val; + onSearch(searchForm.value); + }; + const handleCurrentChange = (val: number) => { + pagination.value.currentPage = val; + // console.log(searchForm.value, 'yzy') + onSearch(searchForm.value); + }; + const exportFormRef = ref(null) + const exportExcel = () => { + let exportTableList = [] + addDialog({ + title: `导出数据`, + props: { + formInline: { + time: '' + } + }, + width: "40%", + closeOnClickModal: false, + contentRenderer: () => h(ExportForm, { ref: exportFormRef, formInline: null }), + beforeSure: (done, { options }) => { + const FormRef = exportFormRef.value.getRef(); + const curData = options.props.formInline; + const exportData = async (formData) => { + const { data, code } = await getLuckyRank({ + ...formData, + page: 1, + page_limit: 20000 + }); + if (code) { + exportTableList = data.lists; + const res = exportTableList.map(item => { + const arr = []; + tableLabel.value.forEach(column => { + arr.push(item[column.prop as string]); + }); + return arr; + }); + const titleList = []; + tableLabel.value.forEach(column => { + titleList.push(column.label); + }); + res.unshift(titleList); + const workSheet = utils.aoa_to_sheet(res); + const workBook = utils.book_new(); + utils.book_append_sheet(workBook, workSheet, "数据报表"); + writeFile(workBook, `幸运币中奖记录列表统计${formData.start_time} - ${formData.end_time}.xlsx`); + message("导出成功", { + type: "success" + }); + done() + } else { + message("获取数据失败,请重试!", { + type: "error" + }); + } + } + FormRef.validate(valid => { + if (valid) { + if (curData.time && curData.time.length) { + exportData({ start_time: curData.time[0] || '', end_time: curData.time[1] || '' }) + } + } + }); + } + }); + + } + return { + searchForm, + searchLabel, + onSearch, + isShow, + tableList, + tableLabel, + pagination, + exportExcel, + handleSizeChange, + handleCurrentChange, + loading + }; +} diff --git a/src/views/Statistical/luckycoinRank/index.vue b/src/views/Statistical/luckycoinRank/index.vue new file mode 100644 index 0000000..05d9d7f --- /dev/null +++ b/src/views/Statistical/luckycoinRank/index.vue @@ -0,0 +1,62 @@ + + + + \ No newline at end of file