index.vue 7.1 KB

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