zhengyiming
2025-09-23 bb3b9d75c09472618f1aebd6f0080fea30969599
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
<template>
  <LoadingLayout :loading="isInitialLoading">
    <AppContainer>
      <ProTableQueryFilterBar @on-reset="reset">
        <template #query>
          <QueryFilterItem tip-content="配置状态">
            <FieldRadio
              v-model="extraParamState.isConfigured"
              :value-enum="IsConfiguredText"
              buttonStyle
              showAllBtn
            />
          </QueryFilterItem>
          <QueryFilterItem>
            <SearchInput
              v-model="extraParamState.keywords"
              style="width: 300px"
              placeholder="企业名称/法人/联系人"
              @on-click-search="getList"
            >
            </SearchInput>
          </QueryFilterItem>
        </template>
        <template #btn>
          <el-button
            v-if="checkSubModuleItemShow('pageButton', 'addBtn')"
            @click="addOrEditEnterprise()"
            icon="Plus"
            type="primary"
            >新增</el-button
          >
        </template>
      </ProTableQueryFilterBar>
      <ProTableV2 v-bind="proTableProps" :columns="column" :operationBtns="operationBtns">
      </ProTableV2>
    </AppContainer>
    <ConfigureDialog v-bind="dialogProps" />
  </LoadingLayout>
</template>
 
<script setup lang="ts">
import {
  ProTableQueryFilterBar,
  OperationBtnType,
  ProTableV2,
  SearchInput,
  LoadingLayout,
  AppContainer,
  QueryFilterItem,
  useFormDialog,
  FieldRadio,
  useTableV2,
} from '@bole-core/components';
import { useAccess, useGlobalEventContext } from '@/hooks';
import { EnterpriseConfigureType, IsConfiguredText } from '@/constants';
import ConfigureDialog from './components/ConfigureDialog.vue';
import { Message } from '@bole-core/core';
import * as enterpriseServices from '@/services/api/enterprise';
 
defineOptions({
  name: 'EnterpriseManageList',
});
 
const operationBtnMap: Record<string, OperationBtnType> = {
  editBtn: { emits: { onClick: (role) => addOrEditEnterprise(role) } },
  detailBtn: { emits: { onClick: (role) => handleDetail(role) } },
  configBtn: { emits: { onClick: (role) => openDialog(role) } },
};
 
const { checkSubModuleItemShow, column, operationBtns } = useAccess({
  operationBtnMap,
});
 
const eventContext = useGlobalEventContext();
 
eventContext.addEvent('enterprise:add', () => {
  getList();
});
 
eventContext.addEvent('enterprise:edit', () => {
  getList(paginationState.pageIndex);
});
 
const router = useRouter();
 
const {
  getDataSource: getList,
  proTableProps,
  paginationState,
  extraParamState,
  reset,
  isInitialLoading,
} = useTableV2(
  async ({ pageIndex, pageSize, isInitialLoading }, extraParamState) => {
    try {
      let params: API.GetEnterprisesQuery = {
        pageModel: {
          rows: pageSize,
          page: pageIndex,
          orderInput: extraParamState.orderInput,
        },
        isConfigured: extraParamState.isConfigured,
        keywords: extraParamState.keywords,
      };
 
      let res = await enterpriseServices.getEnterprises(params, {
        showLoading: !isInitialLoading,
      });
      return res;
    } catch (error) {
      console.log('error: ', error);
    }
  },
  {
    defaultExtraParams: {
      keywords: '',
      orderInput: [{ property: 'id', order: EnumPagedListOrder.Desc }],
      isConfigured: '' as any as boolean,
    },
    queryKey: ['enterpriseServices/getEnterprises'],
    columnsRenderProps: {
      isReal: { type: 'enum', valueEnum: IsRealText },
      isConfigured: { type: 'enum', valueEnum: IsConfiguredText },
    },
  }
);
 
function openDialog(row?: API.GetEnterprisesQueryResultItem) {
  handleEdit({
    id: row.id,
    enterpriseConfigureType: EnterpriseConfigureType.Bank,
  });
}
 
const { dialogProps, handleEdit, dialogState } = useFormDialog({
  onConfirm: handleAddOrEdit,
  defaultFormParams: {
    id: '',
    enterpriseConfigureType: EnterpriseConfigureType.Bank,
  },
});
 
async function handleAddOrEdit() {
  try {
    Message.successMessage('操作成功');
    getList(paginationState.pageIndex);
    dialogState.dialogVisible = false;
  } catch (error) {}
}
 
function addOrEditEnterprise(row?: API.GetEnterprisesQueryResultItem) {
  router.push({ name: 'AddOrEditEnterprise', params: { id: row?.id ?? '' } });
}
function handleDetail(row: API.GetEnterprisesQueryResultItem) {
  router.push({ name: 'EnterpriseDetail', params: { id: row?.id ?? '' } });
}
</script>