Initial commit

This commit is contained in:
南宁网宿科技
2023-06-03 23:57:39 +08:00
commit 13bed2bafb
1017 changed files with 175796 additions and 0 deletions
+244
View File
@@ -0,0 +1,244 @@
<template>
<div class="page">
<a-page-header :ghost="false" title="代报餐管理">
<div class="ele-text-secondary">
代报餐管理,给特定账号添加代报餐权限。
</div>
</a-page-header>
<div class="ele-body">
<a-card :bordered="false">
<!-- 表格 -->
<ele-pro-table
ref="tableRef"
row-key="userId"
:columns="columns"
:height="tableHeight"
:datasource="datasource"
:parse-data="parseData"
v-model:selection="selection"
:scroll="{ x: 800 }"
>
<template #toolbar>
<search
:selection="selection"
@search="reload"
@add="openEdit"
@remove="removeBatch"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'user'">
<User v-if="record.user" :record="record.user" />
</template>
<template v-if="column.key === 'nickname'">
<span>{{ record.nickname }}</span>
</template>
<template v-if="column.key === 'parentUser'">
<User v-if="record.parentUser" :record="record.parentUser" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">营业中</a-tag>
<a-tag v-if="record.status === 1" color="orange">停业中</a-tag>
</template>
<template v-if="column.key === 'comments'">
<a-tooltip :title="record.comments" placement="topLeft">
{{ record.comments }}
</a-tooltip>
</template>
<template v-if="column.key === 'createTime'">
<a-tooltip :title="`${toDateString(record.createTime)}`">
{{ timeAgo(record.createTime) }}
</a-tooltip>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a class="ele-text-danger" @click="remove(record)">移除</a>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<edit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</div>
</template>
<script lang="ts" setup>
import { timeAgo, toTreeData } from 'ele-admin-pro';
import { createVNode, computed, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import { toDateString } from 'ele-admin-pro';
import Search from './components/search.vue';
import Edit from './components/edit.vue';
import {
listBCAgent,
removeBCAgent,
removeBatchBCAgent
} from '@/api/apps/bc/agent';
import type { BCAgent, BCAgentParam } from '@/api/apps/bc/agent/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: '代报餐人/报餐人',
dataIndex: 'nickname',
key: 'nickname',
ellipsis: true
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
sorter: true,
ellipsis: true,
hideInTable: true,
customRender: ({ text }) => toDateString(text)
},
{
title: '操作',
key: 'action',
width: 200,
align: 'center',
hideInSetting: true
}
]);
// 表格选中数据
const selection = ref<BCAgent[]>([]);
// 当前编辑数据
const current = ref<BCAgent | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.brand = filters.brand;
}
return listBCAgent({ ...where, ...orders, page, limit });
};
/* 搜索 */
const reload = (where?: BCAgentParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
// 搜索是否展开
const searchExpand = ref(false);
// 表格固定高度
const fixedHeight = ref(false);
// 表格高度
const tableHeight = computed(() => {
return fixedHeight.value
? searchExpand.value
? 'calc(100vh - 618px)'
: 'calc(100vh - 562px)'
: void 0;
});
/* 打开编辑弹窗 */
const openEdit = (row?: BCAgent) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 数据转为树形结构 */
const parseData = (data) => {
const result: any[] = [];
data.forEach((item) => {
let index = result.findIndex((citem) => item.parentId == citem.userId);
if (index < 0) {
result.push({
userId: item.parentId,
nickname: item.parentName,
children: []
});
index = result.length - 1;
}
result[index].children.push({
userId: item.userId,
nickname: item.nickname,
agentId: item.agentId
});
});
return result;
};
/* 删除单个 */
const remove = (row: BCAgent) => {
console.log(row);
removeBCAgent(row.agentId)
.then((msg) => {
message.success(msg);
reload();
})
.catch((e) => {
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchBCAgent(selection.value.map((d) => d.agentId))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
</script>
<script lang="ts">
export default {
name: 'BCAgentIndex'
};
</script>
<style lang="less" scoped>
// 文字超出隐藏(两行)
// 需要设置文字容器的宽度
.twoline-hide {
width: 320px;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
white-space: normal;
}
</style>