index.vue 7.0 KB

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