index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <script setup lang="ts">
  2. import { reactive, onMounted, ref, nextTick } from "vue";
  3. import { getCustomUserList, lockUser, unlockUser, getUserLockRecord } from "@/api/custom";
  4. import { applyRefund } from "@/api/finance";
  5. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  6. import { useStationScope } from "@/hooks/useStationScope";
  7. import { ExtDLabel } from "@/components/ExtForm";
  8. import { ElMessageBox } from "element-plus";
  9. import { message } from "@/utils/message";
  10. import UserDetail from "./detail.vue";
  11. defineOptions({
  12. name: "AdminUser"
  13. });
  14. const queryRef = ref();
  15. const tableRef = ref();
  16. const detailRef = ref();
  17. const state = reactive({
  18. formQuery: {
  19. mobilePhone: "",
  20. userId: "",
  21. stationId: "",
  22. locked: null as number | null
  23. },
  24. pageQuery: {
  25. pageNum: 1,
  26. pageSize: 10,
  27. total: 0
  28. },
  29. tableData: {
  30. height: 500,
  31. data: [] as Array<any>,
  32. loading: false,
  33. columns: [
  34. { label: "用户ID", prop: "userId", width: 180 },
  35. { label: "归属站点", prop: "stationName", width: 160 },
  36. { label: "手机号", prop: "mobilePhone", width: 130 },
  37. { label: "总余额", prop: "balance", width: 120 },
  38. { label: "充值金额", prop: "rechargeAmount", width: 120 },
  39. { label: "洗车次数", prop: "washTimes", width: 90 },
  40. { label: "消费总额", prop: "amount", width: 120 },
  41. { label: "状态", prop: "status", width: 80 },
  42. { label: "锁定备注", prop: "lockRemark", width: 150 },
  43. { label: "锁定次数", prop: "lockTimes", width: 90 },
  44. { label: "锁定时间", prop: "lockTime", width: 170 },
  45. { label: "注册时间", prop: "registerTime", width: 170 }
  46. ]
  47. },
  48. lockDialog: {
  49. visible: false,
  50. loading: false,
  51. userId: null as number | null,
  52. mobilePhone: "",
  53. lockRemark: "",
  54. lockNotice: ""
  55. },
  56. lockRecordDialog: {
  57. visible: false,
  58. loading: false,
  59. mobilePhone: "",
  60. list: [] as Array<any>
  61. }
  62. });
  63. //站点筛选与全局当前站点联动(回调懒引用,规避 loadData 声明顺序的 TDZ 错误)
  64. useStationScope(state.formQuery, (refresh?: boolean) => loadData(refresh));
  65. onMounted(() => {
  66. loadData();
  67. nextTick(() => {
  68. const bodyHeight = document.body.clientHeight;
  69. const queryHeight = queryRef.value?.$el?.clientHeight || 0;
  70. state.tableData.height = bodyHeight - queryHeight - 230;
  71. });
  72. });
  73. const loadData = (refresh: boolean = false) => {
  74. if (refresh) {
  75. state.pageQuery.pageNum = 1;
  76. }
  77. state.tableData.loading = true;
  78. const params: any = { ...state.formQuery, ...state.pageQuery };
  79. //锁定状态未选时不传参,避免空值被绑定为 Integer 报错
  80. if (params.locked === "" || params.locked === null || params.locked === undefined) {
  81. delete params.locked;
  82. }
  83. getCustomUserList(params)
  84. .then((res: any) => {
  85. const { list, total } = res || {};
  86. state.tableData.data = list || [];
  87. state.pageQuery.total = total || 0;
  88. })
  89. .catch(() => {
  90. state.tableData.data = [];
  91. })
  92. .finally(() => {
  93. state.tableData.loading = false;
  94. });
  95. };
  96. const handleSizeChange = (size: number) => {
  97. state.pageQuery.pageSize = size;
  98. loadData(true);
  99. };
  100. const handleCurrentChange = (page: number) => {
  101. state.pageQuery.pageNum = page;
  102. loadData();
  103. };
  104. const handleSearch = () => {
  105. loadData(true);
  106. };
  107. const handleReset = () => {
  108. state.formQuery = {
  109. mobilePhone: "",
  110. userId: "",
  111. stationId: "",
  112. locked: null
  113. };
  114. loadData(true);
  115. };
  116. const formatMoney = (value: number) => {
  117. if (value === null || value === undefined) return "¥0.00";
  118. return `¥${(value / 100).toFixed(2)}`;
  119. };
  120. const handleDetail = (row: any) => detailRef.value?.open(row);
  121. const handleUserRefundApply = (row: any) => {
  122. ElMessageBox.confirm("确认执行本操作吗?", "退款申请", {
  123. confirmButtonText: "确定",
  124. cancelButtonText: "取消",
  125. type: "warning"
  126. }).then(() => {
  127. ElMessageBox.prompt("请输入退款申请原因", "退款申请", {
  128. confirmButtonText: "提交",
  129. cancelButtonText: "取消",
  130. inputType: "textarea",
  131. draggable: true
  132. })
  133. .then(({ value }) => {
  134. applyRefund({ userId: row.userId, reason: (value || "").trim() })
  135. .then(() => {
  136. message("退款已发起", { type: "success" });
  137. loadData(true);
  138. })
  139. .catch(() => {
  140. // 错误提示由响应拦截器统一处理
  141. });
  142. })
  143. .catch(() => {});
  144. }).catch(() => {});
  145. };
  146. // 打开锁定用户弹窗
  147. const openLockDialog = (row: any) => {
  148. state.lockDialog.userId = row.userId;
  149. state.lockDialog.mobilePhone = row.mobilePhone;
  150. state.lockDialog.lockRemark = "";
  151. state.lockDialog.lockNotice = "";
  152. state.lockDialog.visible = true;
  153. };
  154. // 提交锁定
  155. const confirmLockUser = () => {
  156. state.lockDialog.loading = true;
  157. lockUser({
  158. userId: state.lockDialog.userId as number,
  159. lockRemark: state.lockDialog.lockRemark,
  160. lockNotice: state.lockDialog.lockNotice.trim()
  161. })
  162. .then(() => {
  163. message("锁定成功", { type: "success" });
  164. state.lockDialog.visible = false;
  165. loadData(true);
  166. })
  167. .catch(() => {
  168. // 错误提示由响应拦截器统一处理
  169. })
  170. .finally(() => {
  171. state.lockDialog.loading = false;
  172. });
  173. };
  174. // 打开锁定记录弹窗
  175. const openLockRecordDialog = (row: any) => {
  176. state.lockRecordDialog.mobilePhone = row.mobilePhone;
  177. state.lockRecordDialog.list = [];
  178. state.lockRecordDialog.visible = true;
  179. state.lockRecordDialog.loading = true;
  180. getUserLockRecord(row.userId)
  181. .then((res: any) => {
  182. state.lockRecordDialog.list = res || [];
  183. })
  184. .catch(() => {
  185. // 错误提示由响应拦截器统一处理
  186. })
  187. .finally(() => {
  188. state.lockRecordDialog.loading = false;
  189. });
  190. };
  191. // 解锁用户
  192. const handleUnlockUser = (row: any) => {
  193. ElMessageBox.confirm(
  194. `确认解锁用户『${row.mobilePhone}』?解锁后该用户可正常启动设备与退款`,
  195. "提示",
  196. {
  197. confirmButtonText: "确定",
  198. cancelButtonText: "取消",
  199. type: "warning"
  200. }
  201. ).then(() => {
  202. unlockUser(row.userId).then(() => {
  203. message("解锁成功", { type: "success" });
  204. loadData(true);
  205. });
  206. }).catch(() => {});
  207. };
  208. const isMoneyField = (prop: string) => {
  209. return ["balance", "rechargeAmount", "amount"].includes(prop);
  210. };
  211. </script>
  212. <template>
  213. <div class="page-container">
  214. <el-card shadow="hover">
  215. <template #header>
  216. <span class="card-header">用户管理</span>
  217. </template>
  218. <el-form
  219. ref="queryRef"
  220. :model="state.formQuery"
  221. inline
  222. class="search-form"
  223. >
  224. <el-form-item label="用户ID">
  225. <el-input
  226. v-model="state.formQuery.userId"
  227. placeholder="请输入用户ID"
  228. clearable
  229. @keyup.enter="handleSearch"
  230. />
  231. </el-form-item>
  232. <el-form-item label="手机号">
  233. <el-input
  234. v-model="state.formQuery.mobilePhone"
  235. placeholder="请输入手机号"
  236. clearable
  237. @keyup.enter="handleSearch"
  238. />
  239. </el-form-item>
  240. <el-form-item label="锁定状态">
  241. <el-select
  242. v-model="state.formQuery.locked"
  243. placeholder="请选择锁定状态"
  244. clearable
  245. style="width: 150px"
  246. @change="handleSearch"
  247. >
  248. <el-option label="已锁定" :value="1" />
  249. <el-option label="未锁定" :value="0" />
  250. </el-select>
  251. </el-form-item>
  252. <el-form-item>
  253. <el-button
  254. type="primary"
  255. :icon="useRenderIcon('ri/search-line')"
  256. @click="handleSearch"
  257. >
  258. 查询
  259. </el-button>
  260. <el-button
  261. :icon="useRenderIcon('ri/refresh-line')"
  262. @click="handleReset"
  263. >
  264. 重置
  265. </el-button>
  266. </el-form-item>
  267. </el-form>
  268. <el-table
  269. ref="tableRef"
  270. v-loading="state.tableData.loading"
  271. :data="state.tableData.data"
  272. :height="state.tableData.height"
  273. border
  274. stripe
  275. >
  276. <template #empty>
  277. <el-empty description="暂无数据" />
  278. </template>
  279. <el-table-column
  280. v-for="col in state.tableData.columns"
  281. :key="col.prop"
  282. :prop="col.prop"
  283. :label="col.label"
  284. :width="col.width"
  285. show-overflow-tooltip
  286. >
  287. <template #default="{ row }">
  288. <template v-if="isMoneyField(col.prop)">
  289. {{ formatMoney(row[col.prop]) }}
  290. </template>
  291. <template v-else-if="col.prop === 'status'">
  292. <el-tag v-if="row.lockNotice" type="danger" effect="dark" size="small">锁定</el-tag>
  293. <ExtDLabel v-else type="User.status" :model-value="row.status" />
  294. </template>
  295. <template v-else-if="col.prop === 'lockTimes'">
  296. <el-button
  297. v-if="row.lockTimes > 0"
  298. link
  299. type="danger"
  300. size="small"
  301. @click="openLockRecordDialog(row)"
  302. >
  303. {{ row.lockTimes }}
  304. </el-button>
  305. <span v-else>0</span>
  306. </template>
  307. <template v-else>
  308. {{ row[col.prop] }}
  309. </template>
  310. </template>
  311. </el-table-column>
  312. <el-table-column label="操作" width="200" fixed="right">
  313. <template #default="{ row }">
  314. <el-button type="primary" link size="small" @click="handleDetail(row)">详情</el-button>
  315. <el-button type="primary" link size="small" @click="handleUserRefundApply(row)">
  316. 申请退款
  317. </el-button>
  318. <el-button
  319. v-if="!row.lockNotice"
  320. v-auth="'user.lock'"
  321. type="danger"
  322. link
  323. size="small"
  324. @click="openLockDialog(row)"
  325. >
  326. 锁定
  327. </el-button>
  328. <el-button
  329. v-else
  330. v-auth="'user.lock'"
  331. type="success"
  332. link
  333. size="small"
  334. @click="handleUnlockUser(row)"
  335. >
  336. 解锁
  337. </el-button>
  338. </template>
  339. </el-table-column>
  340. </el-table>
  341. <div class="pagination-container">
  342. <el-pagination
  343. v-model:current-page="state.pageQuery.pageNum"
  344. v-model:page-size="state.pageQuery.pageSize"
  345. :total="state.pageQuery.total"
  346. :page-sizes="[10, 20, 50, 100]"
  347. layout="total, sizes, prev, pager, next, jumper"
  348. @size-change="handleSizeChange"
  349. @current-change="handleCurrentChange"
  350. />
  351. </div>
  352. </el-card>
  353. <!-- 锁定用户弹窗 -->
  354. <el-dialog
  355. v-model="state.lockDialog.visible"
  356. :title="`锁定用户『${state.lockDialog.mobilePhone || ''}』`"
  357. width="520px"
  358. append-to-body
  359. :close-on-click-modal="false"
  360. >
  361. <el-form label-width="90px" size="default">
  362. <el-form-item label="锁定备注">
  363. <el-input
  364. v-model="state.lockDialog.lockRemark"
  365. type="textarea"
  366. :rows="2"
  367. maxlength="200"
  368. show-word-limit
  369. placeholder="仅平台人员可见,用于记录锁定原因"
  370. />
  371. </el-form-item>
  372. <el-form-item label="提示内容" required>
  373. <el-input
  374. v-model="state.lockDialog.lockNotice"
  375. type="textarea"
  376. :rows="3"
  377. maxlength="200"
  378. show-word-limit
  379. placeholder="用户启动设备时强制弹出展示"
  380. />
  381. </el-form-item>
  382. </el-form>
  383. <template #footer>
  384. <el-button @click="state.lockDialog.visible = false">取 消</el-button>
  385. <el-button
  386. :loading="state.lockDialog.loading"
  387. :disabled="!state.lockDialog.lockNotice || !state.lockDialog.lockNotice.trim()"
  388. type="danger"
  389. @click="confirmLockUser"
  390. >
  391. 确定锁定
  392. </el-button>
  393. </template>
  394. </el-dialog>
  395. <!-- 锁定记录弹窗 -->
  396. <el-dialog
  397. v-model="state.lockRecordDialog.visible"
  398. :title="`锁定记录『${state.lockRecordDialog.mobilePhone || ''}』`"
  399. width="900px"
  400. append-to-body
  401. >
  402. <el-table
  403. border
  404. stripe
  405. :data="state.lockRecordDialog.list"
  406. v-loading="state.lockRecordDialog.loading"
  407. max-height="420"
  408. >
  409. <template #empty>
  410. <el-empty description="暂无锁定记录" />
  411. </template>
  412. <el-table-column label="序号" type="index" width="60" align="center" />
  413. <el-table-column label="锁定时间" prop="lockTime" width="160" align="center" />
  414. <el-table-column label="锁定人" prop="lockOperator" width="110" show-overflow-tooltip />
  415. <el-table-column
  416. label="锁定备注(仅平台人员可见)"
  417. prop="lockRemark"
  418. min-width="160"
  419. show-overflow-tooltip
  420. />
  421. <el-table-column label="提示内容" prop="lockNotice" min-width="160" show-overflow-tooltip />
  422. <el-table-column label="状态" width="90" align="center">
  423. <template #default="{ row }">
  424. <el-tag v-if="row.status === 1" type="danger" effect="dark" size="small">锁定中</el-tag>
  425. <el-tag v-else type="info" size="small">已解锁</el-tag>
  426. </template>
  427. </el-table-column>
  428. <el-table-column label="解锁信息" width="200">
  429. <template #default="{ row }">
  430. <div v-if="row.unlockTime">{{ row.unlockTime }}</div>
  431. <div v-if="row.unlockOperator" class="unlock-operator">
  432. 解锁人:{{ row.unlockOperator }}
  433. </div>
  434. </template>
  435. </el-table-column>
  436. </el-table>
  437. <template #footer>
  438. <el-button @click="state.lockRecordDialog.visible = false">关 闭</el-button>
  439. </template>
  440. </el-dialog>
  441. <UserDetail ref="detailRef" />
  442. </div>
  443. </template>
  444. <style scoped lang="scss">
  445. .page-container {
  446. padding: 15px;
  447. }
  448. .card-header { font-size: 16px; font-weight: 600; }
  449. .search-form {
  450. margin-bottom: 15px;
  451. }
  452. .pagination-container {
  453. display: flex;
  454. justify-content: flex-end;
  455. margin-top: 15px;
  456. }
  457. .unlock-operator {
  458. color: var(--el-text-color-secondary);
  459. font-size: 12px;
  460. }
  461. </style>