index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <doc-alert title="【营销】满减送" url="https://doc.iocoder.cn/mall/promotion-record/" />
  3. <!-- 搜索工作栏 -->
  4. <ContentWrap>
  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 label="活动时间" prop="createTime">
  37. <el-date-picker
  38. v-model="queryParams.createTime"
  39. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  40. class="!w-240px"
  41. end-placeholder="活动结束日期"
  42. start-placeholder="活动开始日期"
  43. type="daterange"
  44. value-format="YYYY-MM-DD HH:mm:ss"
  45. />
  46. </el-form-item>
  47. <el-form-item>
  48. <el-button @click="handleQuery">
  49. <Icon class="mr-5px" icon="ep:search" />
  50. 搜索
  51. </el-button>
  52. <el-button @click="resetQuery">
  53. <Icon class="mr-5px" icon="ep:refresh" />
  54. 重置
  55. </el-button>
  56. <el-button
  57. v-hasPermi="['promotion:reward-activity:create']"
  58. plain
  59. type="primary"
  60. @click="openForm('create')"
  61. >
  62. <Icon class="mr-5px" icon="ep:plus" />
  63. 新增
  64. </el-button>
  65. </el-form-item>
  66. </el-form>
  67. </ContentWrap>
  68. <!-- 列表 -->
  69. <ContentWrap>
  70. <el-table v-loading="loading" :data="list" default-expand-all row-key="id">
  71. <el-table-column label="活动名称" prop="name" />
  72. <el-table-column label="活动范围" prop="productScope" >
  73. <template #default="scope">
  74. <dict-tag :type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE" :value="scope.row.productScope" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column
  78. :formatter="dateFormatter"
  79. align="center"
  80. label="活动开始时间"
  81. prop="startTime"
  82. />
  83. <el-table-column
  84. :formatter="dateFormatter"
  85. align="center"
  86. label="活动结束时间"
  87. prop="endTime"
  88. />
  89. <el-table-column align="center" label="状态" prop="status">
  90. <template #default="scope">
  91. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  92. </template>
  93. </el-table-column>
  94. <el-table-column
  95. :formatter="dateFormatter"
  96. align="center"
  97. label="创建时间"
  98. prop="createTime"
  99. width="180"
  100. />
  101. <el-table-column align="center" label="操作">
  102. <template #default="scope">
  103. <el-button
  104. v-hasPermi="['promotion:reward-activity:update']"
  105. link
  106. type="primary"
  107. @click="openForm('update', scope.row.id)"
  108. >
  109. 编辑
  110. </el-button>
  111. <el-button
  112. v-if="scope.row.status === 0"
  113. v-hasPermi="['promotion:reward-activity:close']"
  114. link
  115. type="danger"
  116. @click="handleClose(scope.row.id)"
  117. >
  118. 关闭
  119. </el-button>
  120. <el-button
  121. v-hasPermi="['promotion:reward-activity:delete']"
  122. link
  123. type="danger"
  124. @click="handleDelete(scope.row.id)"
  125. >
  126. 删除
  127. </el-button>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <!-- 分页 -->
  132. <Pagination
  133. v-model:limit="queryParams.pageSize"
  134. v-model:page="queryParams.pageNo"
  135. :total="total"
  136. @pagination="getList"
  137. />
  138. </ContentWrap>
  139. <!-- 表单弹窗:添加/修改 -->
  140. <RewardForm ref="formRef" @success="getList" />
  141. </template>
  142. <script lang="ts" setup>
  143. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  144. import { dateFormatter } from '@/utils/formatTime'
  145. import * as RewardActivityApi from '@/api/mall/promotion/reward/rewardActivity'
  146. import RewardForm from './RewardForm.vue'
  147. defineOptions({ name: 'PromotionRewardActivity' })
  148. const message = useMessage() // 消息弹窗
  149. const { t } = useI18n() // 国际化
  150. const loading = ref(true) // 列表的加载中
  151. const total = ref(0) // 列表的总页数
  152. const list = ref<any[]>([]) // 列表的数据
  153. const queryParams = reactive({
  154. pageNo: 1,
  155. pageSize: 10,
  156. name: undefined,
  157. status: undefined,
  158. createTime: []
  159. })
  160. const queryFormRef = ref() // 搜索的表单
  161. /** 查询列表 */
  162. const getList = async () => {
  163. loading.value = true
  164. try {
  165. const data = await RewardActivityApi.getRewardActivityPage(queryParams)
  166. list.value = data.list
  167. total.value = data.total
  168. } finally {
  169. loading.value = false
  170. }
  171. }
  172. /** 搜索按钮操作 */
  173. const handleQuery = () => {
  174. getList()
  175. }
  176. /** 重置按钮操作 */
  177. const resetQuery = () => {
  178. queryFormRef.value.resetFields()
  179. handleQuery()
  180. }
  181. /** 添加/修改操作 */
  182. const formRef = ref<InstanceType<typeof RewardForm>>()
  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 RewardActivityApi.closeRewardActivity(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 RewardActivityApi.deleteRewardActivity(id)
  205. message.success(t('common.delSuccess'))
  206. // 刷新列表
  207. await getList()
  208. } catch {}
  209. }
  210. /** 初始化 **/
  211. onMounted(() => {
  212. getList()
  213. })
  214. </script>