index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <template>
  2. <div v-loading="pageLoading" class="app-container" :element-loading-text="loadingText">
  3. <div class="category-tabs" style="margin-bottom: 16px; padding: 10px 16px; background: #fff; border-radius: 8px;">
  4. <el-button
  5. v-for="tab in categoryTabs"
  6. :key="tab.key"
  7. :type="activeCategory === tab.key ? 'primary' : 'default'"
  8. @click="handleCategoryChange(tab.key)"
  9. >
  10. {{ tab.label }}
  11. </el-button>
  12. </div>
  13. <!-- 额度管理列表 -->
  14. <template v-if="activeCategory === 'quota'">
  15. <PageSearch
  16. ref="searchRef"
  17. :search-config="searchConfig"
  18. @query-click="handleQueryClick"
  19. @reset-click="handleResetClick"
  20. />
  21. <PageContent ref="contentRef" :content-config="contentConfig">
  22. <template #toolbar="{ toolbarRight, onToolbar, removeIds, cols }">
  23. <CrudToolbarLeft
  24. :remove-ids="removeIds"
  25. :perm-create="['module_payment:quota:create']"
  26. @add="handleOpenDialog('create')"
  27. />
  28. <div class="data-table__toolbar--right">
  29. <CrudToolbarRight :buttons="toolbarRight" :cols="cols" :on-toolbar="onToolbar" />
  30. </div>
  31. </template>
  32. <template #table="{ data, loading, tableRef, onSelectionChange }">
  33. <div class="data-table__content">
  34. <el-table
  35. :ref="tableRef as any"
  36. v-loading="loading"
  37. :data="data"
  38. height="100%"
  39. border
  40. @selection-change="onSelectionChange"
  41. >
  42. <template #empty>
  43. <el-empty :image-size="80" description="暂无数据" />
  44. </template>
  45. <el-table-column
  46. v-if="contentCols.find((col) => col.prop === 'selection')?.show"
  47. type="selection"
  48. min-width="55"
  49. align="center"
  50. />
  51. <el-table-column
  52. v-if="contentCols.find((col) => col.prop === 'quota_id')?.show"
  53. key="quota_id"
  54. label="额度ID"
  55. prop="quota_id"
  56. min-width="150"
  57. show-overflow-tooltip
  58. />
  59. <el-table-column
  60. v-if="contentCols.find((col) => col.prop === 'employee_id')?.show"
  61. key="employee_id"
  62. label="员工ID"
  63. prop="employee_id"
  64. min-width="150"
  65. show-overflow-tooltip
  66. />
  67. <el-table-column
  68. v-if="contentCols.find((col) => col.prop === 'institution_id')?.show"
  69. key="institution_id"
  70. label="制度ID"
  71. prop="institution_id"
  72. min-width="150"
  73. show-overflow-tooltip
  74. />
  75. <el-table-column
  76. v-if="contentCols.find((col) => col.prop === 'quota_type')?.show"
  77. key="quota_type"
  78. label="额度类型"
  79. prop="quota_type"
  80. min-width="100"
  81. >
  82. <template #default="scope">
  83. {{ formatQuotaType(scope.row.quota_type) }}
  84. </template>
  85. </el-table-column>
  86. <el-table-column
  87. v-if="contentCols.find((col) => col.prop === 'total_amount')?.show"
  88. key="total_amount"
  89. label="总金额"
  90. prop="total_amount"
  91. min-width="100"
  92. align="right"
  93. >
  94. <template #default="scope">
  95. {{ scope.row.total_amount ? `¥${scope.row.total_amount.toFixed(2)}` : "-" }}
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. v-if="contentCols.find((col) => col.prop === 'available_amount')?.show"
  100. key="available_amount"
  101. label="可用金额"
  102. prop="available_amount"
  103. min-width="100"
  104. align="right"
  105. >
  106. <template #default="scope">
  107. {{ scope.row.available_amount ? `¥${scope.row.available_amount.toFixed(2)}` : "-" }}
  108. </template>
  109. </el-table-column>
  110. <el-table-column
  111. v-if="contentCols.find((col) => col.prop === 'status')?.show"
  112. key="status"
  113. label="状态"
  114. prop="status"
  115. min-width="100"
  116. >
  117. <template #default="scope">
  118. <el-tag :type="STATUS_TAG_TYPE[scope.row.status]">
  119. {{ STATUS_LABEL[scope.row.status] || scope.row.status }}
  120. </el-tag>
  121. </template>
  122. </el-table-column>
  123. <el-table-column
  124. v-if="contentCols.find((col) => col.prop === 'created_time')?.show"
  125. key="created_time"
  126. label="创建时间"
  127. prop="created_time"
  128. min-width="160"
  129. sortable
  130. />
  131. <el-table-column
  132. v-if="contentCols.find((col) => col.prop === 'operation')?.show"
  133. fixed="right"
  134. label="操作"
  135. align="center"
  136. min-width="160"
  137. >
  138. <template #default="scope">
  139. <el-button
  140. v-hasPerm="['module_payment:quota:detail']"
  141. type="info"
  142. size="small"
  143. link
  144. icon="View"
  145. @click="handleOpenDialog('detail', scope.row.quota_id)"
  146. >
  147. 详情
  148. </el-button>
  149. <el-button
  150. v-hasPerm="['module_payment:quota:update']"
  151. type="primary"
  152. size="small"
  153. link
  154. icon="edit"
  155. @click="handleOpenDialog('update', scope.row.quota_id)"
  156. >
  157. 编辑
  158. </el-button>
  159. </template>
  160. </el-table-column>
  161. </el-table>
  162. </div>
  163. </template>
  164. </PageContent>
  165. <EnhancedDialog
  166. v-model="dialogVisible.visible"
  167. :title="dialogVisible.title"
  168. @close="handleCloseDialog"
  169. >
  170. <template v-if="dialogVisible.type === 'detail'">
  171. <QuotaDetail :quota-id="currentQuotaId" />
  172. </template>
  173. <template v-else>
  174. <QuotaForm
  175. ref="formRef"
  176. :type="dialogVisible.type"
  177. :quota-id="currentQuotaId"
  178. :employee-id="employeeIdFromUrl"
  179. :institution-id="institutionIdFromUrl"
  180. @success="handleFormSuccess"
  181. />
  182. </template>
  183. <template #footer>
  184. <div class="dialog-footer">
  185. <el-button v-if="dialogVisible.type !== 'detail'" type="primary" @click="handleSubmit">
  186. 确定
  187. </el-button>
  188. <el-button v-else type="primary" @click="handleCloseDialog">确定</el-button>
  189. <el-button @click="handleCloseDialog">取消</el-button>
  190. </div>
  191. </template>
  192. </EnhancedDialog>
  193. </template>
  194. <!-- 手工发放批次管理 -->
  195. <template v-if="activeCategory === 'batch'">
  196. <div class="batch-section">
  197. <div style="margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center;">
  198. <h3 style="margin: 0">手工发放批次</h3>
  199. <el-button type="primary" @click="handleCreateBatch">
  200. <el-icon><Plus /></el-icon> 新建发放
  201. </el-button>
  202. </div>
  203. <el-table :data="batchList" border max-height="calc(100vh - 300px)">
  204. <template #empty>
  205. <el-empty :image-size="80" description="暂无发放批次" />
  206. </template>
  207. <el-table-column type="index" label="序号" width="60" />
  208. <el-table-column prop="issue_batch_id" label="批次ID" min-width="180" show-overflow-tooltip />
  209. <el-table-column prop="batch_no" label="批次号" min-width="140" />
  210. <el-table-column prop="issue_name" label="发放名称" min-width="120" />
  211. <el-table-column prop="institution_id" label="制度ID" min-width="160" show-overflow-tooltip />
  212. <el-table-column prop="total_count" label="发放人数" width="80" align="center" />
  213. <el-table-column prop="total_amount" label="总金额" width="120" align="right">
  214. <template #default="scope">
  215. {{ scope.row.total_amount ? `¥${Number(scope.row.total_amount).toFixed(2)}` : "-" }}
  216. </template>
  217. </el-table-column>
  218. <el-table-column prop="status" label="状态" width="80" align="center">
  219. <template #default="scope">
  220. <el-tag :type="ISSUE_BATCH_STATUS_TAG[scope.row.status] || 'info'" size="small">
  221. {{ ISSUE_BATCH_STATUS_LABEL[scope.row.status] || scope.row.status }}
  222. </el-tag>
  223. </template>
  224. </el-table-column>
  225. <el-table-column prop="created_time" label="创建时间" width="160" />
  226. <el-table-column label="操作" width="180" align="center" fixed="right">
  227. <template #default="scope">
  228. <el-button type="primary" size="small" link @click="handleViewBatchRecords(scope.row)">
  229. 发放明细
  230. </el-button>
  231. <el-button
  232. v-if="scope.row.status === 'ACTIVE'"
  233. type="danger"
  234. size="small"
  235. link
  236. @click="handleCancelBatch(scope.row)"
  237. >
  238. 作废
  239. </el-button>
  240. </template>
  241. </el-table-column>
  242. </el-table>
  243. </div>
  244. </template>
  245. <!-- 新建批次弹窗 -->
  246. <el-dialog v-model="batchDialogVisible" title="新建手工发放" width="800px" destroy-on-close @close="handleBatchDialogClose">
  247. <IssueBatchForm
  248. ref="batchFormRef"
  249. :enterprise-id="enterpriseIdFromUrl"
  250. @success="handleBatchCreateSuccess"
  251. />
  252. <template #footer>
  253. <el-button type="primary" @click="handleBatchSubmit">确认发放</el-button>
  254. <el-button @click="batchDialogVisible = false">取消</el-button>
  255. </template>
  256. </el-dialog>
  257. <!-- 发放记录弹窗 -->
  258. <el-dialog v-model="recordsDialogVisible" title="发放明细" width="900px" destroy-on-close>
  259. <IssueBatchDetail
  260. :issue-batch-id="currentBatchId"
  261. :institution-id="currentBatchInstitutionId"
  262. :batch-info="currentBatchInfo"
  263. />
  264. <template #footer>
  265. <el-button type="primary" @click="recordsDialogVisible = false">关闭</el-button>
  266. </template>
  267. </el-dialog>
  268. </div>
  269. </template>
  270. <script setup lang="ts">
  271. defineOptions({
  272. name: "Quota",
  273. inheritAttrs: false,
  274. });
  275. import { Plus } from "@element-plus/icons-vue";
  276. import QuotaAPI, {
  277. QuotaPageQuery,
  278. QUOTA_TYPE_OPTIONS,
  279. STATUS_TAG_TYPE,
  280. STATUS_LABEL,
  281. ISSUE_BATCH_STATUS_TAG,
  282. ISSUE_BATCH_STATUS_LABEL,
  283. } from "@/api/module_payment/quota";
  284. import CrudToolbarLeft from "@/components/CURD/CrudToolbarLeft.vue";
  285. import CrudToolbarRight from "@/components/CURD/CrudToolbarRight.vue";
  286. import PageSearch from "@/components/CURD/PageSearch.vue";
  287. import PageContent from "@/components/CURD/PageContent.vue";
  288. import EnhancedDialog from "@/components/CURD/EnhancedDialog.vue";
  289. import QuotaForm from "./components/QuotaForm.vue";
  290. import QuotaDetail from "./components/QuotaDetail.vue";
  291. import IssueBatchForm from "./components/IssueBatchForm.vue";
  292. import IssueBatchDetail from "./components/IssueBatchDetail.vue";
  293. import type { ISearchConfig, IContentConfig } from "@/components/CURD/types";
  294. import { useCrudList } from "@/components/CURD/useCrudList";
  295. import { useLoadingAction } from "@/composables/useLoadingAction";
  296. import { useRoute } from "vue-router";
  297. import { ElMessage, ElMessageBox } from "element-plus";
  298. import { ref, reactive, computed, onMounted } from "vue";
  299. import { useEnterpriseStore } from "@/store/modules/enterprise.store";
  300. const route = useRoute();
  301. const { searchRef, contentRef, handleQueryClick, handleResetClick, refreshList } =
  302. useCrudList();
  303. const formRef = ref();
  304. const { pageLoading, loadingText, execute: loadingExecute } = useLoadingAction();
  305. const employeeIdFromUrl = computed(() => route.query.employee_id as string | undefined);
  306. const institutionIdFromUrl = computed(() => route.query.institution_id as string | undefined);
  307. const enterpriseIdFromUrl = computed(() => route.query.enterprise_id as string | undefined);
  308. const categoryTabs = [
  309. { key: "quota", label: "额度管理" },
  310. { key: "batch", label: "手工发放" },
  311. ];
  312. const activeCategory = ref("quota");
  313. function handleCategoryChange(key: string) {
  314. activeCategory.value = key;
  315. if (key === "batch") loadBatchList();
  316. }
  317. // ===== 额度管理 =====
  318. const searchConfig = reactive<ISearchConfig>({
  319. permPrefix: "module_payment:quota",
  320. colon: true,
  321. isExpandable: true,
  322. showNumber: 3,
  323. form: { labelWidth: "auto" },
  324. formItems: [
  325. {
  326. prop: "employee_id",
  327. label: "员工ID",
  328. type: "input",
  329. attrs: { placeholder: "请输入员工ID", clearable: true },
  330. },
  331. {
  332. prop: "institution_id",
  333. label: "制度ID",
  334. type: "input",
  335. attrs: { placeholder: "请输入制度ID", clearable: true },
  336. },
  337. {
  338. prop: "status",
  339. label: "状态",
  340. type: "select",
  341. options: [
  342. { label: "全部", value: "" },
  343. { label: "正常", value: "QUOTA_ACTIVE" },
  344. { label: "冻结", value: "QUOTA_FROZEN" },
  345. { label: "已用完", value: "QUOTA_EXHAUSTED" },
  346. { label: "已过期", value: "QUOTA_EXPIRED" },
  347. ],
  348. attrs: { placeholder: "请选择状态", clearable: true, style: { width: "167.5px" } },
  349. },
  350. ],
  351. });
  352. const contentCols = reactive<
  353. Array<{
  354. prop?: string;
  355. label?: string;
  356. show?: boolean;
  357. }>
  358. >([
  359. { prop: "selection", label: "选择框", show: false },
  360. { prop: "index", label: "序号", show: true },
  361. { prop: "quota_id", label: "额度ID", show: true },
  362. { prop: "employee_id", label: "员工ID", show: true },
  363. { prop: "institution_id", label: "制度ID", show: true },
  364. { prop: "quota_type", label: "额度类型", show: true },
  365. { prop: "total_amount", label: "总金额", show: true },
  366. { prop: "available_amount", label: "可用金额", show: true },
  367. { prop: "status", label: "状态", show: true },
  368. { prop: "created_time", label: "创建时间", show: true },
  369. { prop: "operation", label: "操作", show: true },
  370. ]);
  371. const contentConfig = reactive<IContentConfig<QuotaPageQuery>>({
  372. permPrefix: "module_payment:quota",
  373. pk: "quota_id",
  374. cols: contentCols as IContentConfig["cols"],
  375. hideColumnFilter: false,
  376. toolbar: [],
  377. defaultToolbar: ["refresh", "filter"],
  378. pagination: true,
  379. initialParams: computed(() => ({
  380. employee_id: employeeIdFromUrl.value,
  381. institution_id: institutionIdFromUrl.value,
  382. })) as Record<string, unknown>,
  383. indexAction: async (params) => {
  384. const query: QuotaPageQuery = {
  385. page_no: params.page_no,
  386. page_size: params.page_size,
  387. };
  388. if (params.employee_id) query.employee_id = params.employee_id;
  389. if (params.institution_id) query.institution_id = params.institution_id;
  390. if (params.status) query.status = params.status;
  391. const res = await QuotaAPI.listQuota(query);
  392. return {
  393. list: res.data.data?.items || [],
  394. total: res.data.data?.total || 0,
  395. };
  396. },
  397. });
  398. const dialogVisible = reactive({
  399. title: "",
  400. visible: false,
  401. type: "create" as "create" | "update" | "detail",
  402. });
  403. const currentQuotaId = ref<string>();
  404. function handleOpenDialog(type: "create" | "update" | "detail", quotaId?: string) {
  405. dialogVisible.type = type;
  406. currentQuotaId.value = quotaId;
  407. if (type === "create") {
  408. dialogVisible.title = "发放额度";
  409. } else if (type === "update") {
  410. dialogVisible.title = "编辑额度";
  411. } else {
  412. dialogVisible.title = "额度详情";
  413. }
  414. dialogVisible.visible = true;
  415. }
  416. async function handleCloseDialog() {
  417. dialogVisible.visible = false;
  418. }
  419. function handleSubmit() {
  420. formRef.value?.submitForm();
  421. }
  422. function handleFormSuccess() {
  423. dialogVisible.visible = false;
  424. refreshList();
  425. }
  426. async function handleDelete(quotaId?: string) {
  427. if (!quotaId) return;
  428. await loadingExecute({
  429. confirmMessage: "确认删除该额度?",
  430. confirmTitle: "警告",
  431. confirmType: "warning",
  432. loadingText: "正在删除...",
  433. action: () => QuotaAPI.deleteQuota(quotaId),
  434. onSuccess: () => {
  435. ElMessage.success("删除成功");
  436. refreshList();
  437. },
  438. });
  439. }
  440. function formatQuotaType(type?: string) {
  441. if (!type) return "-";
  442. const option = QUOTA_TYPE_OPTIONS.find((item) => item.value === type);
  443. return option ? option.label : type;
  444. }
  445. // ===== 手工发放批次管理 =====
  446. const batchFormRef = ref();
  447. const batchDialogVisible = ref(false);
  448. const recordsDialogVisible = ref(false);
  449. const batchList = ref<any[]>([]);
  450. const currentBatchId = ref("");
  451. const currentBatchInstitutionId = ref("");
  452. const currentBatchInfo = ref<any>({});
  453. async function loadBatchList() {
  454. try {
  455. const store = useEnterpriseStore();
  456. const eid = store.getCurrentEnterprise?.enterprise_id;
  457. const res = await QuotaAPI.issueBatchList({ page_no: 1, page_size: 200, institution_id: institutionIdFromUrl.value });
  458. batchList.value = res?.data?.data?.items || [];
  459. } catch (e) {
  460. console.error("加载批次列表失败", e);
  461. }
  462. }
  463. function handleCreateBatch() {
  464. batchFormRef.value?.resetForm();
  465. batchDialogVisible.value = true;
  466. }
  467. async function handleBatchSubmit() {
  468. const formValid = await batchFormRef.value?.submitForm();
  469. if (!formValid) return;
  470. const formData = batchFormRef.value?.getFormData();
  471. if (!formData) return;
  472. await loadingExecute({
  473. loadingText: "正在发放...",
  474. action: () => QuotaAPI.issueBatchCreate(formData),
  475. onSuccess: (res: any) => {
  476. const data = res?.data?.data || res;
  477. ElMessage.success("发放成功");
  478. batchDialogVisible.value = false;
  479. if (data?.issue_quota_check_failed_list?.length > 0) {
  480. ElMessage.warning(`有 ${data.issue_quota_check_failed_list.length} 条校验失败`);
  481. }
  482. loadBatchList();
  483. },
  484. });
  485. }
  486. function handleBatchDialogClose() {
  487. batchDialogVisible.value = false;
  488. }
  489. function handleViewBatchRecords(row: any) {
  490. currentBatchId.value = row.issue_batch_id;
  491. currentBatchInstitutionId.value = row.institution_id;
  492. currentBatchInfo.value = {
  493. issue_batch_id: row.issue_batch_id,
  494. batch_no: row.batch_no,
  495. issue_name: row.issue_name,
  496. institution_id: row.institution_id,
  497. };
  498. recordsDialogVisible.value = true;
  499. }
  500. function handleCancelBatch(row: any) {
  501. ElMessageBox.confirm(`确认作废发放批次 "${row.issue_name}"?作废后已发放的额度将无法使用。`, "警告", {
  502. confirmButtonText: "确认作废",
  503. cancelButtonText: "取消",
  504. type: "warning",
  505. }).then(async () => {
  506. const store = useEnterpriseStore();
  507. const eid = store.getCurrentEnterprise?.enterprise_id;
  508. if (!eid) {
  509. ElMessage.error("企业ID不存在");
  510. return;
  511. }
  512. await loadingExecute({
  513. loadingText: "正在作废...",
  514. action: () =>
  515. QuotaAPI.issueBatchCancel({
  516. enterprise_id: eid,
  517. institution_id: row.institution_id,
  518. issue_batch_id: row.issue_batch_id,
  519. }),
  520. onSuccess: () => {
  521. ElMessage.success("作废成功");
  522. loadBatchList();
  523. },
  524. });
  525. }).catch(() => {});
  526. }
  527. </script>