gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
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
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
 
import { confirm, DocAlert, Page, useVbenModal } from '..\..\..\..\..\packages\effects\common-ui\src';
import { $t } from '..\..\..\..\..\packages\locales\src';
 
import { message } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  clearBindUser,
  getBrokerageUserPage,
  updateBrokerageEnabled,
} from '#/api/mall/trade/brokerage/user';
 
import { useGridColumns, useGridFormSchema } from './data';
import CreateForm from './modules/create-form.vue';
import BrokerageOrderListModal from './modules/order-list-modal.vue';
import UpdateForm from './modules/update-form.vue';
import BrokerageUserListModal from './modules/user-list-modal.vue';
 
defineOptions({ name: 'TradeBrokerageUser' });
 
const [CreateFormModal, createFormModalApi] = useVbenModal({
  connectedComponent: CreateForm,
  destroyOnClose: true,
});
 
const [UpdateFormModal, updateModalApi] = useVbenModal({
  connectedComponent: UpdateForm,
  destroyOnClose: true,
});
 
const [OrderListModal, orderListModalApi] = useVbenModal({
  connectedComponent: BrokerageOrderListModal,
  destroyOnClose: true,
});
 
const [UserListModal, userListModalApi] = useVbenModal({
  connectedComponent: BrokerageUserListModal,
  destroyOnClose: true,
});
 
/** 刷新表格 */
function handleRefresh() {
  gridApi.query();
}
 
/** 创建分销员 */
function handleCreate() {
  createFormModalApi.open();
}
 
/** 修改分销员 */
function handleUpdateForm(row: MallBrokerageUserApi.BrokerageUser) {
  updateModalApi.setData(row).open();
}
 
/** 打开推广人列表 */
function handleOpenUserList(row: MallBrokerageUserApi.BrokerageUser) {
  userListModalApi.setData(row).open();
}
 
/** 打开推广订单列表 */
function handleOpenOrderList(row: MallBrokerageUserApi.BrokerageUser) {
  orderListModalApi.setData(row).open();
}
 
/** 清除上级推广人 */
async function handleClearBindUser(row: MallBrokerageUserApi.BrokerageUser) {
  const hideLoading = message.loading({
    content: $t('ui.actionMessage.deleting', [row.nickname]),
    duration: 0,
  });
  try {
    await clearBindUser({ id: row.id! });
    message.success($t('ui.actionMessage.deleteSuccess', [row.nickname]));
    handleRefresh();
  } finally {
    hideLoading();
  }
}
 
/** 更新推广资格 */
async function handleBrokerageEnabledChange(
  newEnabled: boolean,
  row: MallBrokerageUserApi.BrokerageUser,
): Promise<boolean | undefined> {
  const text = newEnabled ? '开通' : '关闭';
  try {
    await confirm(`你要将${row.nickname}的推广资格切换为【${text}】吗?`);
  } catch {
    return false;
  }
  // 更新推广资格
  await updateBrokerageEnabled({
    id: row.id!,
    enabled: newEnabled,
  });
  // 提示并返回成功
  message.success($t('ui.actionMessage.operationSuccess'));
  handleRefresh();
  return true;
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  formOptions: {
    schema: useGridFormSchema(),
  },
  gridOptions: {
    columns: useGridColumns(handleBrokerageEnabledChange),
    height: 'auto',
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) => {
          return await getBrokerageUserPage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            ...formValues,
          });
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      refresh: true,
      search: true,
    },
  } as VxeTableGridOptions<MallBrokerageUserApi.BrokerageUser>,
});
</script>
 
<template>
  <Page auto-content-height>
    <template #doc>
      <DocAlert
        title="【交易】分销返佣"
        url="https://doc.iocoder.cn/mall/trade-brokerage/"
      />
    </template>
 
    <!-- 创建分销员 -->
    <CreateFormModal @success="handleRefresh" />
    <!-- 修改分销员 -->
    <UpdateFormModal @success="handleRefresh" />
    <!-- 推广人列表 -->
    <UserListModal />
    <!-- 推广订单列表 -->
    <OrderListModal />
    <Grid table-title="分销用户列表">
      <template #toolbar-tools>
        <TableAction
          :actions="[
            {
              label: $t('ui.actionTitle.create', ['分销员']),
              type: 'primary',
              icon: ACTION_ICON.ADD,
              auth: ['trade:brokerage-user:create'],
              onClick: handleCreate,
            },
          ]"
        />
      </template>
      <template #actions="{ row }">
        <TableAction
          :drop-down-actions="[
            {
              label: '推广人',
              type: 'link',
              auth: ['trade:brokerage-user:user-query'],
              onClick: handleOpenUserList.bind(null, row),
            },
            {
              label: '推广订单',
              type: 'link',
              auth: ['trade:brokerage-user:order-query'],
              onClick: handleOpenOrderList.bind(null, row),
            },
            {
              label: '修改上级推广人',
              type: 'link',
              auth: ['trade:brokerage-user:update-bind-user'],
              onClick: handleUpdateForm.bind(null, row),
            },
            {
              label: '清除上级推广人',
              type: 'link',
              auth: ['trade:brokerage-user:clear-bind-user'],
              ifShow: !!row.bindUserId,
              onClick: handleClearBindUser.bind(null, row),
            },
          ]"
        />
      </template>
    </Grid>
  </Page>
</template>