index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam" :data-callback="dataCallback">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" :icon="Download" @click="exportInfoExcel(scope)"> 导出 </el-button>
  7. </template>
  8. <template #expand="scope">
  9. {{ scope.row }}
  10. </template>
  11. <!-- 表格操作 -->
  12. <template #operation="scope">
  13. <!-- 审批通过和拒绝按钮仅在状态为0时显示 -->
  14. <template v-if="scope.row.status === '0'">
  15. <el-button type="primary" link @click="changeTypes(scope.row, 'pass')"> 审核通过 </el-button>
  16. <el-button type="primary" link @click="changeTypes(scope.row, '')"> 审核拒绝 </el-button>
  17. </template>
  18. <el-button type="primary" link @click="toDetail(scope.row)"> 查看详情 </el-button>
  19. </template>
  20. </ProTable>
  21. <el-dialog v-model="dialogFormVisible" title="审核拒绝" width="500">
  22. <el-form :model="form">
  23. <el-form-item label="" label-width="0">
  24. <el-input v-model="form.comment" autocomplete="off" type="textarea" maxlength="200" />
  25. </el-form-item>
  26. </el-form>
  27. <template #footer>
  28. <div class="dialog-footer">
  29. <el-button @click="closeDialog"> 取消 </el-button>
  30. <el-button type="primary" @click="handleSubmit"> 驳回 </el-button>
  31. </div>
  32. </template>
  33. </el-dialog>
  34. </div>
  35. </template>
  36. <script setup lang="tsx" name="voucherManagement">
  37. import { ref, reactive, onMounted, onActivated } from "vue";
  38. import { useRouter } from "vue-router";
  39. import { ElMessage } from "element-plus";
  40. import ProTable from "@/components/ProTable/index.vue";
  41. import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
  42. import { Download } from "@element-plus/icons-vue";
  43. import { audit, exportExcelStaffConfig, getStaffConfigList } from "@/api/modules/staffConfig";
  44. const router = useRouter();
  45. const dialogFormVisible = ref(false);
  46. const form = reactive({
  47. comment: ""
  48. });
  49. const rowData = ref<any>();
  50. const statusEnum = [
  51. { value: "0", label: "待审核" },
  52. { value: "1", label: "审核通过" },
  53. { value: "2", label: "审核拒绝" }
  54. ];
  55. // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
  56. const initParam = reactive({});
  57. // 定义 filterValues
  58. const filterValues = reactive({});
  59. const getStatusObj = (statusValue: string) => {
  60. const statusObj = statusEnum.find(item => item.value === statusValue);
  61. if (statusObj) {
  62. filterValues.status = statusObj;
  63. } else {
  64. filterValues.status = "";
  65. }
  66. return statusObj;
  67. };
  68. // ProTable 实例
  69. const proTable = ref<ProTableInstance>();
  70. // 页面加载时触发查询
  71. onMounted(() => {
  72. proTable.value?.getTableList();
  73. });
  74. // 从其他页面返回时触发查询
  75. onActivated(() => {
  76. proTable.value?.getTableList();
  77. });
  78. // dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total 这些字段,可以在这里进行处理成这些字段
  79. // 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
  80. const dataCallback = (data: any) => {
  81. return {
  82. list: data.records,
  83. total: data.total
  84. };
  85. };
  86. // 如果你想在请求之前对当前请求参数做一些操作,可以自定义如下函数:params 为当前所有的请求参数(包括分页),最后返回请求列表接口
  87. // 默认不做操作就直接在 ProTable 组件上绑定 :requestApi="getUserList"
  88. const getTableList = (params: any) => {
  89. let newParams = JSON.parse(JSON.stringify(params));
  90. return getStaffConfigList(newParams);
  91. };
  92. // 跳转详情页
  93. const toDetail = row => {
  94. router.push(`/store/voucherManagementDetail?id=${row.id}`);
  95. };
  96. // 表格配置项
  97. const columns = reactive<ColumnProps<any>[]>([
  98. { type: "index", fixed: "left", label: "序号", width: 130 },
  99. { prop: "storeName", label: "所属店铺" },
  100. { prop: "name", label: "名称" },
  101. { prop: "description", label: "描述" },
  102. {
  103. prop: "status",
  104. label: "状态",
  105. render: scope => {
  106. const statusObj = getStatusObj(scope.row.status);
  107. return statusObj ? statusObj.label : "未知状态";
  108. },
  109. search: {
  110. el: "select"
  111. },
  112. enum: statusEnum,
  113. fieldNames: { label: "label", value: "value" }
  114. },
  115. { prop: "operation", label: "操作", fixed: "right", width: 330 }
  116. ]);
  117. const changeTypes = (row: any, status: string) => {
  118. rowData.value = row;
  119. if (status === "pass") {
  120. handleChangeStatus(row, "1");
  121. } else {
  122. form.comment = "";
  123. dialogFormVisible.value = true;
  124. }
  125. };
  126. const handleChangeStatus = async (row: any, status: string) => {
  127. try {
  128. let res = await audit({ id: row.id, status: status, rejectionReason: form.comment });
  129. if (res.code === 200) {
  130. proTable.value?.getTableList();
  131. if (status === "2") closeDialog();
  132. ElMessage.success("审核成功");
  133. }
  134. } catch (error) {
  135. ElMessage.error("操作失败");
  136. }
  137. };
  138. // 导出信息
  139. const exportInfoExcel = async scope => {
  140. let res;
  141. // 获取原始状态值(可能为数字、字符串或 undefined)
  142. const rawStatus = proTable.value.searchParam.status;
  143. // 转换为字符串(处理 undefined/null 为 "" 或保留原始字符串)
  144. const statusParam = rawStatus !== undefined && rawStatus !== null ? String(rawStatus) : undefined;
  145. // 将筛选条件作为参数传递给后台
  146. res = await exportExcelStaffConfig({ status: statusParam });
  147. if (res.code === 200) {
  148. if (!res.data) {
  149. ElMessage.error("暂无可下载数据");
  150. return;
  151. }
  152. const exportFile = document.createElement("a");
  153. exportFile.style.display = "none";
  154. exportFile.download = `代金券管理.xlsx`;
  155. exportFile.href = `${res.data}?timestamp=${new Date().getTime()}`; // 添加时间戳防止缓存
  156. document.body.appendChild(exportFile);
  157. exportFile.click();
  158. document.body.removeChild(exportFile);
  159. ElMessage.success("下载成功");
  160. }
  161. };
  162. // 弹窗提交
  163. const handleSubmit = () => {
  164. if (!form.comment) {
  165. ElMessage.error("请输入审批意见");
  166. return;
  167. }
  168. handleChangeStatus(rowData.value, "2");
  169. };
  170. // 关闭弹窗;
  171. const closeDialog = () => {
  172. dialogFormVisible.value = false;
  173. form.comment = "";
  174. };
  175. </script>
  176. <style lang="scss" scoped>
  177. // 在组件样式中添加
  178. .date-range {
  179. display: block; // 确保换行生效
  180. padding: 0 8px; // 可选:增加内边距
  181. word-wrap: break-word; // 长单词内换行
  182. white-space: normal; // 允许自然换行
  183. }
  184. </style>