index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <doc-alert title="【营销】优惠劵" url="https://doc.iocoder.cn/mall/promotion-coupon/" />
  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="nickname">
  13. <el-input
  14. v-model="queryParams.nickname"
  15. class="!w-240px"
  16. placeholder="请输入会员昵称"
  17. clearable
  18. @keyup="handleQuery"
  19. />
  20. </el-form-item>
  21. <el-form-item label="领取时间" prop="createTime">
  22. <el-date-picker
  23. v-model="queryParams.createTime"
  24. value-format="YYYY-MM-DD HH:mm:ss"
  25. type="daterange"
  26. start-placeholder="开始日期"
  27. end-placeholder="结束日期"
  28. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  29. class="!w-240px"
  30. />
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button @click="handleQuery"> <Icon icon="ep:search" class="mr-5px" />搜索 </el-button>
  34. <el-button @click="resetQuery"> <Icon icon="ep:refresh" class="mr-5px" />重置 </el-button>
  35. </el-form-item>
  36. </el-form>
  37. </ContentWrap>
  38. <ContentWrap>
  39. <!-- Tab 选项:真正的内容在 Lab -->
  40. <el-tabs v-model="activeTab" type="card" @tab-change="onTabChange">
  41. <el-tab-pane
  42. v-for="tab in statusTabs"
  43. :key="tab.value"
  44. :label="tab.label"
  45. :name="tab.value"
  46. />
  47. </el-tabs>
  48. <!-- 列表 -->
  49. <el-table v-loading="loading" :data="list">
  50. <el-table-column label="会员昵称" align="center" min-width="100" prop="nickname" />
  51. <el-table-column label="优惠券名称" align="center" min-width="140" prop="name" />
  52. <el-table-column label="类型" align="center" prop="discountType">
  53. <template #default="scope">
  54. <dict-tag :type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE" :value="scope.row.productScope" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="优惠" min-width="100" prop="discount">
  58. <template #default="scope">
  59. <dict-tag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="scope.row.discountType" />
  60. {{ discountFormat(scope.row) }}
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="领取方式" align="center" prop="takeType">
  64. <template #default="scope">
  65. <dict-tag :type="DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE" :value="scope.row.takeType" />
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="状态" align="center" prop="status">
  69. <template #default="scope">
  70. <dict-tag :type="DICT_TYPE.PROMOTION_COUPON_STATUS" :value="scope.row.status" />
  71. </template>
  72. </el-table-column>
  73. <el-table-column
  74. label="领取时间"
  75. align="center"
  76. prop="createTime"
  77. :formatter="dateFormatter"
  78. width="180"
  79. />
  80. <el-table-column
  81. label="使用时间"
  82. align="center"
  83. prop="useTime"
  84. :formatter="dateFormatter"
  85. width="180"
  86. />
  87. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  88. <template #default="scope">
  89. <el-button
  90. v-hasPermi="['promotion:coupon:delete']"
  91. type="danger"
  92. link
  93. @click="handleDelete(scope.row.id)"
  94. >
  95. 回收
  96. </el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <!-- 分页 -->
  101. <Pagination
  102. v-model:limit="queryParams.pageSize"
  103. v-model:page="queryParams.pageNo"
  104. :total="total"
  105. @pagination="getList"
  106. />
  107. </ContentWrap>
  108. </template>
  109. <script setup lang="ts" name="PromotionCoupon">
  110. import { deleteCoupon, getCouponPage } from '@/api/mall/promotion/coupon/coupon'
  111. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  112. import { dateFormatter } from '@/utils/formatTime'
  113. import { discountFormat } from '@/views/mall/promotion/coupon/formatter'
  114. defineOptions({ name: 'PromotionCoupon' })
  115. const message = useMessage() // 消息弹窗
  116. const loading = ref(true) // 列表的加载中
  117. const total = ref(0) // 列表的总页数
  118. const list = ref([]) // 字典表格数据
  119. // 查询参数
  120. const queryParams = reactive({
  121. pageNo: 1,
  122. pageSize: 10,
  123. createTime: [],
  124. status: undefined,
  125. nickname: undefined
  126. })
  127. const queryFormRef = ref() // 搜索的表单
  128. const activeTab = ref('all') // Tab 筛选
  129. const statusTabs = reactive([
  130. {
  131. label: '全部',
  132. value: 'all'
  133. }
  134. ])
  135. /** 查询列表 */
  136. const getList = async () => {
  137. loading.value = true
  138. // 执行查询
  139. try {
  140. const data = await getCouponPage(queryParams)
  141. list.value = data.list
  142. total.value = data.total
  143. } finally {
  144. loading.value = false
  145. }
  146. }
  147. /** 搜索按钮操作 */
  148. const handleQuery = () => {
  149. queryParams.pageNo = 1
  150. getList()
  151. }
  152. /** 重置按钮操作 */
  153. const resetQuery = () => {
  154. queryFormRef.value?.resetFields()
  155. handleQuery()
  156. }
  157. /** 删除按钮操作 */
  158. const handleDelete = async (id: number) => {
  159. try {
  160. // 二次确认
  161. await message.confirm(
  162. '回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?'
  163. )
  164. // 发起删除
  165. await deleteCoupon(id)
  166. message.notifySuccess('回收成功')
  167. // 重新加载列表
  168. await getList()
  169. } catch {}
  170. }
  171. /** tab 切换 */
  172. const onTabChange = (tabName) => {
  173. queryParams.status = tabName === 'all' ? undefined : tabName
  174. getList()
  175. }
  176. /** 初始化 **/
  177. onMounted(() => {
  178. getList()
  179. // 设置 statuses 过滤
  180. for (const dict of getIntDictOptions(DICT_TYPE.PROMOTION_COUPON_STATUS)) {
  181. statusTabs.push({
  182. label: dict.label,
  183. value: dict.value as string
  184. })
  185. }
  186. })
  187. </script>