index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <doc-alert title="【营销】秒杀活动" url="https://doc.iocoder.cn/mall/promotion-seckill/" />
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. ref="queryFormRef"
  7. :inline="true"
  8. :model="queryParams"
  9. class="-mb-15px"
  10. label-width="68px"
  11. >
  12. <el-form-item label="活动名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. class="!w-240px"
  16. clearable
  17. placeholder="请输入活动名称"
  18. @keyup.enter="handleQuery"
  19. />
  20. </el-form-item>
  21. <el-form-item label="活动状态" prop="status">
  22. <el-select
  23. v-model="queryParams.status"
  24. class="!w-240px"
  25. clearable
  26. placeholder="请选择活动状态"
  27. >
  28. <el-option
  29. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  30. :key="dict.value"
  31. :label="dict.label"
  32. :value="dict.value"
  33. />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button @click="handleQuery">
  38. <Icon class="mr-5px" icon="ep:search" />
  39. 搜索
  40. </el-button>
  41. <el-button @click="resetQuery">
  42. <Icon class="mr-5px" icon="ep:refresh" />
  43. 重置
  44. </el-button>
  45. <el-button
  46. v-hasPermi="['promotion:seckill-activity:create']"
  47. plain
  48. type="primary"
  49. @click="openForm('create')"
  50. >
  51. <Icon class="mr-5px" icon="ep:plus" />
  52. 新增
  53. </el-button>
  54. </el-form-item>
  55. </el-form>
  56. </ContentWrap>
  57. <!-- 列表 -->
  58. <ContentWrap>
  59. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  60. <el-table-column label="活动编号" min-width="80" prop="id" />
  61. <el-table-column label="活动名称" min-width="140" prop="name" />
  62. <el-table-column
  63. :show-overflow-tooltip="false"
  64. label="秒杀时段"
  65. prop="configIds"
  66. width="220px"
  67. >
  68. <template #default="scope">
  69. <el-tag v-for="(configId, index) in scope.row.configIds" :key="index" class="mr-5px">
  70. {{ formatConfigNames(configId) }}
  71. </el-tag>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="活动时间" min-width="210">
  75. <template #default="scope">
  76. {{ formatDate(scope.row.startTime, 'YYYY-MM-DD') }}
  77. ~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="产品图片" min-width="80" prop="spuName">
  81. <template #default="scope">
  82. <el-image
  83. :preview-src-list="[scope.row.picUrl]"
  84. :src="scope.row.picUrl"
  85. class="h-40px w-40px"
  86. preview-teleported
  87. />
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="产品标题" min-width="300" prop="spuName" />
  91. <el-table-column
  92. :formatter="fenToYuanFormat"
  93. label="原价"
  94. min-width="100"
  95. prop="marketPrice"
  96. />
  97. <el-table-column label="原价" min-width="100" prop="marketPrice" />
  98. <el-table-column label="秒杀价" min-width="100" prop="seckillPrice">
  99. <template #default="scope">
  100. {{ formatSeckillPrice(scope.row.products) }}
  101. </template>
  102. </el-table-column>
  103. <el-table-column align="center" label="活动状态" min-width="100" prop="status">
  104. <template #default="scope">
  105. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  106. </template>
  107. </el-table-column>
  108. <el-table-column align="center" label="库存" min-width="80" prop="stock" />
  109. <el-table-column align="center" label="总库存" min-width="80" prop="totalStock" />
  110. <el-table-column
  111. :formatter="dateFormatter"
  112. align="center"
  113. label="创建时间"
  114. prop="createTime"
  115. width="180px"
  116. />
  117. <el-table-column align="center" fixed="right" label="操作" width="150px">
  118. <template #default="scope">
  119. <el-button
  120. v-hasPermi="['promotion:seckill-activity:update']"
  121. link
  122. type="primary"
  123. @click="openForm('update', scope.row.id)"
  124. >
  125. 编辑
  126. </el-button>
  127. <el-button
  128. v-if="scope.row.status === 0"
  129. v-hasPermi="['promotion:seckill-activity:close']"
  130. link
  131. type="danger"
  132. @click="handleClose(scope.row.id)"
  133. >
  134. 关闭
  135. </el-button>
  136. <el-button
  137. v-else
  138. v-hasPermi="['promotion:seckill-activity:delete']"
  139. link
  140. type="danger"
  141. @click="handleDelete(scope.row.id)"
  142. >
  143. 删除
  144. </el-button>
  145. </template>
  146. </el-table-column>
  147. </el-table>
  148. <!-- 分页 -->
  149. <Pagination
  150. v-model:limit="queryParams.pageSize"
  151. v-model:page="queryParams.pageNo"
  152. :total="total"
  153. @pagination="getList"
  154. />
  155. </ContentWrap>
  156. <!-- 表单弹窗:添加/修改 -->
  157. <SeckillActivityForm ref="formRef" @success="getList" />
  158. </template>
  159. <script lang="ts" setup>
  160. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  161. import { dateFormatter, formatDate } from '@/utils/formatTime'
  162. import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
  163. import { SeckillConfigApi } from '@/api/mall/promotion/seckill/seckillConfig'
  164. import SeckillActivityForm from './SeckillActivityForm.vue'
  165. import { fenToYuanFormat } from '@/utils/formatter'
  166. import { fenToYuan } from '@/utils'
  167. defineOptions({ name: 'SeckillActivity' })
  168. const message = useMessage() // 消息弹窗
  169. const { t } = useI18n() // 国际化
  170. const loading = ref(true) // 列表的加载中
  171. const total = ref(0) // 列表的总页数
  172. const list = ref([]) // 列表的数据
  173. const queryParams = reactive({
  174. pageNo: 1,
  175. pageSize: 10,
  176. name: null,
  177. status: null
  178. })
  179. const queryFormRef = ref() // 搜索的表单
  180. const exportLoading = ref(false) // 导出的加载中
  181. /** 查询列表 */
  182. const getList = async () => {
  183. loading.value = true
  184. try {
  185. const data = await SeckillActivityApi.getSeckillActivityPage(queryParams)
  186. list.value = data.list
  187. total.value = data.total
  188. } finally {
  189. loading.value = false
  190. }
  191. }
  192. /** 搜索按钮操作 */
  193. const handleQuery = () => {
  194. queryParams.pageNo = 1
  195. getList()
  196. }
  197. /** 重置按钮操作 */
  198. const resetQuery = () => {
  199. queryFormRef.value.resetFields()
  200. handleQuery()
  201. }
  202. /** 添加/修改操作 */
  203. const formRef = ref()
  204. const openForm = (type: string, id?: number) => {
  205. formRef.value.open(type, id)
  206. }
  207. /** 关闭按钮操作 */
  208. const handleClose = async (id: number) => {
  209. try {
  210. // 关闭的二次确认
  211. await message.confirm('确认关闭该秒杀活动吗?')
  212. // 发起关闭
  213. await SeckillActivityApi.closeSeckillActivity(id)
  214. message.success('关闭成功')
  215. // 刷新列表
  216. await getList()
  217. } catch {}
  218. }
  219. /** 删除按钮操作 */
  220. const handleDelete = async (id: number) => {
  221. try {
  222. // 删除的二次确认
  223. await message.delConfirm()
  224. // 发起删除
  225. await SeckillActivityApi.deleteSeckillActivity(id)
  226. message.success(t('common.delSuccess'))
  227. // 刷新列表
  228. await getList()
  229. } catch {}
  230. }
  231. const configList = ref([]) // 时段配置精简列表
  232. const formatConfigNames = (configId) => {
  233. const config = configList.value.find((item) => item.id === configId)
  234. return config != null ? `${config.name}[${config.startTime} ~ ${config.endTime}]` : ''
  235. }
  236. const formatSeckillPrice = (products) => {
  237. const seckillPrice = Math.min(...products.map((item) => item.seckillPrice))
  238. return `¥${fenToYuan(seckillPrice)}`
  239. }
  240. /** 初始化 **/
  241. onMounted(async () => {
  242. await getList()
  243. // 获得秒杀时间段
  244. configList.value = await SeckillConfigApi.getSimpleSeckillConfigList()
  245. })
  246. </script>