sen
2026-01-14 d88f32029be10190a95dce8958398e806c19b26a
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
<template>
    <el-dialog v-model="dialogVisible" :title="mode === 'internal' ? '请选择内部银行' : '请选择关联客户'" width="85%" destroy-on-close
        @close="handleClose" append-to-body>
        <div class="search-bar">
            <el-form inline :model="queryParams" class="search-form" label-width="80px">
                <el-form-item v-if="mode === 'config'" label="客户名称:">
                    <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable style="width: 180px" />
                </el-form-item>
 
                <el-form-item label="账号编号:">
                    <el-input v-model="queryParams.accountNo" placeholder="请输入账号编号" clearable style="width: 180px" />
                </el-form-item>
 
                <el-form-item label="户名:">
                    <el-input v-model="queryParams.accountName" placeholder="请输入户名" clearable style="width: 180px" />
                </el-form-item>
 
                <el-form-item label="账号类型:">
                    <el-select v-model="queryParams.accountType" placeholder="请选择类型" clearable style="width: 150px">
                        <el-option v-for="dict in sys_account_type" :key="dict.value" :label="dict.label"
                            :value="dict.value" />
                    </el-select>
                </el-form-item>
 
                <el-form-item class="search-btns">
                    <el-button type="primary" icon="Search" @click="handleSearch">搜索</el-button>
                    <el-button plain icon="RefreshLeft" @click="handleReset">清空</el-button>
                </el-form-item>
            </el-form>
        </div>
 
        <el-table ref="customerTableRef" :data="customerList" border size="small" style="width: 100%"
            highlight-current-row row-key="id" @current-change="handleRowSelect" class="custom-highlight-table">
            <el-table-column v-if="mode === 'config'" prop="customerName" align="center" label="客户名称" min-width="120"
                show-overflow-tooltip />
            <el-table-column prop="accountNo" label="账号编号" align="center" show-overflow-tooltip />
            <el-table-column prop="accountName" label="户名" align="center" />
            <el-table-column prop="bankName" label="银行名称" align="center" show-overflow-tooltip />
            <el-table-column prop="branchName" label="支行名称" align="center" show-overflow-tooltip />
 
            <el-table-column prop="accountType" label="账号类型" align="center">
                <template #default="scope">
                    {{ dictFormat(sys_account_type, scope.row.accountType) }}
                </template>
            </el-table-column>
 
            <el-table-column prop="currency" label="币种" align="center">
                <template #default="scope">
                    {{ dictFormat(sys_currency, scope.row.currency) }}
                </template>
            </el-table-column>
 
            <el-table-column prop="status" label="账户状态" align="center">
                <template #default="scope">
                    {{ dictFormat(sys_bank_type, scope.row.status) }}
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="pageF.total > 0" :total="pageF.total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getDataList" />
 
 
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="handleClose">取消</el-button>
                <el-button type="primary" @click="handleConfirm">确定</el-button>
            </div>
        </template>
    </el-dialog>
</template>
 
<script setup lang="ts">
import { ref, reactive, watch, nextTick } from 'vue';
import { ElMessage } from 'element-plus';
import useCurrentInstance from "@/utils/useCurrentInstance";
import { listBankAccountConfig } from "@/api/cwgl/bankAccountConfig";
// import { listInternalBank } from "@/api/cwgl/internalBank"; // 假设这是你的内部银
import { listBankConfig, } from "@/api/cwgl/bankConfig";
 
const { proxy } = useCurrentInstance();
const { sys_currency, sys_account_type, sys_bank_type } = proxy.useDict('sys_currency', 'sys_account_type', 'sys_bank_type');
const dictFormat = (dict: any, value: any) => {
    return proxy.selectDictLabel(dict, value);
}
const props = defineProps({
    visible: { type: Boolean, default: false },
    defaultSelectedId: { type: [String, Number], default: '' },
    mode: { type: String, default: 'config' }
});
 
const emit = defineEmits(['confirm', 'close', 'update:visible']);
 
const queryParams = reactive({
    pageNum: 1,
    pageSize: 10,
    customerName: '',
    accountNo: '',
    accountName: '',
    accountType: '',
});
 
const pageF = reactive({ total: 0 });
const dialogVisible = ref(false);
const customerList = ref([]);
const selectedRow = ref(null);
const customerTableRef = ref();
 
// 获取数据逻辑
// 2. 修改获取数据逻辑 getDataList
const getDataList = async () => {
    try {
        // 核心逻辑:根据 mode 切换 API 方法
        const apiMethod = props.mode === 'internal' ? listBankConfig : listBankAccountConfig;
 
        const res = await apiMethod(queryParams);
 
        if (res.code === 200) {
            customerList.value = res.rows;
            pageF.total = res.total;
            if (props.defaultSelectedId) {
                syncSelection();
            }
        }
    } catch (err) {
        console.error(err);
    }
};
 
// 核心选中同步逻辑
const syncSelection = () => {
    nextTick(() => {
        if (!props.defaultSelectedId || customerList.value.length === 0) return;
 
        const row = customerList.value.find(item => String(item.id) === String(props.defaultSelectedId));
        if (row) {
            selectedRow.value = row;
            // 调用 Element Plus 原生方法设置高亮行
            customerTableRef.value?.setCurrentRow(row);
        }
    });
};
 
const handleSearch = () => {
    queryParams.pageNum = 1;
    getDataList();
};
 
const handleReset = () => {
    Object.keys(queryParams).forEach(key => {
        if (key !== 'pageNum' && key !== 'pageSize') queryParams[key] = '';
    });
    queryParams.pageNum = 1;
    handleSearch();
};
 
const handleRowSelect = (val: any) => {
    selectedRow.value = val;
};
 
const handleConfirm = () => {
    if (!selectedRow.value) return ElMessage.warning('请选择一行数据');
    emit('confirm', { ...selectedRow.value });
    handleClose();
};
 
const handleClose = () => {
    emit('update:visible', false);
    emit('close');
};
 
// 监听弹窗显示,触发数据加载和自动选中
watch(() => props.visible, (newVal) => {
    dialogVisible.value = newVal;
    if (newVal) {
        handleSearch();
    } else {
        selectedRow.value = null;
        customerTableRef.value?.setCurrentRow(null);
    }
});
</script>
 
<style scoped lang="scss">
.search-bar {
    background: #fdfdfd;
    padding: 15px 10px 5px;
    border-bottom: 1px solid #eee;
    margin-bottom: 15px;
 
    .search-btns {
        margin-left: 10px;
    }
}
 
.pagination-container {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
}
 
/* 核心:仿照图片中的淡绿色选中效果 */
.custom-highlight-table {
    :deep(.el-table__body tr.current-row > td) {
        background-color: #e1f3d8 !important;
        /* 图片中的淡绿色 */
        color: #606266;
    }
 
    /* 悬浮效果调整 */
    :deep(.el-table__body tr:hover > td) {
        background-color: #f5f7fa !important;
    }
}
 
.dialog-footer {
    padding-top: 10px;
}
</style>