index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <doc-alert title="【营销】拼团活动" url="https://doc.iocoder.cn/mall/promotion-combination/" />
  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:combination-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 label="活动时间" min-width="210">
  63. <template #default="scope">
  64. {{ formatDate(scope.row.startTime, 'YYYY-MM-DD') }}
  65. ~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="商品图片" min-width="80" prop="spuName">
  69. <template #default="scope">
  70. <el-image
  71. :preview-src-list="[scope.row.picUrl]"
  72. :src="scope.row.picUrl"
  73. class="h-40px w-40px"
  74. preview-teleported
  75. />
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="商品标题" min-width="300" prop="spuName" />
  79. <el-table-column
  80. :formatter="fenToYuanFormat"
  81. label="原价"
  82. min-width="100"
  83. prop="marketPrice"
  84. />
  85. <el-table-column label="拼团价" min-width="100" prop="seckillPrice">
  86. <template #default="scope">
  87. {{ formatCombinationPrice(scope.row.products) }}
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="开团组数" min-width="100" prop="groupCount" />
  91. <el-table-column label="成团组数" min-width="100" prop="groupSuccessCount" />
  92. <el-table-column label="购买次数" min-width="100" prop="recordCount" />
  93. <el-table-column align="center" label="活动状态" min-width="100" prop="status">
  94. <template #default="scope">
  95. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. :formatter="dateFormatter"
  100. align="center"
  101. label="创建时间"
  102. prop="createTime"
  103. width="180px"
  104. />
  105. <el-table-column align="center" fixed="right" label="操作" width="150px">
  106. <template #default="scope">
  107. <el-button
  108. v-hasPermi="['promotion:combination-activity:update']"
  109. link
  110. type="primary"
  111. @click="openForm('update', scope.row.id)"
  112. >
  113. 编辑
  114. </el-button>
  115. <el-button
  116. v-if="scope.row.status === 0"
  117. v-hasPermi="['promotion:combination-activity:close']"
  118. link
  119. type="danger"
  120. @click="handleClose(scope.row.id)"
  121. >
  122. 关闭
  123. </el-button>
  124. <el-button
  125. v-else
  126. v-hasPermi="['promotion:combination-activity:delete']"
  127. link
  128. type="danger"
  129. @click="handleDelete(scope.row.id)"
  130. >
  131. 删除
  132. </el-button>
  133. </template>
  134. </el-table-column>
  135. </el-table>
  136. <!-- 分页 -->
  137. <Pagination
  138. v-model:limit="queryParams.pageSize"
  139. v-model:page="queryParams.pageNo"
  140. :total="total"
  141. @pagination="getList"
  142. />
  143. </ContentWrap>
  144. <!-- 表单弹窗:添加/修改 -->
  145. <CombinationActivityForm ref="formRef" @success="getList" />
  146. </template>
  147. <script lang="ts" setup>
  148. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  149. import { dateFormatter, formatDate } from '@/utils/formatTime'
  150. import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
  151. import CombinationActivityForm from './CombinationActivityForm.vue'
  152. import { fenToYuanFormat } from '@/utils/formatter'
  153. import { fenToYuan } from '@/utils'
  154. defineOptions({ name: 'PromotionBargainActivity' })
  155. const message = useMessage() // 消息弹窗
  156. const { t } = useI18n() // 国际化
  157. const loading = ref(true) // 列表的加载中
  158. const total = ref(0) // 列表的总页数
  159. const list = ref([]) // 列表的数据
  160. const queryParams = reactive({
  161. pageNo: 1,
  162. pageSize: 10,
  163. name: null,
  164. status: null
  165. })
  166. const queryFormRef = ref() // 搜索的表单
  167. /** 查询列表 */
  168. const getList = async () => {
  169. loading.value = true
  170. try {
  171. const data = await CombinationActivityApi.getCombinationActivityPage(queryParams)
  172. list.value = data.list
  173. total.value = data.total
  174. } finally {
  175. loading.value = false
  176. }
  177. }
  178. /** 搜索按钮操作 */
  179. const handleQuery = () => {
  180. queryParams.pageNo = 1
  181. getList()
  182. }
  183. /** 重置按钮操作 */
  184. const resetQuery = () => {
  185. queryFormRef.value.resetFields()
  186. handleQuery()
  187. }
  188. /** 添加/修改操作 */
  189. const formRef = ref()
  190. const openForm = (type: string, id?: number) => {
  191. formRef.value.open(type, id)
  192. }
  193. /** 关闭按钮操作 */
  194. const handleClose = async (id: number) => {
  195. try {
  196. // 关闭的二次确认
  197. await message.confirm('确认关闭该拼团活动吗?')
  198. // 发起关闭
  199. await CombinationActivityApi.closeCombinationActivity(id)
  200. message.success('关闭成功')
  201. // 刷新列表
  202. await getList()
  203. } catch {}
  204. }
  205. /** 删除按钮操作 */
  206. const handleDelete = async (id: number) => {
  207. try {
  208. // 删除的二次确认
  209. await message.delConfirm()
  210. // 发起删除
  211. await CombinationActivityApi.deleteCombinationActivity(id)
  212. message.success(t('common.delSuccess'))
  213. // 刷新列表
  214. await getList()
  215. } catch {}
  216. }
  217. const formatCombinationPrice = (products) => {
  218. const combinationPrice = Math.min(...products.map((item) => item.combinationPrice))
  219. return `¥${fenToYuan(combinationPrice)}`
  220. }
  221. /** 初始化 **/
  222. onMounted(async () => {
  223. await getList()
  224. })
  225. </script>