index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  4. <Search :schema="allSchemas.searchSchema" @reset="setSearchParams" @search="setSearchParams">
  5. <!-- 新增等操作按钮 -->
  6. <template #actionMore>
  7. <el-button
  8. v-hasPermi="['promotion:seckill-activity:create']"
  9. plain
  10. type="primary"
  11. @click="openForm('create')"
  12. >
  13. <Icon class="mr-5px" icon="ep:plus" />
  14. 新增
  15. </el-button>
  16. </template>
  17. </Search>
  18. </ContentWrap>
  19. <!-- 列表 -->
  20. <ContentWrap>
  21. <Table
  22. v-model:currentPage="tableObject.currentPage"
  23. v-model:pageSize="tableObject.pageSize"
  24. :columns="allSchemas.tableColumns"
  25. :data="tableObject.tableList"
  26. :expand="true"
  27. :loading="tableObject.loading"
  28. :pagination="{
  29. total: tableObject.total
  30. }"
  31. @expand-change="expandChange"
  32. >
  33. <template #expand> 展示活动商品和商品相关属性活动配置</template>
  34. <template #configIds="{ row }">
  35. <el-tag v-for="(name, index) in convertSeckillConfigNames(row)" :key="index" class="mr-5px">
  36. {{ name }}
  37. </el-tag>
  38. </template>
  39. <template #action="{ row }">
  40. <el-button
  41. v-hasPermi="['promotion:seckill-activity:update']"
  42. link
  43. type="primary"
  44. @click="openForm('update', row.id)"
  45. >
  46. 编辑
  47. </el-button>
  48. <el-button
  49. v-hasPermi="['promotion:seckill-activity:delete']"
  50. link
  51. type="danger"
  52. @click="handleDelete(row.id)"
  53. >
  54. 删除
  55. </el-button>
  56. </template>
  57. </Table>
  58. </ContentWrap>
  59. <!-- 表单弹窗:添加/修改 -->
  60. <SeckillActivityForm ref="formRef" @success="getList" />
  61. </template>
  62. <script lang="ts" setup>
  63. import { allSchemas } from './seckillActivity.data'
  64. import { getListAllSimple } from '@/api/mall/promotion/seckill/seckillConfig'
  65. import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
  66. import SeckillActivityForm from './SeckillActivityForm.vue'
  67. import { cloneDeep } from 'lodash-es'
  68. defineOptions({ name: 'PromotionSeckillActivity' })
  69. // tableObject:表格的属性对象,可获得分页大小、条数等属性
  70. // tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
  71. // 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
  72. const { tableObject, tableMethods } = useTable({
  73. getListApi: SeckillActivityApi.getSeckillActivityPage, // 分页接口
  74. delListApi: SeckillActivityApi.deleteSeckillActivity // 删除接口
  75. })
  76. // 获得表格的各种操作
  77. const { getList, setSearchParams } = tableMethods
  78. /** 添加/修改操作 */
  79. const formRef = ref()
  80. const openForm = (type: string, id?: number) => {
  81. formRef.value.open(type, id)
  82. }
  83. /** 删除按钮操作 */
  84. const handleDelete = (id: number) => {
  85. tableMethods.delList(id, false)
  86. }
  87. const configList = ref([]) // 时段配置精简列表
  88. const convertSeckillConfigNames = computed(
  89. () => (row) =>
  90. configList.value
  91. ?.filter((item) => row.configIds.includes(item.id))
  92. ?.map((config) => config.name)
  93. )
  94. const expandChange = (row, expandedRows) => {
  95. // TODO puhui:等 CRUD 完事后弄
  96. console.log(row, expandedRows)
  97. }
  98. /** 初始化 **/
  99. onMounted(async () => {
  100. // 处理一下表格列让商品往前
  101. const index = allSchemas.tableColumns.findIndex((item) => item.field === 'spuId')
  102. const column = cloneDeep(allSchemas.tableColumns[index])
  103. allSchemas.tableColumns.splice(index, 1)
  104. // 添加到开头
  105. allSchemas.tableColumns.unshift(column)
  106. await getList()
  107. configList.value = await getListAllSimple()
  108. })
  109. </script>