index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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>
  36. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  37. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  38. <el-button
  39. type="primary"
  40. plain
  41. @click="openForm('create')"
  42. v-hasPermi="['promotion:combination-activity:create']"
  43. >
  44. <Icon icon="ep:plus" class="mr-5px" /> 新增
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. </ContentWrap>
  49. <!-- 列表 -->
  50. <ContentWrap>
  51. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  52. <el-table-column label="活动编号" prop="id" min-width="80" />
  53. <el-table-column label="活动名称" prop="name" min-width="140" />
  54. <el-table-column label="活动时间" min-width="210">
  55. <template #default="scope">
  56. {{ formatDate(scope.row.startTime, 'YYYY-MM-DD') }}
  57. ~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="商品图片" prop="spuName" min-width="80">
  61. <template #default="scope">
  62. <el-image
  63. :src="scope.row.picUrl"
  64. class="h-40px w-40px"
  65. :preview-src-list="[scope.row.picUrl]"
  66. preview-teleported
  67. />
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="商品标题" prop="spuName" min-width="300" />
  71. <el-table-column
  72. label="原价"
  73. prop="combinationFirstPrice"
  74. min-width="100"
  75. :formatter="fenToYuanFormat"
  76. />
  77. <el-table-column
  78. label="拼团价"
  79. prop="combinationMinPrice"
  80. min-width="100"
  81. :formatter="fenToYuanFormat"
  82. />
  83. <el-table-column label="拼团人数" prop="recordUserCount" min-width="100" />
  84. <el-table-column label="参与人数" prop="recordSuccessUserCount" min-width="110" />
  85. <el-table-column label="成团人数" prop="helpUserCount" min-width="100" />
  86. <el-table-column label="活动状态" align="center" prop="status" min-width="100">
  87. <template #default="scope">
  88. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="库存" align="center" prop="stock" min-width="80" />
  92. <el-table-column label="总库存" align="center" prop="totalStock" min-width="80" />
  93. <el-table-column
  94. label="创建时间"
  95. align="center"
  96. prop="createTime"
  97. :formatter="dateFormatter"
  98. width="180px"
  99. />
  100. <el-table-column label="操作" align="center" width="150px" fixed="right">
  101. <template #default="scope">
  102. <el-button
  103. link
  104. type="primary"
  105. @click="openForm('update', scope.row.id)"
  106. v-hasPermi="['promotion:combination-activity:update']"
  107. >
  108. 编辑
  109. </el-button>
  110. <el-button
  111. link
  112. type="danger"
  113. @click="handleClose(scope.row.id)"
  114. v-if="scope.row.status === 0"
  115. v-hasPermi="['promotion:combination-activity:close']"
  116. >
  117. 关闭
  118. </el-button>
  119. <el-button
  120. link
  121. type="danger"
  122. @click="handleDelete(scope.row.id)"
  123. v-else
  124. v-hasPermi="['promotion:combination-activity:delete']"
  125. >
  126. 删除
  127. </el-button>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <!-- 分页 -->
  132. <Pagination
  133. :total="total"
  134. v-model:page="queryParams.pageNo"
  135. v-model:limit="queryParams.pageSize"
  136. @pagination="getList"
  137. />
  138. </ContentWrap>
  139. <!-- 表单弹窗:添加/修改 -->
  140. <CombinationActivityForm ref="formRef" @success="getList" />
  141. </template>
  142. <script setup lang="ts">
  143. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  144. import { dateFormatter } from '@/utils/formatTime'
  145. import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
  146. import CombinationActivityForm from './CombinationActivityForm.vue'
  147. import { formatDate } from '@/utils/formatTime'
  148. import { fenToYuanFormat } from '@/utils/formatter'
  149. defineOptions({ name: 'PromotionBargainActivity' })
  150. const message = useMessage() // 消息弹窗
  151. const { t } = useI18n() // 国际化
  152. const loading = ref(true) // 列表的加载中
  153. const total = ref(0) // 列表的总页数
  154. const list = ref([]) // 列表的数据
  155. const queryParams = reactive({
  156. pageNo: 1,
  157. pageSize: 10,
  158. name: null,
  159. status: null
  160. })
  161. const queryFormRef = ref() // 搜索的表单
  162. const exportLoading = ref(false) // 导出的加载中
  163. /** 查询列表 */
  164. const getList = async () => {
  165. loading.value = true
  166. try {
  167. const data = await CombinationActivityApi.getCombinationActivityPage(queryParams)
  168. list.value = data.list
  169. total.value = data.total
  170. } finally {
  171. loading.value = false
  172. }
  173. }
  174. /** 搜索按钮操作 */
  175. const handleQuery = () => {
  176. queryParams.pageNo = 1
  177. getList()
  178. }
  179. /** 重置按钮操作 */
  180. const resetQuery = () => {
  181. queryFormRef.value.resetFields()
  182. handleQuery()
  183. }
  184. /** 添加/修改操作 */
  185. const formRef = ref()
  186. const openForm = (type: string, id?: number) => {
  187. formRef.value.open(type, id)
  188. }
  189. // TODO 芋艿:这里要改下
  190. /** 关闭按钮操作 */
  191. const handleClose = async (id: number) => {
  192. try {
  193. // 关闭的二次确认
  194. await message.confirm('确认关闭该秒杀活动吗?')
  195. // 发起关闭
  196. await CombinationActivityApi.closeCombinationActivity(id)
  197. message.success('关闭成功')
  198. // 刷新列表
  199. await getList()
  200. } catch {}
  201. }
  202. /** 删除按钮操作 */
  203. const handleDelete = async (id: number) => {
  204. try {
  205. // 删除的二次确认
  206. await message.delConfirm()
  207. // 发起删除
  208. await CombinationActivityApi.deleteCombinationActivity(id)
  209. message.success(t('common.delSuccess'))
  210. // 刷新列表
  211. await getList()
  212. } catch {}
  213. }
  214. /** 初始化 **/
  215. onMounted(async () => {
  216. await getList()
  217. })
  218. </script>