yangyin
2024-11-18 54497207654bd7af80bcd4ec48163fad62b62434
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
<template>
    <div class="custom-drawer">
        <el-drawer v-model="drawerIsShow" direction="rtl" size="40%">
            <template #header>
                <div>
                    <i class="ywifont ywicon-lizi !text-[15px] text-blue-400 cursor-pointer font-bold"></i>
                    <!-- <SvgIcon name="ele-User" :size="16" style="margin-right: 3px; display: inline; vertical-align: middle" /> -->
                    <span> {{ `【${user?.user_name}】提问示例` }} </span>
                </div>
            </template>
            <div class="flex-column h-full">
                <div class="flex-0 flex-col flex">
                    <el-form :inline="true" :model="queryParams">
                        <el-form-item label="标题" prop="title">
                            <el-input v-model="queryParams.title" style="width: 226.4px" placeholder="标题" clearable @input="debounceQueryTable" />
                        </el-form-item>
                        <el-form-item label="分组" prop="group_id">
                            <el-tree-select
                                style="width: 226.4px"
                                filterable
                                v-model="queryParams.group_id"
                                :props="{
                                    id: 'group_id',
                                    label: 'group_name',
                                    children: 'children',
                                }"
                                :data="groupTree ?? []"
                                @change="groupChange"
                                node-key="group_id"
                                :clearable="true"
                                :accordion="false"
                                :expandNode="false"
                                :check-strictly="true"
                                placeholder="分组"
                            >
                            </el-tree-select>
                        </el-form-item>
                    </el-form>
                    <span class="mt-[-12px] mb-[12px]">共有 {{ displayTableData.length }} 条数据</span>
                </div>
                <el-table
                    class="flex-auto"
                    size="small"
                    v-loading="accountTableLoading"
                    border
                    row-key="ID"
                    :data="displayTableData"
                    style="width: 100%"
                >
                    <el-table-column label="序号" fixed="left" width="55" show-overflow-tooltip>
                        <template #default="scope">
                            {{ scope.$index + 1 }}
                        </template>
                    </el-table-column>
 
                    <el-table-column prop="title" label="标题" fixed="left" show-overflow-tooltip />
                    <el-table-column prop="question" label="问题" show-overflow-tooltip />
                </el-table>
            </div>
        </el-drawer>
    </div>
</template>
 
<script setup lang="ts">
import { ref, watch } from 'vue';
import { getUserSampleListByPost } from '/@/api/sampleAdmin/index';
import { useQueryTable } from '/@/hooks/useQueryTable';
import { convertListToTree, debounce, travelTree } from '/@/utils/util';
import { onMounted } from 'vue';
import { getSceneGroupTreeByPost } from '/@/api/scene';
const props = defineProps(['user']);
//#region ====================== 用户账户 ======================
 
const drawerIsShow = defineModel('isShow', {
    type: Boolean,
    default: false,
});
const accountTableData = ref([]);
const accountTableLoading = ref(false);
 
const getSystemAccountByUserID = async () => {
    const res = await getUserSampleListByPost(
        { user_id: props.user.user_id },
        {
            loading: false,
        }
    );
    accountTableData.value = res?.values ?? [];
};
 
//#region ====================== 查询 ======================
const getEmptyParams = () => {
    return {
        title: '',
        group_id: '',
    };
};
const queryParams = ref(getEmptyParams());
const { resetQuery, handleQueryTable, displayTableData } = useQueryTable(
    accountTableData,
    queryParams,
    () => {
        displayTableData.value = accountTableData.value;
    },
    undefined,
    undefined,
    (key, item, queryStr) => {
        if (key === 'group_id') {
            let groupItem;
            travelTree(groupTree.value, (value) => {
                if (value.group_id === queryStr) {
                    groupItem = value;
                    return true;
                }
            });
            if (!groupItem) {
                return false;
            }
 
            return groupItem.children?.some((treeItem) => treeItem.group_id === item.group_id);
        }
    }
);
const debounceQueryTable = debounce(handleQueryTable, 400);
const groupChange = (val) => {
    handleQueryTable();
};
 
//#endregion
 
const groupTree = ref(null);
 
watch(
    () => drawerIsShow.value,
    async (val) => {
        if (!val) {
            accountTableData.value = [];
            queryParams.value = getEmptyParams();
            return;
        }
 
        try {
            await getSystemAccountByUserID();
 
            if (!groupTree.value) {
                const res = await getSceneGroupTreeByPost({
                    loading: false,
                });
                groupTree.value = convertListToTree(res?.groups ?? [], {
                    ID: 'group_id',
                    Children: 'children',
                    ParentID: 'p_group_id',
                });
            }
        } finally {
            accountTableLoading.value = false;
        }
    }
);
 
//#endregion
 
</script>
<style scoped lang="scss"></style>