index.vue 16 KB

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