封装钱包规则下拉框

This commit is contained in:
dzc committed 2025-03-29 11:49:20 +08:00
1 parent c23f369a77
commit 7da1bb9a05
12 files changed
+194 -79

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
<template>
<el-dialog :title="form.id ? '编辑' : '新增'" v-model="visible" :close-on-click-modal="false" draggable>
<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px" v-loading="loading">
<el-row :gutter="24">
<el-col :span="12" class="mb20">
<el-form-item label="商户id" prop="mchId">
<el-input v-model="form.mchId" placeholder="请输入商户id" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="用户id" prop="userId">
<el-input v-model="form.userId" placeholder="请输入用户id" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="用户部门id" prop="userDeptId">
<el-input v-model="form.userDeptId" placeholder="请输入用户部门id" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="MchDeptDialog">
import { useDict } from "/@/hooks/dict"
import { useMessage } from "/@/hooks/message"
import { getObj, addObj, putObj } from "/@/api/wallet/mch-dept"
import { rule } from "/@/utils/validate"
const emit = defineEmits(["refresh"])
// 定义变量内容
const dataFormRef = ref()
const visible = ref(false)
const loading = ref(false)
// 定义字典
// 提交表单数据
const form = reactive({
id: "",
mchId: "",
userId: "",
userDeptId: "",
})
// 定义校验规则
const dataRules = ref({})
// 打开弹窗
const openDialog = (id: string) => {
visible.value = true
form.id = ""
// 重置表单数据
nextTick(() => {
dataFormRef.value?.resetFields()
})
// 获取mchDeptUser信息
if (id) {
form.id = id
getmchDeptUserData(id)
}
}
// 提交
const onSubmit = async () => {
const valid = await dataFormRef.value.validate().catch(() => {})
if (!valid) return false
try {
loading.value = true
form.id ? await putObj(form) : await addObj(form)
useMessage().success(form.id ? "修改成功" : "添加成功")
visible.value = false
emit("refresh")
} catch (err: any) {
useMessage().error(err.msg)
} finally {
loading.value = false
}
}
// 初始化表单数据
const getmchDeptUserData = (id: string) => {
// 获取数据
loading.value = true
getObj(id)
.then((res: any) => {
Object.assign(form, res.data)
})
.finally(() => {
loading.value = false
})
}
// 暴露变量
defineExpose({
openDialog,
})
</script>
+189
View File
@@ -0,0 +1,189 @@
<template>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList">
<el-row>
<el-form-item style="width: 300px" label="商户" prop="merchantName">
<el-input v-model="state.queryForm.merchantName" placeholder="商户" />
</el-form-item>
<el-form-item style="width: 300px" label="用户" prop="userIds">
<select-user v-model="state.queryForm.userIds" />
</el-form-item>
<el-form-item>
<el-button icon="Search" type="primary" @click="getDataList">
{{ $t("common.queryBtn") }}
</el-button>
<el-button icon="Refresh" @click="resetQuery">{{ $t("common.resetBtn") }}</el-button>
</el-form-item>
</el-row>
</el-form>
<el-row>
<div class="mb8" style="width: 100%">
<el-button icon="RefreshLeft" type="primary" class="ml10" @click="syncAll"> 同步全部 </el-button>
<el-button icon="folder-add" type="primary" class="ml10" @click="formDialogRef.openDialog()" v-auth="'wallet_mchDeptUser_add'">
新 增
</el-button>
<el-button
plain
:disabled="multiple"
icon="Delete"
type="primary"
v-auth="'wallet_mchDeptUser_del'"
@click="handleDelete(selectObjs)"
>
删除
</el-button>
<right-toolbar
v-model:showSearch="showSearch"
:export="'wallet_mchDeptUser_export'"
@exportExcel="exportExcel"
class="ml10 mr20"
style="float: right"
@queryTable="getDataList"
></right-toolbar>
</div>
</el-row>
<el-table
:data="state.dataList"
v-loading="state.loading"
border
:cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle"
@selection-change="selectionChangHandle"
@sort-change="sortChangeHandle"
>
<el-table-column type="selection" width="40" align="center" />
<el-table-column type="index" label="#" width="80" />
<el-table-column label="商户">
<el-table-column prop="merchantId" label="商户id" />
<el-table-column prop="merchantName" label="商户名" />
</el-table-column>
<el-table-column label="部门">
<el-table-column prop="deptId" label="部门id" />
<el-table-column prop="deptName" label="部门名" />
</el-table-column>
<el-table-column label="操作" width="150">
<template #default="scope">
<el-button
icon="edit-pen"
text
type="primary"
v-auth="'wallet_mchDeptUser_edit'"
@click="formDialogRef.openDialog(scope.row.id)"
>编辑</el-button
>
<el-button icon="delete" text type="primary" v-auth="'wallet_mchDeptUser_del'" @click="handleDelete([scope.row.id])"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
</div>
<!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
</div>
</template>
<script setup lang="ts" name="systemMchDept">
import { BasicTableProps, useTable } from "/@/hooks/table"
import * as mchDeptUserApi from "/@/api/wallet/mch-dept"
import { useMessage, useMessageBox } from "/@/hooks/message"
import { useDict } from "/@/hooks/dict"
import { ro } from "element-plus/es/locale"
// 引入组件
const FormDialog = defineAsyncComponent(() => import("./form.vue"))
// 定义查询字典
// 定义变量内容
const formDialogRef = ref()
// 搜索变量
const queryRef = ref()
const showSearch = ref(true)
// 多选变量
const selectObjs = ref([]) as any
const multiple = ref(true)
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {},
pageList: mchDeptUserApi.pageJoin,
})
// table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } = useTable(state)
// 同步全部
const syncAll = async () => {
try {
await useMessageBox().confirm("是否同步全部,会先删除")
} catch {
return
}
mchDeptUserApi.asyncAll()
}
// 清空搜索条件
const resetQuery = () => {
// 清空搜索条件
queryRef.value?.resetFields()
// 清空多选
selectObjs.value = []
getDataList()
}
// 导出excel
const exportExcel = () => {
downBlobFile("/wallet/mchDeptUser/export", Object.assign(state.queryForm, { ids: selectObjs }), "mchDeptUser.xlsx")
}
// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
selectObjs.value = objs.map(({ id }) => id)
multiple.value = !objs.length
}
// 删除操作
const handleDelete = async (ids: string[]) => {
try {
await useMessageBox().confirm("此操作将永久删除")
} catch {
return
}
try {
await mchDeptUserApi.delObjs(ids)
getDataList()
useMessage().success("删除成功")
} catch (err: any) {
useMessage().error(err.msg)
}
}
</script>
<style scoped lang="scss">
.status {
display: flex;
align-items: center;
margin-bottom: 2px;
span {
display: inline-block;
}
span:nth-child(1) {
min-width: 60px;
max-width: 100px;
text-align: left;
}
span:nth-child(2) {
flex: 1;
min-width: 50px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>