personnel.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div class="table-box button-table">
  3. <ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam" :data-callback="dataCallback">
  4. <template #operation="scope">
  5. <el-button type="primary" link @click="toDetail(scope.row)"> 查看详情 </el-button>
  6. <!-- 待审核状态显示通过和拒绝按钮 -->
  7. <template v-if="scope.row.status == 0">
  8. <el-button type="success" link @click="handleApprove(scope.row)"> 通过 </el-button>
  9. <el-button type="danger" link @click="handleReject(scope.row)"> 拒绝 </el-button>
  10. </template>
  11. </template>
  12. </ProTable>
  13. </div>
  14. </template>
  15. <script setup lang="tsx" name="personnel">
  16. import { reactive, ref } from "vue";
  17. import { useRouter } from "vue-router";
  18. import { ElMessage, ElMessageBox, ElLoading } from "element-plus";
  19. import ProTable from "@/components/ProTable/index.vue";
  20. import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
  21. import { getPersonnelList, approvePersonnel, rejectPersonnel } from "@/api/modules/operationManagement";
  22. import { localGet } from "@/utils";
  23. const router = useRouter();
  24. const proTable = ref<ProTableInstance>();
  25. // 报名情况枚举:0-待审核, 1-拒绝, 2-通过
  26. const registrationStatusEnum = [
  27. { label: "待审核", value: 0 },
  28. { label: "拒绝", value: 1 },
  29. { label: "通过", value: 2 }
  30. ];
  31. const columns = reactive<ColumnProps<any>[]>([
  32. { prop: "userName", label: "姓名", minWidth: 220 },
  33. { prop: "phone", label: "联系方式", width: 300 },
  34. {
  35. prop: "activityName",
  36. label: "所属活动",
  37. width: 300,
  38. fieldNames: { label: "label", value: "value" },
  39. search: {
  40. el: "input",
  41. props: { placeholder: "请输入活动名称" },
  42. order: 2
  43. }
  44. },
  45. {
  46. prop: "status",
  47. label: "报名情况",
  48. width: 300,
  49. enum: registrationStatusEnum,
  50. fieldNames: { label: "label", value: "value" },
  51. search: { el: "select", props: { placeholder: "请选择" }, order: 1 },
  52. render: (scope: any) => {
  53. // 状态值:0-待审核, 1-拒绝, 2-通过
  54. const status = scope.row.status;
  55. if (status == 2) return "通过";
  56. if (status == 1) return "拒绝";
  57. return "待审核";
  58. }
  59. },
  60. { prop: "operation", label: "操作", fixed: "right", minWidth: 200 }
  61. ]);
  62. const initParam = reactive({
  63. storeId: localGet("createdId")
  64. });
  65. const dataCallback = (data: any) => ({
  66. list: data?.records ?? [],
  67. total: data?.total ?? 0
  68. });
  69. const getTableList = async (params: any) => {
  70. // 显示全屏loading
  71. const loadingInstance = ElLoading.service({
  72. lock: true,
  73. text: "加载中...",
  74. background: "rgba(0, 0, 0, 0.7)"
  75. });
  76. try {
  77. // 转换参数格式以匹配新接口
  78. const newParams: any = {
  79. storeId: params.storeId || localGet("createdId"),
  80. pageNum: params.page || params.pageNum || 1,
  81. pageSize: params.size || params.pageSize || 10
  82. };
  83. // 如果有状态筛选,添加状态参数(注意:搜索字段名是 status)
  84. if (params.status) {
  85. newParams.status = params.status;
  86. }
  87. // 如果有活动类型筛选,添加活动类型参数
  88. if (params.activityType) {
  89. newParams.activityType = params.activityType;
  90. }
  91. // 如果有活动名称筛选,添加活动名称参数
  92. if (params.activityName) {
  93. newParams.activityName = params.activityName;
  94. }
  95. const result = await getPersonnelList(newParams);
  96. return result;
  97. } finally {
  98. // 关闭loading
  99. loadingInstance.close();
  100. }
  101. };
  102. const toDetail = (row: any) => {
  103. router.push(`/operationManagement/personnelDetail?id=${row.id}`);
  104. };
  105. // 审核通过
  106. const handleApprove = async (row: any) => {
  107. try {
  108. await ElMessageBox.confirm("确定要通过该报名吗?", "提示", {
  109. confirmButtonText: "确定",
  110. cancelButtonText: "取消",
  111. type: "warning"
  112. });
  113. const res: any = await approvePersonnel({ id: Number(row.id) });
  114. if (res.code == 200) {
  115. ElMessage.success("审核通过成功");
  116. proTable.value?.getTableList();
  117. } else {
  118. ElMessage.error(res?.msg || res?.message || "审核通过失败");
  119. }
  120. } catch (error: any) {
  121. if (error !== "cancel") {
  122. ElMessage.error(error?.message || "审核通过失败");
  123. }
  124. }
  125. };
  126. // 审核拒绝
  127. const handleReject = async (row: any) => {
  128. try {
  129. const { value: rejectReason } = await ElMessageBox.prompt("请输入拒绝原因", "审核拒绝", {
  130. confirmButtonText: "确定",
  131. cancelButtonText: "取消",
  132. inputType: "textarea",
  133. inputPlaceholder: "请输入拒绝原因",
  134. inputValidator: (value: string) => {
  135. if (!value || value.trim() === "") {
  136. return "拒绝原因不能为空";
  137. }
  138. return true;
  139. }
  140. });
  141. // 再次验证拒绝原因(防止用户绕过验证)
  142. if (!rejectReason || rejectReason.trim() === "") {
  143. ElMessage.warning("拒绝原因不能为空");
  144. return;
  145. }
  146. const res: any = await rejectPersonnel({
  147. id: Number(row.id),
  148. rejectReason: rejectReason.trim()
  149. });
  150. if (res.code == 200) {
  151. ElMessage.success("审核拒绝成功");
  152. proTable.value?.getTableList();
  153. } else {
  154. ElMessage.error(res?.msg || res?.message || "审核拒绝失败");
  155. }
  156. } catch (error: any) {
  157. if (error !== "cancel") {
  158. ElMessage.error(error?.message || "审核拒绝失败");
  159. }
  160. }
  161. };
  162. </script>