250 lines
5.8 KiB
Vue
Raw Normal View History

2025-03-03 16:50:51 +08:00
<template>
2025-03-25 07:53:09 +01:00
<div class="custom-page">
<el-row :gutter="20">
<splitpanes class="default-theme">
<pane size="16">
<el-col>
<custom-table-tree title="行政区域" :data="typeTree" :option="treeOption" @node-click="handleNodeClick" />
</el-col>
</pane>
<pane size="84">
<el-col>
<avue-crud
ref="crudRef"
v-model="state.form"
v-model:search="state.query"
v-model:page="state.pageData"
:table-loading="state.loading"
:data="state.data"
:option="state.options"
@refresh-change="refreshChange"
@search-reset="searchChange"
@search-change="searchChange"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@row-del="rowDel"
>
<template #menu-left>
<el-button type="primary" icon="Plus" @click="onAdd">新增</el-button>
<el-button type="success" icon="download" @click="onExport">导出</el-button>
</template>
<template #menu="scope">
<custom-table-operate :actions="state.options.actions" :data="scope" />
</template>
</avue-crud>
</el-col>
</pane>
</splitpanes>
</el-row>
</div>
2025-03-03 16:50:51 +08:00
</template>
2025-03-04 16:24:17 +08:00
<script setup>
import { ref, reactive, onMounted } from 'vue';
import { useApp } from '@/hooks';
import { CRUD_OPTIONS } from '@/config';
2025-03-06 16:20:26 +08:00
import { useUserStore } from '@/store/modules/user';
2025-03-11 15:58:05 +08:00
import { getRegion } from '@/apis/index';
2025-03-04 16:24:17 +08:00
const { VITE_APP_BASE_API } = import.meta.env;
const app = useApp();
2025-03-06 16:20:26 +08:00
const UserStore = useUserStore();
2025-03-04 16:24:17 +08:00
2025-03-06 16:20:26 +08:00
const crudRef = ref(null);
2025-03-04 16:24:17 +08:00
const state = reactive({
loading: false,
query: {
current: 1,
size: 10,
},
form: {},
selection: [],
options: {
...CRUD_OPTIONS,
addBtnText: '',
addBtn: false,
column: [
2025-03-06 16:20:26 +08:00
{ label: '编号', prop: 'gridManager', addDisplay: false, editDisplay: false },
{
label: '所属上级',
prop: 'villageCode',
type: 'cascader',
checkStrictly: true,
props: {
label: 'areaName',
value: 'areaCode',
children: 'areaChildVOS',
},
dicUrl: `${VITE_APP_BASE_API}/system/area/region?areaCode=530000`,
dicHeaders: {
authorization: UserStore.token,
},
dicFormatter: (res) => res.data ?? [],
rules: [
{
required: true,
message: '请选择',
trigger: 'blur',
},
],
},
{ label: '名称', prop: 'gridManager' },
{ label: '状态', prop: 'gridManager', addDisplay: false, editDisplay: false },
2025-03-04 16:24:17 +08:00
],
actions: [
{
name: (row) => getStatusButtonText(row.status),
icon: 'edit',
event: ({ row }) => rowStatus(row),
},
{
name: '编辑',
icon: 'edit',
event: ({ row }) => rowEdit(row),
},
{
type: 'danger',
name: '删除',
icon: 'delete',
event: ({ row }) => rowDel(row),
},
],
},
pageData: {
total: 0,
currentPage: 1,
pageSize: 10,
},
data: [],
currentRow: {},
});
2025-03-20 09:16:17 +01:00
const typeTree = ref([]);
const treeOption = ref({
nodeKey: 'areaCode',
props: { children: 'areaChildVOS', label: 'areaName' },
});
const townOptions = reactive([]);
const infoData = reactive({
2025-03-04 16:24:17 +08:00
countyId: '',
townId: '',
name: '',
});
const loadData = () => {
//state.loading = true;
// getAnnualList(state.query)
// .then((res) => {
// if (res.code === 200) {
// const { current, size, total, records } = res.data;
// state.data = records;
// state.pageData = {
// currentPage: current || 1,
// pageSize: size || 10,
// total: total,
// };
// }
// })
// .catch((err) => {
// app.$message.error(err.msg);
// state.data = [];
// })
// .finally(() => {
// state.loading = false;
// });
};
2025-03-11 15:58:05 +08:00
const getTree = () => {
getRegion().then((res) => {
if (res.code === 200) {
const { code, data } = res;
typeTree.value = data;
console.info('区域信息', typeTree.value);
}
});
};
2025-03-04 16:24:17 +08:00
onMounted(() => {
2025-03-11 15:58:05 +08:00
getTree();
2025-03-04 16:24:17 +08:00
loadData();
});
// 页数
const currentChange = (current) => {
state.query.current = current;
loadData();
};
// 条数
const sizeChange = (size) => {
state.query.size = size;
loadData();
};
// 搜索
const searchChange = (params, done) => {
if (done) done();
state.query = params;
state.query.current = 1;
loadData();
};
// 刷新
const refreshChange = () => {
loadData();
app.$message.success('刷新成功');
};
// 选择
const selectionChange = (rows) => {
state.selection = rows;
};
const handleNodeClick = (data) => {
2025-03-11 15:58:05 +08:00
// if (data.level == '2') {
// return;
// }
// if (data.level == '0') {
// infoData.countyId = data.id;
// infoData.townId = '';
// }
// if (data.level == '1') {
// let countys =
// typeTree.filter((m) => {
// return m.id == data.pId;
// }) || [];
// let town = countys[0] && countys[0].children ? countys[0].children : [];
// townOptions = town;
// infoData.townId = data.id;
// infoData.countyId = data.pId;
// }
2025-03-04 16:24:17 +08:00
// console.info('infoData', infoData);
};
// 编辑
const rowStatus = (row) => {
console.info('操作状态');
};
const rowDel = (row) => {};
const getStatusButtonText = (status) => {
switch (status) {
case 'active':
return '启用';
case 'inactive':
return '禁用';
}
};
2025-03-06 16:20:26 +08:00
const rowEdit = (row) => {
crudRef.value && crudRef.value.rowEdit(row);
};
2025-03-04 16:24:17 +08:00
const onAdd = () => {
2025-03-06 16:20:26 +08:00
// infoVisible.value = true;
crudRef.value && crudRef.value.rowAdd();
2025-03-04 16:24:17 +08:00
};
const onExport = () => {};
</script>