吉安感知网项目-前端
罗广辉
2026-02-02 6b13e6a3a29a66bd09b5be00a11c4f69929aa3ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<template>
    <basic-container>
        <el-form ref="queryParamsRef" :model="searchParams" class="gd-search-form">
            <el-form-item label="材料名称" prop="materialName">
                <el-input
                    class="gd-input gray"
                    v-model="searchParams.materialName"
                    placeholder="请输入"
                    clearable
                    @clear="handleSearch"
                />
            </el-form-item>
 
            <el-form-item label="所属区划" prop="areaCode">
                <el-tree-select
                    class="gd-select gray"
                    popper-class="gd-tree-select-popper"
                    v-model="searchParams.areaCode"
                    node-key="id"
                    :props="treeSelectProps"
                    placeholder="请选择"
                    clearable
                    filterable
                    @change="handleSearch"
                    :check-strictly="true"
                    lazy
                    :load="loadRegionNode"
                    :render-after-expand="false"
                />
            </el-form-item>
 
            <el-form-item class="gd-search-actions">
                <el-button :icon="RefreshRight" @click="resetForm"></el-button>
                <el-button class="search-btn" :icon="Search" @click="handleSearch"></el-button>
            </el-form-item>
        </el-form>
 
        <div class="gd-table-toolbar">
            <el-button :icon="Plus" color="#4C34FF" type="primary" @click="openForm('add')">新增材料</el-button>
        </div>
 
        <div class="gd-table-container" v-loading="loading">
            <div class="gd-table-content gd-table-content-bg">
                <el-table class="gd-table" :data="list">
                    <el-table-column label="序号" width="80">
                        <template v-slot="{ $index }">
                            {{ $index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="materialName" show-overflow-tooltip label="材料名称" />
                    <el-table-column prop="materialDesc" show-overflow-tooltip label="材料说明" />
                    <el-table-column prop="necessity" show-overflow-tooltip label="必要性">
                        <template v-slot="{ row }">
                            {{ getDictLabel(row.necessity, dictObj.necessity) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="isAllScenario" show-overflow-tooltip label="是否适用全部情形">
                        <template v-slot="{ row }">
                            {{ getDictLabel(String(row.isAllScenario), dictObj.isAllScenario) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="areaName" show-overflow-tooltip label="所属区域" />
                    <el-table-column label="操作" class-name="operation-btns" width="200">
                        <template v-slot="{ row }">
                            <el-link type="primary" @click="openForm('view', row)">查看</el-link>
                            <el-link type="primary" @click="openForm('edit', row)">编辑</el-link>
                            <el-link type="primary" @click="handleDelete(row)">删除</el-link>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
 
            <div class="gd-pagination-parent">
                <el-pagination
                    popper-class="gd-select-popper"
                    v-model:current-page="searchParams.current"
                    v-model:page-size="searchParams.size"
                    layout="total, prev, pager, next, sizes"
                    :total="total"
                    @change="getList"
                />
            </div>
        </div>
 
        <FormDiaLog ref="dialogRef" @success="getList" v-if="dialogVisible" v-model="dialogVisible" />
    </basic-container>
</template>
 
<script setup>
import { Search, RefreshRight, Plus } from '@element-plus/icons-vue'
import { onMounted, ref, provide, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import FormDiaLog from './FormDiaLog.vue'
import { materialsPageApi, materialsRemoveApi, regionLazyTreeApi } from './materialsApi'
import { getDictLabel } from '@ztzf/utils'
 
// 初始化查询参数
const initSearchParams = () => ({
    materialName: '', // 材料名称
    areaCode: '', // 所属区划
    current: 1, // 当前页
    size: 10, // 每页大小
})
const searchParams = ref(initSearchParams()) // 查询参数
const total = ref(0) // 总条数
const loading = ref(true) // 列表加载中
const list = ref([]) // 列表数据
const queryParamsRef = ref(null) // 查询表单实例
const dialogRef = ref(null) // 弹框实例
const dialogVisible = ref(false)
const dictObj = ref({
    necessity: [],
    isAllScenario: [],
}) // 字典对象
 
// 树形选择器配置
const treeSelectProps = {
    value: 'id',
    label: 'name',
    children: 'children',
    // 判断叶子节点
    isLeaf: (data, node) => {
        return data.leaf === true
    },
}
 
provide('dictObj', dictObj)
 
// 获取字典列表
function getDictList() {
    // 必要性字典:必填/可选/容缺
    dictObj.value.necessity = [
        { dictKey: '必填', dictValue: '必填' },
        { dictKey: '可选', dictValue: '可选' },
        { dictKey: '容缺', dictValue: '容缺' },
    ]
    // 是否适用全部情形字典
    dictObj.value.isAllScenario = [
        { dictKey: '1', dictValue: '是' },
        { dictKey: '0', dictValue: '否' },
    ]
}
 
// 懒加载获取区域节点数据
async function loadRegionNode(node, resolve) {
    try {
        // 限制只加载两级,当前节点 level >= 1 时不加载子节点
        if (node.level >= 2) {
            resolve([])
            return
        }
 
        // 初始化加载时传递 code 参数,加载子节点时传递 parentCode 参数
        const params = node.data?.id ? { parentCode: node.data.id } : { code: '360800000000' }
        const res = await regionLazyTreeApi(params)
        const nodes = res?.data?.data || []
 
        // 处理返回的节点数据
        const processedNodes = nodes.map(item => {
            // 判断是否为叶子节点:如果是第二级(node.level === 1)则为叶子节点
            const isLeaf = node.level === 1
 
            return {
                id: item.id || item.value,
                name: item.name || item.title || item.label,
                hasChildren: item.hasChildren || false,
                leaf: isLeaf,
            }
        })
 
        resolve(processedNodes)
    } catch (error) {
        console.error('获取区域数据失败:', error)
        resolve([])
    }
}
 
// 获取列表
async function getList() {
    loading.value = true
    try {
        const res = await materialsPageApi(searchParams.value)
        list.value = res?.data?.data?.records ?? []
        total.value = res?.data?.data?.total ?? 0
    } finally {
        loading.value = false
    }
}
 
// 查询
function handleSearch() {
    searchParams.value.current = 1
    getList()
}
 
// 重置查询
function resetForm() {
    queryParamsRef.value?.resetFields()
    searchParams.value.current = 1
    getList()
}
 
// 新增/编辑/查看 弹框
function openForm(mode, row) {
    dialogVisible.value = true
    nextTick(() => {
        dialogRef.value?.open({ mode, row })
    })
}
 
// 删除
async function handleDelete(row) {
    await ElMessageBox.confirm('确认删除该条记录吗?', '提示', {
        type: 'warning',
        customClass: 'gd-confirm-custom',
        confirmButtonClass: 'gd-confirm-button',
        cancelButtonClass: 'gd-confirm-cancel-button',
    })
    await materialsRemoveApi({ ids: row.id })
    ElMessage.success('删除成功')
    getList()
}
 
onMounted(() => {
    getDictList()
    getList()
})
</script>
 
<style scoped lang="scss"></style>