Files
yxe-admin/src/views/oa/customer/list.vue
T
南宁网宿科技 13bed2bafb Initial commit
2023-06-03 23:57:39 +08:00

353 lines
9.6 KiB
Vue

<template>
<div class="ele-body">
<!-- 表格 -->
<ele-pro-table
ref="tableRef"
row-key="customerId"
:columns="columns"
:datasource="datasource"
v-model:selection="selection"
tool-class="ele-toolbar-form"
:scroll="{ x: 800 }"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
:tab-value="type.value"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'customerName'">
<a-avatar
:size="30"
:src="`${record.customerAvatar}`"
style="margin-right: 4px"
:srcset="`https://file.wsdns.cn/${record.customerAvatar}`"
>
<template #icon>
<UserOutlined />
</template>
</a-avatar>
<a-tooltip title="查看详情">
<a href="#" @click="openInfo(record)">{{ record.customerName }}</a>
</a-tooltip>
</template>
<template v-if="column.key === 'progress'">
<div v-for="(d, i) in progressDict" :key="i">
<span v-if="d.value === record.progress">{{ d.label }}</span>
</div>
</template>
<template v-if="column.key === 'customerType'">
<div v-for="(d, i) in JSON.parse(customerType)" :key="i">
<span v-if="d.value === record.customerType">{{ d.value }}</span>
</div>
</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="red">待审核</a-tag>
<a-tag v-if="record.status === 2" color="purple">已驳回</a-tag>
</template>
<template v-if="column.key === 'nickname'">
<a-tooltip :title="`${record.nickname}`">
<a-avatar :src="record.userAvatar" size="small" />
</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
v-if="type.value === 'my' && loginUser.userId === record.userId"
>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
<a-space v-if="type.value === 'all'" v-role="['admin']">
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
<!-- 编辑弹窗 -->
<CustomerEdit v-model:visible="showEdit" :data="current" @done="reload" />
<!-- 客户详情弹窗 -->
<CustomerInfo v-model:visible="showInfo" :data="current" @done="reload" />
<!-- 批量转移弹窗 -->
<!-- <CustomerMove v-model:visible="showMove" :data="selection" @done="batchMove" />-->
</div>
</template>
<script lang="ts" setup>
import { computed, createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import {
ExclamationCircleOutlined,
UserOutlined
} 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 CustomerEdit from './components/customer-edit.vue';
import CustomerInfo from './components/customer-info.vue';
import {
pageCustomer,
removeCustomer,
removeBatchCustomer
} from '@/api/oa/customer';
import { timeAgo } from 'ele-admin-pro';
import type { Customer, CustomerParam } from '@/api/oa/customer/model';
import { useUserStore } from '@/store/modules/user';
import { getDictionaryOptions } from '@/utils/common';
const userStore = useUserStore();
// 当前用户信息
const loginUser = computed(() => userStore.info ?? {});
const customerType = localStorage.getItem('customerType');
const props = defineProps<{
// 选项卡 id
type?: any;
}>();
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<Customer[]>([]);
// 当前编辑数据
const current = ref<Customer | null>(null);
// 获取字典数据
const progressDict = getDictionaryOptions('customerFollowStatus');
const sourceDict = getDictionaryOptions('customerSource');
const typeDict = getDictionaryOptions('customerType');
// 是否显示资产详情
const showInfo = ref(false);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.progress = filters.progress;
where.customerSource = filters.customerSource;
where.customerType = filters.customerType;
where.status = filters.status;
}
// 搜索条件
if (props.type.value === 'my') {
where.userId = loginUser.value.userId;
} else if (props.type.value === 'all') {
// 全部客户
// where.userId = undefined;
}
return pageCustomer({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
key: 'index',
width: 48,
align: 'center',
fixed: 'left',
hideInSetting: true,
customRender: ({ index }) => index + (tableRef.value?.tableIndex ?? 0)
},
{
title: '客户名称',
dataIndex: 'customerName',
key: 'customerName',
width: 280,
ellipsis: true
},
{
title: '客户标识',
width: 128,
dataIndex: 'customerCode'
},
{
title: '跟进状态',
key: 'progress',
dataIndex: 'progress',
filters: progressDict
},
{
title: '客户来源',
key: 'customerSource',
dataIndex: 'customerSource',
filters: sourceDict
},
{
title: '客户类型',
key: 'customerType',
dataIndex: 'customerType',
filters: typeDict
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
filters: [
{ text: '正常', value: 0 },
{ text: '待审核', value: 1 },
{ text: '已驳回', value: 2 }
]
},
{
title: '备注',
dataIndex: 'comments'
},
{
title: '排序',
dataIndex: 'sortNumber',
sorter: true
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text)
},
{
title: '操作',
key: 'action',
width: 200,
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: CustomerParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: Customer) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 打开用户详情弹窗 */
const openInfo = (row?: Customer) => {
current.value = row ?? null;
showInfo.value = true;
};
/* 删除单个 */
const remove = (row: Customer) => {
const hide = message.loading('请求中..', 0);
removeCustomer(row.customerId)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量转移 */
const batchMove = (userId) => {
console.log(userId, '批量转移0000');
console.log(selection.value);
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchCustomer(
selection.value.map((d) => {
if (loginUser.value.userId === d.userId) {
return d.customerId;
}
})
)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
</script>
<script lang="ts">
export default {
name: 'Customer'
};
</script>
<style lang="less" scoped>
.sys-org-table :deep(.ant-table-body) {
overflow: auto !important;
overflow: overlay !important;
}
.sys-org-table :deep(.ant-table-pagination.ant-pagination) {
padding: 0 4px;
margin-bottom: 0;
}
</style>