index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <doc-alert title="功能开启" url="https://doc.iocoder.cn/mall/build/" />
  3. <!-- 搜索工作栏 -->
  4. <ContentWrap>
  5. <Search :schema="allSchemas.searchSchema" @reset="setSearchParams" @search="setSearchParams">
  6. <!-- 新增等操作按钮 -->
  7. <template #actionMore>
  8. <el-button
  9. v-hasPermi="['promotion:seckill-activity:create']"
  10. plain
  11. type="primary"
  12. @click="openForm('create')"
  13. >
  14. <Icon class="mr-5px" icon="ep:plus" /> 新增
  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 #spuId="{ row }">
  35. <el-image
  36. :src="row.picUrl"
  37. class="mr-5px h-30px w-30px align-middle"
  38. @click="imagePreview(row.picUrl)"
  39. />
  40. <span class="align-middle">{{ row.spuName }}</span>
  41. </template>
  42. <template #configIds="{ row }">
  43. <el-tag v-for="(name, index) in convertSeckillConfigNames(row)" :key="index" class="mr-5px">
  44. {{ name }}
  45. </el-tag>
  46. </template>
  47. <template #action="{ row }">
  48. <el-button
  49. v-hasPermi="['promotion:seckill-activity:update']"
  50. link
  51. type="primary"
  52. @click="openForm('update', row.id)"
  53. >
  54. 编辑
  55. </el-button>
  56. <el-button
  57. v-hasPermi="['promotion:seckill-activity:delete']"
  58. link
  59. type="danger"
  60. @click="handleDelete(row.id)"
  61. >
  62. 删除
  63. </el-button>
  64. </template>
  65. </Table>
  66. </ContentWrap>
  67. <!-- 表单弹窗:添加/修改 -->
  68. <SeckillActivityForm ref="formRef" @success="getList" />
  69. </template>
  70. <script lang="ts" setup>
  71. import { allSchemas } from './seckillActivity.data'
  72. import { getSimpleSeckillConfigList } from '@/api/mall/promotion/seckill/seckillConfig'
  73. import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
  74. import SeckillActivityForm from './SeckillActivityForm.vue'
  75. import { createImageViewer } from '@/components/ImageViewer'
  76. import { sortTableColumns } from '@/hooks/web/useCrudSchemas'
  77. defineOptions({ name: 'PromotionSeckillActivity' })
  78. // tableObject:表格的属性对象,可获得分页大小、条数等属性
  79. // tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
  80. // 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
  81. const { tableObject, tableMethods } = useTable({
  82. getListApi: SeckillActivityApi.getSeckillActivityPage, // 分页接口
  83. delListApi: SeckillActivityApi.deleteSeckillActivity // 删除接口
  84. })
  85. // 获得表格的各种操作
  86. const { getList, setSearchParams } = tableMethods
  87. /** 添加/修改操作 */
  88. const formRef = ref()
  89. const openForm = (type: string, id?: number) => {
  90. formRef.value.open(type, id)
  91. }
  92. /** 删除按钮操作 */
  93. const handleDelete = (id: number) => {
  94. tableMethods.delList(id, false)
  95. }
  96. /** 商品图预览 */
  97. const imagePreview = (imgUrl: string) => {
  98. createImageViewer({
  99. urlList: [imgUrl]
  100. })
  101. }
  102. const configList = ref([]) // 时段配置精简列表
  103. const convertSeckillConfigNames = computed(
  104. () => (row) =>
  105. configList.value
  106. ?.filter((item) => row.configIds.includes(item.id))
  107. ?.map((config) => config.name)
  108. )
  109. const expandChange = (row, expandedRows) => {
  110. // TODO puhui:等 CRUD 完事后弄
  111. console.log(row, expandedRows)
  112. }
  113. /** 初始化 **/
  114. onMounted(async () => {
  115. // 获得活动列表
  116. sortTableColumns(allSchemas.tableColumns, 'spuId')
  117. await getList()
  118. // 获得秒杀时间段
  119. configList.value = await getSimpleSeckillConfigList()
  120. })
  121. </script>