diff --git a/src/views/newuser/newuserList/hook.tsx b/src/views/newuser/newuserList/hook.tsx index 6caf9b0..2879161 100644 --- a/src/views/newuser/newuserList/hook.tsx +++ b/src/views/newuser/newuserList/hook.tsx @@ -1,5 +1,7 @@ import { h, ref, nextTick } from "vue"; import editForm from "./form.vue"; +import ExportForm from '@/components/exportDialog/index.vue'; +import { utils, writeFile } from "xlsx"; import detailView from './detail.vue'; import banUserView from './banUser.vue'; import changePassView from './password.vue'; @@ -394,7 +396,72 @@ export function useData() { } }); }; + 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 queryGiftGiveList({ + ...formData, + send_user: searchForm.value.send_user, + gift_user: searchForm.value.gift_user, + from_id: searchForm.value.from_id, + gift_id: searchForm.value.gift_id, + from: searchForm.value.from, + 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] || '' }) + } + } + }); + } + }); + } // 修改密码 const changePassword = async (rowData: any) => { addDialog({ @@ -432,6 +499,7 @@ export function useData() { } }); }; + return { searchForm, searchLabel, @@ -451,6 +519,7 @@ export function useData() { changePassword, setUserFund, onSeniorSearch, - resetFieldsSearch + resetFieldsSearch, + exportExcel }; } \ No newline at end of file diff --git a/src/views/newuser/newuserList/index.vue b/src/views/newuser/newuserList/index.vue index 723b710..9ef4792 100644 --- a/src/views/newuser/newuserList/index.vue +++ b/src/views/newuser/newuserList/index.vue @@ -23,7 +23,8 @@ const { changePassword, setUserFund, onSeniorSearch, - resetFieldsSearch + resetFieldsSearch, + exportExcel } = useData(); defineOptions({ name: "newuserList" @@ -50,6 +51,11 @@ onMounted(() => {