index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. <div class="table-header-btn">
  7. <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying" v-if="type"> 新建代金券 </el-button>
  8. <el-tabs v-if="showTabs" v-model="activeName" class="tabs" @tab-click="handleClick">
  9. <el-tab-pane v-for="tab in filteredTabOptions" :key="tab.name" :label="tab.label" :name="tab.name" />
  10. </el-tabs>
  11. </div>
  12. </template>
  13. <template #status="scope">
  14. <p>团购状态:{{ allTabOptions.find(item => item.name == scope.row.groupType)?.label ?? "--" }}</p>
  15. <p>审核状态:{{ scope.row.reviewType ?? "--" }}</p> </template
  16. >:
  17. <!-- 表格操作 -->
  18. <template #operation="scope">
  19. <el-button
  20. link
  21. type="primary"
  22. @click="changeTypes(scope.row, 1)"
  23. v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.上架)"
  24. >
  25. 上架
  26. </el-button>
  27. <el-button
  28. link
  29. type="primary"
  30. @click="changeTypes(scope.row, 6)"
  31. v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.下架)"
  32. >
  33. 下架
  34. </el-button>
  35. <el-button
  36. link
  37. type="primary"
  38. @click="changeInventory(scope.row)"
  39. v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.修改库存)"
  40. >
  41. 修改库存
  42. </el-button>
  43. <el-button
  44. link
  45. type="primary"
  46. @click="viewRejectReason(scope.row)"
  47. v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.查看拒绝原因)"
  48. >
  49. 查看拒绝原因
  50. </el-button>
  51. <el-button
  52. type="primary"
  53. link
  54. @click="toDetail(scope.row)"
  55. v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.查看详情) && scope.row.dataType != 1"
  56. >
  57. 查看详情
  58. </el-button>
  59. <el-button link type="primary" @click="editRow(scope.row)" v-if="scope.row.dataType == 1"> 编辑 </el-button>
  60. <el-button
  61. link
  62. type="primary"
  63. @click="deleteRow(scope.row)"
  64. v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.删除) && scope.row.dataType == 1"
  65. >
  66. 删除
  67. </el-button>
  68. </template>
  69. </ProTable>
  70. <el-dialog v-model="dialogFormVisible" title="修改库存" width="500">
  71. <el-form ref="ruleFormRef" :model="formInventory" :rules="rules" @submit.prevent>
  72. <el-form-item label="套餐名">
  73. {{ formInventory.name }}
  74. </el-form-item>
  75. <el-form-item label="剩余库存">
  76. {{ formInventory.singleQty }}
  77. </el-form-item>
  78. <el-form-item label="修改库存" prop="newInventory">
  79. <el-input v-model="formInventory.newInventory" placeholder="请输入" />
  80. </el-form-item>
  81. </el-form>
  82. <template #footer>
  83. <div class="dialog-footer">
  84. <el-button @click="closeDialog"> 取消 </el-button>
  85. <el-button type="primary" @click="handleSubmit"> 确定 </el-button>
  86. </div>
  87. </template>
  88. </el-dialog>
  89. <!-- 查看拒绝原因弹窗 -->
  90. <el-dialog v-model="rejectReasonDialogVisible" title="查看拒绝原因" width="600px">
  91. <div class="reject-reason-content">
  92. <div class="reject-reason-item">
  93. <div class="reject-reason-label">代金券名称:</div>
  94. <div class="reject-reason-value">
  95. {{ rejectReasonData.name || "--" }}
  96. </div>
  97. </div>
  98. <div class="reject-reason-item">
  99. <div class="reject-reason-label">拒绝原因:</div>
  100. <div class="reject-reason-value reject-reason-text">
  101. {{ rejectReasonData.approvalComments || "暂无拒绝原因" }}
  102. </div>
  103. </div>
  104. </div>
  105. <template #footer>
  106. <div class="dialog-footer">
  107. <el-button type="primary" @click="closeRejectReasonDialog"> 确定 </el-button>
  108. </div>
  109. </template>
  110. </el-dialog>
  111. </div>
  112. </template>
  113. <script setup lang="tsx" name="voucherManagement">
  114. import { computed, onActivated, onMounted, reactive, ref, watch } from "vue";
  115. import { useRouter } from "vue-router";
  116. import type { FormInstance, FormRules } from "element-plus";
  117. import { ElMessage } from "element-plus";
  118. import ProTable from "@/components/ProTable/index.vue";
  119. import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
  120. import { Plus } from "@element-plus/icons-vue";
  121. import { delThaliById, getThaliList, updateNum, updateStatus } from "@/api/modules/voucherManagement";
  122. import { ElMessageBox } from "element-plus/es";
  123. import { localGet, usePermission } from "@/utils";
  124. const router = useRouter();
  125. const dialogFormVisible = ref(false);
  126. const formInventory: any = ref({
  127. id: "",
  128. name: "",
  129. singleQty: "",
  130. newInventory: ""
  131. });
  132. const rowData = ref<any>();
  133. const activeName = ref("");
  134. // 查看拒绝原因弹窗相关
  135. const rejectReasonDialogVisible = ref(false);
  136. const rejectReasonData = ref<any>({
  137. name: "",
  138. approvalComments: ""
  139. });
  140. // 定义表单类型
  141. interface RuleForm {
  142. newInventory: string;
  143. }
  144. const ruleFormRef = ref<FormInstance>();
  145. const rules = reactive<FormRules<RuleForm>>({
  146. newInventory: [
  147. { required: true, message: "请输入库存数量", trigger: "blur" },
  148. {
  149. pattern: /^(0|[1-9][0-9]*)$/,
  150. message: "请输入整数,不允许输入小数,负数",
  151. trigger: "blur"
  152. },
  153. {
  154. validator: (rule: any, value: any, callback: any) => {
  155. if (value) {
  156. const numValue = Number(value);
  157. if (!isNaN(numValue) && numValue > 10000) {
  158. callback(new Error("库存不得大于10000"));
  159. return;
  160. }
  161. }
  162. callback();
  163. },
  164. trigger: "blur"
  165. }
  166. ]
  167. });
  168. const statusEnum = [
  169. { value: "0", label: "待审核" },
  170. { value: "1", label: "审核通过" },
  171. { value: "2", label: "审核驳回" }
  172. ];
  173. // ProTable 实例(需要在使用它的地方之前定义)
  174. const proTable = ref<ProTableInstance>();
  175. // 表格配置项
  176. const columns = reactive<ColumnProps<any>[]>([
  177. {
  178. prop: "index",
  179. label: "序号",
  180. width: 100,
  181. render: (scope: any) => {
  182. return scope.$index + (proTable.value!.pageable.pageNum - 1) * proTable.value!.pageable.pageSize + 1;
  183. }
  184. },
  185. {
  186. prop: "name",
  187. label: "代金券名称",
  188. search: {
  189. el: "input"
  190. }
  191. },
  192. {
  193. prop: "price",
  194. label: "价格",
  195. render: (scope: any) => {
  196. return scope.row.price ? `¥${scope.row.price}` : "--";
  197. }
  198. },
  199. {
  200. prop: "saleNum",
  201. label: "已售",
  202. render: scope => {
  203. return scope.row.saleNum === null || !scope.row.saleNum ? "--" : scope.row.saleNum;
  204. }
  205. },
  206. {
  207. prop: "singleQty",
  208. label: "剩余库存",
  209. render: scope => {
  210. return scope.row.singleQty === null ? "--" : scope.row.singleQty;
  211. }
  212. },
  213. {
  214. prop: "endDate",
  215. label: "结束时间"
  216. },
  217. {
  218. prop: "reviewType",
  219. label: "审核状态",
  220. isShow: false,
  221. render: scope => {
  222. const statusObj = statusEnum.find(item => item.value === scope.row.reviewType);
  223. return statusObj ? statusObj.label : "--";
  224. },
  225. search: {
  226. el: "select"
  227. },
  228. enum: statusEnum,
  229. fieldNames: { label: "label", value: "value" }
  230. },
  231. {
  232. prop: "status",
  233. label: "状态"
  234. },
  235. { prop: "operation", label: "操作", fixed: "right", width: 330 }
  236. ]);
  237. const allTabOptions = [
  238. { label: "全部", name: "" },
  239. { label: "草稿", name: "0" },
  240. { label: "进行中", name: "5" },
  241. { label: "未开始", name: "2" },
  242. { label: "已下架", name: "6" },
  243. { label: "已售罄", name: "4" },
  244. { label: "已结束", name: "7" }
  245. ];
  246. // 状态枚举:0草稿 1待审核 2未开始 3审核拒绝 4已售罄 5进行中 6已下架 7已结束
  247. const STATUS = {
  248. 草稿: 0,
  249. 待审核: 1,
  250. 未开始: 2,
  251. 审核拒绝: 3,
  252. 已售罄: 4,
  253. 进行中: 5,
  254. 已下架: 6,
  255. 已结束: 7
  256. } as const;
  257. // 操作按钮权限配置:定义每个操作按钮在哪些状态下显示
  258. const OPERATION_PERMISSIONS = {
  259. // 查看详情:待审核、未开始、审核拒绝、进行中、已售罄、已下架
  260. 查看详情: [STATUS.待审核, STATUS.未开始, STATUS.审核拒绝, STATUS.进行中, STATUS.已售罄, STATUS.已下架],
  261. // 上架:未开始、已下架
  262. 上架: [STATUS.未开始, STATUS.已下架],
  263. // 下架:进行中
  264. 下架: [STATUS.进行中],
  265. // 修改库存:未开始、进行中、已售罄
  266. 修改库存: [STATUS.未开始, STATUS.进行中, STATUS.已售罄],
  267. // 编辑:草稿、审核拒绝、已售罄、已下架、已结束
  268. 编辑: [STATUS.草稿, STATUS.审核拒绝, STATUS.已售罄, STATUS.已下架, STATUS.已结束],
  269. // 删除:草稿、未开始、审核拒绝、已售罄、已结束
  270. 删除: [STATUS.草稿, STATUS.未开始, STATUS.审核拒绝, STATUS.已售罄, STATUS.已结束],
  271. // 查看拒绝原因:审核拒绝
  272. 查看拒绝原因: [STATUS.审核拒绝]
  273. } as const;
  274. // 判断按钮是否显示的工具函数
  275. const canShowButton = (status: number, allowedStatuses: readonly number[]) => {
  276. return allowedStatuses.includes(status);
  277. };
  278. // 获取当前审核状态
  279. const currentAuditStatus = computed(() => {
  280. if (!proTable.value?.searchParam) return "";
  281. return proTable.value.searchParam.reviewType || "";
  282. });
  283. // 控制 el-tabs 是否显示:当审核状态为空或审核通过时显示
  284. const showTabs = computed(() => {
  285. const status = currentAuditStatus.value;
  286. return !status || status === "1";
  287. });
  288. // 根据审核状态过滤 tabOptions:如果审核状态为空,只显示草稿;审核通过时,显示除草稿外的所有标签页
  289. const filteredTabOptions = computed(() => {
  290. const status = currentAuditStatus.value;
  291. if (!status) {
  292. return allTabOptions;
  293. } else if (status == "1") {
  294. // 审核通过时,显示除草稿外的所有标签页
  295. return allTabOptions.filter(tab => tab.name != "0");
  296. }
  297. return [];
  298. });
  299. // 监听审核状态变化
  300. watch(
  301. currentAuditStatus,
  302. newStatus => {
  303. if (!newStatus || newStatus === "-2") {
  304. activeName.value = "";
  305. }
  306. },
  307. { immediate: true }
  308. );
  309. const dataType = computed(() => {
  310. if (!activeName.value) return 2;
  311. return activeName.value === "0" ? 1 : 0;
  312. });
  313. // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
  314. const initParam = reactive({
  315. storeId: localGet("createdId"),
  316. groupType: localGet("businessSection"),
  317. status: activeName,
  318. dataType: dataType
  319. });
  320. const type = ref(false);
  321. // 页面加载时触发查询
  322. onMounted(async () => {
  323. type.value = await usePermission("新建代金券");
  324. proTable.value?.getTableList();
  325. });
  326. // 从其他页面返回时触发查询
  327. onActivated(() => {
  328. proTable.value?.getTableList();
  329. });
  330. // dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total 这些字段,可以在这里进行处理成这些字段
  331. // 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
  332. const dataCallback = (data: any) => {
  333. return {
  334. list: data.records,
  335. total: data.total
  336. };
  337. };
  338. // 如果你想在请求之前对当前请求参数做一些操作,可以自定义如下函数:params 为当前所有的请求参数(包括分页),最后返回请求列表接口
  339. // 默认不做操作就直接在 ProTable 组件上绑定 :requestApi="getUserList"
  340. const getTableList = (params: any) => {
  341. let newParams = JSON.parse(JSON.stringify(params));
  342. return getThaliList(newParams);
  343. };
  344. const newGroupBuying = () => {
  345. router.push(`/voucherManagement/newVoucher?type=add`);
  346. };
  347. // 跳转详情页
  348. const toDetail = row => {
  349. router.push(`/voucherManagement/detail?id=${row.id}`);
  350. };
  351. const editRow = row => {
  352. router.push(`/voucherManagement/newVoucher?id=${row.id}&type=edit`);
  353. };
  354. const deleteRow = row => {
  355. ElMessageBox.confirm("确定要删除吗?", "提示", {
  356. confirmButtonText: "确定",
  357. cancelButtonText: "取消",
  358. type: "warning"
  359. }).then(() => {
  360. const params = {
  361. id: row.id,
  362. groupType: localGet("businessSection")
  363. };
  364. delThaliById(params).then(() => {
  365. ElMessage.success("删除成功");
  366. proTable.value?.getTableList();
  367. });
  368. });
  369. };
  370. const handleClick = () => {};
  371. const changeTypes = async (row, status) => {
  372. rowData.value = row;
  373. let res = await updateStatus({ id: row.id, status: status, approvalComments: "" });
  374. if (res && res.code == 200) {
  375. ElMessage.success("操作成功");
  376. proTable.value?.getTableList();
  377. }
  378. };
  379. const changeInventory = (row: any) => {
  380. formInventory.value.id = row.id;
  381. formInventory.value.name = row.name;
  382. formInventory.value.singleQty = row.singleQty;
  383. formInventory.value.newInventory = "";
  384. dialogFormVisible.value = true;
  385. };
  386. // 弹窗提交
  387. const handleSubmit = async () => {
  388. if (!ruleFormRef.value) return;
  389. await ruleFormRef.value.validate(async (valid, fields) => {
  390. if (valid) {
  391. let res = await updateNum({ id: formInventory.value.id, singleQty: formInventory.value.newInventory });
  392. if (res && res.code == 200) {
  393. ElMessage.success("修改成功");
  394. dialogFormVisible.value = false;
  395. proTable.value?.getTableList();
  396. }
  397. }
  398. });
  399. };
  400. // 关闭弹窗;
  401. const closeDialog = () => {
  402. dialogFormVisible.value = false;
  403. formInventory.value = {
  404. id: "",
  405. name: "",
  406. singleQty: "",
  407. newInventory: ""
  408. };
  409. };
  410. // 查看拒绝原因
  411. const viewRejectReason = (row: any) => {
  412. rejectReasonData.value = {
  413. name: row.name || "--",
  414. approvalComments: row.approvalComments || "--"
  415. };
  416. rejectReasonDialogVisible.value = true;
  417. };
  418. // 关闭拒绝原因弹窗
  419. const closeRejectReasonDialog = () => {
  420. rejectReasonDialogVisible.value = false;
  421. rejectReasonData.value = {
  422. name: "",
  423. approvalComments: ""
  424. };
  425. };
  426. </script>
  427. <style lang="scss" scoped>
  428. // 在组件样式中添加
  429. .date-range {
  430. display: block; // 确保换行生效
  431. padding: 0 8px; // 可选:增加内边距
  432. word-wrap: break-word; // 长单词内换行
  433. white-space: normal; // 允许自然换行
  434. }
  435. .table-header-btn {
  436. .button {
  437. margin-bottom: 10px;
  438. }
  439. .tabs {
  440. :deep(.el-tabs__nav-wrap::after) {
  441. height: 0;
  442. }
  443. }
  444. }
  445. .reject-reason-content {
  446. padding: 20px 0;
  447. .reject-reason-item {
  448. display: flex;
  449. margin-bottom: 20px;
  450. &:last-child {
  451. margin-bottom: 0;
  452. }
  453. .reject-reason-label {
  454. flex-shrink: 0;
  455. min-width: 100px;
  456. font-size: 14px;
  457. font-weight: 500;
  458. color: #606266;
  459. }
  460. .reject-reason-value {
  461. flex: 1;
  462. font-size: 14px;
  463. color: #303133;
  464. word-break: break-word;
  465. &.reject-reason-text {
  466. min-height: 80px;
  467. padding: 12px;
  468. line-height: 1.6;
  469. white-space: pre-wrap;
  470. background-color: #f5f7fa;
  471. border-radius: 4px;
  472. }
  473. }
  474. }
  475. }
  476. </style>