index.vue 3.8 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-config:create']"
  10. plain
  11. type="primary"
  12. @click="openForm('create')"
  13. >
  14. <Icon class="mr-5px" icon="ep:plus" />
  15. 新增
  16. </el-button>
  17. </template>
  18. </Search>
  19. </ContentWrap>
  20. <!-- 列表 -->
  21. <ContentWrap>
  22. <Table
  23. v-model:currentPage="tableObject.currentPage"
  24. v-model:pageSize="tableObject.pageSize"
  25. :columns="allSchemas.tableColumns"
  26. :data="tableObject.tableList"
  27. :loading="tableObject.loading"
  28. :pagination="{
  29. total: tableObject.total
  30. }"
  31. >
  32. <template #sliderPicUrls="{ row }">
  33. <el-image
  34. v-for="(item, index) in row.sliderPicUrls"
  35. :key="index"
  36. :src="item"
  37. class="w-60px h-60px mr-10px"
  38. @click="imagePreview(row.sliderPicUrls)"
  39. />
  40. </template>
  41. <template #status="{ row }">
  42. <el-switch
  43. v-model="row.status"
  44. :active-value="0"
  45. :inactive-value="1"
  46. @change="handleStatusChange(row)"
  47. />
  48. </template>
  49. <template #action="{ row }">
  50. <el-button
  51. v-hasPermi="['promotion:seckill-config:update']"
  52. link
  53. type="primary"
  54. @click="openForm('update', row.id)"
  55. >
  56. 编辑
  57. </el-button>
  58. <el-button
  59. v-hasPermi="['promotion:seckill-config:delete']"
  60. link
  61. type="danger"
  62. @click="handleDelete(row.id)"
  63. >
  64. 删除
  65. </el-button>
  66. </template>
  67. </Table>
  68. </ContentWrap>
  69. <!-- 表单弹窗:添加/修改 -->
  70. <SeckillConfigForm ref="formRef" @success="getList" />
  71. </template>
  72. <script lang="ts" name="PromotionSeckillConfig" setup>
  73. import { allSchemas } from './seckillConfig.data'
  74. import * as SeckillConfigApi from '@/api/mall/promotion/seckill/seckillConfig'
  75. import SeckillConfigForm from './SeckillConfigForm.vue'
  76. import { createImageViewer } from '@/components/ImageViewer'
  77. import { CommonStatusEnum } from '@/utils/constants'
  78. const message = useMessage() // 消息弹窗
  79. // tableObject:表格的属性对象,可获得分页大小、条数等属性
  80. // tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
  81. // 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
  82. const { tableObject, tableMethods } = useTable({
  83. getListApi: SeckillConfigApi.getSeckillConfigPage, // 分页接口
  84. delListApi: SeckillConfigApi.deleteSeckillConfig // 删除接口
  85. })
  86. // 获得表格的各种操作
  87. const { getList, setSearchParams } = tableMethods
  88. /** 添加/修改操作 */
  89. const formRef = ref()
  90. const openForm = (type: string, id?: number) => {
  91. formRef.value.open(type, id)
  92. }
  93. /** 删除按钮操作 */
  94. const handleDelete = (id: number) => {
  95. tableMethods.delList(id, false)
  96. }
  97. /** 修改用户状态 */
  98. const handleStatusChange = async (row: SeckillConfigApi.SeckillConfigVO) => {
  99. try {
  100. // 修改状态的二次确认
  101. const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
  102. await message.confirm('确认要"' + text + '""' + row.name + '?')
  103. // 发起修改状态
  104. await SeckillConfigApi.updateSeckillConfigStatus(row.id, row.status)
  105. // 刷新列表
  106. await getList()
  107. } catch {
  108. // 取消后,进行恢复按钮
  109. row.status =
  110. row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
  111. }
  112. }
  113. /** 轮播图预览预览 */
  114. const imagePreview = (args) => {
  115. createImageViewer({
  116. urlList: args
  117. })
  118. }
  119. /** 初始化 **/
  120. onMounted(() => {
  121. getList()
  122. })
  123. </script>